X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.nattable%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fnattable%2FTreeNode.java;h=30a37e3292205da607911c2d757528bf555d47f5;hp=941c6f319be56e491909cc35472e7173a5040ccf;hb=145a2884933f2ffdd48d6835729e58f1152d274e;hpb=bd5bc6e45f700e755b61bd112631796631330ecb diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/TreeNode.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/TreeNode.java index 941c6f319..30a37e329 100644 --- a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/TreeNode.java +++ b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/TreeNode.java @@ -38,6 +38,7 @@ public class TreeNode implements IAdaptable { TreeNode parent; List children = new ArrayList(); boolean expanded; + boolean autoExpanded = false; public TreeNode(NodeContext context, GeViewerContext explorerContext) { this.context = context; @@ -47,13 +48,13 @@ public class TreeNode implements IAdaptable { explorerContext.getContextToNodeMap().add(context, this); } - int getDepth() { + public int getDepth() { if (parent == null) return 0; return parent.getDepth() + 1; } - int listIndex; + int listIndex = -1; public int getListIndex() { return listIndex; @@ -79,6 +80,27 @@ public class TreeNode implements IAdaptable { return expanded; } + public boolean isHidden() { + TreeNode n = parent; + while (n != null) { + if (!n.isExpanded()) + return true; + n = n.getParent(); + } + return false; + } + + public TreeNode getCollapsedAncestor() { + TreeNode collapsed = null; + TreeNode n = parent; + while (n != null) { + if (!n.isExpanded()) + collapsed = n; + n = n.getParent(); + } + return collapsed; + } + public NodeContext getContext() { return context; } @@ -92,9 +114,8 @@ public class TreeNode implements IAdaptable { Map runtimeLabels; public String getValueString(int column) { - if (column == 0) { + if (column == 0) initData(); - } if (labeler != null) { String key = explorerContext.getGe().getColumns()[column].getKey(); String s = null; @@ -199,7 +220,7 @@ public class TreeNode implements IAdaptable { } - private void initData() { + public void initData() { labeler = manager.query(context, BuiltinKeys.SELECTED_LABELER); imager = manager.query(context, BuiltinKeys.SELECTED_IMAGER); labelDecorators = manager.query(context, BuiltinKeys.LABEL_DECORATORS); @@ -319,7 +340,13 @@ public class TreeNode implements IAdaptable { } for (int i = oldCount; i < childContexts.length; i++) { - addChild(childContexts[i], explorerContext); + Integer oldIndex = indexes.getLeft(i); + if (oldIndex == null) { + addChild(childContexts[i], explorerContext); + } else { + TreeNode n = oldChildren.get(oldIndex); + children.add(n); + } } } else { for (int i = 0; i < childContexts.length; i++) { @@ -363,5 +390,10 @@ public class TreeNode implements IAdaptable { return context.getAdapter(adapter); } + + @Override + public String toString() { + return "TreeNode: " + listIndex + " " + (expanded ? "(+)" : "(-)") + " " + context ; + } }