Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2015-05-06 08:55:34 +0000
committervincent lorenzo2015-06-09 08:47:05 +0000
commit9f7cf5b07caa4708addc32550f45f3a751ba8dee (patch)
tree5297bbaaecf7446e2701ce5d8301fe2ec562744d
parent7e138d091f8c26cd16668618a4555b0ff4fd8058 (diff)
downloadorg.eclipse.papyrus-9f7cf5b07caa4708addc32550f45f3a751ba8dee.tar.gz
org.eclipse.papyrus-9f7cf5b07caa4708addc32550f45f3a751ba8dee.tar.xz
org.eclipse.papyrus-9f7cf5b07caa4708addc32550f45f3a751ba8dee.zip
463764: [Tree Table] Impossible to sort columns
Change-Id: Ic0cb174e66079e5e9a3e533e61118eb96f714fef Reviewed-on: https://git.eclipse.org/r/49736 Tested-by: Hudson CI Reviewed-by: vincent lorenzo <vincent.lorenzo@cea.fr>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/comparator/TableCellLabelProviderComparator.java81
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/comparator/TreeTableCellLabelProviderComparator.java118
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java82
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/RowSortModelConfiguration.java49
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/TableClickSortConfiguration.java39
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/TreeTableClickSortConfiguration.java38
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/PapyrusSortingState.java97
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/AbstractTableComparatorChooser.java334
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/ComparatorChain.java73
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseKeyboardSortingStrategy.java74
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseOnlySortingStrategy.java68
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseOnlySortingStrategyWithUndo.java47
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/ReverseComparator.java62
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/SortingState.java382
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/SortingStrategy.java39
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/TableColumnComparator.java95
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layerstack/ColumnHeaderLayerStack.java273
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java94
-rwxr-xr-x[-rw-r--r--]plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManager.java1602
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManagerForEventList.java1722
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ICompositeAxisManager.java9
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ITreeItemAxisComparator.java230
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/cell/CellManagerFactory.java30
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java86
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java58
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java24
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/AbstractNattableCellLabelProvider.java7
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/AbstractGlazedListSortModel.java72
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortModel.java16
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/IPapyrusSortModel.java7
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusColumnAccessor.java92
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusCompositeGlazedListSortModel.java238
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusGlazedListsSortModel.java184
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatColumnTableFormat.java214
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatTableComparatorChooser.java37
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/copy/NatTableComparatorChooser.java116
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/tree/DatumTreeFormat.java237
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/LabelProviderFullCellContextElementWrapper.java277
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigAttributes.java6
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/SortLabelProviderFullCellContextElementWrapper.java70
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableHelper.java20
41 files changed, 5343 insertions, 2056 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/comparator/TableCellLabelProviderComparator.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/comparator/TableCellLabelProviderComparator.java
new file mode 100644
index 00000000000..09efb6b682e
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/comparator/TableCellLabelProviderComparator.java
@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.comparator;
+
+
+import java.text.Collator;
+import java.util.Comparator;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
+import org.eclipse.papyrus.infra.nattable.utils.Constants;
+import org.eclipse.papyrus.infra.nattable.utils.LabelProviderFullCellContextElementWrapper;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.utils.SortLabelProviderFullCellContextElementWrapper;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+
+/**
+ * This comparator is used to sort rows selected column header. This comparator uses the text returned by the label provider used by the table
+ *
+ */
+public class TableCellLabelProviderComparator implements Comparator<SortLabelProviderFullCellContextElementWrapper> {
+
+ /**
+ * the label stack to use for the comparison
+ */
+ private final LabelStack stack;
+
+ /**
+ * the wrapper used for the first value
+ */
+ private final LabelProviderFullCellContextElementWrapper wrapper1;
+
+ /**
+ * the wrapper used for the second value
+ */
+ private final LabelProviderFullCellContextElementWrapper wrapper2;
+
+ /**
+ * Constructor.
+ *
+ */
+ public TableCellLabelProviderComparator() {
+ this.stack = new LabelStack(GridRegion.BODY);
+ this.wrapper1 = new LabelProviderFullCellContextElementWrapper();
+ this.wrapper2 = new LabelProviderFullCellContextElementWrapper();
+ this.wrapper1.setConfigLabels(this.stack);
+ this.wrapper2.setConfigLabels(this.stack);
+ }
+
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ *
+ * @param sortWrapper
+ * @param sortWrapper2
+ * @return
+ */
+ @Override
+ public int compare(SortLabelProviderFullCellContextElementWrapper sortWrapper1, SortLabelProviderFullCellContextElementWrapper sortWrapper2) {
+ final IConfigRegistry configRegistry = sortWrapper1.getConfigRegistry();
+ LabelProviderService serv = configRegistry.getConfigAttribute(NattableConfigAttributes.LABEL_PROVIDER_SERVICE_CONFIG_ATTRIBUTE, org.eclipse.nebula.widgets.nattable.style.DisplayMode.NORMAL, NattableConfigAttributes.LABEL_PROVIDER_SERVICE_ID);
+
+ final String txt1 = serv.getLabelProvider(Constants.TABLE_LABEL_PROVIDER_CONTEXT).getText(sortWrapper1);
+ final String txt2 = serv.getLabelProvider(Constants.TABLE_LABEL_PROVIDER_CONTEXT).getText(sortWrapper2);
+
+ int res = Collator.getInstance().compare(txt1, txt2);
+ return res;
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/comparator/TreeTableCellLabelProviderComparator.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/comparator/TreeTableCellLabelProviderComparator.java
new file mode 100644
index 00000000000..b944e47f67b
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/comparator/TreeTableCellLabelProviderComparator.java
@@ -0,0 +1,118 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.comparator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
+import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.papyrus.infra.nattable.manager.axis.ITreeItemAxisComparator;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.utils.SortLabelProviderFullCellContextElementWrapper;
+import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
+
+
+/**
+ * @author VL222926
+ *
+ * The comparator used to sort the rows selecting column header in case of a TreeTable
+ *
+ */
+public class TreeTableCellLabelProviderComparator extends TableCellLabelProviderComparator {
+
+ /**
+ * the comparator to use
+ */
+ private ITreeItemAxisComparator comparator;
+
+ /**
+ * Constructor.
+ *
+ * @param configRegistry
+ */
+ public TreeTableCellLabelProviderComparator(IConfigRegistry configRegistry) {
+ comparator = new ITreeItemAxisComparator(configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID));
+ }
+
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ *
+ * @param o1
+ * @param o2
+ * @return
+ */
+ @Override
+ public int compare(SortLabelProviderFullCellContextElementWrapper sortWrapper1, SortLabelProviderFullCellContextElementWrapper sortWrapper2) {
+ // get interesting fields and do required check about values
+
+ final IConfigRegistry configRegistry = sortWrapper1.getConfigRegistry();
+
+ ISortModel sortModel = configRegistry.getConfigAttribute(NattableConfigAttributes.ROW_SORT_MODEl, DisplayMode.NORMAL);
+ // get and check the column index
+ int selectedColumn = sortWrapper1.getColumnIndex();
+ Assert.isTrue(selectedColumn == sortWrapper2.getColumnIndex());
+ Object row1 = sortWrapper1.getRowObject();
+ Object col1 = sortWrapper1.getColumnObject();
+
+ Object row2 = sortWrapper2.getRowObject();
+ Object col2 = sortWrapper2.getColumnObject();
+
+ int colIndex1 = sortWrapper1.getColumnIndex();
+ int colIndex2 = sortWrapper2.getColumnIndex();
+
+ Assert.isTrue(colIndex1 == colIndex2);
+ SortDirectionEnum direction = sortModel.getSortDirection(colIndex1);
+ if (row1 == row2 && col1 == col2) {
+ return 0;
+ }
+
+ // check required in case of TreeTable
+ if (row1 instanceof ITreeItemAxis && row2 instanceof ITreeItemAxis) {
+ ITreeItemAxis axis1 = (ITreeItemAxis) row1;
+ ITreeItemAxis axis2 = (ITreeItemAxis) row2;
+ List<ITreeItemAxis> path1 = new ArrayList<ITreeItemAxis>();
+ List<ITreeItemAxis> path2 = new ArrayList<ITreeItemAxis>();
+ TableHelper.getPath(path1, axis1);
+ TableHelper.getPath(path2, axis2);
+ Object rep1 = AxisUtils.getRepresentedElement(axis1);
+ Object rep2 = AxisUtils.getRepresentedElement(axis2);
+
+ // when the parent is not common between the 2 compared elements OR when at least one of the element is a TreeFillingConfiguration, we must not compare CellValue,
+ // we must compare the location in the tree
+ if ((path1.size() != path2.size()) || (axis1.getParent() != axis2.getParent()) || (rep1 instanceof TreeFillingConfiguration || rep2 instanceof TreeFillingConfiguration)) {
+ // we must not compare cell values must location in the tree
+ int res = comparator.compare(axis1, axis2);
+
+ if (direction == SortDirectionEnum.DESC) {
+ res = -res;// to preserve the order of the TreeFillingConfiguration declared in the model
+ }
+ return res;
+ } else {
+ return super.compare(sortWrapper1, sortWrapper2);
+
+ }
+ } else if (row1 instanceof ITreeItemAxis || row2 instanceof ITreeItemAxis) {
+ throw new UnsupportedOperationException();
+ }
+
+ return super.compare(sortWrapper1, sortWrapper2);
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java
index 233e6e49331..2623a0702ab 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java
@@ -1,41 +1,41 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.configuration;
-
-import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator;
-import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator;
-import org.eclipse.nebula.widgets.nattable.sort.config.DefaultSortConfiguration;
-import org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum;
-import org.eclipse.papyrus.infra.nattable.painter.CustomImagePainter;
-import org.eclipse.papyrus.infra.nattable.painter.CustomizedCellPainter;
-import org.eclipse.papyrus.infra.nattable.painter.PapyrusSortableHeaderTextPainter;
-
-/**
- * The configuration used to do the sort
- *
- * @author vl222926
- *
- */
-public class PapyrusClickSortConfiguration extends DefaultSortConfiguration {
-
- /**
- *
- * Constructor.
- *
- */
- public PapyrusClickSortConfiguration() {
- super(new BeveledBorderDecorator(new CellPainterDecorator(new PapyrusSortableHeaderTextPainter(new CustomizedCellPainter(), CellEdgeEnum.RIGHT), CellEdgeEnum.LEFT, new CustomImagePainter())));
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.configuration;
+
+import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator;
+import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator;
+import org.eclipse.nebula.widgets.nattable.sort.config.DefaultSortConfiguration;
+import org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum;
+import org.eclipse.papyrus.infra.nattable.painter.CustomImagePainter;
+import org.eclipse.papyrus.infra.nattable.painter.CustomizedCellPainter;
+import org.eclipse.papyrus.infra.nattable.painter.PapyrusSortableHeaderTextPainter;
+
+/**
+ * The abstract configuration used for the sort the sort
+ *
+ * @author vl222926
+ *
+ */
+public abstract class PapyrusClickSortConfiguration extends DefaultSortConfiguration {
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public PapyrusClickSortConfiguration() {
+ super(new BeveledBorderDecorator(new CellPainterDecorator(new PapyrusSortableHeaderTextPainter(new CustomizedCellPainter(), CellEdgeEnum.RIGHT), CellEdgeEnum.LEFT, new CustomImagePainter())));
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/RowSortModelConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/RowSortModelConfiguration.java
new file mode 100644
index 00000000000..e7723d2c9a4
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/RowSortModelConfiguration.java
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.configuration;
+
+import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+
+/**
+ * @author VL222926
+ * This class allows to register the sort model used by nattable
+ */
+public class RowSortModelConfiguration extends AbstractRegistryConfiguration {
+
+ /**
+ * the sort model used by the table
+ */
+ private final ISortModel sortModel;
+
+ /**
+ * Constructor.
+ *
+ */
+ public RowSortModelConfiguration(ISortModel sortModel) {
+ this.sortModel = sortModel;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.config.IConfiguration#configureRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param configRegistry
+ */
+ @Override
+ public void configureRegistry(IConfigRegistry configRegistry) {
+ configRegistry.registerConfigAttribute(NattableConfigAttributes.ROW_SORT_MODEl, this.sortModel);
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/TableClickSortConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/TableClickSortConfiguration.java
new file mode 100644
index 00000000000..d80a85d721d
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/TableClickSortConfiguration.java
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.configuration;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.sort.SortConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.comparator.TableCellLabelProviderComparator;
+
+/**
+ * @author VL222926
+ *
+ * Configuration used for the sort for a flat/normal table
+ *
+ */
+public class TableClickSortConfiguration extends PapyrusClickSortConfiguration {
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.config.DefaultSortConfiguration#configureRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param configRegistry
+ */
+ @Override
+ public void configureRegistry(IConfigRegistry configRegistry) {
+ super.configureRegistry(configRegistry);
+ configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new TableCellLabelProviderComparator());
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/TreeTableClickSortConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/TreeTableClickSortConfiguration.java
new file mode 100644
index 00000000000..30003460963
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/TreeTableClickSortConfiguration.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.configuration;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.sort.SortConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.comparator.TreeTableCellLabelProviderComparator;
+
+/**
+ * @author VL222926
+ * Configuration used for the sort for a tree table
+ */
+public class TreeTableClickSortConfiguration extends PapyrusClickSortConfiguration {
+
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.config.DefaultSortConfiguration#configureRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param configRegistry
+ */
+ @Override
+ public void configureRegistry(IConfigRegistry configRegistry) {
+ super.configureRegistry(configRegistry);
+ configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new TreeTableCellLabelProviderComparator(configRegistry));
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/PapyrusSortingState.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/PapyrusSortingState.java
new file mode 100644
index 00000000000..6959dc2dfc2
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/PapyrusSortingState.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.glazedlists;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.nattable.glazedlists.copy.AbstractTableComparatorChooser;
+import org.eclipse.papyrus.infra.nattable.glazedlists.copy.SortingState;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+
+//import ca.odell.glazedlists.gui.AbstractTableComparatorChooser;
+import ca.odell.glazedlists.gui.TableFormat;
+
+/**
+ * @author VL222926
+ *
+ */
+public class PapyrusSortingState extends SortingState {
+
+ /**
+ * the table manager
+ */
+ private INattableModelManager manager;
+
+ /**
+ * Constructor.
+ *
+ * @param tableComparatorChooser
+ */
+ public PapyrusSortingState(AbstractTableComparatorChooser<Object> tableComparatorChooser, INattableModelManager manager) {
+ super(tableComparatorChooser);
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.glazedlists.copy.SortingState#createSortingColumn(ca.odell.glazedlists.gui.TableFormat, int)
+ *
+ * @param tableFormat
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ protected SortingColumn createSortingColumn(TableFormat tableFormat, int columnIndex) {
+ return new PapyrusSortingColumn(tableFormat, columnIndex, manager);
+ }
+
+ public class PapyrusSortingColumn extends SortingColumn {
+
+ /**
+ * the sorted axis
+ */
+ private Object axis;
+
+ /**
+ * the table manager
+ */
+ private INattableModelManager manager;
+
+ /**
+ * Constructor.
+ *
+ * @param tableFormat
+ * @param column
+ */
+ public PapyrusSortingColumn(TableFormat tableFormat, int column, INattableModelManager manager) {
+ super(tableFormat, column);
+ this.manager = manager;
+ this.axis = this.manager.getColumnElement(column);
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.glazedlists.copy.SortingState.SortingColumn#getColumn()
+ *
+ * @return
+ */
+ @Override
+ public int getColumn() {
+ return this.manager.getColumnElementsList().indexOf(axis);
+ }
+
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/AbstractTableComparatorChooser.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/AbstractTableComparatorChooser.java
new file mode 100644
index 00000000000..ab7bdd86456
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/AbstractTableComparatorChooser.java
@@ -0,0 +1,334 @@
+/* Glazed Lists (c) 2003-2006 */
+/* http://publicobject.com/glazedlists/ publicobject.com,*/
+/* O'Dell Engineering Ltd.*/
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Comparator;
+import java.util.List;
+
+import ca.odell.glazedlists.SortedList;
+//import ca.odell.glazedlists.impl.gui.MouseKeyboardSortingStrategy;
+//import ca.odell.glazedlists.impl.gui.MouseOnlySortingStrategy;
+//import ca.odell.glazedlists.impl.gui.SortingState;
+//import ca.odell.glazedlists.impl.gui.MouseOnlySortingStrategyWithUndo;
+//import ca.odell.glazedlists.impl.sort.TableColumnComparator;
+import ca.odell.glazedlists.gui.TableFormat;
+
+/**
+ * A TableComparatorChooser is a tool that allows the user to sort a table
+ * widget by clicking on the table's headers. It requires that the table has a
+ * SortedList as a source as the sorting on that list is used.
+ *
+ * @author <a href="mailto:kevin@swank.ca">Kevin Maltby</a>
+ */
+public abstract class AbstractTableComparatorChooser<E> {
+
+ /**
+ * Emulate the sorting behaviour of Windows Explorer and Mac OS X Finder.
+ *
+ * <p>
+ * Single clicks toggles between forward and reverse. If multiple comparators are available for a particular column, they will be cycled in order.
+ *
+ * <p>
+ * At most one column can be sorted at a time.
+ */
+ public static final Object SINGLE_COLUMN = new MouseOnlySortingStrategy(false);
+
+ /**
+ * Sort multiple columns without use of the keyboard. Single clicks cycle
+ * through comparators, double clicks clear all secondary sorts before
+ * performing the normal behaviour.
+ *
+ * <p>
+ * This is the original sorting strategy provided by Glazed Lists, with a limitation that it is impossible to clear a sort order that is already in place. It's designed to be used with multiple columns and multiple comparators per column.
+ *
+ * <p>
+ * The overall behaviour is as follows:
+ *
+ * <li>Click: sort this column. If it's already sorted, reverse the sort order. If its already reversed, sort using the column's next comparator in forward order. If there are no more comparators, go to the first comparator. If there are multiple sort
+ * columns, sort this column after those columns.
+ *
+ * <li>Double click: like a single click, but clear all sorting columns first.
+ */
+ public static final Object MULTIPLE_COLUMN_MOUSE = new MouseOnlySortingStrategy(true);
+
+ /**
+ * Sort multiple columns without use of the keyboard. Single clicks cycle
+ * through comparators. Single click on the last comparator of the primary
+ * sort column will clear the entire sort (for all columns).
+ *
+ * <p>
+ * This is an improvement over the original sorting strategy provided by Glazed Lists, since it gives a reasonable mechanism for clearing a sort order that is already in place. It's designed to be used with multiple columns and multiple comparators per
+ * column.
+ *
+ * <p>
+ * The overall behaviour is as follows:
+ *
+ * <li>Click: sort this column. If it's already sorted, reverse the sort order. If its already reversed, sort using the column's next comparator in forward order. If there are no more comparators, clear ALL column comparators. If there are multiple sort
+ * columns, sort this column after those columns.
+ */
+ public static final Object MULTIPLE_COLUMN_MOUSE_WITH_UNDO = new MouseOnlySortingStrategyWithUndo();
+
+ /**
+ * Emulate the sorting behaviour of SUN's TableSorter, by Philip Milne et. al.
+ *
+ * <p>
+ * This is not a direct adaptation since we choose to support potentially many Comparators per column, whereas TableSorter is limited to one.
+ *
+ * <p>
+ * For reference, this is TableSorter's behaviour, copied shamelessly from that project's source file:
+ *
+ * <li>Mouse-click: Clears the sorting gui of all other columns and advances the sorting gui of that column through three values: {NOT_SORTED, ASCENDING, DESCENDING} (then back to NOT_SORTED again).
+ *
+ * <li>SHIFT-mouse-click: Clears the sorting gui of all other columns and cycles the sorting gui of the column through the same three values, in the opposite order: {NOT_SORTED, DESCENDING, ASCENDING}.
+ *
+ * <li>CONTROL-mouse-click and CONTROL-SHIFT-mouse-click: as above except that the changes to the column do not cancel the statuses of columns that are already sorting - giving a way to initiate a compound sort.
+ *
+ * @see <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html">Table tutorial</a>
+ */
+ public static final Object MULTIPLE_COLUMN_KEYBOARD = new MouseKeyboardSortingStrategy();
+
+ /** the sorted list to choose the comparators for */
+ protected SortedList<E> sortedList;
+
+ /** the columns to sort over */
+ private TableFormat<? super E> tableFormat;
+
+ /** the potentially foreign comparator associated with the sorted list */
+ protected Comparator<? super E> sortedListComparator = null;
+
+ /** manage which columns are sorted and in which order */
+ protected SortingState sortingState;
+
+ /**
+ * Create a {@link AbstractTableComparatorChooser} that sorts the specified {@link SortedList} over the specified columns.
+ */
+ protected AbstractTableComparatorChooser(SortedList<E> sortedList, TableFormat<? super E> tableFormat) {
+ this.sortedList = sortedList;
+ this.sortingState = createSortingState();
+ this.setTableFormat(tableFormat);
+
+ this.sortingState.addPropertyChangeListener(new SortingStateListener());
+ }
+
+ /**
+ * Returns the object which models the current sorting state of all columns
+ * in the table.
+ */
+ protected SortingState createSortingState() {
+ return new SortingState(this);
+ }
+
+ /**
+ * Handle changes to the sorting state by applying the new comparator
+ * to the {@link SortedList}.
+ */
+ private class SortingStateListener implements PropertyChangeListener {
+ public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
+ rebuildComparator();
+ }
+ }
+
+ /**
+ * Updates the comparator in use and applies it to the table.
+ */
+ protected void rebuildComparator() {
+ final Comparator<E> rebuiltComparator = sortingState.buildComparator();
+
+ // select the new comparator
+ sortedList.getReadWriteLock().writeLock().lock();
+ try {
+ sortedListComparator = rebuiltComparator;
+ sortedList.setComparator(rebuiltComparator);
+ } finally {
+ sortedList.getReadWriteLock().writeLock().unlock();
+ }
+ }
+
+ /**
+ * Adjusts the TableFormat this comparator chooser uses when selecting
+ * comparators. Calling this method will clear any active sorting.
+ */
+ protected void setTableFormat(TableFormat<? super E> tableFormat) {
+ this.tableFormat = tableFormat;
+
+ // handle a change in the layout of our columns
+ sortingState.rebuildColumns(tableFormat);
+ }
+
+
+ /**
+ * Gets the list of comparators for the specified column. The user is
+ * free to add comparators to this list or clear the list if the specified
+ * column cannot be sorted.
+ */
+ public List<Comparator> getComparatorsForColumn(int column) {
+ return sortingState.getColumns().get(column).getComparators();
+ }
+
+ /**
+ * Get the columns that the TableComparatorChooser is sorting by.
+ *
+ * @return a List of Integers. The first Integer is the primary sorting column,
+ * the second is the secondary, etc. This list may be empty but never null.
+ */
+ public List<Integer> getSortingColumns() {
+ return sortingState.getSortingColumnIndexes();
+ }
+
+ /**
+ * Gets the index comparator in use for the specified column. This comparator
+ * may be retrieved using {@link #getComparatorsForColumn(int)}.
+ *
+ * @return the comparator index for the specified column, or -1 if that column
+ * is not being used to sort.
+ */
+ public int getColumnComparatorIndex(int column) {
+ return sortingState.getColumns().get(column).getComparatorIndex();
+ }
+
+ /**
+ * Gets whether the comparator in use for the specified column is reverse.
+ */
+ public boolean isColumnReverse(int column) {
+ return sortingState.getColumns().get(column).isReverse();
+ }
+
+ /**
+ * Append the comparator specified by the column, comparator index and reverse
+ * parameters to the end of the sequence of comparators this {@link AbstractTableComparatorChooser} is sorting the {@link SortedList} by.
+ *
+ * <p>
+ * <i>Append</i> implies that if this {@link AbstractTableComparatorChooser} is already sorting that list by another column, this comparator will only be used to break ties from that {@link Comparator}. If the table is already sorting by the specified
+ * column, it will be silently discarded.
+ *
+ * <p>
+ * Suppose we're currently not sorting the table, this method will cause the table to be sorted by the column specified. If we are sorting the table by some column c, this will sort by that column first and the column specified here second.
+ *
+ * <p>
+ * If this {@link AbstractTableComparatorChooser} doesn't support multiple column sort, this will replace the current {@link Comparator} rather than appending to it.
+ *
+ * @param column
+ * the column to sort by
+ * @param comparatorIndex
+ * the comparator to use, specify <code>0</code> for the
+ * default comparator.
+ * @param reverse
+ * whether to reverse the specified comparator.
+ */
+ public void appendComparator(int column, int comparatorIndex, boolean reverse) {
+ sortingState.appendComparator(column, comparatorIndex, reverse);
+ sortingState.fireSortingChanged();
+ }
+
+ /**
+ * Clear all sorting state and set the {@link SortedList} to use its
+ * natural order.
+ */
+ public void clearComparator() {
+ sortingState.clearComparators();
+ sortingState.fireSortingChanged();
+ }
+
+ /**
+ * Examines the current {@link Comparator} of the SortedList and
+ * adds icons to the table header renderers in response.
+ *
+ * <p>
+ * To do this, clicks are injected into each of the corresponding <code>ColumnClickTracker</code>s.
+ */
+ protected void redetectComparator(Comparator<? super E> currentComparator) {
+ sortedListComparator = currentComparator;
+ sortingState.detectStateFromComparator(currentComparator);
+ }
+
+ /**
+ * Gets the sorting style currently applied to the specified column.
+ */
+ protected int getSortingStyle(int column) {
+ return sortingState.getColumns().get(column).getSortingStyle();
+ }
+
+ /**
+ * Creates a {@link Comparator} that can compare list elements
+ * given a {@link Comparator} that can compare column values for the specified
+ * column. This returns a {@link Comparator} that extracts the table values for
+ * the specified column and then delegates the actual comparison to the specified
+ * comparator.
+ */
+ public Comparator createComparatorForElement(Comparator<E> comparatorForColumn, int column) {
+ return new TableColumnComparator<E>(tableFormat, column, comparatorForColumn);
+ }
+
+ /**
+ * Encode the current sorting state as a {@link String}. This specially formatted {@link String} is ideal for persistence using any preferences API. The
+ * state of this {@link AbstractTableComparatorChooser} can be restored
+ * by passing the return value of this method to {@link #fromString(String)}.
+ */
+ @Override
+ public String toString() {
+ return sortingState.toString();
+ }
+
+ /**
+ * <p>
+ * This class is capable of representing its own state with a String, to persist sorting state externally. The format uses zero or more column specifications, separated by commas. Here are some valid examples:
+ *
+ * <table border>
+ * <tr>
+ * <th>String Representation</th>
+ * <th>Description</th>
+ * </tr>
+ * <tr>
+ * <td><code>"column 3"</code></td>
+ * <td>Sort using the column at index 3, using that column's first comparator, in forward order</td>
+ * </tr>
+ * <tr>
+ * <td><code>"column 3 reversed"</code></td>
+ * <td>Sort using the column at index 3, using that column's first comparator, in reverse order</td>
+ * </tr>
+ * <tr>
+ * <td><code>"column 3, column 1"</code></td>
+ * <td>Sort using the column at index 3, using that column's first comparator, in forward order<br>
+ * <i>then by</i><br>
+ * the column at index 1, using that column's first comparator, in forward order.</td>
+ * </tr>
+ * <tr>
+ * <td><code>"column 3 comparator 2"</code></td>
+ * <td>Sort using the column at index 3, using that column's comparator at index 2, in forward order</td>
+ * </tr>
+ * <tr>
+ * <td><code>"column 3 comparator 2 reversed"</code></td>
+ * <td>Sort using the column at index 3, using that column's comparator at index 2, in reverse order</td>
+ * </tr>
+ * <tr>
+ * <td><code>"column 3 reversed, column 1 comparator 2, column 5 comparator 1 reversed, column 0"</code></td>
+ * <td>Sort using the column at index 3, using that column's first comparator, in reverse order<br>
+ * <i>then by</i><br>
+ * the column at index 1, using that column's comparator at index 2, in forward order<br>
+ * <i>then by</i><br>
+ * the column at index 5, using that column's comparator at index 1, in reverse order<br>
+ * <i>then by</i><br>
+ * the column at index 0, using that column's first comparator, in forward order.</td>
+ * </tr>
+ * </table>
+ *
+ * <p>
+ * More formally, the grammar for this String representation is as follows: <br>
+ * <code>&lt;COLUMN&gt; = column &lt;COLUMN INDEX&gt; (comparator &lt;COMPARATOR INDEX&gt;)? (reversed)?</code> <br>
+ * <code>&lt;COMPARATOR SPEC&gt; = ( &lt;COLUMN&gt; (, &lt;COLUMN&gt;)* )?</code>
+ */
+ public void fromString(String stringEncoded) {
+ sortingState.fromString(stringEncoded);
+ sortingState.fireSortingChanged();
+ }
+
+ public void dispose() {
+ // null out references to potentially long lived objects
+ this.sortedList = null;
+ this.tableFormat = null;
+ this.sortedListComparator = null;
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/ComparatorChain.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/ComparatorChain.java
new file mode 100644
index 00000000000..5b03e90f320
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/ComparatorChain.java
@@ -0,0 +1,73 @@
+/* Glazed Lists (c) 2003-2006 */
+/* http://publicobject.com/glazedlists/ publicobject.com,*/
+/* O'Dell Engineering Ltd.*/
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+// for specifying a sorting algorithm
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * A comparator chain compares objects using a list of Comparators. The
+ * first comparison where the objects differ is returned.
+ *
+ * @author <a href="mailto:jesse@swank.ca">Jesse Wilson</a>
+ */
+public final class ComparatorChain<T> implements Comparator<T> {
+
+ /** the comparators to execute in sequence */
+ private final Comparator<T>[] comparators;
+
+ /**
+ * Creates a comparator chain that evaluates the specified comparators in
+ * sequence. A defensive copy of the
+ *
+ * @param comparators
+ * a list of objects implementing {@link Comparator}
+ */
+ public ComparatorChain(List<Comparator<T>> comparators) {
+ this.comparators = comparators.toArray(new Comparator[comparators.size()]);
+ }
+
+ /**
+ * Compares the two objects with each comparator in sequence.
+ */
+ public int compare(T alpha, T beta) {
+ for (int i = 0; i < comparators.length; i++) {
+ int compareResult = comparators[i].compare(alpha, beta);
+ if (compareResult != 0)
+ return compareResult;
+ }
+ return 0;
+ }
+
+ /**
+ * Retrieves the {@link Comparator}s composing this <code>ComparatorChain</code>.
+ */
+ public Comparator<T>[] getComparators() {
+ return comparators;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ final ComparatorChain that = (ComparatorChain) o;
+
+ if (!Arrays.equals(comparators, that.comparators))
+ return false;
+
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseKeyboardSortingStrategy.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseKeyboardSortingStrategy.java
new file mode 100644
index 00000000000..cc850edc0d3
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseKeyboardSortingStrategy.java
@@ -0,0 +1,74 @@
+/* Glazed Lists (c) 2003-2006 */
+/* http://publicobject.com/glazedlists/ publicobject.com,*/
+/* O'Dell Engineering Ltd.*/
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+import java.util.List;
+
+/**
+ * @see ca.odell.glazedlists.gui.AbstractTableComparatorChooser#MULTIPLE_COLUMN_KEYBOARD
+ *
+ * @author <a href="mailto:jesse@swank.ca">Jesse Wilson</a>
+ */
+public class MouseKeyboardSortingStrategy implements SortingStrategy {
+
+ /** a column is sorted in forward, reverse or not at all */
+ private static final int NONE = 0;
+ private static final int FORWARD = 1;
+ private static final int REVERSE = 2;
+
+ /**
+ * Adjust the sorting state based on receiving the specified click event.
+ */
+ public void columnClicked(SortingState sortingState, int column, int clicks, boolean shift, boolean control) {
+ SortingState.SortingColumn sortingColumn = sortingState.getColumns().get(column);
+ if (sortingColumn.getComparators().isEmpty())
+ return;
+ List<SortingState.SortingColumn> recentlyClickedColumns = sortingState.getRecentlyClickedColumns();
+
+ // figure out which comparator and reverse state we were on before
+ int comparatorIndexBefore = sortingColumn.getComparatorIndex();
+ final int forwardReverseNoneBefore;
+ if (comparatorIndexBefore == -1)
+ forwardReverseNoneBefore = NONE;
+ else
+ forwardReverseNoneBefore = sortingColumn.isReverse() ? REVERSE : FORWARD;
+
+ // figure out which comparator and reverse state we shall go to
+ int forwardReverseNoneAfter;
+ int comparatorIndexAfter;
+ boolean moreComparators = comparatorIndexBefore + 1 < sortingColumn.getComparators().size();
+ boolean lastDirective = shift ? forwardReverseNoneBefore == FORWARD : forwardReverseNoneBefore == REVERSE;
+
+ // if we're on the last mode of this comparator, go to the next comparator
+ if (moreComparators && lastDirective) {
+ comparatorIndexAfter = (comparatorIndexBefore + 1) % sortingColumn.getComparators().size();
+ forwardReverseNoneAfter = forwardReverseNoneBefore == FORWARD ? REVERSE : FORWARD;
+
+ // otherwise merely toggle forward/reverse/none
+ } else {
+ comparatorIndexAfter = comparatorIndexBefore != -1 ? comparatorIndexBefore : 0;
+ forwardReverseNoneAfter = (shift ? forwardReverseNoneBefore + 2 : forwardReverseNoneBefore + 1) % 3;
+ }
+
+ // clean up if necessary
+ if (!control) {
+ sortingState.clearComparators();
+ }
+
+ // prepare the latest column
+ if (forwardReverseNoneAfter == NONE) {
+ sortingColumn.clear();
+ recentlyClickedColumns.remove(sortingColumn);
+ } else {
+ sortingColumn.setComparatorIndex(comparatorIndexAfter);
+ sortingColumn.setReverse(forwardReverseNoneAfter == REVERSE);
+ if (!recentlyClickedColumns.contains(sortingColumn)) {
+ recentlyClickedColumns.add(sortingColumn);
+ }
+ }
+
+ // rebuild the sorting state
+ sortingState.fireSortingChanged();
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseOnlySortingStrategy.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseOnlySortingStrategy.java
new file mode 100644
index 00000000000..92f4a33abcd
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseOnlySortingStrategy.java
@@ -0,0 +1,68 @@
+/* Glazed Lists (c) 2003-2006 */
+/* http://publicobject.com/glazedlists/ publicobject.com,*/
+/* O'Dell Engineering Ltd.*/
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @see ca.odell.glazedlists.gui.AbstractTableComparatorChooser#SINGLE_COLUMN
+ * @see ca.odell.glazedlists.gui.AbstractTableComparatorChooser#MULTIPLE_COLUMN_MOUSE
+ *
+ * @author <a href="mailto:jesse@swank.ca">Jesse Wilson</a>
+ */
+public final class MouseOnlySortingStrategy implements SortingStrategy {
+
+ /** if false, other sorting columns will be cleared before a click takes effect */
+ private final boolean multipleColumnSort;
+
+ /**
+ * Create a new {@link8 ca.odell.glazedlists.impl.gui.MouseOnlySortingStrategy}, sorting multiple
+ * columns or not as specified.
+ */
+ public MouseOnlySortingStrategy(boolean multipleColumnSort) {
+ this.multipleColumnSort = multipleColumnSort;
+ }
+
+ /**
+ * Adjust the sorting state based on receiving the specified clicks.
+ */
+ public void columnClicked(SortingState sortingState, int column, int clicks, boolean shift, boolean control) {
+ SortingState.SortingColumn clickedColumn = sortingState.getColumns().get(column);
+ if (clickedColumn.getComparators().isEmpty())
+ return;
+
+ List<SortingState.SortingColumn> recentlyClickedColumns = sortingState.getRecentlyClickedColumns();
+
+ // on a double click, clear all click counts
+ if (clicks == 2) {
+ for (Iterator<SortingState.SortingColumn> i = recentlyClickedColumns.iterator(); i.hasNext();) {
+ SortingState.SortingColumn sortingColumn = i.next();
+ sortingColumn.clear();
+ }
+ recentlyClickedColumns.clear();
+
+ // if we're only sorting one column at a time, clear other columns
+ } else if (!multipleColumnSort) {
+ for (Iterator<SortingState.SortingColumn> i = recentlyClickedColumns.iterator(); i.hasNext();) {
+ SortingState.SortingColumn sortingColumn = i.next();
+ if (sortingColumn != clickedColumn) {
+ sortingColumn.clear();
+ }
+ }
+ recentlyClickedColumns.clear();
+ }
+
+ // add a click to the newly clicked column if it has any comparators
+ int netClicks = 1 + clickedColumn.getComparatorIndex() * 2 + (clickedColumn.isReverse() ? 1 : 0);
+ clickedColumn.setComparatorIndex((netClicks / 2) % clickedColumn.getComparators().size());
+ clickedColumn.setReverse(netClicks % 2 == 1);
+ if (!recentlyClickedColumns.contains(clickedColumn)) {
+ recentlyClickedColumns.add(clickedColumn);
+ }
+
+ // rebuild the sorting state
+ sortingState.fireSortingChanged();
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseOnlySortingStrategyWithUndo.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseOnlySortingStrategyWithUndo.java
new file mode 100644
index 00000000000..7da69380fe5
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/MouseOnlySortingStrategyWithUndo.java
@@ -0,0 +1,47 @@
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+import java.util.List;
+
+/**
+ * @see ca.odell.glazedlists.gui.AbstractTableComparatorChooser#MULTIPLE_COLUMN_MOUSE_WITH_UNDO
+ *
+ * @author James Lemieux
+ */
+public class MouseOnlySortingStrategyWithUndo implements SortingStrategy {
+
+ /**
+ * The normal MouseOnlySortingStrategy that is decorated with the ability
+ * to clear the sort from the table.
+ */
+ private final SortingStrategy decorated = new MouseOnlySortingStrategy(true);
+
+ public void columnClicked(SortingState sortingState, int column, int clicks, boolean shift, boolean control) {
+ final SortingState.SortingColumn clickedColumn = sortingState.getColumns().get(column);
+
+ // if the column defines no Comparators, we don't need to alter the table's Comparator
+ if (clickedColumn.getComparators().isEmpty())
+ return;
+
+ final List<SortingState.SortingColumn> recentlyClickedColumns = sortingState.getRecentlyClickedColumns();
+
+ final boolean wasPrimarySortColumnClicked = !recentlyClickedColumns.isEmpty() && clickedColumn == recentlyClickedColumns.get(0);
+ final boolean isPrimarySortColumnReversed = clickedColumn.isReverse();
+ final boolean isLastComparatorForPrimarySortColumn = clickedColumn.getComparatorIndex() == clickedColumn.getComparators().size() - 1;
+
+ // if the following conditions exist on this click:
+ // a) the column that was clicked was the column providing the primary sort
+ // b) the primary sort column is currently reversed
+ // c) the primary sort column is currently sorting using its last Comparator
+ //
+ // then deviate from the normal behaviour of MouseOnlySortingStrategy by
+ // removing all sorting from the table
+ if (wasPrimarySortColumnClicked && isPrimarySortColumnReversed && isLastComparatorForPrimarySortColumn) {
+ sortingState.clearComparators();
+ sortingState.fireSortingChanged();
+ return;
+ }
+
+ // otherwise, proceed with the normal MouseOnlySortingStrategy
+ decorated.columnClicked(sortingState, column, clicks, shift, control);
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/ReverseComparator.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/ReverseComparator.java
new file mode 100644
index 00000000000..92473d7f71b
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/ReverseComparator.java
@@ -0,0 +1,62 @@
+/* Glazed Lists (c) 2003-2006 */
+/* http://publicobject.com/glazedlists/ publicobject.com,*/
+/* O'Dell Engineering Ltd.*/
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+// for specifying a sorting algorithm
+import java.util.Comparator;
+
+/**
+ * A comparator that reverses the sequence of a source comparator.
+ *
+ * @author <a href="mailto:jesse@swank.ca">Jesse Wilson</a>
+ */
+public final class ReverseComparator<T> implements Comparator<T> {
+
+ /** the normal comparator to flip */
+ private Comparator<T> source;
+
+ /**
+ * Create a new reverse comparator that reverses the sequence
+ * of the specified comparator.
+ */
+ public ReverseComparator(Comparator<T> source) {
+ this.source = source;
+ }
+
+ /**
+ * Compares the specified objects and flips the result.
+ */
+ public int compare(T alpha, T beta) {
+ return source.compare(beta, alpha);
+ }
+
+ /**
+ * Retrieves the source {@link Comparator} for this ReverseComparator
+ */
+ public Comparator<T> getSourceComparator() {
+ return source;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ final ReverseComparator that = (ReverseComparator) o;
+
+ if (!source.equals(that.source))
+ return false;
+
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int hashCode() {
+ return source.hashCode();
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/SortingState.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/SortingState.java
new file mode 100644
index 00000000000..240010cb02e
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/SortingState.java
@@ -0,0 +1,382 @@
+/* Glazed Lists (c) 2003-2006 */
+/* http://publicobject.com/glazedlists/ publicobject.com,*/
+/* O'Dell Engineering Ltd.*/
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import ca.odell.glazedlists.GlazedLists;
+//import ca.odell.glazedlists.gui.AbstractTableComparatorChooser;
+import ca.odell.glazedlists.gui.AdvancedTableFormat;
+import ca.odell.glazedlists.gui.TableFormat;
+//import ca.odell.glazedlists.impl.sort.ComparatorChain;
+//import ca.odell.glazedlists.impl.sort.ReverseComparator;
+//import ca.odell.glazedlists.impl.sort.TableColumnComparator;
+
+/**
+ * Keep track of which columns are sorted and how. This is
+ * largely independent of how that state is applied to a <code>SortedList</code>, which is managed independently by <code>TableComparatorChooser</code>.
+ *
+ * <p>
+ * Users must explicity call {@link #fireSortingChanged()} in order to prepare a new Comparator for the target table.
+ *
+ * @author <a href="mailto:jesse@swank.ca">Jesse Wilson</a>
+ */
+public class SortingState {
+
+ /** this regular expression for parsing the string representation of a column */
+ private static final Pattern FROM_STRING_PATTERN = Pattern.compile("^\\s*column\\s+(\\d+)(\\s+comparator\\s+(\\d+))?(\\s+(reversed))?\\s*$", Pattern.CASE_INSENSITIVE);
+
+ /** the sorting style on a column is used for icon choosing */
+ protected static final int COLUMN_UNSORTED = 0;
+ protected static final int COLUMN_PRIMARY_SORTED = 1;
+ protected static final int COLUMN_PRIMARY_SORTED_REVERSE = 2;
+ protected static final int COLUMN_PRIMARY_SORTED_ALTERNATE = 3;
+ protected static final int COLUMN_PRIMARY_SORTED_ALTERNATE_REVERSE = 4;
+ protected static final int COLUMN_SECONDARY_SORTED = 5;
+ protected static final int COLUMN_SECONDARY_SORTED_REVERSE = 6;
+ protected static final int COLUMN_SECONDARY_SORTED_ALTERNATE = 7;
+ protected static final int COLUMN_SECONDARY_SORTED_ALTERNATE_REVERSE = 8;
+
+ /** the columns and their click counts in indexed order */
+ protected List<SortingColumn> sortingColumns;
+
+ /** a list that contains all ColumnClickTrackers with non-zero click counts in their visitation order */
+ protected List<SortingColumn> recentlyClickedColumns = new ArrayList<SortingColumn>(2);
+
+ private final AbstractTableComparatorChooser tableComparatorChooser;
+
+ /** whom to notify when the sorting state is chaged */
+ private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
+
+ public SortingState(AbstractTableComparatorChooser tableComparatorChooser) {
+ this.tableComparatorChooser = tableComparatorChooser;
+ }
+
+ public AbstractTableComparatorChooser getTableComparatorChooser() {
+ return tableComparatorChooser;
+ }
+
+ public void fireSortingChanged() {
+ changeSupport.firePropertyChange("comparator", null, null);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ public Comparator buildComparator() {
+ // build a new comparator
+ if (recentlyClickedColumns.isEmpty()) {
+ return null;
+ } else {
+ List<Comparator<Object>> comparators = new ArrayList<Comparator<Object>>(recentlyClickedColumns.size());
+ for (Iterator<SortingColumn> i = recentlyClickedColumns.iterator(); i.hasNext();) {
+ SortingColumn sortingColumn = i.next();
+ Comparator comparator = sortingColumn.getComparator();
+ if (comparator == null)
+ throw new IllegalStateException();
+ comparators.add(comparator);
+ }
+
+ return GlazedLists.chainComparators(comparators);
+ }
+ }
+
+ /**
+ * @return the indices of the columns currently being sorted.
+ */
+ public List<Integer> getSortingColumnIndexes() {
+ final List<Integer> sortingColumns = new ArrayList<Integer>();
+ final List<SortingState.SortingColumn> recentlyClickedColumns = getRecentlyClickedColumns();
+ for (int c = 0; c < recentlyClickedColumns.size(); c++) {
+ SortingState.SortingColumn clickedColumn = recentlyClickedColumns.get(c);
+ sortingColumns.add(new Integer(clickedColumn.getColumn()));
+ }
+ return sortingColumns;
+ }
+
+ public void appendComparator(int column, int comparatorIndex, boolean reverse) {
+ if (column > getColumns().size())
+ throw new IllegalArgumentException("invalid column " + column + ", must be in range 0, " + sortingColumns.size());
+ if (comparatorIndex >= sortingColumns.get(column).getComparators().size())
+ throw new IllegalArgumentException("invalid comparator index " + comparatorIndex + ", must be in range 0, " + sortingColumns.get(column).getComparators().size());
+ if (recentlyClickedColumns.contains(getColumns().get(column)))
+ return;
+
+ // add clicks to the specified column
+ SortingColumn sortingColumn = sortingColumns.get(column);
+ sortingColumn.setComparatorIndex(comparatorIndex);
+ sortingColumn.setReverse(reverse);
+
+ // rebuild the clicked column list
+ recentlyClickedColumns.add(sortingColumn);
+ }
+
+ public void detectStateFromComparator(Comparator foreignComparator) {
+ // Clear the current click counts
+ clearComparators();
+
+ // Populate a list of Comparators
+ final List<Comparator> comparatorsList;
+ if (foreignComparator == null) {
+ comparatorsList = Collections.emptyList();
+ } else if (foreignComparator instanceof ComparatorChain) {
+ ComparatorChain chain = (ComparatorChain) foreignComparator;
+ comparatorsList = Arrays.asList(chain.getComparators());
+ } else {
+ comparatorsList = Collections.singletonList(foreignComparator);
+ }
+
+ // walk through the list of Comparators and assign click counts
+ for (Iterator<Comparator> i = comparatorsList.iterator(); i.hasNext();) {
+ // get the current comparator
+ Comparator comparator = i.next();
+ boolean reverse = false;
+ if (comparator instanceof ReverseComparator) {
+ reverse = true;
+ comparator = ((ReverseComparator) comparator).getSourceComparator();
+ }
+
+ // discover where to add clicks for this comparator
+ for (int c = 0; c < sortingColumns.size(); c++) {
+ if (recentlyClickedColumns.contains(sortingColumns.get(c))) {
+ continue;
+ }
+ int comparatorIndex = sortingColumns.get(c).getComparators().indexOf(comparator);
+ if (comparatorIndex != -1) {
+ final SortingColumn columnClickTracker = sortingColumns.get(c);
+ columnClickTracker.setComparatorIndex(comparatorIndex);
+ columnClickTracker.setReverse(reverse);
+ recentlyClickedColumns.add(columnClickTracker);
+ }
+ }
+ }
+ }
+
+ public void clearComparators() {
+ // clear the click counts
+ for (Iterator<SortingColumn> i = recentlyClickedColumns.iterator(); i.hasNext();) {
+ SortingColumn sortingColumn = i.next();
+ sortingColumn.clear();
+ }
+ recentlyClickedColumns.clear();
+ }
+
+ /**
+ * When the column model is changed, this resets the column clicks and
+ * comparator list for each column.
+ */
+ public void rebuildColumns(TableFormat tableFormat) {
+ // build the column click trackers
+ final int columnCount = tableFormat.getColumnCount();
+
+ sortingColumns = new ArrayList<SortingColumn>(columnCount);
+ for (int i = 0; i < columnCount; i++) {
+ sortingColumns.add(createSortingColumn(tableFormat, i));
+ }
+
+ recentlyClickedColumns.clear();
+ }
+
+ protected SortingColumn createSortingColumn(TableFormat tableFormat, int columnIndex) {
+ return new SortingColumn(tableFormat, columnIndex);
+ }
+
+ public List<SortingColumn> getColumns() {
+ return sortingColumns;
+ }
+
+ public List<SortingColumn> getRecentlyClickedColumns() {
+ return recentlyClickedColumns;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuffer result = new StringBuffer();
+ for (Iterator<Integer> i = getSortingColumnIndexes().iterator(); i.hasNext();) {
+ final int columnIndex = i.next().intValue();
+ final SortingState.SortingColumn sortingColumn = getColumns().get(columnIndex);
+
+ // write the column index
+ result.append("column ");
+ result.append(columnIndex);
+
+ // write the comparator index
+ final int comparatorIndex = sortingColumn.getComparatorIndex();
+ if (comparatorIndex != 0) {
+ result.append(" comparator ");
+ result.append(comparatorIndex);
+ }
+
+ // write reversed
+ if (sortingColumn.isReverse()) {
+ result.append(" reversed");
+ }
+
+ // add a comma if more columns exist
+ if (i.hasNext()) {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+
+ public void fromString(String stringEncoded) {
+ clearComparators();
+
+ // parse each column part in sequence using regex groups
+ String[] parts = stringEncoded.split(",");
+ for (int p = 0; p < parts.length; p++) {
+ // skip empty strings
+ if (parts[p].trim().length() == 0)
+ continue;
+
+ Matcher matcher = FROM_STRING_PATTERN.matcher(parts[p]);
+
+ if (!matcher.find())
+ throw new IllegalArgumentException("Failed to parse column spec, \"" + parts[p] + "\"");
+
+ int columnIndex = Integer.parseInt(matcher.group(1));
+ int comparatorIndex = matcher.group(3) == null ? 0 : Integer.parseInt(matcher.group(3));
+ boolean reversedComparator = matcher.group(5) != null;
+
+ // bail on invalid data
+ if (columnIndex >= sortingColumns.size())
+ continue;
+ if (comparatorIndex >= sortingColumns.get(columnIndex).getComparators().size())
+ continue;
+
+ // add this comparator in sequence
+ appendComparator(columnIndex, comparatorIndex, reversedComparator);
+ }
+
+ }
+
+ public class SortingColumn {
+ /** the column whose sorting state is being managed */
+ private final int column;
+ /** the sequence of comparators for this column */
+ private final List<Comparator> comparators = new ArrayList<Comparator>(1);
+ /** whether this column is sorted in reverse order */
+ private boolean reverse = false;
+ /** the comparator in the comparator list to sort by */
+ private int comparatorIndex = -1;
+
+
+ public SortingColumn(TableFormat tableFormat, int column) {
+ this.column = column;
+
+ // add the preferred comparator for AdvancedTableFormat
+ if (tableFormat instanceof AdvancedTableFormat) {
+ AdvancedTableFormat advancedTableFormat = (AdvancedTableFormat) tableFormat;
+ Comparator columnComparator = advancedTableFormat.getColumnComparator(column);
+ if (columnComparator != null)
+ comparators.add(new TableColumnComparator(tableFormat, column, columnComparator));
+ // otherwise just add the default comparator
+ } else {
+ comparators.add(new TableColumnComparator(tableFormat, column));
+ }
+ }
+
+ public void clear() {
+ this.reverse = false;
+ this.comparatorIndex = -1;
+ }
+
+ public int getColumn() {
+ return column;
+ }
+
+ /**
+ * Gets the index of the comparator to use for this column.
+ */
+ public void setComparatorIndex(int comparatorIndex) {
+ assert (comparatorIndex < comparators.size());
+ this.comparatorIndex = comparatorIndex;
+ }
+
+ public int getComparatorIndex() {
+ return comparatorIndex;
+ }
+
+ /**
+ * Gets the list of comparators for this column.
+ */
+ public List<Comparator> getComparators() {
+ return comparators;
+ }
+
+ /**
+ * Gets the current best comparator to sort this column.
+ */
+ public Comparator getComparator() {
+ if (comparatorIndex == -1)
+ return null;
+ Comparator comparator = comparators.get(getComparatorIndex());
+ if (isReverse())
+ comparator = GlazedLists.reverseComparator(comparator);
+ return comparator;
+ }
+
+ /**
+ * Get whether this column is in reverse order.
+ */
+ public boolean isReverse() {
+ return reverse;
+ }
+
+ public void setReverse(boolean reverse) {
+ this.reverse = reverse;
+ }
+
+ /**
+ * Gets the sorting style for this column.
+ */
+ public int getSortingStyle() {
+ if (comparatorIndex == -1)
+ return COLUMN_UNSORTED;
+ boolean primaryColumn = !recentlyClickedColumns.isEmpty() && recentlyClickedColumns.get(0) == this;
+ boolean primaryComparator = getComparatorIndex() == 0;
+
+ if (primaryColumn) {
+ if (!isReverse()) {
+ if (primaryComparator)
+ return COLUMN_PRIMARY_SORTED;
+ else
+ return COLUMN_PRIMARY_SORTED_ALTERNATE;
+ } else {
+ if (primaryComparator)
+ return COLUMN_PRIMARY_SORTED_REVERSE;
+ else
+ return COLUMN_PRIMARY_SORTED_ALTERNATE_REVERSE;
+ }
+ } else {
+ if (!isReverse()) {
+ if (primaryComparator)
+ return COLUMN_SECONDARY_SORTED;
+ else
+ return COLUMN_SECONDARY_SORTED_ALTERNATE;
+ } else {
+ if (primaryComparator)
+ return COLUMN_SECONDARY_SORTED_REVERSE;
+ else
+ return COLUMN_SECONDARY_SORTED_ALTERNATE_REVERSE;
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/SortingStrategy.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/SortingStrategy.java
new file mode 100644
index 00000000000..69fd1a449ec
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/SortingStrategy.java
@@ -0,0 +1,39 @@
+/* Glazed Lists (c) 2003-2006 */
+/* http://publicobject.com/glazedlists/ publicobject.com,*/
+/* O'Dell Engineering Ltd.*/
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+/**
+ * Behaviour that defines how to interpret a mouse click on a table's header.
+ *
+ * <p>
+ * This interface is intentionally stateless so that a single instance can be shared between multiple <code>TableComparatorChooser</code>s.
+ *
+ * <p>
+ * This interface is <strong>not</strong> designed to be implemented by users of <code>TableComparatorChooser</code> and is not guaranteed to be backward compatible between releases. Users are encouraged to use the predefined constant values in
+ * {@link ca.odell.glazedlists.gui.AbstractTableComparatorChooser}.
+ *
+ * @author <a href="mailto:jesse@swank.ca">Jesse Wilson</a>
+ */
+public interface SortingStrategy {
+
+ /**
+ * This method is called each time a user attempts to adjust the sort order
+ * enforced by a <code>TableComparatorChooser</code> by clicking in a table
+ * header. The implementation is expected to adjust the <code>sortingState</code> as necessary and call {@link SortingState#fireSortingChanged()} afterward to honour the new
+ * sorting state.
+ *
+ * @param sortingState
+ * an object which models the details regarding which
+ * columns are enforcing sort order
+ * @param column
+ * the column that was clicked on
+ * @param clicks
+ * the number of recorded mouse clicks
+ * @param shift
+ * <tt>true</tt> if the shift key was down at the time of the click
+ * @param control
+ * <tt>true</tt> if the control key was down at the time of the click
+ */
+ public void columnClicked(SortingState sortingState, int column, int clicks, boolean shift, boolean control);
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/TableColumnComparator.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/TableColumnComparator.java
new file mode 100644
index 00000000000..bfb7935383a
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/glazedlists/copy/TableColumnComparator.java
@@ -0,0 +1,95 @@
+/* Glazed Lists (c) 2003-2006 */
+/* http://publicobject.com/glazedlists/ publicobject.com,*/
+/* O'Dell Engineering Ltd.*/
+package org.eclipse.papyrus.infra.nattable.glazedlists.copy;
+
+import ca.odell.glazedlists.GlazedLists;
+import ca.odell.glazedlists.gui.TableFormat;
+
+import java.util.Comparator;
+
+/**
+ * A comparator that sorts a table by the column that was clicked.
+ */
+public class TableColumnComparator<E> implements Comparator<E> {
+
+ /** the table format knows to map objects to their fields */
+ private TableFormat<? super E> tableFormat;
+
+ /** the field of interest */
+ private int column;
+
+ /** comparison is delegated to a ComparableComparator */
+ private Comparator comparator = null;
+
+ /**
+ * Creates a new TableColumnComparator that sorts objects by the specified
+ * column using the specified table format.
+ */
+ public TableColumnComparator(TableFormat<? super E> tableFormat, int column) {
+ this(tableFormat, column, GlazedLists.comparableComparator());
+ }
+
+ /**
+ * Creates a new TableColumnComparator that sorts objects by the specified
+ * column using the specified table format and the specified comparator.
+ */
+ public TableColumnComparator(TableFormat<? super E> tableFormat, int column, Comparator comparator) {
+ this.column = column;
+ this.tableFormat = tableFormat;
+ this.comparator = comparator;
+ }
+
+ /**
+ * Compares the two objects, returning a result based on how they compare.
+ */
+ public int compare(E alpha, E beta) {
+ final Object alphaField = tableFormat.getColumnValue(alpha, column);
+ final Object betaField = tableFormat.getColumnValue(beta, column);
+ try {
+ return comparator.compare(alphaField, betaField);
+ // throw a 'nicer' exception if the class does not implement Comparable
+ } catch (ClassCastException e) {
+ final IllegalStateException illegalStateException;
+ if (comparator == GlazedLists.comparableComparator()) {
+ illegalStateException = new IllegalStateException("TableComparatorChooser can not sort objects \"" + alphaField + "\", \"" + betaField + "\" that do not implement Comparable.");
+ } else {
+ illegalStateException = new IllegalStateException("TableComparatorChooser can not sort objects \"" + alphaField + "\", \"" + betaField + "\" using the provided Comparator.");
+ }
+ illegalStateException.initCause(e);
+ throw illegalStateException;
+ }
+ }
+
+ /**
+ * Test if this TableColumnComparator is equal to the other specified
+ * TableColumnComparator.
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ final TableColumnComparator that = (TableColumnComparator) o;
+
+ if (column != that.column)
+ return false;
+ if (!comparator.equals(that.comparator))
+ return false;
+ if (!tableFormat.equals(that.tableFormat))
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result;
+ result = tableFormat.hashCode();
+ result = 29 * result + column;
+ result = 29 * result + comparator.hashCode();
+ return result;
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layerstack/ColumnHeaderLayerStack.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layerstack/ColumnHeaderLayerStack.java
index a85f3e926f2..84ac4e5de32 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layerstack/ColumnHeaderLayerStack.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layerstack/ColumnHeaderLayerStack.java
@@ -1,117 +1,156 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.layerstack;
-
-
-
-import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
-import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
-import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
-import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
-import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
-import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
-import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
-import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
-import org.eclipse.papyrus.infra.nattable.configuration.PapyrusColumnHeaderStyleConfiguration;
-import org.eclipse.papyrus.infra.nattable.configuration.PapyrusColumnResizeBindingsConfiguration;
-import org.eclipse.papyrus.infra.nattable.dataprovider.BodyDataProvider;
-import org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel;
-import org.eclipse.papyrus.infra.nattable.utils.DefaultSizeUtils;
-
-/**
- *
- * @author vl222926
- *
- */
-public class ColumnHeaderLayerStack extends AbstractLayerTransform {
-
-
- DataLayer indexDataLayer;
-
- DataLayer labelDataLayer;
-
- /**
- *
- * Constructor.
- *
- * @param dataProvider
- * @param bodyLayer
- * @param bodyDataProvider
- */
- @Deprecated
- public ColumnHeaderLayerStack(final IDataProvider dataProvider, final BodyLayerStack bodyLayer, final BodyDataProvider bodyDataProvider, final IPapyrusSortModel sortModel) {
- DataLayer dataLayer = new DataLayer(dataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
- ColumnHeaderLayer colHeaderLayer = new ColumnHeaderLayer(dataLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
- colHeaderLayer.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
- colHeaderLayer.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
- SortHeaderLayer<ISortModel> sortHeaderLayer = new SortHeaderLayer<ISortModel>(colHeaderLayer, sortModel, false);
-
- setUnderlyingLayer(sortHeaderLayer);
- setRegionName(GridRegion.COLUMN_HEADER);
- }
-
-
- /**
- *
- * Constructor.
- *
- * @param indexDataProvider
- * the index data provider
- * @param labelDataProvider
- * the label data provider
- * @param bodyLayer
- * the body layer
- */
- public ColumnHeaderLayerStack(final IDataProvider indexDataProvider, final IDataProvider labelDataProvider, final BodyLayerStack bodyLayer, final IPapyrusSortModel sortModel) {
- // 1. create the index row layer
- final DataLayer dataLayer = new DataLayer(indexDataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
- indexDataLayer = dataLayer;
- ColumnHeaderLayer indexHeader = new ColumnHeaderLayer(dataLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
-
- // 2. create a composite layer to be able to have several columns in row header + add label header
- final CompositeLayer compositeLayer = new CompositeLayer(1, 2);
- compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, indexHeader, 0, 0);
-
- final DataLayer labelLayer = new DataLayer(labelDataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
- labelDataLayer = labelLayer;
- final ColumnHeaderLayer labelHeaderLayer = new ColumnHeaderLayer(labelLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
- labelHeaderLayer.setRegionName(GridRegion.ROW_HEADER);
-
- compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, labelHeaderLayer, 0, 1);
-
-
- // 3. configure the layer
- indexHeader.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
- indexHeader.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
-
-
- compositeLayer.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
- compositeLayer.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
-
- SortHeaderLayer<ISortModel> sortHeaderLayer = new SortHeaderLayer<ISortModel>(compositeLayer, sortModel, false);
-
- setUnderlyingLayer(sortHeaderLayer);
- setRegionName(GridRegion.COLUMN_HEADER);
- }
-
-
- public DataLayer getColumnIndexDataLayer() {
- return indexDataLayer;
- }
-
- public DataLayer getColumnLabelDataLayer() {
- return labelDataLayer;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.layerstack;
+
+
+
+import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
+import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
+import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
+import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
+import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
+import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
+import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
+import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
+import org.eclipse.papyrus.infra.nattable.configuration.PapyrusColumnHeaderStyleConfiguration;
+import org.eclipse.papyrus.infra.nattable.configuration.PapyrusColumnResizeBindingsConfiguration;
+import org.eclipse.papyrus.infra.nattable.dataprovider.BodyDataProvider;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel;
+import org.eclipse.papyrus.infra.nattable.sort.PapyrusCompositeGlazedListSortModel;
+import org.eclipse.papyrus.infra.nattable.sort.PapyrusGlazedListsSortModel;
+import org.eclipse.papyrus.infra.nattable.utils.DefaultSizeUtils;
+
+/**
+ *
+ * @author vl222926
+ *
+ */
+public class ColumnHeaderLayerStack extends AbstractLayerTransform {
+
+
+ DataLayer indexDataLayer;
+
+ DataLayer labelDataLayer;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param dataProvider
+ * @param bodyLayer
+ * @param bodyDataProvider
+ */
+ @Deprecated
+ public ColumnHeaderLayerStack(final IDataProvider dataProvider, final BodyLayerStack bodyLayer, final BodyDataProvider bodyDataProvider, final IPapyrusSortModel sortModel) {
+ DataLayer dataLayer = new DataLayer(dataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
+ ColumnHeaderLayer colHeaderLayer = new ColumnHeaderLayer(dataLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
+ colHeaderLayer.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
+ colHeaderLayer.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
+ SortHeaderLayer<ISortModel> sortHeaderLayer = new SortHeaderLayer<ISortModel>(colHeaderLayer, sortModel, false);
+
+ setUnderlyingLayer(sortHeaderLayer);
+ setRegionName(GridRegion.COLUMN_HEADER);
+ }
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param indexDataProvider
+ * the index data provider
+ * @param labelDataProvider
+ * the label data provider
+ * @param bodyLayer
+ * the body layer
+ */
+ public ColumnHeaderLayerStack(final IDataProvider indexDataProvider, final IDataProvider labelDataProvider, final BodyLayerStack bodyLayer, final IPapyrusSortModel sortModel) {
+ // 1. create the index row layer
+ final DataLayer dataLayer = new DataLayer(indexDataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
+ indexDataLayer = dataLayer;
+ ColumnHeaderLayer indexHeader = new ColumnHeaderLayer(dataLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
+
+ // 2. create a composite layer to be able to have several columns in row header + add label header
+ final CompositeLayer compositeLayer = new CompositeLayer(1, 2);
+ compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, indexHeader, 0, 0);
+
+ final DataLayer labelLayer = new DataLayer(labelDataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
+ labelDataLayer = labelLayer;
+ final ColumnHeaderLayer labelHeaderLayer = new ColumnHeaderLayer(labelLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
+ labelHeaderLayer.setRegionName(GridRegion.ROW_HEADER);
+
+ compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, labelHeaderLayer, 0, 1);
+
+
+ // 3. configure the layer
+ indexHeader.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
+ indexHeader.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
+
+
+ compositeLayer.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
+ compositeLayer.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
+
+ SortHeaderLayer<ISortModel> sortHeaderLayer = new SortHeaderLayer<ISortModel>(compositeLayer, sortModel, false);
+
+ setUnderlyingLayer(sortHeaderLayer);
+ setRegionName(GridRegion.COLUMN_HEADER);
+ }
+
+ // TODO, remove arg sortModel ?
+
+ // TODO : add IConfigRegistry ?
+ public ColumnHeaderLayerStack(final INattableModelManager manager, final IDataProvider indexDataProvider, final IDataProvider labelDataProvider, final BodyLayerStack bodyLayer, final IPapyrusSortModel sortModel) {
+ // 1. create the index row layer
+ final DataLayer dataLayer = new DataLayer(indexDataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
+ indexDataLayer = dataLayer;
+ ColumnHeaderLayer indexHeader = new ColumnHeaderLayer(dataLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
+
+ // 2. create a composite layer to be able to have several columns in row header + add label header
+ final CompositeLayer compositeLayer = new CompositeLayer(1, 2);
+ compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, indexHeader, 0, 0);
+
+ final DataLayer labelLayer = new DataLayer(labelDataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
+ labelDataLayer = labelLayer;
+ final ColumnHeaderLayer labelHeaderLayer = new ColumnHeaderLayer(labelLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
+ labelHeaderLayer.setRegionName(GridRegion.ROW_HEADER);
+
+ compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, labelHeaderLayer, 0, 1);
+
+
+ // 3. configure the layer
+ indexHeader.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
+ indexHeader.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
+
+
+ compositeLayer.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
+ compositeLayer.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
+
+ ((PapyrusCompositeGlazedListSortModel)sortModel).setColumnHeaderLayer(compositeLayer);
+ SortHeaderLayer<ISortModel> sortHeaderLayer = new SortHeaderLayer<ISortModel>(compositeLayer, sortModel, false);
+
+ setUnderlyingLayer(sortHeaderLayer);
+ setRegionName(GridRegion.COLUMN_HEADER);
+ }
+
+
+ public DataLayer getColumnIndexDataLayer() {
+ return indexDataLayer;
+ }
+
+ public DataLayer getColumnLabelDataLayer() {
+ return labelDataLayer;
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java
index dc5e75c1203..3e10db4ae19 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java
@@ -83,6 +83,8 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
*/
protected List<TreeFillingConfiguration> currentFillingConfiguration;
+ protected ITreeItemAxisComparator comparator;
+
/**
* @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#init(org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager, org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation,
* org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider)
@@ -95,6 +97,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
public void init(INattableModelManager manager, AxisManagerRepresentation rep, AbstractAxisProvider provider) {
super.init(manager, rep, provider);
this.currentFillingConfiguration = FillingConfigurationUtils.getTreeFillingConfiguration(getTable(), representedAxisManager);
+ this.comparator = new ITreeItemAxisComparator(this.tableManager, this);
}
/**
@@ -114,7 +117,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
* @param objectToAdd
* the object to add as child of the parent axis
* @return
- * the created {@link ITreeItemAxis} representing objectToAdd
+ * the created {@link ITreeItemAxis} representing objectToAdd
*/
protected final ITreeItemAxis addObject(final ITreeItemAxis parentAxis, final Object objectToAdd) {
final ITreeItemAxis newAxis = createITreeItemAxis(parentAxis, objectToAdd);
@@ -127,15 +130,15 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
try {
- if(null != getTableEditingDomain()){
+ if (null != getTableEditingDomain()) {
GMFUnsafe.write(getTableEditingDomain(), new Runnable() {
-
+
@Override
public void run() {
newAxis.setExpanded(true);
}
});
- }else{
+ } else {
newAxis.setExpanded(true);
}
} catch (InterruptedException e) {
@@ -158,7 +161,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
* TODO : find a better way to get the tree layer
*
* @return
- * the tree layer
+ * the tree layer
*/
private TreeLayer getTreeLayer() {
NatTable natTable = (NatTable) getTableManager().getAdapter(NatTable.class);
@@ -177,7 +180,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
* @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsColumnManager()
*
* @return
- * always false
+ * always false
*/
@Override
public boolean canBeUsedAsColumnManager() {
@@ -236,52 +239,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
*/
@Override
public int compare(ISortModel sortModel, int depth, ITreeItemAxis axis1, ITreeItemAxis axis2) {
- if (axis1 == axis2) {
- return 0;
- }
- if (axis1.getParent() != axis2.getParent()) {
- Activator.log.warn("There is probably a bug, we are comparing 2 elements from differents level in the tree"); //$NON-NLS-1$
- return 0;
- }
- Object el1 = axis1.getElement();
- Object el2 = axis2.getElement();
- int index1 = -2;
- int index2 = -2;
-
- // we are comparing 2 filling configurations
- if (el1 instanceof TreeFillingConfiguration) {
- Assert.isTrue(el2 instanceof TreeFillingConfiguration);
- final List<TreeFillingConfiguration> confs = FillingConfigurationUtils.getTreeFillingConfiguration(getTable(), representedAxisManager);
-
- index1 = confs.indexOf(el1);
- index2 = confs.indexOf(el2);
- } else {// we must compare values
- // parent1 and parent2 are axis representing filling configuration
- ITreeItemAxis parent1 = axis1.getParent();
- if (parent1 == null) {
- // its root element, filled by DnD
- List<IAxis> axis = getRepresentedContentProvider().getAxis();
- index1 = axis.indexOf(axis1);
- index2 = axis.indexOf(axis2);
- } else {
- TreeFillingConfiguration conf = (TreeFillingConfiguration) parent1.getElement();
- ITreeItemAxis grandFather1 = parent1.getParent();
- Object context = null;
- if (grandFather1 == null) {
- context = getTableContext();
- } else {
- context = grandFather1.getElement();
- }
- Collection<?> values = getCellValueAsCollection(conf.getAxisUsedAsAxisProvider(), context);
- if (values instanceof List<?>) {
- index1 = ((List<?>) values).indexOf(axis1.getElement());
- index2 = ((List<?>) values).indexOf(axis2.getElement());
- }
- }
- }
-
- int res = index1 - index2;
- return Integer.signum(res);
+ return this.comparator.compare(axis1, axis2);
}
/**
@@ -291,7 +249,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
* @param objectToAdd
* the object to add
* @return
- * the ITreeItemAxis created to represents this object
+ * the ITreeItemAxis created to represents this object
*/
protected abstract ITreeItemAxis createITreeItemAxis(ITreeItemAxis parentAxis, Object objectToAdd);
@@ -410,35 +368,27 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
fillChildrenForSemanticElement(null);
}
+
/**
*
* @param iaxis
* @param rowElement
* the element
* @return
- * a collection of all values for the intersection of the iaxis and the row element. These values are not yet filtered by the method {@link #isAllowedContents(Object, Object, TreeFillingConfiguration, int)}
+ * a collection of all values for the intersection of the iaxis and the row element. These values are not yet filtered by the method {@link #isAllowedContents(Object, Object, TreeFillingConfiguration, int)}
+ *
+ * @deprecated : use directly CellManagerFactory.INSTANCE.getCrossValueAsCollection(iaxis, rowElement, this.tableManager);
*/
+ @Deprecated
protected final Collection<?> getCellValueAsCollection(final Object iaxis, final Object rowElement) {
- Object value = CellManagerFactory.INSTANCE.getCrossValue(iaxis, rowElement, this.tableManager);
- Collection<?> collection = Collections.emptyList();
-
- if (value instanceof Collection<?>) {
- collection = (Collection<?>) value;
- } else if (value instanceof Object[]) {
- collection = Arrays.asList(value);
- } else if (value != null) {
- collection = Collections.singletonList(value);
- }
-
- return collection;
+ return CellManagerFactory.INSTANCE.getCrossValueAsCollection(iaxis, rowElement, this.tableManager);
}
-
/**
*
* @param axis
* an object
* @return
- * the depth of the axis
+ * the depth of the axis
*/
protected int getDepth(final ITreeItemAxis axis) {
final INattableModelManager manager = getTableManager();
@@ -457,7 +407,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
* @param depth
* the depth of the new element
* @return
- * a collection with all values accepted as children of the rowElement. Returned values have been filtered by the method {@link #isAllowedContents(Object, Object, TreeFillingConfiguration, int)}
+ * a collection with all values accepted as children of the rowElement. Returned values have been filtered by the method {@link #isAllowedContents(Object, Object, TreeFillingConfiguration, int)}
*/
protected final Collection<?> getFilteredValueAsCollection(final TreeFillingConfiguration conf, final Object rowElement, final int depth) {
Collection<?> values = getCellValueAsCollection(conf.getAxisUsedAsAxisProvider(), rowElement);
@@ -476,7 +426,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
* @param axis
* an axis
* @return
- * the real depth of an element (semantic or {@link TreeFillingConfiguration}), that is to say than for {@link TreeFillingConfiguration} we return {@link TreeFillingConfiguration#getDepth()} and for a semantic element
+ * the real depth of an element (semantic or {@link TreeFillingConfiguration}), that is to say than for {@link TreeFillingConfiguration} we return {@link TreeFillingConfiguration#getDepth()} and for a semantic element
* we returns the depth of the {@link TreeFillingConfiguration} parent of the {@link ITreeItemAxis} represented it.
*/
public final int getSemanticDepth(final ITreeItemAxis axis) {
@@ -692,7 +642,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
* @param object
* the element
* @return
- * the {@link ITreeItemAxis} representing this element or <code>null</code> if not found
+ * the {@link ITreeItemAxis} representing this element or <code>null</code> if not found
*/
public static final ITreeItemAxis getITreeItemAxisRepresentingObject(final Collection<ITreeItemAxis> possibleRepresentation, Object object) {
for (ITreeItemAxis axis : possibleRepresentation) {
@@ -1168,7 +1118,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa
/**
*
* @return
- * the row hide show layer
+ * the row hide show layer
*/
protected final RowHideShowLayer getRowHideShowLayer() {
if (this.tableManager != null && this.tableManager.getBodyLayerStack() != null) {
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManager.java
index 7860fdc3226..823156ca004 100644..100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManager.java
@@ -1,791 +1,811 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.manager.axis;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.TreeMap;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.common.command.UnexecutableCommand;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.edit.command.MoveCommand;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
-import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.nattable.messages.Messages;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
-import org.eclipse.papyrus.infra.nattable.utils.AxisComparator;
-import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.infra.widgets.providers.CompoundFilteredRestrictedContentProvider;
-import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider;
-
-/**
- * This axis manager allows to encapsulated others axis manager. It allows to manage the contents of the table.
- * When this contents is stored in the table metamodel, It is able to manage the Add/Remove and Move elements in the list of the displayed elements
- *
- * @author VL222926
- *
- */
-public class CompositeAxisManager extends AbstractAxisManager implements ICompositeAxisManager {
-
- /**
- * the id of this manager
- */
- @SuppressWarnings("unused")
- private static final String MANAGER_ID = "org.eclipse.papyrus.infra.nattable.composite.axis.manager"; //$NON-NLS-1$
-
- /**
- * the sub managers
- */
- protected List<IAxisManager> subManagers;
-
- /**
- * the comparator used to sort the axis
- */
- protected Comparator<Object> axisComparator;
-
- /**
- *
- * @param notification
- * the notification
- */
- @Override
- protected void axisManagerHasChanged(final Notification notification) {
- if (notification.isTouch()) {
- return;
- }
- final List<Object> newListValue = new ArrayList<Object>(this.managedObject);
- boolean needRefresh = false;
- int eventType = notification.getEventType();
- switch (eventType) {
- case Notification.ADD:
- final Object addedValue = notification.getNewValue();
- final int index = notification.getPosition();
-
- newListValue.add(index, addedValue);
- needRefresh = true;
- break;
- case Notification.ADD_MANY:
- final Collection<?> addedValues = (Collection<?>) notification.getNewValue();
- // final int lisIndex = notification.getPosition();
- newListValue.addAll(addedValues);
- needRefresh = true;
- break;
- case Notification.EVENT_TYPE_COUNT:
- break;
- case Notification.MOVE:
- final Object movedObject = notification.getNewValue();
- final int newPos = notification.getPosition();
- newListValue.remove(movedObject);
- newListValue.add(newPos, movedObject);
- needRefresh = true;
- break;
- case Notification.REMOVE:
- final Object removedObject = notification.getOldValue();
- newListValue.remove(removedObject);
- needRefresh = true;
- break;
- case Notification.REMOVE_MANY:
- final Collection<?> removedValues = (Collection<?>) notification.getOldValue();
- newListValue.removeAll(removedValues);
- needRefresh = true;
- break;
- case Notification.REMOVING_ADAPTER:
- break;
- case Notification.RESOLVE:
- break;
- case Notification.SET:
- break;
- case Notification.UNSET:
- break;
- default:
- break;
- }
- if (needRefresh) {
- this.managedObject.clear();
- this.managedObject.addAll(newListValue);
- newListValue.clear();
- getTableManager().updateAxisContents(getRepresentedContentProvider());
- }
-
- }
-
-
- /**
- * Initialize the list of the managed elements which are owned by the model
- */
- @Override
- protected void initializeManagedObjectList() {
- for (final IAxis current : getRepresentedContentProvider().getAxis()) {
- this.managedObject.add(current);
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#setSubAxisManager(java.util.List)
- *
- * @param managers
- */
- @Override
- public void setSubAxisManager(final List<IAxisManager> managers) {
- this.subManagers = managers;
- updateAxisContents();
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#dispose()
- *
- */
- @Override
- public void dispose() {
- super.dispose();
- for (final IAxisManager current : this.subManagers) {
- current.dispose();
- }
- this.subManagers.clear();
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsRowManager()
- *
- * @return
- */
- @Override
- public boolean canBeUsedAsRowManager() {
- boolean answer = true;
- final Iterator<IAxisManager> iter = this.subManagers.iterator();
- while (iter.hasNext() && answer) {
- answer = iter.next().canBeUsedAsRowManager();
- }
- return answer;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsColumnManager()
- *
- * @return
- */
- @Override
- public boolean canBeUsedAsColumnManager() {
- boolean answer = true;
- final Iterator<IAxisManager> iter = this.subManagers.iterator();
- while (iter.hasNext() && answer) {
- answer = iter.next().canBeUsedAsColumnManager();
- }
- return answer;
- }
-
- @Override
- public boolean canCreateAxisElement(String elementId) {
- boolean canCreateAxisElement = false;
- for (IAxisManager manager : subManagers) {
- canCreateAxisElement |= manager.canCreateAxisElement(elementId);
- }
- return canCreateAxisElement;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_AddAxisCommand);
- for (final IAxisManager current : this.subManagers) {
- final Command tmp = current.getAddAxisCommand(domain, objectToAdd);
- if (tmp != null) {
- cmd.append(tmp);
- }
- }
- if (cmd.isEmpty()) {
- return null;
- }
- return cmd;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_AddAxisCommand);
- for (final IAxisManager current : this.subManagers) {
- final Command tmp = current.getComplementaryAddAxisCommand(domain, objectToAdd);
- if (tmp != null) {
- cmd.append(tmp);
- }
- }
- if (cmd.isEmpty()) {
- return null;
- }
- return cmd;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#updateAxisContents()
- *
- */
- @Override
- public synchronized void updateAxisContents() {
- final List<Object> displayedElement = getElements();
- synchronized (displayedElement) {
- displayedElement.clear();
- displayedElement.addAll(this.managedObject);
- if (this.subManagers != null) {
- for (final IAxisManager current : this.subManagers) {
- if (current.isDynamic()) {
- displayedElement.addAll(current.getAllManagedAxis());
- }
- }
- }
- if (this.axisComparator != null) {
- Collections.sort(displayedElement, this.axisComparator);
- } else {
-
- }
- }
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAllowedContents(java.lang.Object)
- *
- * @param object
- * @return
- */
- @Override
- public boolean isAllowedContents(Object object) {
- for (final IAxisManager current : this.subManagers) {
- if (current.isAllowedContents(object)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canMoveAxis()
- *
- * @return
- */
- @Override
- public boolean canMoveAxis() {
- for (final IAxisManager current : this.subManagers) {
- if (!current.canMoveAxis() || current.isDynamic()) {
- return false;
- }
- }
- return true;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#sortAxisByName(boolean, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
- *
- * @param inverted
- * @param configRegistry
- */
- @Override
- public void sortAxisByName(boolean alphabeticOrder, final IConfigRegistry configRegistry) {
- if (canMoveAxis()) {
- final List<IAxis> axis = new ArrayList<IAxis>(getRepresentedContentProvider().getAxis());
- Collections.sort(axis, new AxisComparator(alphabeticOrder, configRegistry));
- final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(getRepresentedContentProvider());
- final AbstractEditCommandRequest request = new SetRequest(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), axis);
- final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getRepresentedContentProvider());
- final ICommand cmd = provider.getEditCommand(request);
- domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
- }
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#createPossibleAxisContentProvider(boolean)
- *
- * @param isRestricted
- * @return a contents provider for this axis or <code>null</code> if it is not allowed
- */
- @Override
- public IRestrictedContentProvider createPossibleAxisContentProvider(boolean isRestricted) {
-
- CompoundFilteredRestrictedContentProvider compoundContentProvider = null;
- for (final IAxisManager current : this.subManagers) {
- IRestrictedContentProvider contentProvider = current.createPossibleAxisContentProvider(isRestricted);
- if (contentProvider != null) {
- if (compoundContentProvider == null) {
- compoundContentProvider = new CompoundFilteredRestrictedContentProvider();
- }
- compoundContentProvider.add(contentProvider);
- }
- }
- return compoundContentProvider;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getDestroyAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToDestroy
- * @return
- */
- @Override
- public Command getDestroyAxisCommand(TransactionalEditingDomain domain, Collection<Object> objectToDestroy) {
- final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_DestroyAxisCommand);
- for (final IAxisManager current : this.subManagers) {
- final Command tmp = current.getDestroyAxisCommand(domain, objectToDestroy);
- if (tmp != null) {
- cmd.append(tmp);
- }
- }
- if (cmd.isEmpty()) {
- return null;
- }
- return cmd;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAllManagedAxis()
- *
- * @return
- */
- @Override
- public List<Object> getAllManagedAxis() {
- initializeManagedObjectList();
- final List<Object> allExistingAxis = new ArrayList<Object>();
- for (IAxisManager manager : this.subManagers) {
- Collection<Object> managerPossibleElements = manager.getAllManagedAxis();
- if (managerPossibleElements != null) {
- allExistingAxis.addAll(managerPossibleElements);
- }
- }
- return allExistingAxis;
- }
-
- /**
- *
- * @param resolve
- * if <code>true</code> the path will be resolved
- * @return
- * a list with the managed objects
- */
- public List<Object> getAllManagedAxis(final boolean resolve) {
- final List<Object> allExistingAxis = new ArrayList<Object>();
- for (final IAxis current : getRepresentedContentProvider().getAxis()) {
- Object representedElement = AxisUtils.getRepresentedElement(current);
- if (resolve && current instanceof IdAxis) {
- representedElement = getResolvedPath((IdAxis) current);
- }
- allExistingAxis.add(representedElement);
- }
- for (IAxisManager manager : this.subManagers) {
- if (manager.isDynamic()) {
- final List<Object> managerPossibleElements = manager.getAllManagedAxis();
- if (managerPossibleElements != null) {
- allExistingAxis.addAll(managerPossibleElements);
- }
- }
- }
- return allExistingAxis;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave()
- *
- * @return
- * <code>true</code> if one of the encapsulated manager is a slave
- */
- @Override
- public boolean isSlave() {
- for (final IAxisManager manager : this.subManagers) {
- if (manager.isSlave()) {
- return true;
- }
- }
- return false;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isDynamic()
- *
- * @return
- * <code>true</code> if one of the embedded axis manager is dynamic
- */
- @Override
- public boolean isDynamic() {
- for (final IAxisManager manager : this.subManagers) {
- if (manager.isDynamic()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canDropAxisElement(java.util.Collection)
- *
- * @param objectsToAdd
- * @return
- */
- @Override
- public boolean canDropAxisElement(Collection<Object> objectsToAdd) {
- for (final IAxisManager current : this.subManagers) {
- if (current.canDropAxisElement(objectsToAdd)) {
- return true;
- }
- }
- return false;
- }
-
-
- /**
- *
- * @param elementToMove
- * @param newIndex
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#moveAxis(java.lang.Object, int)
- */
- @Override
- public void moveAxis(Object elementToMove, int newIndex) {
- if (!isDynamic() && elementToMove instanceof IAxis) {
- TransactionalEditingDomain domain = getTableEditingDomain();
- final Command command = MoveCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), elementToMove, newIndex);
- if(null != domain){
- domain.getCommandStack().execute(command);
- }else{
- command.execute();
- }
- }
- }
-
- @Override
- public boolean canEditAxisHeader(final NatEventData axisIndex) {
- axisIndex.getColumnPosition();// TODO
- if (canEditAxisHeader()) {// TODO
- return true;
- } else {
- return false;// TODO : we need to iterate on the contents to know if it is possible or not
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canEditAxisHeader()
- *
- * @return
- */
- @Override
- public boolean canEditAxisHeader() {
- for (final IAxisManager current : this.subManagers) {
- if (!current.canEditAxisHeader()) {
- return false;
- }
- }
- return true;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
- *
- * @param axis
- * @return
- */
- @Override
- public String getElementAxisName(final IAxis axis) {
- final AxisManagerRepresentation manager = axis.getManager();
- for (final IAxisManager man : this.subManagers) {
- if (man.getAxisManagerRepresentation() == manager) {
- return man.getElementAxisName(axis);
- }
- }
- if (canEditAxisHeader()) {
- return null;
- } else {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- *
- * @param axis
- * an axis
- * @return
- * the axis manager managing this axis
- */
- protected IAxisManager getAxisManager(final IAxis axis) {
- final AxisManagerRepresentation rep = axis.getManager();
- for (final IAxisManager man : this.subManagers) {
- if (man.getAxisManagerRepresentation() == rep) {
- return man;
- }
- }
- return null;// must be impossible
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canDestroyAxis(java.lang.Integer)
- *
- * @param axisPosition
- * @return
- */
- @Override
- public boolean canDestroyAxis(final Integer axisPosition) {
- final List<Object> elements = getElements();
- final Object element = elements.get(axisPosition);
- if (element instanceof IAxis) {
- return getAxisManager((IAxis) element).canDestroyAxis(axisPosition);
- }
- // not yet managed
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer)
- *
- * @param axisPosition
- * @return
- */
- @Override
- public boolean canDestroyAxisElement(Integer axisPosition) {
- final List<Object> elements = getElements();
- final Object element = elements.get(axisPosition);
- if (element instanceof IAxis) {
- return getAxisManager((IAxis) element).canDestroyAxisElement(axisPosition);
- } else if (subManagers.size() == 1) {
- return subManagers.get(0).canDestroyAxisElement(axisPosition);
- }
- // not yet managed
- return false;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(TransactionalEditingDomain, java.lang.Integer)
- *
- * @param domain
- * @param axisPosition
- * @return
- */
- @Override
- public Command getDestroyAxisElementCommand(TransactionalEditingDomain domain, Integer axisPosition) {
- final List<Object> elements = getElements();
- final Object element = elements.get(axisPosition);
- if (element instanceof IAxis) {
- return getAxisManager((IAxis) element).getDestroyAxisElementCommand(domain, axisPosition);
- } else if (subManagers.size() == 1) {
- return subManagers.get(0).getDestroyAxisElementCommand(domain, axisPosition);
- }
- // not yet managed
- return UnexecutableCommand.INSTANCE;
- }
-
- @Override
- public boolean canBeSavedAsConfig() {
- boolean canBeSavedAsConfig = true;
- for (IAxisManager manager : subManagers) {
- canBeSavedAsConfig &= manager.canBeSavedAsConfig();
- }
- return canBeSavedAsConfig;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAdapter(java.lang.Class)
- *
- * @param adapter
- * @return
- */
- @Override
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- for (final IAxisManager current : this.subManagers) {
- if (current.getClass() == adapter) {
- return current;
- }
- }
- return super.getAdapter(adapter);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#isInSortedState()
- *
- * @return
- */
- @Override
- public boolean isInSortedState() {
- return this.axisComparator != null;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#setAxisComparator(java.util.Comparator)
- *
- * @param comp
- */
- @Override
- public void setAxisComparator(final Comparator<Object> comp) {
- this.axisComparator = comp;
- if (this.axisComparator != null) {
- List<Object> displayedElement = getElements();
- synchronized (displayedElement) {
- Collections.sort(displayedElement, comp);
- getTableManager().refreshNatTable();// useful?
- }
- } else {
- getTableManager().updateAxisContents(getRepresentedContentProvider());
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAlreadyManaged(java.lang.Object)
- *
- * @param object
- * @return
- */
- @Override
- public boolean isAlreadyManaged(final Object object) {
- for (final IAxisManager current : this.subManagers) {
- if (current.isAlreadyManaged(object)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#getSetNewAxisOrderCommand(java.util.List)
- *
- * @param newOrder
- * @return
- */
- @Override
- public Command getSetNewAxisOrderCommand(final List<Object> newOrder) {
- if (canMoveAxis() && !isDynamic()) {
- return new RecordingCommand(getTableEditingDomain()) {
-
- @Override
- protected void doExecute() {
- final TreeMap<Integer, IAxis> order = new TreeMap<Integer, IAxis>();
- final AbstractAxisProvider provider = getRepresentedContentProvider();
- for (int i = 0; i < provider.getAxis().size(); i++) {
- final IAxis currentAxis = provider.getAxis().get(i);
- int index = newOrder.indexOf(currentAxis);
- if (index != -1) {
- order.put(Integer.valueOf(index), currentAxis);
- } else {
- Object resolvedObject = AxisUtils.getRepresentedElement(currentAxis);
- if (currentAxis instanceof IdAxis) {
- resolvedObject = getResolvedPath((IdAxis) currentAxis);
- }
- index = newOrder.indexOf(resolvedObject);
- if (index == -1) {
- throw new IndexOutOfBoundsException("A reordered element can't be resolved"); //$NON-NLS-1$
- }
- order.put(Integer.valueOf(index), currentAxis);
- }
- }
-
- final List<IAxis> newValues = new ArrayList<IAxis>();
- newValues.addAll(order.values());
- SetCommand.create(getTableEditingDomain(), provider, NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), newValues).execute();
- }
- };
- }
- return null;
- }
-
- /**
- *
- * @param axisManagerId
- * an axis
- * @return
- * the axis manager managing it
- */
- protected IAxisManager findAxisManager(final IAxis axis) {
- final String axisManagerId = axis.getManager().getAxisManagerId();
- for (final IAxisManager currentManager : this.subManagers) {
- if (currentManager.getAxisManagerRepresentation().getAxisManagerId().equals(axisManagerId)) {
- return currentManager;
- }
- }
- return null;
- }
-
- /**
- *
- * @param idAxis
- * an idAxis
- * @return
- * the resolved path or the {@link String} represented by the idAxis if the path can't be resolved
- */
- protected Object getResolvedPath(final IdAxis idAxis) {
- final String path = idAxis.getElement();
- final IAxisManager manager = findAxisManager(idAxis);
- if (manager instanceof IIdAxisManager) {
- final Object resolvedElement = ((IIdAxisManager) manager).resolvedPath(path);
- if (resolvedElement != null) {
- return resolvedElement;
- }
- }
- return path;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.manager.axis;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TreeMap;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.edit.command.MoveCommand;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.nattable.messages.Messages;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
+import org.eclipse.papyrus.infra.nattable.utils.AxisComparator;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.widgets.providers.CompoundFilteredRestrictedContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider;
+
+/**
+ * This axis manager allows to encapsulated others axis manager. It allows to manage the contents of the table.
+ * When this contents is stored in the table metamodel, It is able to manage the Add/Remove and Move elements in the list of the displayed elements
+ *
+ * @author VL222926
+ *
+ */
+public class CompositeAxisManager extends AbstractAxisManager implements ICompositeAxisManager {
+
+ /**
+ * the id of this manager
+ */
+ @SuppressWarnings("unused")
+ private static final String MANAGER_ID = "org.eclipse.papyrus.infra.nattable.composite.axis.manager"; //$NON-NLS-1$
+
+ /**
+ * the sub managers
+ */
+ protected List<IAxisManager> subManagers;
+
+ /**
+ * the comparator used to sort the axis
+ */
+ protected Comparator<Object> axisComparator;
+
+ /**
+ *
+ * @param notification
+ * the notification
+ */
+ @Override
+ protected void axisManagerHasChanged(final Notification notification) {
+ if (notification.isTouch()) {
+ return;
+ }
+ final List<Object> newListValue = new ArrayList<Object>(this.managedObject);
+ boolean needRefresh = false;
+ int eventType = notification.getEventType();
+ switch (eventType) {
+ case Notification.ADD:
+ final Object addedValue = notification.getNewValue();
+ final int index = notification.getPosition();
+
+ newListValue.add(index, addedValue);
+ needRefresh = true;
+ break;
+ case Notification.ADD_MANY:
+ final Collection<?> addedValues = (Collection<?>) notification.getNewValue();
+ // final int lisIndex = notification.getPosition();
+ newListValue.addAll(addedValues);
+ needRefresh = true;
+ break;
+ case Notification.EVENT_TYPE_COUNT:
+ break;
+ case Notification.MOVE:
+ final Object movedObject = notification.getNewValue();
+ final int newPos = notification.getPosition();
+ newListValue.remove(movedObject);
+ newListValue.add(newPos, movedObject);
+ needRefresh = true;
+ break;
+ case Notification.REMOVE:
+ final Object removedObject = notification.getOldValue();
+ newListValue.remove(removedObject);
+ needRefresh = true;
+ break;
+ case Notification.REMOVE_MANY:
+ final Collection<?> removedValues = (Collection<?>) notification.getOldValue();
+ newListValue.removeAll(removedValues);
+ needRefresh = true;
+ break;
+ case Notification.REMOVING_ADAPTER:
+ break;
+ case Notification.RESOLVE:
+ break;
+ case Notification.SET:
+ break;
+ case Notification.UNSET:
+ break;
+ // case Notification.NO_FEATURE_ID:
+ // break;
+ // case Notification.NO_INDEX:
+ // break;
+ default:
+ break;
+ }
+ if (needRefresh) {
+ this.managedObject.clear();
+ this.managedObject.addAll(newListValue);
+ newListValue.clear();
+ getTableManager().updateAxisContents(getRepresentedContentProvider());
+ }
+
+ }
+
+
+ /**
+ * Initialize the list of the managed elements which are owned by the model
+ */
+ @Override
+ protected void initializeManagedObjectList() {
+ for (final IAxis current : getRepresentedContentProvider().getAxis()) {
+ this.managedObject.add(current);
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#setSubAxisManager(java.util.List)
+ *
+ * @param managers
+ */
+ @Override
+ public void setSubAxisManager(final List<IAxisManager> managers) {
+ this.subManagers = managers;
+ updateAxisContents();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ for (final IAxisManager current : this.subManagers) {
+ current.dispose();
+ }
+ this.subManagers.clear();
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsRowManager()
+ *
+ * @return
+ */
+ @Override
+ public boolean canBeUsedAsRowManager() {
+ boolean answer = true;
+ final Iterator<IAxisManager> iter = this.subManagers.iterator();
+ while (iter.hasNext() && answer) {
+ answer = iter.next().canBeUsedAsRowManager();
+ }
+ return answer;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsColumnManager()
+ *
+ * @return
+ */
+ @Override
+ public boolean canBeUsedAsColumnManager() {
+ boolean answer = true;
+ final Iterator<IAxisManager> iter = this.subManagers.iterator();
+ while (iter.hasNext() && answer) {
+ answer = iter.next().canBeUsedAsColumnManager();
+ }
+ return answer;
+ }
+
+ @Override
+ public boolean canCreateAxisElement(String elementId) {
+ boolean canCreateAxisElement = false;
+ for (IAxisManager manager : subManagers) {
+ canCreateAxisElement |= manager.canCreateAxisElement(elementId);
+ }
+ return canCreateAxisElement;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param objectToAdd
+ * @return
+ */
+ @Override
+ public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
+ final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_AddAxisCommand);
+ for (final IAxisManager current : this.subManagers) {
+ final Command tmp = current.getAddAxisCommand(domain, objectToAdd);
+ if (tmp != null) {
+ cmd.append(tmp);
+ }
+ }
+ if (cmd.isEmpty()) {
+ return null;
+ }
+ return cmd;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param objectToAdd
+ * @return
+ */
+ @Override
+ public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
+ final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_AddAxisCommand);
+ for (final IAxisManager current : this.subManagers) {
+ final Command tmp = current.getComplementaryAddAxisCommand(domain, objectToAdd);
+ if (tmp != null) {
+ cmd.append(tmp);
+ }
+ }
+ if (cmd.isEmpty()) {
+ return null;
+ }
+ return cmd;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#updateAxisContents()
+ *
+ */
+ @Override
+ public synchronized void updateAxisContents() {
+ final List<Object> displayedElement = getElements();
+ synchronized (displayedElement) {
+ displayedElement.clear();
+ displayedElement.addAll(this.managedObject);
+ if (this.subManagers != null) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.isDynamic()) {
+ displayedElement.addAll(current.getAllManagedAxis());
+ }
+ }
+ }
+ if (this.axisComparator != null) {
+ Collections.sort(displayedElement, this.axisComparator);
+ } else {
+
+ }
+ }
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAllowedContents(java.lang.Object)
+ *
+ * @param object
+ * @return
+ */
+ @Override
+ public boolean isAllowedContents(Object object) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.isAllowedContents(object)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canMoveAxis()
+ *
+ * @return
+ */
+ @Override
+ public boolean canMoveAxis() {
+ for (final IAxisManager current : this.subManagers) {
+ if (!current.canMoveAxis() || current.isDynamic()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#sortAxisByName(boolean, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param inverted
+ * @param configRegistry
+ */
+ @Override
+ public void sortAxisByName(boolean alphabeticOrder, final IConfigRegistry configRegistry) {
+ if (canMoveAxis()) {
+ final List<IAxis> axis = new ArrayList<IAxis>(getRepresentedContentProvider().getAxis());
+ Collections.sort(axis, new AxisComparator(alphabeticOrder, configRegistry));
+ final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(getRepresentedContentProvider());
+ final AbstractEditCommandRequest request = new SetRequest(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), axis);
+ final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getRepresentedContentProvider());
+ final ICommand cmd = provider.getEditCommand(request);
+ domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
+ }
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#createPossibleAxisContentProvider(boolean)
+ *
+ * @param isRestricted
+ * @return a contents provider for this axis or <code>null</code> if it is not allowed
+ */
+ @Override
+ public IRestrictedContentProvider createPossibleAxisContentProvider(boolean isRestricted) {
+
+ CompoundFilteredRestrictedContentProvider compoundContentProvider = null;
+ for (final IAxisManager current : this.subManagers) {
+ IRestrictedContentProvider contentProvider = current.createPossibleAxisContentProvider(isRestricted);
+ if (contentProvider != null) {
+ if (compoundContentProvider == null) {
+ compoundContentProvider = new CompoundFilteredRestrictedContentProvider();
+ }
+ compoundContentProvider.add(contentProvider);
+ }
+ }
+ return compoundContentProvider;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getDestroyAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param objectToDestroy
+ * @return
+ */
+ @Override
+ public Command getDestroyAxisCommand(TransactionalEditingDomain domain, Collection<Object> objectToDestroy) {
+ final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_DestroyAxisCommand);
+ for (final IAxisManager current : this.subManagers) {
+ final Command tmp = current.getDestroyAxisCommand(domain, objectToDestroy);
+ if (tmp != null) {
+ cmd.append(tmp);
+ }
+ }
+ if (cmd.isEmpty()) {
+ return null;
+ }
+ return cmd;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAllManagedAxis()
+ *
+ * @return
+ */
+ @Override
+ public List<Object> getAllManagedAxis() {
+ initializeManagedObjectList();
+ final List<Object> allExistingAxis = new ArrayList<Object>();
+ for (IAxisManager manager : this.subManagers) {
+ Collection<Object> managerPossibleElements = manager.getAllManagedAxis();
+ if (managerPossibleElements != null) {
+ allExistingAxis.addAll(managerPossibleElements);
+ }
+ }
+ return allExistingAxis;
+ }
+
+ /**
+ *
+ * @param resolve
+ * if <code>true</code> the path will be resolved
+ * @return
+ * a list with the managed objects
+ */
+ public List<Object> getAllManagedAxis(final boolean resolve) {
+ final List<Object> allExistingAxis = new ArrayList<Object>();
+ for (final IAxis current : getRepresentedContentProvider().getAxis()) {
+ Object representedElement = AxisUtils.getRepresentedElement(current);
+ if (resolve && current instanceof IdAxis) {
+ representedElement = getResolvedPath((IdAxis) current);
+ }
+ allExistingAxis.add(representedElement);
+ }
+ for (IAxisManager manager : this.subManagers) {
+ if (manager.isDynamic()) {
+ final List<Object> managerPossibleElements = manager.getAllManagedAxis();
+ if (managerPossibleElements != null) {
+ allExistingAxis.addAll(managerPossibleElements);
+ }
+ }
+ }
+ return allExistingAxis;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave()
+ *
+ * @return
+ * <code>true</code> if one of the encapsulated manager is a slave
+ */
+ @Override
+ public boolean isSlave() {
+ for (final IAxisManager manager : this.subManagers) {
+ if (manager.isSlave()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isDynamic()
+ *
+ * @return
+ * <code>true</code> if one of the embedded axis manager is dynamic
+ */
+ @Override
+ public boolean isDynamic() {
+ for (final IAxisManager manager : this.subManagers) {
+ if (manager.isDynamic()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canDropAxisElement(java.util.Collection)
+ *
+ * @param objectsToAdd
+ * @return
+ */
+ @Override
+ public boolean canDropAxisElement(Collection<Object> objectsToAdd) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.canDropAxisElement(objectsToAdd)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ *
+ * @param elementToMove
+ * @param newIndex
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#moveAxis(java.lang.Object, int)
+ */
+ @Override
+ public void moveAxis(Object elementToMove, int newIndex) {
+ if (!isDynamic() && elementToMove instanceof IAxis) {
+ TransactionalEditingDomain domain = getTableEditingDomain();
+ final Command command = MoveCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), elementToMove, newIndex);
+ domain.getCommandStack().execute(command);
+ }
+ }
+
+ @Override
+ public boolean canEditAxisHeader(final NatEventData axisIndex) {
+ axisIndex.getColumnPosition();// TODO
+ if (canEditAxisHeader()) {// TODO
+ return true;
+ } else {
+ return false;// TODO : we need to iterate on the contents to know if it is possible or not
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canEditAxisHeader()
+ *
+ * @return
+ */
+ @Override
+ public boolean canEditAxisHeader() {
+ for (final IAxisManager current : this.subManagers) {
+ if (!current.canEditAxisHeader()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
+ *
+ * @param axis
+ * @return
+ */
+ @Override
+ public String getElementAxisName(final IAxis axis) {
+ final AxisManagerRepresentation manager = axis.getManager();
+ for (final IAxisManager man : this.subManagers) {
+ if (man.getAxisManagerRepresentation() == manager) {
+ return man.getElementAxisName(axis);
+ }
+ }
+ if (canEditAxisHeader()) {
+ return null;
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ *
+ * @param axis
+ * an axis
+ * @return
+ * the axis manager managing this axis
+ *
+ * @deprecated, use getSubAxisManagerFor
+ */
+ @Deprecated
+ protected IAxisManager getAxisManager(final IAxis axis) {
+ final AxisManagerRepresentation rep = axis.getManager();
+ for (final IAxisManager man : this.subManagers) {
+ if (man.getAxisManagerRepresentation() == rep) {
+ return man;
+ }
+ }
+ return null;// must be impossible
+ }
+
+ /**
+ *
+ * @param axis
+ * an axis
+ * @return
+ * the axis manager managing this axis
+ */
+ @Override
+ public IAxisManager getSubAxisManagerFor(final IAxis axis) {
+ final AxisManagerRepresentation rep = axis.getManager();
+ for (final IAxisManager man : this.subManagers) {
+ if (man.getAxisManagerRepresentation() == rep) {
+ return man;
+ }
+ }
+ return null;// must be impossible
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canDestroyAxis(java.lang.Integer)
+ *
+ * @param axisPosition
+ * @return
+ */
+ @Override
+ public boolean canDestroyAxis(final Integer axisPosition) {
+ final List<Object> elements = getElements();
+ final Object element = elements.get(axisPosition);
+ if (element instanceof IAxis) {
+ return getSubAxisManagerFor((IAxis) element).canDestroyAxis(axisPosition);
+ }
+ // not yet managed
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer)
+ *
+ * @param axisPosition
+ * @return
+ */
+ @Override
+ public boolean canDestroyAxisElement(Integer axisPosition) {
+ final List<Object> elements = getElements();
+ final Object element = elements.get(axisPosition);
+ if (element instanceof IAxis) {
+ return getSubAxisManagerFor((IAxis) element).canDestroyAxisElement(axisPosition);
+ } else if (subManagers.size() == 1) {
+ return subManagers.get(0).canDestroyAxisElement(axisPosition);
+ }
+ // not yet managed
+ return false;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(TransactionalEditingDomain, java.lang.Integer)
+ *
+ * @param domain
+ * @param axisPosition
+ * @return
+ */
+ @Override
+ public Command getDestroyAxisElementCommand(TransactionalEditingDomain domain, Integer axisPosition) {
+ final List<Object> elements = getElements();
+ final Object element = elements.get(axisPosition);
+ if (element instanceof IAxis) {
+ return getSubAxisManagerFor((IAxis) element).getDestroyAxisElementCommand(domain, axisPosition);
+ } else if (subManagers.size() == 1) {
+ return subManagers.get(0).getDestroyAxisElementCommand(domain, axisPosition);
+ }
+ // not yet managed
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ @Override
+ public boolean canBeSavedAsConfig() {
+ boolean canBeSavedAsConfig = true;
+ for (IAxisManager manager : subManagers) {
+ canBeSavedAsConfig &= manager.canBeSavedAsConfig();
+ }
+ return canBeSavedAsConfig;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAdapter(java.lang.Class)
+ *
+ * @param adapter
+ * @return
+ */
+ @Override
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.getClass() == adapter) {
+ return current;
+ }
+ }
+ return super.getAdapter(adapter);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#isInSortedState()
+ *
+ * @return
+ */
+ @Override
+ public boolean isInSortedState() {
+ return this.axisComparator != null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#setAxisComparator(java.util.Comparator)
+ *
+ * @param comp
+ */
+ @Override
+ public void setAxisComparator(final Comparator<Object> comp) {
+ this.axisComparator = comp;
+ if (this.axisComparator != null) {
+ List<Object> displayedElement = getElements();
+ synchronized (displayedElement) {
+ Collections.sort(displayedElement, comp);
+ getTableManager().refreshNatTable();// useful?
+ }
+ } else {
+ getTableManager().updateAxisContents(getRepresentedContentProvider());
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAlreadyManaged(java.lang.Object)
+ *
+ * @param object
+ * @return
+ */
+ @Override
+ public boolean isAlreadyManaged(final Object object) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.isAlreadyManaged(object)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#getSetNewAxisOrderCommand(java.util.List)
+ *
+ * @param newOrder
+ * @return
+ */
+ @Override
+ public Command getSetNewAxisOrderCommand(final List<Object> newOrder) {
+ if (canMoveAxis() && !isDynamic()) {
+ return new RecordingCommand(getTableEditingDomain()) {
+
+ @Override
+ protected void doExecute() {
+ final TreeMap<Integer, IAxis> order = new TreeMap<Integer, IAxis>();
+ final AbstractAxisProvider provider = getRepresentedContentProvider();
+ for (int i = 0; i < provider.getAxis().size(); i++) {
+ final IAxis currentAxis = provider.getAxis().get(i);
+ int index = newOrder.indexOf(currentAxis);
+ if (index != -1) {
+ order.put(Integer.valueOf(index), currentAxis);
+ } else {
+ Object resolvedObject = AxisUtils.getRepresentedElement(currentAxis);
+ if (currentAxis instanceof IdAxis) {
+ resolvedObject = getResolvedPath((IdAxis) currentAxis);
+ }
+ index = newOrder.indexOf(resolvedObject);
+ if (index == -1) {
+ throw new IndexOutOfBoundsException("A reordered element can't be resolved"); //$NON-NLS-1$
+ }
+ order.put(Integer.valueOf(index), currentAxis);
+ }
+ }
+
+ final List<IAxis> newValues = new ArrayList<IAxis>();
+ newValues.addAll(order.values());
+ SetCommand.create(getTableEditingDomain(), provider, NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), newValues).execute();
+ }
+ };
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param axisManagerId
+ * an axis
+ * @return
+ * the axis manager managing it
+ */
+ protected IAxisManager findAxisManager(final IAxis axis) {
+ final String axisManagerId = axis.getManager().getAxisManagerId();
+ for (final IAxisManager currentManager : this.subManagers) {
+ if (currentManager.getAxisManagerRepresentation().getAxisManagerId().equals(axisManagerId)) {
+ return currentManager;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param idAxis
+ * an idAxis
+ * @return
+ * the resolved path or the {@link String} represented by the idAxis if the path can't be resolved
+ */
+ protected Object getResolvedPath(final IdAxis idAxis) {
+ final String path = idAxis.getElement();
+ final IAxisManager manager = findAxisManager(idAxis);
+ if (manager instanceof IIdAxisManager) {
+ final Object resolvedElement = ((IIdAxisManager) manager).resolvedPath(path);
+ if (resolvedElement != null) {
+ return resolvedElement;
+ }
+ }
+ return path;
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManagerForEventList.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManagerForEventList.java
index af0b69e8979..b527288a7ab 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManagerForEventList.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/CompositeAxisManagerForEventList.java
@@ -1,849 +1,873 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.nattable.manager.axis;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.TreeMap;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.common.command.UnexecutableCommand;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.edit.command.MoveCommand;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.ResourceSetListener;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
-import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.nattable.listener.UpdateTableContentListener;
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.messages.Messages;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
-import org.eclipse.papyrus.infra.nattable.utils.AxisComparator;
-import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
-import org.eclipse.papyrus.infra.nattable.utils.EventListHelper;
-import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.infra.widgets.providers.CompoundFilteredRestrictedContentProvider;
-import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider;
-
-import ca.odell.glazedlists.EventList;
-
-/**
- * @author VL222926
- *
- */
-public class CompositeAxisManagerForEventList extends AbstractAxisManagerForEventList implements IAxisManagerForEventList, ICompositeAxisManager {
-
- /**
- * the id of this manager
- */
- @SuppressWarnings("unused")
- private static final String MANAGER_ID = "org.eclipse.papyrus.infra.nattable.composite.axis.manager.event.list"; //$NON-NLS-1$
-
- /**
- * the sub managers
- */
- protected List<IAxisManagerForEventList> subManagers;
-
- /**
- * the comparator used to sort the axis
- */
- protected Comparator<Object> axisComparator;
-
- /**
- * the resouce set listener
- */
- private ResourceSetListener resourceSetListener;
-
- /**
- * Constructor.
- *
- */
- public CompositeAxisManagerForEventList(final EventList<Object> eventList) {
- setEventList(eventList);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManagerForEventList#addListeners()
- *
- */
- @Override
- protected void addListeners() {
- this.resourceSetListener = new UpdateTableContentListener(getTableManager(), this);
- if (getTableEditingDomain() != null) {
- getTableEditingDomain().addResourceSetListener(this.resourceSetListener);
- }
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#setSubAxisManager(java.util.List)
- *
- * @param managers
- */
- @Override
- public final void setSubAxisManager(final List<IAxisManager> managers) {
- throw new UnsupportedOperationException("Use setSubAxisManagers(List<IAxisManagerForEventList> manager)"); //$NON-NLS-1$
- }
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#init(org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager, org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation,
- * org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider)
- *
- * @param manager
- * @param rep
- * @param provider
- */
- @Override
- public void init(INattableModelManager manager, AxisManagerRepresentation rep, AbstractAxisProvider provider) {
- super.init(manager, rep, provider);
- for (final IAxis current : getRepresentedContentProvider().getAxis()) {
- if (current instanceof ITreeItemAxis) {
- EventListHelper.addToEventList(eventList, current);
- }
- }
- }
-
- /**
- * @param subManagers
- * the subManagers to set
- */
- public void setSubManagers(List<IAxisManagerForEventList> subManagers) {
- this.subManagers = subManagers;
- for (IAxisManagerForEventList current : subManagers) {
- current.setEventList(eventList);
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#dispose()
- *
- */
- @Override
- public void dispose() {
- super.dispose();
- for (final IAxisManager current : this.subManagers) {
- current.dispose();
- }
- this.subManagers.clear();
-
- }
-
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#removeListeners()
- *
- */
- @Override
- protected void removeListeners() {
- if (getTableEditingDomain() != null && resourceSetListener != null) {
- getTableEditingDomain().removeResourceSetListener(this.resourceSetListener);
- this.resourceSetListener = null;
- }
- super.removeListeners();
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsRowManager()
- *
- * @return
- */
- @Override
- public boolean canBeUsedAsRowManager() {
- boolean answer = true;
- final Iterator<IAxisManagerForEventList> iter = this.subManagers.iterator();
- while (iter.hasNext() && answer) {
- answer = iter.next().canBeUsedAsRowManager();
- }
- return answer;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsColumnManager()
- *
- * @return
- */
- @Override
- public boolean canBeUsedAsColumnManager() {
- boolean answer = true;
- final Iterator<IAxisManagerForEventList> iter = this.subManagers.iterator();
- while (iter.hasNext() && answer) {
- answer = iter.next().canBeUsedAsColumnManager();
- }
- return answer;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canCreateAxisElement(java.lang.String)
- *
- * @param elementId
- * @return
- */
- @Override
- public boolean canCreateAxisElement(String elementId) {
- boolean canCreateAxisElement = false;
- for (IAxisManager manager : subManagers) {
- canCreateAxisElement |= manager.canCreateAxisElement(elementId);
- }
- return canCreateAxisElement;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- if (FillingConfigurationUtils.hasTreeFillingConfigurationForDepth(this.tableManager.getTable(), 0)) {
- return null;
- }
- final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_AddAxisCommand);
- for (final IAxisManager current : this.subManagers) {
- final Command tmp = current.getAddAxisCommand(domain, objectToAdd);
- if (tmp != null) {
- cmd.append(tmp);
- }
- }
- if (cmd.isEmpty()) {
- return null;
- }
- return cmd;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManagerForEventList#initializeManagedObjectList()
- *
- */
- @Override
- protected void initializeManagedObjectList() {
- // nothing to do
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_AddAxisCommand);
- for (final IAxisManager current : this.subManagers) {
- final Command tmp = current.getComplementaryAddAxisCommand(domain, objectToAdd);
- if (tmp != null) {
- cmd.append(tmp);
- }
- }
- if (cmd.isEmpty()) {
- return null;
- }
- return cmd;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAllowedContents(java.lang.Object)
- *
- * @param object
- * @return
- */
- @Override
- public boolean isAllowedContents(Object object) {
- for (final IAxisManager current : this.subManagers) {
- if (current.isAllowedContents(object)) {
- return true;
- }
- }
- return false;
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canMoveAxis()
- *
- * @return
- */
- @Override
- public boolean canMoveAxis() {
- for (final IAxisManager current : this.subManagers) {
- if (!current.canMoveAxis() || current.isDynamic()) {
- return false;
- }
- }
- return true;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#sortAxisByName(boolean, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
- *
- * @param inverted
- * @param configRegistry
- */
- @Override
- public void sortAxisByName(boolean alphabeticOrder, final IConfigRegistry configRegistry) {
- if (canMoveAxis()) {
- final List<IAxis> axis = new ArrayList<IAxis>(getRepresentedContentProvider().getAxis());
- Collections.sort(axis, new AxisComparator(alphabeticOrder, configRegistry));
- final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(getRepresentedContentProvider());
- final AbstractEditCommandRequest request = new SetRequest(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), axis);
- final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getRepresentedContentProvider());
- final ICommand cmd = provider.getEditCommand(request);
- domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#createPossibleAxisContentProvider(boolean)
- *
- * @param isRestricted
- * @return a contents provider for this axis or <code>null</code> if it is not allowed
- */
- @Override
- public IRestrictedContentProvider createPossibleAxisContentProvider(boolean isRestricted) {
-
- CompoundFilteredRestrictedContentProvider compoundContentProvider = null;
- for (final IAxisManager current : this.subManagers) {
- IRestrictedContentProvider contentProvider = current.createPossibleAxisContentProvider(isRestricted);
- if (contentProvider != null) {
- if (compoundContentProvider == null) {
- compoundContentProvider = new CompoundFilteredRestrictedContentProvider();
- }
- compoundContentProvider.add(contentProvider);
- }
- }
- return compoundContentProvider;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getDestroyAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToDestroy
- * @return
- */
- @Override
- public Command getDestroyAxisCommand(TransactionalEditingDomain domain, Collection<Object> objectToDestroy) {
- final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_DestroyAxisCommand);
- for (final IAxisManager current : this.subManagers) {
- final Command tmp = current.getDestroyAxisCommand(domain, objectToDestroy);
- if (tmp != null) {
- cmd.append(tmp);
- }
- }
- if (cmd.isEmpty()) {
- return null;
- }
- return cmd;
- }
-
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave()
- *
- * @return
- * <code>true</code> if one of the encapsulated manager is a slave
- */
- @Override
- public boolean isSlave() {
- for (final IAxisManager manager : this.subManagers) {
- if (manager.isSlave()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isDynamic()
- *
- * @return
- * <code>true</code> if one of the embedded axis manager is dynamic
- */
- @Override
- public boolean isDynamic() {
- for (final IAxisManager manager : this.subManagers) {
- if (manager.isDynamic()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canDropAxisElement(java.util.Collection)
- *
- * @param objectsToAdd
- * @return
- */
- @Override
- public boolean canDropAxisElement(Collection<Object> objectsToAdd) {
- for (final IAxisManager current : this.subManagers) {
- if (current.canDropAxisElement(objectsToAdd)) {
- return true;
- }
- }
- return false;
- }
-
-
- /**
- *
- * @param elementToMove
- * @param newIndex
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#moveAxis(java.lang.Object, int)
- */
- @Override
- public void moveAxis(Object elementToMove, int newIndex) {
- if (!isDynamic() && elementToMove instanceof IAxis) {
- TransactionalEditingDomain domain = getTableEditingDomain();
- final Command command = MoveCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), elementToMove, newIndex);
- domain.getCommandStack().execute(command);
- }
- }
-
- @Override
- public boolean canEditAxisHeader(final NatEventData axisIndex) {
- if (canEditAxisHeader()) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canEditAxisHeader()
- *
- * @return
- */
- @Override
- public boolean canEditAxisHeader() {
- for (final IAxisManager current : this.subManagers) {
- if (!current.canEditAxisHeader()) {
- return false;
- }
- }
- return true;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
- *
- * @param axis
- * @return
- */
- @Override
- public String getElementAxisName(final IAxis axis) {
- final AxisManagerRepresentation manager = axis.getManager();
- for (final IAxisManager man : this.subManagers) {
- if (man.getAxisManagerRepresentation() == manager) {
- return man.getElementAxisName(axis);
- }
- }
- if (canEditAxisHeader()) {
- return null;
- } else {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- *
- * @param axis
- * an axis
- * @return
- * the axis manager managing this axis
- */
- protected IAxisManager getAxisManager(final IAxis axis) {
- final AxisManagerRepresentation rep = axis.getManager();
- for (final IAxisManager man : this.subManagers) {
- if (man.getAxisManagerRepresentation() == rep) {
- return man;
- }
- }
- return null;// must be impossible
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canDestroyAxis(java.lang.Integer)
- *
- * @param axisPosition
- * @return
- */
- @Override
- public boolean canDestroyAxis(final Integer axisPosition) {
- final List<Object> elements = getElements();
- final Object element = elements.get(axisPosition);
- if (element instanceof IAxis) {
- return getAxisManager((IAxis) element).canDestroyAxis(axisPosition);
- }
- // not yet managed
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer)
- *
- * @param axisPosition
- * @return
- */
- @Override
- public boolean canDestroyAxisElement(Integer axisPosition) {
- final List<Object> elements = getElements();
- final Object element = elements.get(axisPosition);
- if (element instanceof IAxis) {
- return getAxisManager((IAxis) element).canDestroyAxisElement(axisPosition);
- } else if (subManagers.size() == 1) {
- return subManagers.get(0).canDestroyAxisElement(axisPosition);
- }
- // not yet managed
- return false;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(TransactionalEditingDomain, java.lang.Integer)
- *
- * @param domain
- * @param axisPosition
- * @return
- */
- @Override
- public Command getDestroyAxisElementCommand(TransactionalEditingDomain domain, Integer axisPosition) {
- final List<Object> elements = getElements();
- final Object element = elements.get(axisPosition);
- if (element instanceof IAxis) {
- return getAxisManager((IAxis) element).getDestroyAxisElementCommand(domain, axisPosition);
- } else if (subManagers.size() == 1) {
- return subManagers.get(0).getDestroyAxisElementCommand(domain, axisPosition);
- }
- // not yet managed
- return UnexecutableCommand.INSTANCE;
- }
-
- @Override
- public boolean canBeSavedAsConfig() {
- boolean canBeSavedAsConfig = true;
- for (IAxisManager manager : subManagers) {
- canBeSavedAsConfig &= manager.canBeSavedAsConfig();
- }
- return canBeSavedAsConfig;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAdapter(java.lang.Class)
- *
- * @param adapter
- * @return
- */
- @Override
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- for (final IAxisManager current : this.subManagers) {
- if (current.getClass() == adapter) {
- return current;
- }
- }
- return super.getAdapter(adapter);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#isInSortedState()
- *
- * @return
- */
- @Override
- public boolean isInSortedState() {
- return this.axisComparator != null;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#setAxisComparator(java.util.Comparator)
- *
- * @param comp
- */
- @Override
- public void setAxisComparator(final Comparator<Object> comp) {
- this.axisComparator = comp;
- if (this.axisComparator != null) {
- List<Object> displayedElement = getElements();
- synchronized (displayedElement) {
- Collections.sort(displayedElement, comp);
- getTableManager().refreshNatTable();// useful?
- }
- } else {
- getTableManager().updateAxisContents(getRepresentedContentProvider());
- }
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAlreadyManaged(java.lang.Object)
- *
- * @param object
- * @return
- */
- @Override
- public boolean isAlreadyManaged(final Object object) {
- for (final IAxisManager current : this.subManagers) {
- if (current.isAlreadyManaged(object)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#getSetNewAxisOrderCommand(java.util.List)
- *
- * @param newOrder
- * @return
- */
- @Override
- public Command getSetNewAxisOrderCommand(final List<Object> newOrder) {
- if (canMoveAxis() && !isDynamic()) {
- return new RecordingCommand(getTableEditingDomain()) {
-
- @Override
- protected void doExecute() {
- final TreeMap<Integer, IAxis> order = new TreeMap<Integer, IAxis>();
- final AbstractAxisProvider provider = getRepresentedContentProvider();
- for (int i = 0; i < provider.getAxis().size(); i++) {
- final IAxis currentAxis = provider.getAxis().get(i);
- int index = newOrder.indexOf(currentAxis);
- if (index != -1) {
- order.put(Integer.valueOf(index), currentAxis);
- } else {
- Object resolvedObject = AxisUtils.getRepresentedElement(currentAxis);
- if (currentAxis instanceof IdAxis) {
- resolvedObject = getResolvedPath((IdAxis) currentAxis);
- }
- index = newOrder.indexOf(resolvedObject);
- if (index == -1) {
- throw new IndexOutOfBoundsException("A reordered element can't be resolved"); //$NON-NLS-1$
- }
- order.put(Integer.valueOf(index), currentAxis);
- }
- }
-
- final List<IAxis> newValues = new ArrayList<IAxis>();
- newValues.addAll(order.values());
- SetCommand.create(getTableEditingDomain(), provider, NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), newValues).execute();
- }
- };
- }
- return null;
- }
-
- /**
- *
- * @param axisManagerId
- * an axis
- * @return
- * the axis manager managing it
- */
- protected IAxisManager findAxisManager(final IAxis axis) {
- final String axisManagerId = axis.getManager().getAxisManagerId();
- for (final IAxisManager currentManager : this.subManagers) {
- if (currentManager.getAxisManagerRepresentation().getAxisManagerId().equals(axisManagerId)) {
- return currentManager;
- }
- }
- return null;
- }
-
- /**
- *
- * @param idAxis
- * an idAxis
- * @return
- * the resolved path or the {@link String} represented by the idAxis if the path can't be resolved
- */
- protected Object getResolvedPath(final IdAxis idAxis) {
- final String path = idAxis.getElement();
- final IAxisManager manager = findAxisManager(idAxis);
- if (manager instanceof IIdAxisManager) {
- final Object resolvedElement = ((IIdAxisManager) manager).resolvedPath(path);
- if (resolvedElement != null) {
- return resolvedElement;
- }
- }
- return path;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManagerForEventList#manageSetNotification(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- protected void manageSetNotification(Notification notification) {
- propagateEvent(notification);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManagerForEventList#manageUnsetNotification(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- protected void manageUnsetNotification(Notification notification) {
- propagateEvent(notification);
- }
-
- @Override
- protected void manageAddNotification(final Notification notification) {
- final Object newValue = notification.getNewValue();
- if (newValue instanceof IAxis && ((IAxis) newValue).eContainer() == getRepresentedContentProvider()) {
- EventListHelper.addToEventList(eventList, newValue);
- }
- propagateEvent(notification);
- }
-
-
-
- @Override
- protected void manageAddManyNotification(final Notification notification) {
- final Object newValue = notification.getNewValue();
- if (newValue instanceof Collection<?>) {
- for (Object current : (Collection<?>) newValue) {
- if (current instanceof IAxis && ((IAxis) current).eContainer() == getRepresentedContentProvider()) {
- EventListHelper.addToEventList(eventList, current);
- }
- }
-
- }
- propagateEvent(notification);
- }
-
- @Override
- protected void manageMoveNotification(final Notification notification) {
- propagateEvent(notification);
- }
-
- @Override
- protected void manageRemoveNotification(final Notification notification) {
- final Object oldValue = notification.getOldValue();
- propagateEvent(notification);
- if (oldValue instanceof IAxis) {
- EventListHelper.removeFromEventList(eventList, oldValue);
- }
- }
-
- @Override
- protected void manageRemoveManyNotification(final Notification notification) {
- final Object oldValue = notification.getNewValue();
- propagateEvent(notification);
- if (oldValue instanceof Collection<?>) {
- for (Object current : (Collection<?>) oldValue) {
- if (current instanceof IAxis) {
- EventListHelper.removeFromEventList(eventList, current);
- }
- }
-
- }
- }
-
- /**
- * This method propagates the notification to the submanagers in order to update the event list
- *
- * @param notification
- * a notification
- *
- */
- protected void propagateEvent(Notification notification) {
- for (final IAxisManager current : this.subManagers) {
- if (current instanceof IAxisManagerForEventList) {
- ((IAxisManagerForEventList) current).manageEvent(notification);
- }
- }
- // must not be done here -> to many refresh are done
- // getTableManager().refreshNatTable();
- }
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#updateAxisContents()
- * @deprecated must be removed from the API
- */
- @Override
- @Deprecated
- public void updateAxisContents() {
- // nothing to do
- }
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ITreeItemAxisManagerForEventList#treeFillingConfigurationHaveChanged()
- *
- */
- @Override
- public void fillingConfigurationsHaveChanged() {
- for (final IAxisManager current : this.subManagers) {
- if (current instanceof IAxisManagerForEventList) {
- ((IAxisManagerForEventList) current).fillingConfigurationsHaveChanged();
- }
- }
- // required
- getTableManager().refreshNatTable();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.manager.axis;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TreeMap;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.edit.command.MoveCommand;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.ResourceSetListener;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.nattable.listener.UpdateTableContentListener;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.messages.Messages;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
+import org.eclipse.papyrus.infra.nattable.utils.AxisComparator;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.EventListHelper;
+import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.widgets.providers.CompoundFilteredRestrictedContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider;
+
+import ca.odell.glazedlists.EventList;
+
+/**
+ * @author VL222926
+ *
+ */
+public class CompositeAxisManagerForEventList extends AbstractAxisManagerForEventList implements IAxisManagerForEventList, ICompositeAxisManager {
+
+ /**
+ * the id of this manager
+ */
+ @SuppressWarnings("unused")
+ private static final String MANAGER_ID = "org.eclipse.papyrus.infra.nattable.composite.axis.manager.event.list"; //$NON-NLS-1$
+
+ /**
+ * the sub managers
+ */
+ protected List<IAxisManagerForEventList> subManagers;
+
+ /**
+ * the comparator used to sort the axis
+ */
+ protected Comparator<Object> axisComparator;
+
+ /**
+ * the resouce set listener
+ */
+ private ResourceSetListener resourceSetListener;
+
+ /**
+ * Constructor.
+ *
+ */
+ public CompositeAxisManagerForEventList(final EventList<Object> eventList) {
+ setEventList(eventList);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManagerForEventList#addListeners()
+ *
+ */
+ @Override
+ protected void addListeners() {
+ this.resourceSetListener = new UpdateTableContentListener(getTableManager(), this);
+ if (null != getTableEditingDomain()) {
+ getTableEditingDomain().addResourceSetListener(this.resourceSetListener);
+ }
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#setSubAxisManager(java.util.List)
+ *
+ * @param managers
+ */
+ @Override
+ public final void setSubAxisManager(final List<IAxisManager> managers) {
+ throw new UnsupportedOperationException("Use setSubAxisManagers(List<IAxisManagerForEventList> manager)"); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#init(org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager, org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation,
+ * org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider)
+ *
+ * @param manager
+ * @param rep
+ * @param provider
+ */
+ @Override
+ public void init(INattableModelManager manager, AxisManagerRepresentation rep, AbstractAxisProvider provider) {
+ super.init(manager, rep, provider);
+ for (final IAxis current : getRepresentedContentProvider().getAxis()) {
+ if (current instanceof ITreeItemAxis) {
+ EventListHelper.addToEventList(eventList, current);
+ }
+ }
+ }
+
+ /**
+ * @param subManagers
+ * the subManagers to set
+ */
+ public void setSubManagers(List<IAxisManagerForEventList> subManagers) {
+ this.subManagers = subManagers;
+ for (IAxisManagerForEventList current : subManagers) {
+ current.setEventList(eventList);
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ removeListeners();
+ super.dispose();
+ for (final IAxisManager current : this.subManagers) {
+ current.dispose();
+ }
+ this.subManagers.clear();
+
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#removeListeners()
+ *
+ */
+ @Override
+ protected void removeListeners() {
+ if (null != getTableEditingDomain()) {
+ getTableEditingDomain().removeResourceSetListener(this.resourceSetListener);
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsRowManager()
+ *
+ * @return
+ */
+ @Override
+ public boolean canBeUsedAsRowManager() {
+ boolean answer = true;
+ final Iterator<IAxisManagerForEventList> iter = this.subManagers.iterator();
+ while (iter.hasNext() && answer) {
+ answer = iter.next().canBeUsedAsRowManager();
+ }
+ return answer;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canBeUsedAsColumnManager()
+ *
+ * @return
+ */
+ @Override
+ public boolean canBeUsedAsColumnManager() {
+ boolean answer = true;
+ final Iterator<IAxisManagerForEventList> iter = this.subManagers.iterator();
+ while (iter.hasNext() && answer) {
+ answer = iter.next().canBeUsedAsColumnManager();
+ }
+ return answer;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canCreateAxisElement(java.lang.String)
+ *
+ * @param elementId
+ * @return
+ */
+ @Override
+ public boolean canCreateAxisElement(String elementId) {
+ boolean canCreateAxisElement = false;
+ for (IAxisManager manager : subManagers) {
+ canCreateAxisElement |= manager.canCreateAxisElement(elementId);
+ }
+ return canCreateAxisElement;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param objectToAdd
+ * @return
+ */
+ @Override
+ public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
+ if (FillingConfigurationUtils.hasTreeFillingConfigurationForDepth(this.tableManager.getTable(), 0)) {
+ return null;
+ }
+ final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_AddAxisCommand);
+ for (final IAxisManager current : this.subManagers) {
+ final Command tmp = current.getAddAxisCommand(domain, objectToAdd);
+ if (tmp != null) {
+ cmd.append(tmp);
+ }
+ }
+ if (cmd.isEmpty()) {
+ return null;
+ }
+ return cmd;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManagerForEventList#initializeManagedObjectList()
+ *
+ */
+ @Override
+ protected void initializeManagedObjectList() {
+ // nothing to do
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param objectToAdd
+ * @return
+ */
+ @Override
+ public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
+ final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_AddAxisCommand);
+ for (final IAxisManager current : this.subManagers) {
+ final Command tmp = current.getComplementaryAddAxisCommand(domain, objectToAdd);
+ if (tmp != null) {
+ cmd.append(tmp);
+ }
+ }
+ if (cmd.isEmpty()) {
+ return null;
+ }
+ return cmd;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAllowedContents(java.lang.Object)
+ *
+ * @param object
+ * @return
+ */
+ @Override
+ public boolean isAllowedContents(Object object) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.isAllowedContents(object)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canMoveAxis()
+ *
+ * @return
+ */
+ @Override
+ public boolean canMoveAxis() {
+ for (final IAxisManager current : this.subManagers) {
+ if (!current.canMoveAxis() || current.isDynamic()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#sortAxisByName(boolean, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param inverted
+ * @param configRegistry
+ */
+ @Override
+ public void sortAxisByName(boolean alphabeticOrder, final IConfigRegistry configRegistry) {
+ if (canMoveAxis()) {
+ final List<IAxis> axis = new ArrayList<IAxis>(getRepresentedContentProvider().getAxis());
+ Collections.sort(axis, new AxisComparator(alphabeticOrder, configRegistry));
+ final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(getRepresentedContentProvider());
+ final AbstractEditCommandRequest request = new SetRequest(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), axis);
+ final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getRepresentedContentProvider());
+ final ICommand cmd = provider.getEditCommand(request);
+ domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#createPossibleAxisContentProvider(boolean)
+ *
+ * @param isRestricted
+ * @return a contents provider for this axis or <code>null</code> if it is not allowed
+ */
+ @Override
+ public IRestrictedContentProvider createPossibleAxisContentProvider(boolean isRestricted) {
+
+ CompoundFilteredRestrictedContentProvider compoundContentProvider = null;
+ for (final IAxisManager current : this.subManagers) {
+ IRestrictedContentProvider contentProvider = current.createPossibleAxisContentProvider(isRestricted);
+ if (contentProvider != null) {
+ if (compoundContentProvider == null) {
+ compoundContentProvider = new CompoundFilteredRestrictedContentProvider();
+ }
+ compoundContentProvider.add(contentProvider);
+ }
+ }
+ return compoundContentProvider;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getDestroyAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param objectToDestroy
+ * @return
+ */
+ @Override
+ public Command getDestroyAxisCommand(TransactionalEditingDomain domain, Collection<Object> objectToDestroy) {
+ final CompoundCommand cmd = new CompoundCommand(Messages.CompositeAxisManager_DestroyAxisCommand);
+ for (final IAxisManager current : this.subManagers) {
+ final Command tmp = current.getDestroyAxisCommand(domain, objectToDestroy);
+ if (tmp != null) {
+ cmd.append(tmp);
+ }
+ }
+ if (cmd.isEmpty()) {
+ return null;
+ }
+ return cmd;
+ }
+
+
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave()
+ *
+ * @return
+ * <code>true</code> if one of the encapsulated manager is a slave
+ */
+ @Override
+ public boolean isSlave() {
+ for (final IAxisManager manager : this.subManagers) {
+ if (manager.isSlave()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isDynamic()
+ *
+ * @return
+ * <code>true</code> if one of the embedded axis manager is dynamic
+ */
+ @Override
+ public boolean isDynamic() {
+ for (final IAxisManager manager : this.subManagers) {
+ if (manager.isDynamic()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canDropAxisElement(java.util.Collection)
+ *
+ * @param objectsToAdd
+ * @return
+ */
+ @Override
+ public boolean canDropAxisElement(Collection<Object> objectsToAdd) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.canDropAxisElement(objectsToAdd)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ *
+ * @param elementToMove
+ * @param newIndex
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#moveAxis(java.lang.Object, int)
+ */
+ @Override
+ public void moveAxis(Object elementToMove, int newIndex) {
+ if (!isDynamic() && elementToMove instanceof IAxis) {
+ TransactionalEditingDomain domain = getTableEditingDomain();
+ final Command command = MoveCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), elementToMove, newIndex);
+ domain.getCommandStack().execute(command);
+ }
+ }
+
+ @Override
+ public boolean canEditAxisHeader(final NatEventData axisIndex) {
+ if (canEditAxisHeader()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canEditAxisHeader()
+ *
+ * @return
+ */
+ @Override
+ public boolean canEditAxisHeader() {
+ for (final IAxisManager current : this.subManagers) {
+ if (!current.canEditAxisHeader()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
+ *
+ * @param axis
+ * @return
+ */
+ @Override
+ public String getElementAxisName(final IAxis axis) {
+ final AxisManagerRepresentation manager = axis.getManager();
+ for (final IAxisManager man : this.subManagers) {
+ if (man.getAxisManagerRepresentation() == manager) {
+ return man.getElementAxisName(axis);
+ }
+ }
+ if (canEditAxisHeader()) {
+ return null;
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ *
+ * @param axis
+ * an axis
+ * @return
+ * the axis manager managing this axis
+ *
+ * @Deprecated since Eclipse Mars, use getSubAxisManagerFor instead
+ */
+ @Deprecated
+ protected IAxisManager getAxisManager(final IAxis axis) {
+ final AxisManagerRepresentation rep = axis.getManager();
+ for (final IAxisManager man : this.subManagers) {
+ if (man.getAxisManagerRepresentation() == rep) {
+ return man;
+ }
+ }
+ return null;// must be impossible
+ }
+
+ /**
+ *
+ * @param axis
+ * an axis
+ * @return
+ * the axis manager managing this axis
+ */
+ public IAxisManager getSubAxisManagerFor(final IAxis axis) {
+ final AxisManagerRepresentation rep = axis.getManager();
+ for (final IAxisManager man : this.subManagers) {
+ if (man.getAxisManagerRepresentation() == rep) {
+ return man;
+ }
+ }
+ return null;// must be impossible
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canDestroyAxis(java.lang.Integer)
+ *
+ * @param axisPosition
+ * @return
+ */
+ @Override
+ public boolean canDestroyAxis(final Integer axisPosition) {
+ final List<Object> elements = getElements();
+ final Object element = elements.get(axisPosition);
+ if (element instanceof IAxis) {
+ return getSubAxisManagerFor((IAxis) element).canDestroyAxis(axisPosition);
+ }
+ // not yet managed
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer)
+ *
+ * @param axisPosition
+ * @return
+ */
+ @Override
+ public boolean canDestroyAxisElement(Integer axisPosition) {
+ final List<Object> elements = getElements();
+ final Object element = elements.get(axisPosition);
+ if (element instanceof IAxis) {
+ return getSubAxisManagerFor((IAxis) element).canDestroyAxisElement(axisPosition);
+ } else if (subManagers.size() == 1) {
+ return subManagers.get(0).canDestroyAxisElement(axisPosition);
+ }
+ // not yet managed
+ return false;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(TransactionalEditingDomain, java.lang.Integer)
+ *
+ * @param domain
+ * @param axisPosition
+ * @return
+ */
+ @Override
+ public Command getDestroyAxisElementCommand(TransactionalEditingDomain domain, Integer axisPosition) {
+ final List<Object> elements = getElements();
+ final Object element = elements.get(axisPosition);
+ if (element instanceof IAxis) {
+ return getSubAxisManagerFor((IAxis) element).getDestroyAxisElementCommand(domain, axisPosition);
+ } else if (subManagers.size() == 1) {
+ return subManagers.get(0).getDestroyAxisElementCommand(domain, axisPosition);
+ }
+ // not yet managed
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ @Override
+ public boolean canBeSavedAsConfig() {
+ boolean canBeSavedAsConfig = true;
+ for (IAxisManager manager : subManagers) {
+ canBeSavedAsConfig &= manager.canBeSavedAsConfig();
+ }
+ return canBeSavedAsConfig;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAdapter(java.lang.Class)
+ *
+ * @param adapter
+ * @return
+ */
+ @Override
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.getClass() == adapter) {
+ return current;
+ }
+ }
+ return super.getAdapter(adapter);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#isInSortedState()
+ *
+ * @return
+ */
+ @Override
+ public boolean isInSortedState() {
+ return this.axisComparator != null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#setAxisComparator(java.util.Comparator)
+ *
+ * @param comp
+ */
+ @Override
+ // seem not used now
+ public void setAxisComparator(final Comparator<Object> comp) {
+ this.axisComparator = comp;
+ if (this.axisComparator != null) {
+ List<Object> displayedElement = getElements();
+ synchronized (displayedElement) {
+ Collections.sort(displayedElement, comp);
+ getTableManager().refreshNatTable();// useful?
+ }
+ } else {
+ getTableManager().updateAxisContents(getRepresentedContentProvider());
+ }
+ }
+
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAlreadyManaged(java.lang.Object)
+ *
+ * @param object
+ * @return
+ */
+ @Override
+ public boolean isAlreadyManaged(final Object object) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current.isAlreadyManaged(object)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#getSetNewAxisOrderCommand(java.util.List)
+ *
+ * @param newOrder
+ * @return
+ */
+ @Override
+ public Command getSetNewAxisOrderCommand(final List<Object> newOrder) {
+ if (canMoveAxis() && !isDynamic()) {
+ return new RecordingCommand(getTableEditingDomain()) {
+
+ @Override
+ protected void doExecute() {
+ final TreeMap<Integer, IAxis> order = new TreeMap<Integer, IAxis>();
+ final AbstractAxisProvider provider = getRepresentedContentProvider();
+ for (int i = 0; i < provider.getAxis().size(); i++) {
+ final IAxis currentAxis = provider.getAxis().get(i);
+ int index = newOrder.indexOf(currentAxis);
+ if (index != -1) {
+ order.put(Integer.valueOf(index), currentAxis);
+ } else {
+ Object resolvedObject = AxisUtils.getRepresentedElement(currentAxis);
+ if (currentAxis instanceof IdAxis) {
+ resolvedObject = getResolvedPath((IdAxis) currentAxis);
+ }
+ index = newOrder.indexOf(resolvedObject);
+ if (index == -1) {
+ throw new IndexOutOfBoundsException("A reordered element can't be resolved"); //$NON-NLS-1$
+ }
+ order.put(Integer.valueOf(index), currentAxis);
+ }
+ }
+
+ final List<IAxis> newValues = new ArrayList<IAxis>();
+ newValues.addAll(order.values());
+ SetCommand.create(getTableEditingDomain(), provider, NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), newValues).execute();
+ }
+ };
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @param axisManagerId
+ * an axis
+ * @return
+ * the axis manager managing it
+ *
+ * @deprecated since Eclipse Mars, use getSubAxisManagerFor instead
+ */
+ @Deprecated
+ protected IAxisManager findAxisManager(final IAxis axis) {
+ final String axisManagerId = axis.getManager().getAxisManagerId();
+ for (final IAxisManager currentManager : this.subManagers) {
+ if (currentManager.getAxisManagerRepresentation().getAxisManagerId().equals(axisManagerId)) {
+ return currentManager;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @param idAxis
+ * an idAxis
+ * @return
+ * the resolved path or the {@link String} represented by the idAxis if the path can't be resolved
+ */
+ protected Object getResolvedPath(final IdAxis idAxis) {
+ final String path = idAxis.getElement();
+ final IAxisManager manager = getSubAxisManagerFor(idAxis);
+ if (manager instanceof IIdAxisManager) {
+ final Object resolvedElement = ((IIdAxisManager) manager).resolvedPath(path);
+ if (resolvedElement != null) {
+ return resolvedElement;
+ }
+ }
+ return path;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManagerForEventList#manageSetNotification(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ protected void manageSetNotification(Notification notification) {
+ propagateEvent(notification);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManagerForEventList#manageUnsetNotification(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ protected void manageUnsetNotification(Notification notification) {
+ propagateEvent(notification);
+ }
+
+ @Override
+ protected void manageAddNotification(final Notification notification) {
+ final Object newValue = notification.getNewValue();
+ if (newValue instanceof IAxis && ((IAxis) newValue).eContainer() == getRepresentedContentProvider()) {
+ EventListHelper.addToEventList(eventList, newValue);
+ }
+ propagateEvent(notification);
+ }
+
+
+
+ @Override
+ protected void manageAddManyNotification(final Notification notification) {
+ final Object newValue = notification.getNewValue();
+ if (newValue instanceof Collection<?>) {
+ for (Object current : (Collection<?>) newValue) {
+ if (current instanceof IAxis && ((IAxis) current).eContainer() == getRepresentedContentProvider()) {
+ EventListHelper.addToEventList(eventList, current);
+ }
+ }
+
+ }
+ propagateEvent(notification);
+ }
+
+ @Override
+ protected void manageMoveNotification(final Notification notification) {
+ propagateEvent(notification);
+ }
+
+ @Override
+ protected void manageRemoveNotification(final Notification notification) {
+ final Object oldValue = notification.getOldValue();
+ propagateEvent(notification);
+ if (oldValue instanceof IAxis) {
+ EventListHelper.removeFromEventList(eventList, oldValue);
+ }
+ }
+
+ @Override
+ protected void manageRemoveManyNotification(final Notification notification) {
+ final Object oldValue = notification.getNewValue();
+ propagateEvent(notification);
+ if (oldValue instanceof Collection<?>) {
+ for (Object current : (Collection<?>) oldValue) {
+ if (current instanceof IAxis) {
+ EventListHelper.removeFromEventList(eventList, current);
+ }
+ }
+
+ }
+ }
+
+ /**
+ * This method propagates the notification to the submanagers in order to update the event list
+ *
+ * @param notification
+ * a notification
+ *
+ */
+ protected void propagateEvent(Notification notification) {
+ for (final IAxisManager current : this.subManagers) {
+ if (current instanceof IAxisManagerForEventList) {
+ ((IAxisManagerForEventList) current).manageEvent(notification);
+ }
+ }
+ // must not be done here -> to many refresh are done
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ICompositeAxisManager#updateAxisContents()
+ * @deprecated must be removed from the API
+ */
+ @Override
+ @Deprecated
+ public void updateAxisContents() {
+ // nothing to do
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.ITreeItemAxisManagerForEventList#treeFillingConfigurationHaveChanged()
+ *
+ */
+ @Override
+ public void fillingConfigurationsHaveChanged() {
+ for (final IAxisManager current : this.subManagers) {
+ if (current instanceof IAxisManagerForEventList) {
+ ((IAxisManagerForEventList) current).fillingConfigurationsHaveChanged();
+ }
+ }
+ // required
+ getTableManager().refreshNatTable();
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ICompositeAxisManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ICompositeAxisManager.java
index a9222849be4..e1774884c0f 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ICompositeAxisManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ICompositeAxisManager.java
@@ -19,6 +19,7 @@ import java.util.List;
import org.eclipse.emf.common.command.Command;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
/**
@@ -74,5 +75,13 @@ public interface ICompositeAxisManager extends IAxisManager {
*/
public Command getSetNewAxisOrderCommand(final List<Object> newOrder);
+ /**
+ *
+ * @param axis
+ * an axis
+ * @return
+ * the axis manager managing this axis
+ */
+ public IAxisManager getSubAxisManagerFor(final IAxis axis) ;
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ITreeItemAxisComparator.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ITreeItemAxisComparator.java
new file mode 100644
index 00000000000..5a2bd89dea9
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/ITreeItemAxisComparator.java
@@ -0,0 +1,230 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.manager.axis;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.papyrus.commands.Activator;
+import org.eclipse.papyrus.infra.nattable.manager.cell.CellManagerFactory;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration;
+import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils;
+import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
+
+/**
+ * This comparator is used to sort the ITreeItemAxis in the table according to the UML Model and the table model (order of the filling configuration).
+ * The sort of the row selecting the header IS NOI DONE HERE!
+ *
+ *
+ */
+public class ITreeItemAxisComparator implements Comparator<ITreeItemAxis> {
+
+ /**
+ * the table manager
+ */
+ private INattableModelManager manager;
+
+ /**
+ * the axis manager
+ */
+ private IAxisManager axisManager;
+
+ /**
+ * Constructor.
+ *
+ * @param representedAxisManager
+ *
+ */
+ public ITreeItemAxisComparator(INattableModelManager tableManager) {
+ this(tableManager, null);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param tableManager
+ * the table manager
+ * @param axisManager
+ * the axis manager representation, if <code>null</code>, we will deduce it from the compared axis. If you are during the opening of the table, you MUST define it, because
+ * we won't be able to deduce it from the IAxis.
+ */
+ public ITreeItemAxisComparator(INattableModelManager tableManager, AbstractTreeAxisManagerForEventList axisManager) {
+ this.manager = tableManager;
+ this.axisManager = axisManager;
+ }
+
+ private int compareObjectWithDifferentParent(ITreeItemAxis axis1, ITreeItemAxis axis2) {
+ ITreeItemAxis parent1 = axis1.getParent();
+ ITreeItemAxis parent2 = axis2.getParent();
+ Assert.isTrue(parent1 != parent2);
+
+ List<ITreeItemAxis> path1 = new ArrayList<ITreeItemAxis>();
+ List<ITreeItemAxis> path2 = new ArrayList<ITreeItemAxis>();
+ TableHelper.getPath(path1, axis1);
+ TableHelper.getPath(path2, axis2);
+ if (path1.size() == path2.size()) {
+ int indexToCompare = path1.size() - 1;
+ indexToCompare--;
+ // depth is currently not used and has no meaning in this case
+ return compare(path1.get(indexToCompare), path2.get(indexToCompare));
+ }
+ if (path1.size() > path2.size()) {
+ List<ITreeItemAxis> tmp = path2;
+ path2 = path1;
+ path1 = tmp;
+ }
+
+ // path1 is shortest than path2
+ Collections.reverse(path1);
+ ITreeItemAxis firstCommon = null;
+ for (ITreeItemAxis current : path1) {
+ if (path2.contains(current)) {
+ firstCommon = current;
+ break;
+ }
+ }
+
+ Collections.reverse(path1);
+ if (firstCommon == null) {
+ Activator.log.warn("No common ITreeItemAxis found"); //$NON-NLS-1$
+ throw new UnsupportedOperationException("Not yet implemented, please submit us a bug, with your example"); //$NON-NLS-1$
+ } else if (path1.get(path1.size() - 1) == firstCommon) {
+ // Activator.log.warn("no really common");
+ return 0;
+ } else {
+ int index1 = path1.indexOf(firstCommon);
+ int index2 = path2.indexOf(firstCommon);
+ return compare(path1.get(index1++), path2.get(index2++));
+ }
+ }
+
+ /**
+ *
+ * @param axis1
+ * @param axis2
+ * @return
+ * the axis manager representation
+ */
+ protected AxisManagerRepresentation getAxisManagerRepresentation(ITreeItemAxis axis1, ITreeItemAxis axis2) {
+ if (this.axisManager != null) {
+ return this.axisManager.getAxisManagerRepresentation();
+ }
+ IAxisManager axisManager = manager.getRowAxisManager();// return null when we are opening the table
+ Assert.isTrue(axisManager instanceof ICompositeAxisManager);
+
+ IAxisManager subAxisManager1 = ((ICompositeAxisManager) axisManager).getSubAxisManagerFor(axis1);
+ IAxisManager subAxisManager2 = ((ICompositeAxisManager) axisManager).getSubAxisManagerFor(axis2);
+ if ((subAxisManager1 != null || subAxisManager2 != null) && (subAxisManager1 != subAxisManager2)) {
+ throw new UnsupportedOperationException("this case is not yet supported"); //$NON-NLS-1$
+ }
+ return subAxisManager1.getAxisManagerRepresentation();
+ }
+
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ *
+ * @param o1
+ * @param o2
+ * @return
+ */
+ @Override
+ public int compare(ITreeItemAxis axis1, ITreeItemAxis axis2) {
+ if (axis1 == axis2) {
+ return 0;
+ }
+
+ if (axis1.getParent() != axis2.getParent()) {
+ return compareObjectWithDifferentParent(axis1, axis2);
+ }
+ Object el1 = axis1.getElement();
+ Object el2 = axis2.getElement();
+ int index1, index2;
+
+ // we are comparing 2 filling configurations
+ if (el1 instanceof TreeFillingConfiguration) {
+ Assert.isTrue(el2 instanceof TreeFillingConfiguration);
+ int depth1 = ((TreeFillingConfiguration) el1).getDepth();
+ int depth2 = ((TreeFillingConfiguration) el2).getDepth();
+ if (depth1 != depth2) {
+ // impossible
+ throw new UnsupportedOperationException("Please fill a bug with your example"); //$NON-NLS-1$
+ }
+ final List<TreeFillingConfiguration> confs = FillingConfigurationUtils.getTreeFillingConfiguration(manager.getTable(), getAxisManagerRepresentation(axis1, axis2));
+ index1 = confs.indexOf(el1);
+ index2 = confs.indexOf(el2);
+ } else {// we must compare values
+ // parent1 and parent2 are axis representing filling configuration
+ ITreeItemAxis parent1 = axis1.getParent();
+ if (parent1 == null) {
+ // its root element, filled by DnD
+
+ List<IAxis> axis = getAxisManager(axis1, axis2).getRepresentedContentProvider().getAxis();
+ index1 = axis.indexOf(axis1);
+ index2 = axis.indexOf(axis2);
+ } else {
+ TreeFillingConfiguration conf = (TreeFillingConfiguration) parent1.getElement();
+ ITreeItemAxis grandFather1 = parent1.getParent();
+ Object context = null;
+ if (grandFather1 == null) {
+ context = manager.getTable().getContext();
+ } else {
+ context = grandFather1.getElement();
+ }
+ Collection<?> values = CellManagerFactory.INSTANCE.getCrossValueAsCollection(conf.getAxisUsedAsAxisProvider(), context, this.manager);
+ if (values instanceof List<?>) {
+ index1 = ((List<?>) values).indexOf(axis1.getElement());
+ index2 = ((List<?>) values).indexOf(axis2.getElement());
+ } else {
+ index1 = index2 = 0;
+ }
+ }
+ }
+
+ int res = index1 - index2;
+ return Integer.signum(res);
+ }
+
+ /**
+ *
+ * @param axis1
+ * the first axis
+ * @param axis2
+ * the second axis
+ * @return
+ * the axis manager used
+ */
+ private IAxisManager getAxisManager(ITreeItemAxis axis1, ITreeItemAxis axis2) {
+ if (this.axisManager != null) {
+ return this.axisManager;
+ } else {
+ IAxisManager axisManager = manager.getRowAxisManager(); // will return null during the opening of the table
+ Assert.isTrue(axisManager instanceof ICompositeAxisManager);
+ IAxisManager subAxisManager1 = ((ICompositeAxisManager) axisManager).getSubAxisManagerFor(axis1);
+ IAxisManager subAxisManager2 = ((ICompositeAxisManager) axisManager).getSubAxisManagerFor(axis2);
+ if (subAxisManager1 != null && subAxisManager1 != subAxisManager2) {
+ throw new UnsupportedOperationException("this case is not yet supported"); //$NON-NLS-1$
+ }
+ return subAxisManager1;
+ }
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/cell/CellManagerFactory.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/cell/CellManagerFactory.java
index a7249931132..14d5f9f2901 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/cell/CellManagerFactory.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/cell/CellManagerFactory.java
@@ -13,6 +13,9 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.manager.cell;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
@@ -280,4 +283,31 @@ public final class CellManagerFactory {
}
return UnexecutableCommand.INSTANCE;
}
+
+
+ /**
+ *
+ * @param columnElement
+ * a column element
+ * @param rowElement
+ * a row element
+ * @param tableManager
+ * the table manager
+ * @return
+ * a collection of all values for the intersection of the columnElement and the row element.
+ */
+ public final Collection<?> getCrossValueAsCollection(final Object columnElement, final Object rowElement, final INattableModelManager tableManager) {
+ Object value = CellManagerFactory.INSTANCE.getCrossValue(columnElement, rowElement, tableManager);
+ if (value == null) {
+ return Collections.emptyList();
+ }
+ if (value instanceof Collection<?>) {
+ return (Collection<?>) value;
+ }
+
+ if (value instanceof Object[]) {
+ return Arrays.asList(value);
+ }
+ return Collections.emptyList();
+ }
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
index 7270087f71d..592f3ae43cf 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
@@ -86,8 +86,9 @@ import org.eclipse.papyrus.infra.nattable.configuration.CellEditorAxisConfigurat
import org.eclipse.papyrus.infra.nattable.configuration.CornerConfiguration;
import org.eclipse.papyrus.infra.nattable.configuration.FilterRowAxisConfiguration;
import org.eclipse.papyrus.infra.nattable.configuration.FilterRowCustomConfiguration;
-import org.eclipse.papyrus.infra.nattable.configuration.PapyrusClickSortConfiguration;
import org.eclipse.papyrus.infra.nattable.configuration.PapyrusHeaderMenuConfiguration;
+import org.eclipse.papyrus.infra.nattable.configuration.RowSortModelConfiguration;
+import org.eclipse.papyrus.infra.nattable.configuration.TableClickSortConfiguration;
import org.eclipse.papyrus.infra.nattable.dataprovider.AbstractCompositeDataProvider;
import org.eclipse.papyrus.infra.nattable.dataprovider.BodyDataProvider;
import org.eclipse.papyrus.infra.nattable.dataprovider.ColumnIndexHeaderDataProvider;
@@ -124,7 +125,6 @@ import org.eclipse.papyrus.infra.nattable.provider.PapyrusNatTableToolTipProvide
import org.eclipse.papyrus.infra.nattable.provider.TableSelectionProvider;
import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection;
import org.eclipse.papyrus.infra.nattable.selection.ISelectionExtractor;
-import org.eclipse.papyrus.infra.nattable.sort.ColumnSortModel;
import org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.DefaultSizeUtils;
@@ -242,7 +242,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* the sort model used for rows
*/
- private IPapyrusSortModel rowSortModel;
+ protected IPapyrusSortModel rowSortModel;
private ISelectionExtractor selectionExtractor;
@@ -251,13 +251,6 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
*/
private ResourceSetListener resourceSetListener;
- private IWorkbenchPartSite site;
-
- private MenuManager menuMgr;
-
- private Menu menu;
-
-
/**
* the filter configuration
*/
@@ -300,6 +293,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
protected final TransactionalEditingDomain getContextEditingDomain() {
return this.contextEditingDomain;
}
+
/**
*
* @see org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager#createNattable(org.eclipse.swt.widgets.Composite, int, org.eclipse.ui.IWorkbenchPartSite)
@@ -312,7 +306,6 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
@Override
public NatTable createNattable(final Composite parent, final int style, final IWorkbenchPartSite site) {
this.bodyDataProvider = new BodyDataProvider(this);
- this.site = site;
this.bodyLayerStack = new BodyLayerStack(this.bodyDataProvider, this);
@@ -326,7 +319,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
// this.columnHeaderDataProvider = new ColumnHeaderDataProvider(this);
// this.columnHeaderDataProvider = new ColumnHeaderDataProvider(this);
// this.columnHeaderLayerStack = new ColumnHeaderLayerStack(this.columnHeaderDataProvider, this.bodyLayerStack, this.bodyDataProvider, getRowSortModel());
- this.columnHeaderLayerStack = new ColumnHeaderLayerStack(indexColumnProvider, labelColumnProvider, this.bodyLayerStack, getRowSortModel());
+ this.columnHeaderLayerStack = new ColumnHeaderLayerStack(this, indexColumnProvider, labelColumnProvider, this.bodyLayerStack, getRowSortModel());
this.rowHeaderLayerStack = createRowHeaderLayerStack(this.bodyLayerStack);
rowHeaderDataProvider = new CompositeRowHeaderDataProvider(this);
@@ -356,9 +349,9 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
// we register nattable configuration
this.natTable.addConfiguration(new PapyrusHeaderMenuConfiguration());
- this.natTable.addConfiguration(new PapyrusClickSortConfiguration());
+ addClickSortConfiguration(this.natTable);
this.natTable.addConfiguration(new FilterRowCustomConfiguration());
-
+ this.natTable.addConfiguration(new RowSortModelConfiguration(getRowSortModel()));
// we register some information in the config registry of the nattable widget
IConfigRegistry configRegistry = this.natTable.getConfigRegistry();
@@ -398,8 +391,8 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
if (site != null) {
- this.menuMgr = createMenuManager(this.natTable);
- this.menu = menuMgr.createContextMenu(this.natTable);
+ final MenuManager menuMgr = createMenuManager(this.natTable);
+ final Menu menu = menuMgr.createContextMenu(this.natTable);
this.natTable.setMenu(menu);
this.selectionProvider = new TableSelectionProvider(this, this.bodyLayerStack.getSelectionLayer());
@@ -413,7 +406,16 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
return this.natTable;
}
-
+ /**
+ * Configure the row sort selecting column header
+ *
+ * @param natTable
+ * the nattable widget
+ */
+ protected void addClickSortConfiguration(NatTable natTable) {
+ natTable.addConfiguration(new TableClickSortConfiguration());
+ }
+
/**
* @return
* the filter strategy to use
@@ -613,7 +615,18 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
* @return
*/
public MenuManager createMenuManager(final NatTable natTable) {
- final MenuManager menuManager = new MenuManager("#PopUp", "org.eclipse.papyrus.infra.nattable.widget.menu");
+ final MenuManager menuManager = new MenuManager("#PopUp", "org.eclipse.papyrus.infra.nattable.widget.menu") { //$NON-NLS-1$ //$NON-NLS-2$
+
+ @Override
+ public void add(final IAction action) {
+ super.add(action);
+ }
+
+ @Override
+ public void add(final IContributionItem item) {
+ super.add(item);
+ }
+ };
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menuManager.setRemoveAllWhenShown(true);
@@ -1120,37 +1133,19 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
@Override
public void dispose() {
- if (this.selectionProvider != null) {
- this.selectionProvider.dispose();
- }
-
- if (site != null) {
- site.setSelectionProvider(null);
- this.site = null;
- }
-
- if(this.menu!=null){
- this.menu.dispose();
- this.menu=null;
- }
-
- if(this.menuMgr!=null){
- this.menuMgr.dispose();
- this.menuMgr = null;
- }
-
if (this.bodyDataProvider != null) {
this.bodyLayerStack.removeLayerListener(resizeAxisListener);
this.bodyDataProvider.dispose();
}
if (this.rowHeaderDataProvider != null) {
+ this.rowHeaderLayerStack.removeLayerListener(resizeRowHeaderListener);
this.rowHeaderDataProvider.dispose();
}
- this.rowHeaderLayerStack.removeLayerListener(resizeRowHeaderListener);
if (this.columnHeaderDataProvider != null) {
+ this.columnHeaderLayerStack.removeLayerListener(resizeColumnHeaderListener);
this.columnHeaderDataProvider.dispose();
}
- this.columnHeaderLayerStack.removeLayerListener(resizeColumnHeaderListener);
+
if (this.tableEditingDomain != null && this.resourceSetListener != null) {
this.tableEditingDomain.removeResourceSetListener(this.resourceSetListener);
@@ -1161,7 +1156,6 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
this.tableEditingDomain = null;
this.contextEditingDomain = null;
this.tableContext = null;
- this.natTable.dispose();
}
public EObject getTableContext() {
@@ -1173,17 +1167,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
return this.table;
}
- /**
- *
- * @return
- * the created sort model to use for
- */
- protected IPapyrusSortModel getRowSortModel() {
- if (this.rowSortModel == null) {
- this.rowSortModel = new ColumnSortModel(this);
- }
- return this.rowSortModel;
- }
+ protected abstract IPapyrusSortModel getRowSortModel();
/**
*
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
index 86ed66a2d35..9f3925518c7 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
@@ -92,6 +92,8 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.BooleanVa
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.IntValueStyle;
import org.eclipse.papyrus.infra.nattable.selection.ISelectionExtractor;
import org.eclipse.papyrus.infra.nattable.selection.ObjectsSelectionExtractor;
+import org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel;
+import org.eclipse.papyrus.infra.nattable.sort.PapyrusCompositeGlazedListSortModel;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.CellMapKey;
import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils;
@@ -120,6 +122,7 @@ import com.google.common.collect.HashBiMap;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.FilterList;
import ca.odell.glazedlists.GlazedLists;
+import ca.odell.glazedlists.SortedList;
import ca.odell.glazedlists.event.ListEvent;
import ca.odell.glazedlists.event.ListEventListener;
@@ -386,32 +389,65 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
}
+ protected SortedList<Object> rowSortedList;
+
+ protected SortedList<Object> columnSortedList;
+
/**
- *
+ *
* @return
- * the new list to use for vertical element
+ * the new list to use for vertical element
*/
protected List<Object> createVerticalElementList() {
// return Collections.synchronizedList(new ArrayList<Object>());
this.basicVerticalList = GlazedLists.eventList(new ArrayList<Object>());
// it required than vertical element is a filter list -> warning to invert axis?
- this.verticalFilterList = new FilterList<Object>(this.basicVerticalList);
+ this.columnSortedList = new SortedList<Object>(this.basicVerticalList, null);
+ this.verticalFilterList = new FilterList<Object>(this.columnSortedList);
return this.verticalFilterList;
}
/**
- *
+ *
* @return
- * the new list to use for horizontal element
+ * the new list to use for horizontal element
*/
protected List<Object> createHorizontalElementList() {
// return Collections.synchronizedList(new ArrayList<Object>());
this.basicHorizontalList = GlazedLists.eventList(new ArrayList<Object>());
- FilterList<Object> filteredList = new FilterList<Object>(this.basicHorizontalList);
+ this.rowSortedList = new SortedList<Object>(this.basicHorizontalList, null);
+ FilterList<Object> filteredList = new FilterList<Object>(this.rowSortedList);
this.horizontalFilterList = filteredList;
return this.horizontalFilterList;
}
+ public SortedList<Object> getRowSortedList() {
+ return this.rowSortedList;
+ }
+
+ public SortedList<Object> getColumnSortedList() {
+ return this.columnSortedList;
+ }
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.table.AbstractNattableWidgetManager#getRowSortModel()
+ *
+ * @return
+ */
+ @Override
+ protected IPapyrusSortModel getRowSortModel() {
+ if (this.rowSortModel == null) {
+ boolean inverted = getTable().isInvertAxis();
+ if (inverted) {
+ this.rowSortModel = new PapyrusCompositeGlazedListSortModel(this, getColumnSortedList(), getRowSortedList(), inverted);
+ } else {
+ this.rowSortModel = new PapyrusCompositeGlazedListSortModel(this, getRowSortedList(), getColumnSortedList(), inverted);
+ }
+ }
+ return this.rowSortModel;
+
+
+ }
+
@Override
public NatTable createNattable(Composite parent, int style, IWorkbenchPartSite site) {
@@ -649,20 +685,28 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
EventList<Object> newHorizontalBasicList = this.basicVerticalList;
EventList<Object> newVerticalBasicList = this.basicHorizontalList;
+ SortedList<Object> newHorizontalSortedList = this.rowSortedList;
+ SortedList<Object> newVerticalSortedList = this.columnSortedList;
+
FilterList<Object> newVerticalFilterLilst = this.horizontalFilterList;
FilterList<Object> newHorizontalFilterList = this.verticalFilterList;
this.basicVerticalList = newVerticalBasicList;
this.basicHorizontalList = newHorizontalBasicList;
+
this.horizontalFilterList = newHorizontalFilterList;
this.verticalFilterList = newVerticalFilterLilst;
+ this.rowSortedList = newHorizontalSortedList;
+ this.columnSortedList = newVerticalSortedList;
+
NattableModelManager.this.rowManager = newRowManager;
NattableModelManager.this.columnManager = newColumnManager;
this.rowManager.setAxisComparator(null);
this.columnManager.setAxisComparator(null);
+ ((IPapyrusSortModel) getRowSortModel()).setTableInverted(getTable().isInvertAxis());
updateToggleActionState();
// configureNatTable();
@@ -730,7 +774,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
final List<IAxisManager> managers = new ArrayList<IAxisManager>();
for (AxisManagerRepresentation current : representations) {
final IAxisManager manager = AxisManagerFactory.INSTANCE.getAxisManager(current);
- assert manager != null;
+ Assert.isNotNull(manager);
manager.init(this, current, contentProvider);
managers.add(manager);
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java
index b653f77b2d6..ae1a1f548f8 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java
@@ -30,6 +30,7 @@ import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.papyrus.commands.Activator;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe;
import org.eclipse.papyrus.infra.nattable.command.CommandIds;
+import org.eclipse.papyrus.infra.nattable.configuration.TreeTableClickSortConfiguration;
import org.eclipse.papyrus.infra.nattable.layerstack.BodyLayerStack;
import org.eclipse.papyrus.infra.nattable.layerstack.RowHeaderHierarchicalLayerStack;
import org.eclipse.papyrus.infra.nattable.layerstack.RowHeaderLayerStack;
@@ -66,6 +67,7 @@ import org.eclipse.ui.commands.ICommandService;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.FilterList;
import ca.odell.glazedlists.GlazedLists;
+import ca.odell.glazedlists.SortedList;
import ca.odell.glazedlists.TreeList;
import ca.odell.glazedlists.TreeList.Format;
@@ -127,9 +129,12 @@ public class TreeNattableModelManager extends NattableModelManager implements IT
EventList<Object> eventList = GlazedLists.eventList(new ArrayList<Object>());
eventList = GlazedLists.threadSafeList(eventList);
this.basicHorizontalList = eventList;
- treeFormat = new DatumTreeFormat(new ColumnSortModel(this));
+ // must be created before the row sort model
+ this.rowSortedList = new SortedList<Object>(this.basicHorizontalList, null);
+ treeFormat = new DatumTreeFormat(getRowSortModel());
this.expansionModel = new DatumExpansionModel();
- this.horizontalFilterList = new FilterList<Object>(this.basicHorizontalList);
+
+ this.horizontalFilterList = new FilterList<Object>(this.rowSortedList);
this.treeList = new TreeList(this.horizontalFilterList, treeFormat, expansionModel);
return this.treeList;
@@ -166,6 +171,17 @@ public class TreeNattableModelManager extends NattableModelManager implements IT
}
/**
+ * @see org.eclipse.papyrus.infra.nattable.manager.table.AbstractNattableWidgetManager#addClickSortConfiguration(org.eclipse.nebula.widgets.nattable.NatTable)
+ *
+ * @param natTable
+ */
+ @Override
+ protected void addClickSortConfiguration(NatTable natTable) {
+ natTable.addConfiguration(new TreeTableClickSortConfiguration());
+ }
+
+
+ /**
* @see org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager#updateToggleActionState()
*
*/
@@ -379,7 +395,7 @@ public class TreeNattableModelManager extends NattableModelManager implements IT
protected Adapter createInvertAxisListener() {
return null;
}
-
+
/**
* Modify the axis when it is disposed.
*
@@ -415,7 +431,7 @@ public class TreeNattableModelManager extends NattableModelManager implements IT
}
final List<IAxis> iAxis = getHorizontalAxisProvider().getAxis();
- if (iAxis != null && !iAxis.isEmpty()) { // see bug 467706: [Table 2] Tree Table with no tree filling configuration on depth==0 can't be reopened
+ if (iAxis != null && !iAxis.isEmpty()) { // see bug 467706: [Table 2] Tree Table with no tree filling configuration on depth==0 can't be reopened
// we need to remove the children which are not serialized from the root of the table, to be able to reopen
Runnable runnable = new Runnable() {
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/AbstractNattableCellLabelProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/AbstractNattableCellLabelProvider.java
index 01488f287b6..b0aa4c976f4 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/AbstractNattableCellLabelProvider.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/AbstractNattableCellLabelProvider.java
@@ -24,6 +24,7 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.I
import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderContextElementWrapper;
import org.eclipse.papyrus.infra.nattable.utils.LabelConfigurationManagementUtils;
import org.eclipse.papyrus.infra.nattable.utils.LabelProviderCellContextElementWrapper;
+import org.eclipse.papyrus.infra.nattable.utils.LabelProviderFullCellContextElementWrapper;
import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
@@ -121,6 +122,9 @@ public abstract class AbstractNattableCellLabelProvider implements IFilteredLabe
* the row object for this cell
*/
protected Object getRowObject(final ILayerCell cell, final IConfigRegistry registry) {
+ if(cell instanceof LabelProviderFullCellContextElementWrapper){
+ return ((LabelProviderFullCellContextElementWrapper) cell).getRowObject();
+ }
int rowIndex = cell.getRowIndex();
INattableModelManager provider = getAxisContentProvider(registry);
return provider.getRowElement(rowIndex);
@@ -134,6 +138,9 @@ public abstract class AbstractNattableCellLabelProvider implements IFilteredLabe
* the column object for this cell
*/
protected Object getColumnObject(final ILayerCell cell, final IConfigRegistry registry) {
+ if(cell instanceof LabelProviderFullCellContextElementWrapper){
+ return ((LabelProviderFullCellContextElementWrapper) cell).getColumnObject();
+ }
int columnIndex = cell.getColumnIndex();
INattableModelManager provider = getAxisContentProvider(registry);
return provider.getColumnElement(columnIndex);
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/AbstractGlazedListSortModel.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/AbstractGlazedListSortModel.java
new file mode 100644
index 00000000000..55626e53b99
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/AbstractGlazedListSortModel.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.sort;
+
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
+import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.ui.services.IDisposable;
+
+/**
+ * @author VL222926
+ *
+ */
+public abstract class AbstractGlazedListSortModel implements ISortModel, ILayerListener, IDisposable {
+
+ /**
+ * the table manager
+ */
+ private INattableModelManager tableManager;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param manager
+ * the table manager to use
+ */
+ public AbstractGlazedListSortModel(final INattableModelManager manager) {
+ this.tableManager = manager;
+ }
+
+ /**
+ *
+ * @return
+ * the table manager to use
+ */
+ protected final INattableModelManager getTableManager() {
+ return this.tableManager;
+ }
+
+ /**
+ *
+ * @return
+ * the config registry to use
+ */
+ protected final IConfigRegistry getIConfigRegistry() {
+ NatTable natTable = (NatTable) this.tableManager.getAdapter(NatTable.class);
+ return natTable.getConfigRegistry();
+ }
+
+ /**
+ * @see org.eclipse.ui.services.IDisposable#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ this.tableManager = null;
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortModel.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortModel.java
index ebe95a946c4..280421dca1c 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortModel.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortModel.java
@@ -28,6 +28,12 @@ import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.tools.comparator.CompositeComparator;
+/**
+ * @Deprecated since Eclipse Mars
+ * @author VL222926
+ *
+ */
+@Deprecated
public class ColumnSortModel implements IPapyrusSortModel {
@@ -247,4 +253,14 @@ public class ColumnSortModel implements IPapyrusSortModel {
return null;
}
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel#setTableInverted(boolean)
+ *
+ * @param isInverted
+ */
+ @Override
+ public void setTableInverted(boolean isInverted) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/IPapyrusSortModel.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/IPapyrusSortModel.java
index 33d1ff6ef5f..ff9b8db231b 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/IPapyrusSortModel.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/IPapyrusSortModel.java
@@ -27,4 +27,11 @@ public interface IPapyrusSortModel extends ISortModel {
* remove axis which have been destroyed from the comparison
*/
public void updateSort();
+
+ /**
+ *
+ * @param isInverted
+ * <code>true</code> when the table isInverted
+ */
+ public void setTableInverted(boolean isInverted);
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusColumnAccessor.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusColumnAccessor.java
new file mode 100644
index 00000000000..af4821421ca
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusColumnAccessor.java
@@ -0,0 +1,92 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.sort;
+
+import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
+import org.eclipse.papyrus.infra.nattable.manager.cell.CellManagerFactory;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+
+/**
+ *
+ * @author VL222926
+ *
+ */
+public class PapyrusColumnAccessor implements IColumnAccessor<Object> {
+
+ // private IConfigRegistry configRegistry;
+
+ private INattableModelManager manager;
+
+ // use me on luna only
+ // public PapyrusColumnAccesor(IConfigRegistry configRegistry) {
+ // this.configRegistry = configRegistry;
+ // }
+
+ /**
+ * Constructor.
+ *
+ */
+ // remove me on mars
+ public PapyrusColumnAccessor(INattableModelManager manager) {
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.data.IColumnAccessor#getDataValue(java.lang.Object, int)
+ *
+ * @param rowObject
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ public Object getDataValue(Object rowObject, int columnIndex) {
+ INattableModelManager manager = getTableManager();
+ return CellManagerFactory.INSTANCE.getCrossValue(manager.getColumnElement(columnIndex), rowObject, manager);
+ }
+
+ /**
+ * @return
+ */
+ private INattableModelManager getTableManager() {
+ // on luna
+ return this.manager;
+
+ // on mars;
+ // return this.configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.data.IColumnAccessor#setDataValue(java.lang.Object, int, java.lang.Object)
+ *
+ * @param rowObject
+ * @param columnIndex
+ * @param newValue
+ */
+ @Override
+ public void setDataValue(Object rowObject, int columnIndex, Object newValue) {
+ throw new UnsupportedOperationException("Not yet implemented"); //$NON-NLS-1$
+
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.data.IColumnAccessor#getColumnCount()
+ *
+ * @return
+ */
+ @Override
+ public int getColumnCount() {
+ return getTableManager().getColumnCount();
+ }
+
+} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusCompositeGlazedListSortModel.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusCompositeGlazedListSortModel.java
new file mode 100644
index 00000000000..7767a14b002
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusCompositeGlazedListSortModel.java
@@ -0,0 +1,238 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.sort;
+
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
+import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.ui.services.IDisposable;
+
+import ca.odell.glazedlists.SortedList;
+
+/**
+ * @author VL222926
+ *
+ */
+public class PapyrusCompositeGlazedListSortModel extends AbstractGlazedListSortModel implements IPapyrusSortModel, IDisposable {
+
+ /**
+ * the column sort model
+ */
+ private PapyrusGlazedListsSortModel columnSortModel;
+
+ /**
+ * the row sort model
+ */
+ private PapyrusGlazedListsSortModel rowSortModel;
+
+ /**
+ * <code>true</code> if the table is inverted
+ */
+ private boolean isTableInverted = false;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param manager
+ * the table manager
+ * @param realRowObjectList
+ * the real row object list (ignoring invert axis)
+ * @param realColumnObjectList
+ * the real column object list (ignoring invert axis)
+ */
+ public PapyrusCompositeGlazedListSortModel(final INattableModelManager manager, final SortedList<Object> realRowObjectList, final SortedList<Object> realColumnObjectList, final boolean isInverted) {
+ super(manager);
+ this.isTableInverted = isInverted;
+ IColumnAccessor<Object> columnAccessor = new PapyrusColumnAccessor(manager);
+ // the column sort model, sort the row list
+ this.columnSortModel = new PapyrusGlazedListsSortModel(manager, realRowObjectList, columnAccessor);
+ // the row sort model, sort the column list
+ this.rowSortModel = new PapyrusGlazedListsSortModel(manager, realColumnObjectList, columnAccessor);
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel#updateSort()
+ *
+ */
+ @Override
+ public void updateSort() {
+ // TODO required ?
+
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.ILayerListener#handleLayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)
+ *
+ * @param event
+ */
+ @Override
+ public void handleLayerEvent(ILayerEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#getSortedColumnIndexes()
+ *
+ * @return
+ */
+ @Override
+ public List<Integer> getSortedColumnIndexes() {
+ if (isTableInverted) {
+ return this.rowSortModel.getSortedColumnIndexes();
+ }
+ return this.columnSortModel.getSortedColumnIndexes();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#isColumnIndexSorted(int)
+ *
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ public boolean isColumnIndexSorted(int columnIndex) {
+ if (isTableInverted) {
+ return this.rowSortModel.isColumnIndexSorted(columnIndex);
+ }
+ return this.columnSortModel.isColumnIndexSorted(columnIndex);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#getSortDirection(int)
+ *
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ public SortDirectionEnum getSortDirection(int columnIndex) {
+ if (isTableInverted) {
+ return this.rowSortModel.getSortDirection(columnIndex);
+ }
+ return this.columnSortModel.getSortDirection(columnIndex);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#getSortOrder(int)
+ *
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ public int getSortOrder(int columnIndex) {
+ if (isTableInverted) {
+ return this.rowSortModel.getSortOrder(columnIndex);
+ }
+ return this.columnSortModel.getSortOrder(columnIndex);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#getComparatorsForColumnIndex(int)
+ *
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ public List<Comparator> getComparatorsForColumnIndex(int columnIndex) {
+ if (isTableInverted) {
+ return this.rowSortModel.getComparatorsForColumnIndex(columnIndex);
+ }
+ return this.columnSortModel.getComparatorsForColumnIndex(columnIndex);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#sort(int, org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum, boolean)
+ *
+ * @param columnIndex
+ * @param sortDirection
+ * @param accumulate
+ */
+ @Override
+ public void sort(int columnIndex, SortDirectionEnum sortDirection, boolean accumulate) {
+ if (isTableInverted) {
+ this.rowSortModel.sort(columnIndex, sortDirection, accumulate);
+ } else {
+ this.columnSortModel.sort(columnIndex, sortDirection, accumulate);
+ }
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#clear()
+ *
+ */
+ @Override
+ public void clear() {
+ // TODO Auto-generated method stub
+ }
+
+
+
+ /**
+ * @param compositeLayer
+ */
+ // TODO : try to remove me
+ public void setColumnHeaderLayer(ILayer compositeLayer) {
+ this.rowSortModel.setColumnHeaderLayer(compositeLayer);
+ this.columnSortModel.setColumnHeaderLayer(compositeLayer);
+ }
+
+
+ /**
+ * @see org.eclipse.ui.services.IDisposable#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ this.columnSortModel.dispose();
+ this.rowSortModel.dispose();
+ this.rowSortModel = null;
+ this.columnSortModel = null;
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel#setTableInverted(boolean)
+ *
+ * @param isInverted
+ */
+ @Override
+ public void setTableInverted(boolean isInverted) {
+ this.isTableInverted = isInverted;
+ this.rowSortModel.clear();
+ this.columnSortModel.clear();
+ }
+
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#getColumnComparator(int)
+ *
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ public Comparator<?> getColumnComparator(int columnIndex) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusGlazedListsSortModel.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusGlazedListsSortModel.java
new file mode 100644
index 00000000000..f96d8d6d356
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusGlazedListsSortModel.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Original authors and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.papyrus.infra.nattable.sort;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
+import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyResolver;
+//import org.eclipse.nebula.widgets.nattable.extension.glazedlists.NatColumnTableFormat;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
+import org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent;
+import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
+import org.eclipse.papyrus.infra.nattable.glazedlists.PapyrusSortingState;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.sort.copy.NatTableComparatorChooser;
+
+import ca.odell.glazedlists.SortedList;
+
+
+/**
+ *
+ * @author VL222926
+ * This class provides the sort model for an axis
+ */
+public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
+
+ /**
+ * the column accessor
+ */
+ protected IColumnAccessor<Object> columnAccessor;
+
+ /**
+ * the sorted list
+ */
+ protected SortedList<Object> sortedList;
+
+ // TODO : useful
+ private NatTableComparatorChooser<Object> comparatorChooser;
+ // protected SortedList<T> sortedList;
+
+ // TODO : useful ?
+ protected IColumnPropertyResolver columnPropertyResolver;
+
+ // TODO : useful ?
+ protected ILayer columnHeaderDataLayer;
+
+
+ /**
+ * Constructor.
+ *
+ * @param manager
+ * @param sortedList
+ * @param columnAccessor
+ */
+ public PapyrusGlazedListsSortModel(INattableModelManager manager, SortedList<Object> sortedList, IColumnAccessor<Object> columnAccessor) {
+ super(manager);
+ this.columnAccessor = columnAccessor;
+ this.sortedList = sortedList;
+ }
+
+
+
+ protected PapyrusNatColumnTableFormat<Object> f;
+
+ protected NatTableComparatorChooser<Object> getComparatorChooser() {
+
+ if (comparatorChooser == null) {
+ f = new PapyrusNatColumnTableFormat<Object>(columnAccessor, getTableManager(), columnHeaderDataLayer);
+ comparatorChooser =
+ new PapyrusNatTableComparatorChooser(sortedList, f) {
+
+ /**
+ * @see ca.odell.glazedlists.gui.AbstractTableComparatorChooser#createSortingState()
+ *
+ * @return
+ */
+ @Override
+ protected org.eclipse.papyrus.infra.nattable.glazedlists.copy.SortingState createSortingState() {
+ return new PapyrusSortingState(this, getTableManager());
+ }
+ };
+ }
+
+ return comparatorChooser;
+ }
+
+ protected IConfigRegistry getConfigRegistry() {
+ NatTable nat = (NatTable) getTableManager().getAdapter(NatTable.class);
+ return nat.getConfigRegistry();
+ }
+
+ @Override
+ public List<Integer> getSortedColumnIndexes() {
+ return getComparatorChooser().getSortingColumns();
+ }
+
+ @Override
+ public int getSortOrder(int columnIndex) {
+ return getComparatorChooser().getClickSequence(columnIndex);
+ }
+
+ @Override
+ public SortDirectionEnum getSortDirection(int columnIndex) {
+ return getComparatorChooser().getSortDirectionForColumnIndex(columnIndex);
+ }
+
+ @Override
+ public boolean isColumnIndexSorted(int columnIndex) {
+ return getComparatorChooser().isColumnIndexSorted(columnIndex);
+ }
+
+ @Override
+ public List<Comparator> getComparatorsForColumnIndex(int columnIndex) {
+ return getComparatorChooser().getComparatorsForColumn(columnIndex);
+ }
+
+ @Override
+ public void sort(int columnIndex, SortDirectionEnum sortDirection, boolean accumulate) {
+ getComparatorChooser().sort(columnIndex, sortDirection, accumulate);
+ }
+
+ @Override
+ public void clear() {
+ getComparatorChooser().clearComparator();
+ }
+
+ @Override
+ public void handleLayerEvent(ILayerEvent event) {
+ if (event instanceof StructuralRefreshEvent && ((StructuralRefreshEvent) event).isHorizontalStructureChanged()) {
+ String test = getComparatorChooser().toString();
+ this.comparatorChooser = null;
+ getComparatorChooser().fromString(test);
+ }
+ }
+
+ /**
+ * @param compositeLayer
+ */
+ // TODO : try to remove me
+ public void setColumnHeaderLayer(ILayer compositeLayer) {
+ this.columnHeaderDataLayer = compositeLayer;
+ this.columnHeaderDataLayer.addLayerListener(this);// useful ?
+ if (f != null) {
+ f.setColumnHeaderDataLayer(columnHeaderDataLayer);
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel#updateSort()
+ *
+ */
+ // @Override
+ public void updateSort() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#getColumnComparator(int)
+ *
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ public Comparator<?> getColumnComparator(int columnIndex) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatColumnTableFormat.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatColumnTableFormat.java
new file mode 100644
index 00000000000..b242ac8b176
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatColumnTableFormat.java
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Original authors and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.papyrus.infra.nattable.sort;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.config.NullComparator;
+import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
+import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.sort.SortConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.SortLabelProviderFullCellContextElementWrapper;
+
+import ca.odell.glazedlists.gui.AdvancedTableFormat;
+
+/**
+ *
+ * @author VL222926
+ *
+ * @param <R>
+ */
+public class PapyrusNatColumnTableFormat<R> implements AdvancedTableFormat<R> {
+
+ /**
+ * size of the cache
+ */
+ private static final int SORT_LABEL_PROVIDER_CACHE_SIZE = 2;
+
+ /**
+ * the index of the value to use in the cache
+ */
+ private int cacheIndex = 0;
+
+ /**
+ * the cache used to avoid to create too many wrapper during the sort
+ */
+ private List<SortLabelProviderFullCellContextElementWrapper> sortLabelProviderCache = null;
+
+
+ /**
+ * the column accessor
+ */
+ private IColumnAccessor<R> columnAccessor;
+
+ /**
+ * the column header data layer
+ */
+ private ILayer columnHeaderDataLayer;
+
+ /**
+ * the table manager
+ */
+ private INattableModelManager manager;
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param columnAccessor
+ * the column accessor
+ * @param manager
+ * the table manager
+ * @param columnHeaderDataLayer
+ * the column header data layer
+ */
+ public PapyrusNatColumnTableFormat(IColumnAccessor<R> columnAccessor, INattableModelManager manager, ILayer columnHeaderDataLayer) {
+ this.manager = manager;
+ this.columnHeaderDataLayer = columnHeaderDataLayer;
+ this.columnAccessor = columnAccessor;
+
+ // we init the cache of returned values for the comparison
+ // initCache();//we can not do it here, because the config registry is not yet available
+
+ }
+
+ /**
+ * init the cache to use
+ */
+ private void initCache() {
+ this.sortLabelProviderCache = new ArrayList<SortLabelProviderFullCellContextElementWrapper>();
+ for (int i = 0; i < SORT_LABEL_PROVIDER_CACHE_SIZE; i++) {
+ SortLabelProviderFullCellContextElementWrapper w = new SortLabelProviderFullCellContextElementWrapper();
+ w.setConfigLabels(new LabelStack(GridRegion.BODY));
+ w.setConfigRegistry(getConfigRegistry());
+ this.sortLabelProviderCache.add(w);
+ }
+ }
+
+ /**
+ *
+ * @param layer
+ * the column header data layer
+ */
+ public void setColumnHeaderDataLayer(ILayer layer) {
+ this.columnHeaderDataLayer = layer;
+ }
+
+ /**
+ *
+ * @return
+ * the config registry
+ */
+ private IConfigRegistry getConfigRegistry() {
+ NatTable natTable = (NatTable) this.manager.getAdapter(NatTable.class);
+ return natTable.getConfigRegistry();
+ }
+
+ /**
+ *
+ * @see ca.odell.glazedlists.gui.AdvancedTableFormat#getColumnClass(int)
+ *
+ * @param col
+ * @return
+ */
+ public Class<?> getColumnClass(int col) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Comparator<?> getColumnComparator(final int col) {
+ if (this.columnHeaderDataLayer == null) {
+ return null;
+ }
+ ILayerCell cell = null;
+ Comparator<?> comparator = null;
+
+ cell = columnHeaderDataLayer.getCellByPosition(col, 0);
+ if (cell == null) {
+ comparator = new NullComparator();// config registry is not yet here!
+ // ().getConfigAttribute(
+ // SortConfigAttributes.SORT_COMPARATOR,
+ // DisplayMode.NORMAL,
+ // GridRegion.BODY);
+ } else {
+ comparator = getConfigRegistry().getConfigAttribute(
+ SortConfigAttributes.SORT_COMPARATOR,
+ cell.getDisplayMode(),
+ cell.getConfigLabels().getLabels());
+ }
+ return (comparator instanceof NullComparator) ? null : comparator;
+ }
+
+ /**
+ *
+ * @see ca.odell.glazedlists.gui.TableFormat#getColumnName(int)
+ *
+ * @param col
+ * @return
+ */
+ public String getColumnName(int col) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ *
+ * @see ca.odell.glazedlists.gui.TableFormat#getColumnCount()
+ *
+ * @return
+ */
+ public int getColumnCount() {
+ return columnAccessor.getColumnCount();
+ }
+
+
+ /**
+ *
+ * @see ca.odell.glazedlists.gui.TableFormat#getColumnValue(java.lang.Object, int)
+ *
+ * @param rowObj
+ * @param col
+ * @return
+ */
+ public Object getColumnValue(R rowObj, int col) {
+ if (this.sortLabelProviderCache == null) {
+ initCache();
+ }
+ SortLabelProviderFullCellContextElementWrapper w = this.sortLabelProviderCache.get(cacheIndex);
+
+ if (AxisUtils.getRepresentedElement(rowObj) instanceof TreeFillingConfiguration) {
+ w.setDataValue(null);// it is not necessary to look for a value which does not exist
+ } else {
+ w.setDataValue(this.columnAccessor.getDataValue(rowObj, col));
+ }
+
+ w.setRowObject(rowObj);
+ w.setColumnObject(this.manager.getColumnElement(col));
+ w.setColumnIndex(col);
+
+ // we increment the index of the cached value to use
+ this.cacheIndex++;
+ if (this.cacheIndex == SORT_LABEL_PROVIDER_CACHE_SIZE) {
+ this.cacheIndex = 0;
+ }
+ return w;
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatTableComparatorChooser.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatTableComparatorChooser.java
new file mode 100644
index 00000000000..c3611870cd0
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatTableComparatorChooser.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.sort;
+
+import org.eclipse.papyrus.infra.nattable.sort.copy.NatTableComparatorChooser;
+
+import ca.odell.glazedlists.SortedList;
+import ca.odell.glazedlists.gui.TableFormat;
+
+/**
+ * @author VL222926
+ *
+ */
+public class PapyrusNatTableComparatorChooser extends NatTableComparatorChooser<Object> {
+
+ /**
+ * Constructor.
+ *
+ * @param sortedList
+ * @param tableFormat
+ */
+ public PapyrusNatTableComparatorChooser(SortedList<Object> sortedList, TableFormat<Object> tableFormat) {
+ super(sortedList, tableFormat);
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/copy/NatTableComparatorChooser.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/copy/NatTableComparatorChooser.java
new file mode 100644
index 00000000000..964221f6ffe
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/copy/NatTableComparatorChooser.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Original authors and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.papyrus.infra.nattable.sort.copy;
+
+import static org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum.ASC;
+import static org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum.DESC;
+import static org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum.NONE;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
+import org.eclipse.papyrus.infra.nattable.glazedlists.copy.AbstractTableComparatorChooser;
+
+
+import ca.odell.glazedlists.SortedList;
+//import ca.odell.glazedlists.gui.AbstractTableComparatorChooser;
+//import ca.odell.glazedlists.gui.AbstractTableComparatorChooser;
+import ca.odell.glazedlists.gui.TableFormat;
+
+public class NatTableComparatorChooser<T> extends AbstractTableComparatorChooser<T> {
+
+ public NatTableComparatorChooser(SortedList<T> sortedList, TableFormat<T> tableFormat) {
+ super(sortedList, tableFormat);
+ }
+
+ //TODO Vincent Lorenzo has changed the API, I add public
+ public void sort(int columnIndex, SortDirectionEnum sortDirection, boolean accumulate) {
+ if(getComparatorsForColumn(columnIndex).isEmpty()){
+ return;
+ }
+ if (!accumulate) {
+ clearComparator();
+ }
+
+ switch (sortDirection) {
+ case NONE:
+ removeSortingColumnIndex(columnIndex);
+ break;
+ case ASC:
+ removeSortingColumnIndex(columnIndex);
+ appendComparator(columnIndex, 0, false);
+ break;
+ case DESC:
+ removeSortingColumnIndex(columnIndex);
+ appendComparator(columnIndex, 0, true);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void removeSortingColumnIndex(int columnIndex) {
+ // Save comparators
+ List<ComparatorInfo> comparatorInfos = new ArrayList<ComparatorInfo>();
+ for (int sortingColumnIndex : getSortingColumns()) {
+ if (sortingColumnIndex != columnIndex) {
+ boolean reverse = isColumnReverse(sortingColumnIndex);
+ comparatorInfos.add(new ComparatorInfo(sortingColumnIndex, reverse));
+ }
+ }
+
+ clearComparator();
+
+ // Rebuild comparators
+ for (ComparatorInfo comparatorInfo : comparatorInfos) {
+ appendComparator(comparatorInfo.columnIndex, 0, comparatorInfo.isReverse);
+ }
+ }
+
+ public boolean isColumnIndexSorted(int columnIndex) {
+ return getSortingColumns().contains(Integer.valueOf(columnIndex));
+ }
+
+ public SortDirectionEnum getSortDirectionForColumnIndex(int columnIndex) {
+ boolean sorted = getSortingColumns().contains(Integer.valueOf(columnIndex));
+ if (!sorted) {
+ return NONE;
+ }
+ return isColumnReverse(columnIndex) ? DESC : ASC;
+ }
+
+ /**
+ * @return The order in which this column was clicked.
+ * Zero indexed. -1 if the column wasn't recently clicked.
+ *
+ * Example: If column indexes 20, 10, 25 are clicked in that order,
+ * clickSequence(10) is 2.
+ */
+ //TODO : Vincent Lorenzo changed the API here, I add public!
+ public int getClickSequence(int columnIndex) {
+ return getSortingColumns().indexOf(Integer.valueOf(columnIndex));
+ }
+
+ /**
+ * Helper object for tracking existing comparators
+ */
+ private class ComparatorInfo {
+ final int columnIndex;
+ final boolean isReverse;
+
+ ComparatorInfo(int columnIndex, boolean reverse) {
+ this.columnIndex = columnIndex;
+ this.isReverse = reverse;
+ }
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/tree/DatumTreeFormat.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/tree/DatumTreeFormat.java
index cdc892f8c93..e4a11e86299 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/tree/DatumTreeFormat.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/tree/DatumTreeFormat.java
@@ -1,124 +1,113 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.nattable.tree;
-
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
-import org.eclipse.papyrus.infra.nattable.manager.axis.CompositeTreeAxisManagerForEventList;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
-
-import ca.odell.glazedlists.TreeList;
-
-/**
- * @author VL222926
- *
- */
-public class DatumTreeFormat implements TreeList.Format<ITreeItemAxis> {
-
- /**
- * the axis manager providing comparator
- */
- private CompositeTreeAxisManagerForEventList axisManager;
-
- /** the comparator used to sort rows with the same sort than the model */
- private Map<Integer, Comparator<ITreeItemAxis>> comparator = new HashMap<Integer, Comparator<ITreeItemAxis>>();
-
- /**
- * the sort model to use
- */
- private final ISortModel sortModel;
-
- /**
- *
- * Constructor.
- *
- * @param sortModel
- */
- public DatumTreeFormat(ISortModel sortModel) {
- this.sortModel = sortModel;
- }
-
- /**
- *
- * @see ca.odell.glazedlists.TreeList.Format#getPath(java.util.List, java.lang.Object)
- *
- * @param path
- * @param element
- */
- @Override
- public void getPath(List<ITreeItemAxis> path, ITreeItemAxis element) {
- path.add(element);
- ITreeItemAxis parent = element.getParent();
- while (parent != null) {
- path.add(0, parent);
- parent = parent.getParent();
- }
- }
-
- /**
- *
- * @see ca.odell.glazedlists.TreeList.Format#allowsChildren(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public boolean allowsChildren(final ITreeItemAxis element) {
- return true;
- }
-
- /**
- *
- * @param axisManager
- * the axis
- */
- public final void setTreeComparatorProvider(final CompositeTreeAxisManagerForEventList comparatorProvider) {
- this.axisManager = comparatorProvider;
- }
-
- /**
- *
- * @see ca.odell.glazedlists.TreeList.Format#getComparator(int)
- *
- * @param depth
- * @return
- */
- @Override
- public Comparator<ITreeItemAxis> getComparator(final int depth) {
- if (this.axisManager == null) {
- return null;
- }
- if (!this.comparator.containsKey(Integer.valueOf(depth))) {
- Comparator<ITreeItemAxis> comparator = new Comparator<ITreeItemAxis>() {
- /**
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- *
- * @param o1
- * @param o2
- * @return
- */
- @Override
- public int compare(ITreeItemAxis o1, ITreeItemAxis o2) {
- return axisManager.compare(sortModel, depth, o1, o2);
- }
- };
- this.comparator.put(Integer.valueOf(depth), comparator);
- }
- return this.comparator.get(Integer.valueOf(depth));
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.tree;
+
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
+import org.eclipse.nebula.widgets.nattable.tree.SortableTreeComparator;
+import org.eclipse.papyrus.infra.nattable.manager.axis.CompositeTreeAxisManagerForEventList;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
+import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
+
+import ca.odell.glazedlists.TreeList;
+
+/**
+ * @author VL222926
+ *
+ */
+public class DatumTreeFormat implements TreeList.Format<ITreeItemAxis> {
+
+ /**
+ * the axis manager providing comparator
+ */
+ private CompositeTreeAxisManagerForEventList axisManager;
+
+ /**
+ * the sort model to use
+ */
+ private final ISortModel sortModel;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param sortModel
+ */
+ public DatumTreeFormat(ISortModel sortModel) {
+ this.sortModel = sortModel;
+ }
+
+ /**
+ *
+ * @see ca.odell.glazedlists.TreeList.Format#getPath(java.util.List, java.lang.Object)
+ *
+ * @param path
+ * @param element
+ */
+ @Override
+ public void getPath(List<ITreeItemAxis> path, ITreeItemAxis element) {
+ TableHelper.getPath(path, element);
+ }
+
+ /**
+ *
+ * @see ca.odell.glazedlists.TreeList.Format#allowsChildren(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public boolean allowsChildren(final ITreeItemAxis element) {
+ return true;
+ }
+
+ /**
+ *
+ * @param axisManager
+ * the axis
+ */
+ public final void setTreeComparatorProvider(final CompositeTreeAxisManagerForEventList comparatorProvider) {
+ this.axisManager = comparatorProvider;
+ }
+
+ /**
+ *
+ * @see ca.odell.glazedlists.TreeList.Format#getComparator(int)
+ *
+ * @param depth
+ * @return
+ */
+ @Override
+ public Comparator<ITreeItemAxis> getComparator(final int depth) {
+ if (this.axisManager == null) {
+ return null;
+ }
+ return new SortableTreeComparator<ITreeItemAxis>(new Comparator<ITreeItemAxis>() {
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ *
+ * @param o1
+ * @param o2
+ * @return
+ */
+ // @Override
+ public int compare(ITreeItemAxis o1, ITreeItemAxis o2) {
+ return axisManager.compare(sortModel, depth, o1, o2);
+ }
+
+ }, sortModel);
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/LabelProviderFullCellContextElementWrapper.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/LabelProviderFullCellContextElementWrapper.java
new file mode 100644
index 00000000000..c316c130c9e
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/LabelProviderFullCellContextElementWrapper.java
@@ -0,0 +1,277 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.utils;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * @author VL222926
+ *
+ * This wrapper allows to store cell value, with its column object and its row object
+ *
+ */
+public class LabelProviderFullCellContextElementWrapper implements ILabelProviderCellContextElementWrapper {
+
+ /**
+ * the value wrapped by the class
+ */
+ private Object cellValue;
+
+ /**
+ * the label stack
+ */
+ private LabelStack labelStack;
+
+ /**
+ * the row object for this cell
+ */
+ private Object rowObject;
+
+ /**
+ * the columnObject for this cell
+ */
+ private Object columnObject;
+
+ /**
+ * the config registry
+ */
+ private IConfigRegistry configRegistry;
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.utils.ILabelProviderContextElementWrapper#getConfigRegistry()
+ *
+ * @return
+ */
+ @Override
+ public IConfigRegistry getConfigRegistry() {
+ return this.configRegistry;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.utils.ILabelProviderContextElementWrapper#getObject()
+ *
+ * @return
+ */
+ @Override
+ public Object getObject() {
+ return this.cellValue;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getOriginColumnPosition()
+ *
+ * @return
+ */
+ @Override
+ public int getOriginColumnPosition() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getOriginRowPosition()
+ *
+ * @return
+ */
+ @Override
+ public int getOriginRowPosition() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getLayer()
+ *
+ * @return
+ */
+ @Override
+ public ILayer getLayer() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getColumnPosition()
+ *
+ * @return
+ */
+ @Override
+ public int getColumnPosition() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getRowPosition()
+ *
+ * @return
+ */
+ @Override
+ public int getRowPosition() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getColumnIndex()
+ *
+ * @return
+ */
+ @Override
+ public int getColumnIndex() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getRowIndex()
+ *
+ * @return
+ */
+ @Override
+ public int getRowIndex() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getColumnSpan()
+ *
+ * @return
+ */
+ @Override
+ public int getColumnSpan() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getRowSpan()
+ *
+ * @return
+ */
+ @Override
+ public int getRowSpan() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#isSpannedCell()
+ *
+ * @return
+ */
+ @Override
+ public boolean isSpannedCell() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getDisplayMode()
+ *
+ * @return
+ */
+ @Override
+ public String getDisplayMode() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getConfigLabels()
+ *
+ * @return
+ */
+ @Override
+ public LabelStack getConfigLabels() {
+ return this.labelStack;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getDataValue()
+ *
+ * @return
+ */
+ @Override
+ public Object getDataValue() {
+ return this.cellValue;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell#getBounds()
+ *
+ * @return
+ */
+ @Override
+ public Rectangle getBounds() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ *
+ * @param cellValue
+ * the new cell value to wrap
+ */
+ public void setDataValue(Object cellValue) {
+ this.cellValue = cellValue;
+ }
+
+ /**
+ *
+ * @param labelStack
+ * the new label stack to use
+ */
+ public void setConfigLabels(LabelStack labelStack) {
+ this.labelStack = labelStack;
+ }
+
+ /**
+ *
+ * @return
+ * the row object for this cell
+ */
+ public Object getRowObject() {
+ return rowObject;
+ }
+
+ /**
+ *
+ * @param rowObject
+ * the row object for this cell
+ */
+ public void setRowObject(Object rowObject) {
+ this.rowObject = rowObject;
+ }
+
+ /**
+ *
+ * @return
+ * the column object for this cell
+ */
+ public Object getColumnObject() {
+ return columnObject;
+ }
+
+ /**
+ *
+ * @param columnObject
+ * the column object for this cell
+ */
+ public void setColumnObject(Object columnObject) {
+ this.columnObject = columnObject;
+ }
+
+ /**
+ *
+ * @param configRegistry
+ * the config registry to use
+ */
+ public void setConfigRegistry(IConfigRegistry configRegistry) {
+ this.configRegistry = configRegistry;
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigAttributes.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigAttributes.java
index d98360b7cdd..5c050a4ae9b 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigAttributes.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigAttributes.java
@@ -14,6 +14,7 @@
package org.eclipse.papyrus.infra.nattable.utils;
import org.eclipse.nebula.widgets.nattable.filterrow.TextMatchingMode;
+import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
import org.eclipse.nebula.widgets.nattable.style.ConfigAttribute;
import org.eclipse.papyrus.infra.nattable.comparator.ObjectNameAndPathComparator;
import org.eclipse.papyrus.infra.nattable.display.converter.ObjectNameAndPathDisplayConverter;
@@ -101,4 +102,9 @@ public class NattableConfigAttributes {
*/
public static final ConfigAttribute<IFilterValueToMatchManager> FILTER_VALUE_TO_MATCH_MANAGER = new ConfigAttribute<IFilterValueToMatchManager>();
+ /**
+ * the config attribute used to register the sort model
+ */
+ public static final ConfigAttribute<ISortModel> ROW_SORT_MODEl = new ConfigAttribute<ISortModel>();
+
} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/SortLabelProviderFullCellContextElementWrapper.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/SortLabelProviderFullCellContextElementWrapper.java
new file mode 100644
index 00000000000..2f4369cf1cc
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/SortLabelProviderFullCellContextElementWrapper.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.utils;
+
+/**
+ * @author VL222926
+ *
+ * This class allows us to wrap cell value, with sort information.
+ */
+public class SortLabelProviderFullCellContextElementWrapper extends LabelProviderFullCellContextElementWrapper {
+
+ /**
+ * boolean indicating if we are sorting row
+ */
+ private boolean sortingRow;
+
+ /**
+ * the index of the column that we are sorting
+ */
+ private int columnIndex;
+
+ /**
+ *
+ * @param sortingRow
+ * <code>true</code> if we are sorting rows
+ */
+ public void setSortingRow(boolean sortingRow) {
+ this.sortingRow = sortingRow;
+ }
+
+ /**
+ *
+ * @return
+ * <code>true</code> if we are sorting rows
+ */
+ public boolean isSortingRow() {
+ return this.sortingRow;
+ }
+
+ /**
+ *
+ * @param colIndex
+ * the index of the column that we are sorting
+ */
+ public void setColumnIndex(int colIndex) {
+ this.columnIndex = colIndex;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.utils.LabelProviderFullCellContextElementWrapper#getColumnIndex()
+ *
+ * @return
+ */
+ @Override
+ public int getColumnIndex() {
+ return this.columnIndex;
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableHelper.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableHelper.java
index 6cbbb7d2b53..0cee794d98f 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableHelper.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/TableHelper.java
@@ -13,12 +13,15 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.utils;
+import java.util.List;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.NattableFactory;
import org.eclipse.papyrus.infra.nattable.model.nattable.NattablePackage;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.CellEditorDeclaration;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
@@ -296,5 +299,22 @@ public class TableHelper {
}
return declaration;
}
+
+
+ /**
+ *
+ * @see ca.odell.glazedlists.TreeList.Format#getPath(java.util.List, java.lang.Object)
+ *
+ * @param path
+ * @param element
+ */
+ public static final void getPath(List<ITreeItemAxis> path, ITreeItemAxis element) {
+ path.add(element);
+ ITreeItemAxis parent = element.getParent();
+ while (parent != null) {
+ path.add(0, parent);
+ parent = parent.getParent();
+ }
+ }
}

Back to the top