aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Pauzies2013-11-26 02:55:19 (EST)
committerDirk Fauth2013-11-26 02:55:19 (EST)
commitcfa501cc6838c1cb54b27571fd32ce61d50c616d (patch)
tree53a27993b44c50f16dbcf2d1a15dcdfb662babe3
parent8aee89ad346d91b0fc61f82115ee95c903cf2ca0 (diff)
downloadorg.eclipse.nebula.widgets.nattable-cfa501cc6838c1cb54b27571fd32ce61d50c616d.zip
org.eclipse.nebula.widgets.nattable-cfa501cc6838c1cb54b27571fd32ce61d50c616d.tar.gz
org.eclipse.nebula.widgets.nattable-cfa501cc6838c1cb54b27571fd32ce61d50c616d.tar.bz2
Bug 416095 - Improved performance by using FilterList instead of
retrieving the children of the TreeNode directly Signed-off-by: Alexandre Pauzies <alexandre@pauzies.com>
-rw-r--r--org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java58
1 files changed, 47 insertions, 11 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java b/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java
index db56c6a..c95617e 100644
--- a/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java
@@ -10,10 +10,12 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy;
-import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Observable;
import java.util.Observer;
+import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
@@ -26,7 +28,9 @@ import org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent
import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
import ca.odell.glazedlists.EventList;
+import ca.odell.glazedlists.FilterList;
import ca.odell.glazedlists.TreeList;
+import ca.odell.glazedlists.matchers.Matcher;
public class GroupByDataLayer<T> extends DataLayer implements Observer {
@@ -61,9 +65,12 @@ public class GroupByDataLayer<T> extends DataLayer implements Observer {
private final GroupByColumnAccessor<T> groupByColumnAccessor;
+ private final IColumnAccessor<T> columnAccessor;
+
private final GroupByTreeFormat<T> treeFormat;
-
+
/** Map the group to a dynamic list of group elements */
+ private final Map<GroupByObject, FilterList<T>> filtersByGroup = new ConcurrentHashMap<GroupByObject, FilterList<T>>();
public GroupByDataLayer(GroupByModel groupByModel, EventList<T> eventList, IColumnAccessor<T> columnAccessor) {
this(groupByModel, eventList, columnAccessor, null, true);
@@ -83,6 +90,7 @@ public class GroupByDataLayer<T> extends DataLayer implements Observer {
public GroupByDataLayer(GroupByModel groupByModel, EventList<T> eventList, IColumnAccessor<T> columnAccessor,
IConfigRegistry configRegistry, boolean useDefaultConfiguration) {
this.eventList = eventList;
+ this.columnAccessor = columnAccessor;
groupByModel.addObserver(this);
@@ -187,17 +195,45 @@ public class GroupByDataLayer<T> extends DataLayer implements Observer {
}
}
- @SuppressWarnings("unchecked")
- public List<T> getElementsInGroup(GroupByObject groupDescriptor) {
- List<T> children = new ArrayList<T>();
- for (Object o : treeData.getChildren(groupDescriptor, true)) {
- if (o instanceof GroupByObject) {
- // do nothing
- } else {
- children.add((T) o);
+ /**
+ * Get the list of elements for a group, create it if it doesn't exists.<br/>
+ * We could also use treeData.getChildren(groupDescriptor, true) but it's less efficient.
+ * @param groupDescriptor The description of the group (columnIndexes..)
+ * @return The FilterList of elements
+ */
+ public FilterList<T> getElementsInGroup(GroupByObject groupDescriptor) {
+ FilterList<T> elementsInGroup = filtersByGroup.get(groupDescriptor);
+ if (elementsInGroup == null) {
+ elementsInGroup = new FilterList<T>(eventList, new GroupDescriptorMatcher<T>(groupDescriptor, columnAccessor));
+ filtersByGroup.put(groupDescriptor, elementsInGroup);
+ }
+ return elementsInGroup;
+ }
+
+ /**
+ * To find out if an element is part of a group
+ */
+ public static class GroupDescriptorMatcher<T> implements Matcher<T> {
+
+ private final GroupByObject group;
+ private final IColumnAccessor<T> columnAccessor;
+
+ public GroupDescriptorMatcher(GroupByObject group, IColumnAccessor<T> columnAccessor) {
+ this.group = group;
+ this.columnAccessor = columnAccessor;
+ }
+
+ @Override
+ public boolean matches(T element) {
+ for (Entry<Integer, Object> desc : group.getDescriptor()) {
+ int columnIndex = desc.getKey();
+ Object groupName = desc.getValue();
+ if (!groupName.equals(columnAccessor.getDataValue((T) element, columnIndex))) {
+ return false;
+ }
}
+ return true;
}
- return children;
}
}