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%2FGETreeRowModel.java;h=241fdfb420056c02b908c25d4aeeef94ed3ac6cb;hp=762b47ce008ab29f1e96d8ed520ba402d0e685d5;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/GETreeRowModel.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/GETreeRowModel.java index 762b47ce0..241fdfb42 100644 --- a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/GETreeRowModel.java +++ b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/GETreeRowModel.java @@ -1,243 +1,243 @@ -package org.simantics.browsing.ui.nattable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; - -import org.eclipse.nebula.widgets.nattable.tree.ITreeData; -import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel; -import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModelListener; - -import it.unimi.dsi.fastutil.ints.IntOpenHashSet; - -/** - * ITreeRowModel that does not automatically expand all child nodes (as TreeRowModel does). - * - * @author Marko Luukkainen - * - * @param - */ -public class GETreeRowModel implements ITreeRowModel{ - //private final HashSet parentIndexes = new HashSet(); - //private final TIntHashSet parentIndexes = new TIntHashSet(1000, 0.8f); - private final IntOpenHashSet expandedIndexes = new IntOpenHashSet(); - - private final Collection listeners = new HashSet(); - - private final ITreeData treeData; - - public GETreeRowModel(ITreeData treeData) { - this.treeData = treeData; - } - - public void registerRowGroupModelListener(ITreeRowModelListener listener) { - this.listeners.add(listener); - } - - public void notifyListeners() { - for (ITreeRowModelListener listener : this.listeners) { - listener.treeRowModelChanged(); - } - } - - public int depth(int index) { - return this.treeData.getDepthOfData(this.treeData.getDataAtIndex(index)); - } - - public boolean isLeaf(int index) { - return !hasChildren(index); - } - - public String getObjectAtIndexAndDepth(int index, int depth) { - return this.treeData.formatDataForDepth(depth,this.treeData.getDataAtIndex(index)); - } - - public boolean hasChildren(int index) { - return this.treeData.hasChildren(this.treeData.getDataAtIndex(index)); - } - - public boolean isCollapsed(int index) { - return !this.expandedIndexes.contains(index); - } - - public void clear() { - this.expandedIndexes.clear(); - } - - @Override - public boolean isCollapsible(int index) { - return hasChildren(index); - } - - @Override - public List collapse(int index) { - this.expandedIndexes.remove(index); - notifyListeners(); - List list = getChildIndexes(index); - //this.parentIndexes.addAll(list); - return list; - } - - - - @Override - public List expand(int index) { - this.expandedIndexes.add(index); - notifyListeners(); - List children = getExpandedChildIndexes(index); - return children; - } - - @Override - public List collapseAll() { - return null; - } - - - @Override - public List expandToLevel(int level) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List expandToLevel(T object, int level) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List expandAll() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List expandToLevel(int parentIndex, int level) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getChildren(int parentIndex) { - T t = treeData.getDataAtIndex(parentIndex); - return treeData.getChildren(t,true); - } - - @Override - public List getDirectChildren(int parentIndex) { - return treeData.getChildren(parentIndex); - } - - - @Override - public List collapse(T object) { - int index = treeData.indexOf(object); - return collapse(index); - } - - @Override - public List expand(T object) { - int index = treeData.indexOf(object); - return expand(index); - } - - @Override - public boolean isCollapsed(T object) { - int index = treeData.indexOf(object); - return isCollapsed(index); - } - - - @SuppressWarnings("unchecked") - public List getChildIndexes(int parentIndex) { - List result = new ArrayList(); - T t = this.treeData.getDataAtIndex(parentIndex); - if (t == null) - return Collections.EMPTY_LIST; - List children = this.treeData.getChildren(t); - for (T child : children) { - int index = this.treeData.indexOf(child); - if (index >= 0) { - result.add(index); - result.addAll(getChildIndexes(index)); - } else { - result.addAll(getChildIndexes(child)); - } - } - return result; - } - - public List getChildIndexes(T t) { - List result = new ArrayList(); - List children = this.treeData.getChildren(t); - for (T child : children) { - int index = this.treeData.indexOf(child); - if (index >= 0) { - result.add(index); - result.addAll(getChildIndexes(index)); - } else { - result.addAll(getChildIndexes(child)); - } - } - return result; - } - - @SuppressWarnings("unchecked") - public List getExpandedChildIndexes(int parentIndex) { - List result = new ArrayList(); - T t = this.treeData.getDataAtIndex(parentIndex); - if (t == null) - return Collections.EMPTY_LIST; - List children = this.treeData.getChildren(t); - for (T child : children) { - int index = this.treeData.indexOf(child); - if (index >= 0) { - result.add(index); - if (expandedIndexes.contains(index)) - result.addAll(getExpandedChildIndexes(index)); - } else { - result.addAll(getExpandedChildIndexes(child)); - } - } - return result; - } - - public List getExpandedChildIndexes(T t) { - List result = new ArrayList(); - List children = this.treeData.getChildren(t); - for (T child : children) { - int index = this.treeData.indexOf(child); - if (index >= 0) { - result.add(index); - if (expandedIndexes.contains(index)) - result.addAll(getExpandedChildIndexes(index)); - } else { - result.addAll(getExpandedChildIndexes(child)); - } - } - return result; - } - - @Override - public List getDirectChildIndexes(int parentIndex) { - List result = new ArrayList(); - T t = this.treeData.getDataAtIndex(parentIndex); - if (t == null) - return Collections.EMPTY_LIST; - List children = this.treeData.getChildren(t); - for (T child : children) { - int index = this.treeData.indexOf(child); - if (index >= 0) { - result.add(index); - } - } - return result; - } - - public ITreeData getTreeData() { - return treeData; - } -} +package org.simantics.browsing.ui.nattable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + +import org.eclipse.nebula.widgets.nattable.tree.ITreeData; +import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel; +import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModelListener; + +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; + +/** + * ITreeRowModel that does not automatically expand all child nodes (as TreeRowModel does). + * + * @author Marko Luukkainen + * + * @param + */ +public class GETreeRowModel implements ITreeRowModel{ + //private final HashSet parentIndexes = new HashSet(); + //private final TIntHashSet parentIndexes = new TIntHashSet(1000, 0.8f); + private final IntOpenHashSet expandedIndexes = new IntOpenHashSet(); + + private final Collection listeners = new HashSet(); + + private final ITreeData treeData; + + public GETreeRowModel(ITreeData treeData) { + this.treeData = treeData; + } + + public void registerRowGroupModelListener(ITreeRowModelListener listener) { + this.listeners.add(listener); + } + + public void notifyListeners() { + for (ITreeRowModelListener listener : this.listeners) { + listener.treeRowModelChanged(); + } + } + + public int depth(int index) { + return this.treeData.getDepthOfData(this.treeData.getDataAtIndex(index)); + } + + public boolean isLeaf(int index) { + return !hasChildren(index); + } + + public String getObjectAtIndexAndDepth(int index, int depth) { + return this.treeData.formatDataForDepth(depth,this.treeData.getDataAtIndex(index)); + } + + public boolean hasChildren(int index) { + return this.treeData.hasChildren(this.treeData.getDataAtIndex(index)); + } + + public boolean isCollapsed(int index) { + return !this.expandedIndexes.contains(index); + } + + public void clear() { + this.expandedIndexes.clear(); + } + + @Override + public boolean isCollapsible(int index) { + return hasChildren(index); + } + + @Override + public List collapse(int index) { + this.expandedIndexes.remove(index); + notifyListeners(); + List list = getChildIndexes(index); + //this.parentIndexes.addAll(list); + return list; + } + + + + @Override + public List expand(int index) { + this.expandedIndexes.add(index); + notifyListeners(); + List children = getExpandedChildIndexes(index); + return children; + } + + @Override + public List collapseAll() { + return null; + } + + + @Override + public List expandToLevel(int level) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List expandToLevel(T object, int level) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List expandAll() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List expandToLevel(int parentIndex, int level) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getChildren(int parentIndex) { + T t = treeData.getDataAtIndex(parentIndex); + return treeData.getChildren(t,true); + } + + @Override + public List getDirectChildren(int parentIndex) { + return treeData.getChildren(parentIndex); + } + + + @Override + public List collapse(T object) { + int index = treeData.indexOf(object); + return collapse(index); + } + + @Override + public List expand(T object) { + int index = treeData.indexOf(object); + return expand(index); + } + + @Override + public boolean isCollapsed(T object) { + int index = treeData.indexOf(object); + return isCollapsed(index); + } + + + @SuppressWarnings("unchecked") + public List getChildIndexes(int parentIndex) { + List result = new ArrayList(); + T t = this.treeData.getDataAtIndex(parentIndex); + if (t == null) + return Collections.EMPTY_LIST; + List children = this.treeData.getChildren(t); + for (T child : children) { + int index = this.treeData.indexOf(child); + if (index >= 0) { + result.add(index); + result.addAll(getChildIndexes(index)); + } else { + result.addAll(getChildIndexes(child)); + } + } + return result; + } + + public List getChildIndexes(T t) { + List result = new ArrayList(); + List children = this.treeData.getChildren(t); + for (T child : children) { + int index = this.treeData.indexOf(child); + if (index >= 0) { + result.add(index); + result.addAll(getChildIndexes(index)); + } else { + result.addAll(getChildIndexes(child)); + } + } + return result; + } + + @SuppressWarnings("unchecked") + public List getExpandedChildIndexes(int parentIndex) { + List result = new ArrayList(); + T t = this.treeData.getDataAtIndex(parentIndex); + if (t == null) + return Collections.EMPTY_LIST; + List children = this.treeData.getChildren(t); + for (T child : children) { + int index = this.treeData.indexOf(child); + if (index >= 0) { + result.add(index); + if (expandedIndexes.contains(index)) + result.addAll(getExpandedChildIndexes(index)); + } else { + result.addAll(getExpandedChildIndexes(child)); + } + } + return result; + } + + public List getExpandedChildIndexes(T t) { + List result = new ArrayList(); + List children = this.treeData.getChildren(t); + for (T child : children) { + int index = this.treeData.indexOf(child); + if (index >= 0) { + result.add(index); + if (expandedIndexes.contains(index)) + result.addAll(getExpandedChildIndexes(index)); + } else { + result.addAll(getExpandedChildIndexes(child)); + } + } + return result; + } + + @Override + public List getDirectChildIndexes(int parentIndex) { + List result = new ArrayList(); + T t = this.treeData.getDataAtIndex(parentIndex); + if (t == null) + return Collections.EMPTY_LIST; + List children = this.treeData.getChildren(t); + for (T child : children) { + int index = this.treeData.indexOf(child); + if (index >= 0) { + result.add(index); + } + } + return result; + } + + public ITreeData getTreeData() { + return treeData; + } +}