[Bug #779] Fix bug

The tree was still listening to the previous TreeModel which caused
that it didn't receive the new updates to the tree.

FEA: ItEr68S04BugFixing
This commit is contained in:
Óscar González Fernández 2011-01-10 17:26:10 +01:00
parent 13a238d00f
commit dea21997f6
2 changed files with 32 additions and 8 deletions

View file

@ -122,6 +122,8 @@ public class OrderTemplatesController extends GenericForwardComposer implements
}
private void showEditWindow() {
// openTemplateTree is not called if it's the first tab shown
bindTemplatesTreeWithModel();
bindAdvancesComponentWithCurrentTemplate();
bindMaterialsControllerWithCurrentTemplate();
bindCriterionRequirementControllerWithCurrentTemplate();
@ -219,6 +221,7 @@ public class OrderTemplatesController extends GenericForwardComposer implements
if (isAllValid()) {
model.confirmSave();
model.initEdit(getTemplate());
bindTemplatesTreeWithModel();
messagesForUser.showMessage(Level.INFO, _("Template saved"));
}
}
@ -273,25 +276,40 @@ public class OrderTemplatesController extends GenericForwardComposer implements
breadcrumbs.appendChild(new Label(_("Project Templates")));
}
/**
* Ensures that the tree component is correctly initialized. It's called
* from templates.zul page when selecting the tab.
* <p>
* Please not that this method is not called if the first tab shown is the
* templates tree tab.
* </p>
*/
public void openTemplateTree() {
if (treeComponent == null) {
final TemplatesTreeController treeController = new TemplatesTreeController(
model, this);
treeComponent = (TreeComponent) editWindow.getFellow("orderElementTree");
treeComponent.useController(treeController);
controlSelectionWithOnClick(getTreeFrom(treeComponent));
treeController.setReadOnly(false);
}
final Tree tree = (Tree) treeComponent.getFellowIfAny("tree");
if (tree.getModel() == null) {
setTreeRenderer(treeComponent);
reloadTree(treeComponent);
}
bindTemplatesTreeWithModel();
}
private void reloadTree(TreeComponent orderElementsTree) {
final Tree tree = (Tree) orderElementsTree.getFellowIfAny("tree");
tree.setModel(orderElementsTree.getController().getTreeModel());
private void bindTemplatesTreeWithModel() {
if (treeComponent == null) {
// if the tree is not initialized yet no bind has to be done
return;
}
treeComponent.getController().bindModelIfNeeded();
}
private Tree getTreeFrom(TreeComponent treeComponent) {
return (Tree) treeComponent.getFellowIfAny("tree");
}
private void controlSelectionWithOnClick(final Tree tree) {
tree.addEventListener(Events.ON_SELECT, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {

View file

@ -108,6 +108,12 @@ public abstract class TreeController<T extends ITreeNode<T>> extends
return (getModel() != null) ? getModel().asTree() : null;
}
public void bindModelIfNeeded() {
if (tree.getModel() != getTreeModel()) {
tree.setModel(getTreeModel());
}
}
protected abstract EntitiesTree<T> getModel();
public void unindent() {