[Bug #688] Fix bug 'Not unique in the new ID space: expandAllButton'

FEA: ItEr62S05BugFixing
This commit is contained in:
Diego Pino Garcia 2010-10-24 18:17:48 +02:00
parent 2d102d234f
commit dd30fff6e8
2 changed files with 44 additions and 19 deletions

View file

@ -23,6 +23,8 @@ package org.zkoss.ganttz.util;
import java.util.ArrayList;
import java.util.List;
import org.zkoss.zk.ui.Component;
/**
* Utility methods to find components
* @author Óscar González Fernández <ogonzalez@igalia.com>
@ -43,4 +45,14 @@ public class ComponentsFinder {
return result;
}
public static Component findById(String id,
List<? extends Component> children) {
for (Component child : children) {
if (child.getId().equals(id)) {
return child;
}
}
return null;
}
}

View file

@ -55,6 +55,7 @@ import org.navalplanner.web.orders.assigntemplates.TemplateFinderPopup.IOnResult
import org.navalplanner.web.templates.IOrderTemplatesControllerEntryPoints;
import org.navalplanner.web.tree.TreeController;
import org.zkoss.ganttz.IPredicate;
import org.zkoss.ganttz.util.ComponentsFinder;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.WrongValueException;
@ -234,25 +235,7 @@ public class OrderElementTreeController extends TreeController<OrderElement> {
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
orderElementFilter.getChildren().clear();
// Add the expand/collapse button to the tool bar
final Button expandAllButton = new Button();
expandAllButton.setId("expandAllButton");
expandAllButton.setClass("planner-command");
expandAllButton.setTooltiptext(_("Expand/Collapse all"));
expandAllButton.setImage("/common/img/ico_expand.png");
expandAllButton.addEventListener("onClick", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
if (expandAllButton.getSclass().equals("planner-command")) {
expandAll();
expandAllButton.setSclass("planner-command clicked");
} else {
collapseAll();
expandAllButton.setSclass("planner-command");
}
}
});
orderElementFilter.getParent().getChildren().add(expandAllButton);
appendExpandCollapseButton();
// Configuration of the order elements filter
Component filterComponent = Executions.createComponents(
@ -272,6 +255,36 @@ public class OrderElementTreeController extends TreeController<OrderElement> {
.getFellow("templateFinderPopupAtTree");
}
private void appendExpandCollapseButton() {
List<Component> children = orderElementFilter.getParent().getChildren();
// Is already added?
Button button = (Button) ComponentsFinder.findById("expandAllButton", children);
if (button != null) {
return;
}
// Append expand/collapse button
final Button expandAllButton = new Button();
expandAllButton.setId("expandAllButton");
expandAllButton.setClass("planner-command");
expandAllButton.setTooltiptext(_("Expand/Collapse all"));
expandAllButton.setImage("/common/img/ico_expand.png");
expandAllButton.addEventListener("onClick", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
if (expandAllButton.getSclass().equals("planner-command")) {
expandAll();
expandAllButton.setSclass("planner-command clicked");
} else {
collapseAll();
expandAllButton.setSclass("planner-command");
}
}
});
children.add(expandAllButton);
}
public void expandAll() {
Set<Treeitem> childrenSet = new HashSet<Treeitem>();
Treechildren children = tree.getTreechildren();