this.paintableId = uidl.getId();
this.immediate = uidl.hasAttribute("immediate");
-
+
disabled = uidl.getBooleanAttribute("disabled");
isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect");
TreeNode rootNode = (TreeNode) keyToNode.get(uidl
.getStringAttribute("rootKey"));
if (rootNode != null) {
+ if (!rootNode.getState()) {
+ // expanding node happened server side
+ rootNode.setState(true, false);
+ }
rootNode.renderChildNodes(uidl.getChildIterator());
}
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
- if(disabled)
+ if (disabled)
return;
Element target = DOM.eventGetTarget(event);
if (DOM.compare(target, nodeCaptionSpan)) {
}
private void toggleState() {
- this.setState(!getState());
+ this.setState(!getState(), true);
}
protected void constructDom() {
if (uidl.getTag().equals("node")) {
if (uidl.getChidlCount() == 0) {
- // TODO "loading indicator"
+ childNodeContainer.setVisible(false);
} else {
renderChildNodes(uidl.getChildIterator());
childrenLoaded = true;
}
if (uidl.getBooleanAttribute("expanded") && !getState()) {
- open = true;
+ setState(true, false);
}
if (uidl.getBooleanAttribute("selected")) {
}
}
- private void setState(boolean b) {
- if (open == b)
+ private void setState(boolean state, boolean notifyServer) {
+ if (open == state)
return;
- if (b) {
- if (!childrenLoaded) {
- ITree.this.client.updateVariable(paintableId, "expand",
- new String[] { key }, true);
+ if (state) {
+ if (!childrenLoaded && notifyServer) {
+ client.updateVariable(paintableId, "requestChildTree",
+ true, false);
}
+ if (notifyServer)
+ client.updateVariable(paintableId, "expand",
+ new String[] { key }, true);
addStyleName(CLASSNAME + "-expanded");
childNodeContainer.setVisible(true);
} else {
removeStyleName(CLASSNAME + "-expanded");
childNodeContainer.setVisible(false);
- // TODO notify server
+ if (notifyServer)
+ client.updateVariable(paintableId, "collapse",
+ new String[] { key }, true);
}
- open = b;
+ open = state;
}
private boolean getState() {
private void renderChildNodes(Iterator i) {
childNodeContainer.clear();
+ childNodeContainer.setVisible(true);
while (i.hasNext()) {
UIDL childUidl = (UIDL) i.next();
// actions are in bit weird place, don't mix them with children,
* @return True iff the expand operation succeeded
*/
public boolean expandItem(Object itemId) {
+ return expandItem(itemId, true);
+ }
+
+ /**
+ * Expands an item.
+ *
+ * @param itemId
+ * the item id.
+ * @param sendChildTree
+ * flag to indicate if client needs subtree or not (may be cached)
+ * @return True iff the expand operation succeeded
+ */
+ private boolean expandItem(Object itemId, boolean sendChildTree) {
// Succeeds if the node is already expanded
if (isExpanded(itemId)) {
this.expandedItemId = itemId;
if (this.initialPaint) {
requestRepaint();
- } else {
+ } else if(sendChildTree) {
requestPartialRepaint();
}
fireExpandEvent(itemId);
// Expands recursively
while (!todo.isEmpty()) {
Object id = todo.pop();
- if (areChildrenAllowed(id) && !expandItem(id)) {
+ if (areChildrenAllowed(id) && !expandItem(id, false)) {
result = false;
}
if (hasChildren(id)) {
todo.addAll(getChildren(id));
}
}
-
+ requestRepaint();
return result;
}
// Expands the nodes
if (variables.containsKey("expand")) {
+ boolean sendChildTree = false;
+ if(variables.containsKey("requestChildTree")) {
+ sendChildTree = true;
+ }
String[] keys = (String[]) variables.get("expand");
for (int i = 0; i < keys.length; i++) {
Object id = this.itemIdMapper.get(keys[i]);
if (id != null) {
- expandItem(id);
+ expandItem(id, sendChildTree);
}
}
}