Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2020-06-18 12:12:55 +0000
committerVincent Lorenzo2020-06-25 15:06:36 +0000
commitf0923298d96776f44b7c6625ee8a524bb3adcd08 (patch)
tree9d9b3697f321c1d24210f40059d94153f9c5e893 /plugins
parent4e88f8511802fd00252736078238b8225e087738 (diff)
downloadorg.eclipse.papyrus-f0923298d96776f44b7c6625ee8a524bb3adcd08.tar.gz
org.eclipse.papyrus-f0923298d96776f44b7c6625ee8a524bb3adcd08.tar.xz
org.eclipse.papyrus-f0923298d96776f44b7c6625ee8a524bb3adcd08.zip
Bug 486733 - [Table] Sorted rows by column header is not saved
Change-Id: Id87d0e93c5321c3bd9818226acd6b75ce4316c05 Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/doc/org.eclipse.papyrus.api.migration.doc/src/site/mediawiki/4.8.0_to_5.0.0_migration.mediawiki4
-rwxr-xr-xplugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/images/SortStyleName_snapshot1.pngbin0 -> 42874 bytes
-rwxr-xr-xplugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/images/SortStyleName_snapshot2.pngbin0 -> 42591 bytes
-rw-r--r--plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableDevDoc.mediawiki23
-rwxr-xr-xplugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableUserDoc.mediawiki5
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java13
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortUtils.java131
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusGlazedListsSortModel.java83
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/PapyrusNatTableComparatorChooser.java19
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/SaveSortedColumnCommand.java120
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java15
11 files changed, 394 insertions, 19 deletions
diff --git a/plugins/doc/org.eclipse.papyrus.api.migration.doc/src/site/mediawiki/4.8.0_to_5.0.0_migration.mediawiki b/plugins/doc/org.eclipse.papyrus.api.migration.doc/src/site/mediawiki/4.8.0_to_5.0.0_migration.mediawiki
index c199ffd0091..9db1d69b338 100755
--- a/plugins/doc/org.eclipse.papyrus.api.migration.doc/src/site/mediawiki/4.8.0_to_5.0.0_migration.mediawiki
+++ b/plugins/doc/org.eclipse.papyrus.api.migration.doc/src/site/mediawiki/4.8.0_to_5.0.0_migration.mediawiki
@@ -19,3 +19,7 @@ all others are deprecated and will be removed.
***new methods '''updatePositions''', to update position of referenced elements (rows/columns/cells) after a refresh
***new methods '''buildSingleCellSelection''', '''getSelectedElements''', '''getSingleSelectedCells''', '''addSelectedRow''', '''addSelectedColumn''', '''removeSelectedRow''', '''removeSelectedColumn''', '''copyRowsSelection''', '''copyColumnsSelection'''
***methods '''getFullySelectedRows''' and '''getFullySelectedColumns''' changed without breaking API: before the returned map used the row index as key, and now this same map use the row position as key. To obtain the row index, you must call '''selectionLayer.getRowIndexByPosition'''
+
+*bug 486733
+**'''PapyrusNatTableComparatorChooser'''
+***change visibility from protected to public for method '''rebuildComparator''' \ No newline at end of file
diff --git a/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/images/SortStyleName_snapshot1.png b/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/images/SortStyleName_snapshot1.png
new file mode 100755
index 00000000000..76848227aec
--- /dev/null
+++ b/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/images/SortStyleName_snapshot1.png
Binary files differ
diff --git a/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/images/SortStyleName_snapshot2.png b/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/images/SortStyleName_snapshot2.png
new file mode 100755
index 00000000000..7fd77dbd01a
--- /dev/null
+++ b/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/images/SortStyleName_snapshot2.png
Binary files differ
diff --git a/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableDevDoc.mediawiki b/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableDevDoc.mediawiki
index 98846b0cac4..a0ff4d2cbd2 100644
--- a/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableDevDoc.mediawiki
+++ b/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableDevDoc.mediawiki
@@ -1656,6 +1656,29 @@ If you need to declare your own comparator and you extend <code>org.eclipse.papy
* In case of filtering on several column in the same time, we will display only the rows matching all applied filters
* In case of collection in a cell, the row matches if the collection contains the wanted element
+=How to define columns sorted by default=
+Since Papyrus 5.0, it is possible to define column which will be sorted by default.
+In order to do that, you must select the axis to sorted in your '''TableConfiguration''' file, then
+*add it a '''StringValueStyle'''
+*name this style '''sort'''
+*give it a string value with this format: <number>_<direction>, where
+**number is the column sort sequence. The biggest number is the first sorted column, then we decrease until 0 for the last sorted column.
+**direction must be '''ASC''' (alphabetic order) or '''DESC''' (reverse alphabetic order).
+
+==Example==
+To sort the rows by alphabetic order according to the value of 2 columns A and B. You want to start the sort with the values of column A, then continuing the sort with the values of column B when the values of A are equals. To obtain this behavior, you need to define:
+*for A: 0_ASC - first sorted column
+*for B: 1_ASC - last sorted column
+
+[[File:images/SortStyleName_snapshot1.png|frame|none|Sort configuration for column A]]
+
+[[File:images/SortStyleName_snapshot2.png|frame|none|Sort configuration for column B]]
+
+==How does it works?==
+*The sorted columns are save with the command <code>org.eclipse.papyrus.infra.nattable.sort.SaveSortedColumnCommand</code>.
+*The apply/reapply (after a refresh/a reload or a table creation) is done by the class <code> org.eclipse.papyrus.infra.nattable.sort.PapyrusGlazedListsSortModel</code>.
+*The comparator chooser use a specific format to apply sort. This format is given by the method <code>org.eclipse.papyrus.infra.nattable.sort.ColumnSortUtils.buildComparatorValues(INattableModelManager)</code>
+
=Cell Editor=
Papyrus table provides several kinds of cell editors, for example, editors for ValueSpecification and UML NamedElement:
*textual editor
diff --git a/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableUserDoc.mediawiki b/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableUserDoc.mediawiki
index 0bfdc078ec4..b949ec8c665 100755
--- a/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableUserDoc.mediawiki
+++ b/plugins/doc/org.eclipse.papyrus.infra.nattable.doc/src/site/mediawiki/tableUserDoc.mediawiki
@@ -154,7 +154,7 @@ Moreover Tree table provides some specific features
::*##, then left click on the wanted column header : the rows are sorted ascending,
::*## clicking a second time, the rows are sorted descending
::*## clickling a third time, the rows return to the default sort
-::*# Pressing MAJ + ALT allows to sort rows using several columns. The last selected column is the first one used to do the sort
+::*# Pressing SHIFT + ALT allows to sort rows using several columns. The last selected column is the first one used to do the sort
::* Update of the sorted state
::*# new row added to the table will be sorted
::*# modifying a value is a sorted column (from the table or another Papyrus View) doesn't change the sort of the rows for 2 reasons
@@ -162,6 +162,7 @@ Moreover Tree table provides some specific features
::*## usability: the edited row will change of location, so the table will blink and scroll)
::*# destroying a sorted column will not update the sort, to avoid to disturb the user
::*# Invert Axis in a sorted state will clear the sort
+::* the sort status is saved in the table and it is undoable (this point has been added for Papyrus 5.0)
; Remove Column/Row<br>
::* Select the header of the axis to remove then right click and select Remove Column/Row. The axis will be remove of the table, but the represented element will continue to be in the model.<br>
@@ -254,7 +255,7 @@ the provided configuration
| colspan="5" style="text-align: center;" | Yes (F2, or Double click on a cell)
|-
| Sort Row Axis clicking on column header
-| colspan="5" style="text-align: center;" | Yes (ALT-Click on column header, or MAJ-ALT-Click to sort on several columns)
+| colspan="5" style="text-align: center;" | Yes (ALT-Click on column header, or SHIFT-ALT-Click to sort on several columns)
|-
| Change Columns Order
| colspan="5" style="text-align: center;" | Yes
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 225bef6f109..17032da16a8 100644
--- 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
@@ -14,7 +14,7 @@
* Nicolas Boulay (Esterel Technologies SAS) - Bug 497467
* Sebastien Bordes (Esterel Technologies SAS) - Bug 497738
* Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220, 526146, 515737, 516314
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 559973, 560318, 562619, 562646, 517617, 532452
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 559973, 560318, 562619, 562646, 517617, 532452, 486733
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.manager.table;
@@ -49,6 +49,7 @@ import org.eclipse.emf.transaction.ResourceSetChangeEvent;
import org.eclipse.emf.transaction.ResourceSetListener;
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
@@ -74,6 +75,7 @@ import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
import org.eclipse.nebula.widgets.nattable.util.GCFactory;
import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.emf.gmf.command.NestingNotifyingWorkspaceCommandStack;
import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization;
import org.eclipse.papyrus.infra.nattable.Activator;
import org.eclipse.papyrus.infra.nattable.command.CommandIds;
@@ -106,6 +108,7 @@ 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.model.nattable.nattablestyle.NamedStyle;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NattablestylePackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.StringValueStyle;
import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection;
import org.eclipse.papyrus.infra.nattable.selection.ISelectionExtractor;
import org.eclipse.papyrus.infra.nattable.selection.ObjectsSelectionExtractor;
@@ -2004,6 +2007,14 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
final Object oldValue = notification.getOldValue();
final int type = notification.getEventType();
+ // ignore all from style about sort
+ if (newValue instanceof StringValueStyle && ((StringValueStyle) newValue).getName().equals("sort")) {
+ return; // nothing to do
+ }
+ if (oldValue instanceof StringValueStyle && ((StringValueStyle) oldValue).getName().equals("sort")) {
+ return; // nothing to do
+ }
+
if (notifier instanceof IAxis && notification.getFeature() == NattablestylePackage.eINSTANCE.getStyledElement_Styles()) {
// the change is on a style of an IAxis
final String styleName;
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortUtils.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortUtils.java
new file mode 100755
index 00000000000..7dfc3d00b24
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/ColumnSortUtils.java
@@ -0,0 +1,131 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) <vincent.lorenzo@cea.fr> - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.sort;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
+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.nattablestyle.NattablestylePackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.StringValueStyle;
+import org.eclipse.papyrus.infra.nattable.sort.copy.NatTableComparatorChooser;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
+
+/**
+ * Utility class for sort column feature
+ *
+ * @since 7.0
+ */
+public class ColumnSortUtils {
+
+ private static final String SEPARATOR = "_"; //$NON-NLS-1$
+
+ /**
+ * Constructor.
+ *
+ */
+ private ColumnSortUtils() {
+ // to prevent instantiation
+ }
+
+ /**
+ *
+ * @param chooser
+ * the comparator chooser
+ * @param columnIndex
+ * the index of the column
+ * @return
+ * the string value to save in the {@link StringValueStyle} to store the sort state of the column identified by its index
+ * the string must be respect this syntax: number_direction, where number is the order sequence of the column and direction is {@link SortDirectionEnum}
+ *
+ */
+ public static final String buildSortStringValue(final NatTableComparatorChooser<?> chooser, int columnIndex) {
+ final int clickSequence = chooser.getClickSequence(columnIndex);
+ final SortDirectionEnum direction = chooser.getSortDirectionForColumnIndex(columnIndex);
+ final StringBuilder builder = new StringBuilder();
+ builder.append(clickSequence);
+ builder.append(SEPARATOR);
+ builder.append(direction.toString());
+ return builder.toString();
+ }
+
+ /**
+ *
+ * @param manager
+ * the table manager
+ * @return
+ * the string to use to init the comparator.
+ * the returned string is conform to the grammar defined defined in the java doc of
+ * {@link org.eclipse.papyrus.infra.nattable.glazedlists.copy.AbstractTableComparatorChooser.fromString(String)}
+ *
+ */
+ public static final String buildComparatorValues(final INattableModelManager manager) {
+ final Map<StringValueStyle, IAxis> sortedAxis = new TreeMap<>(new SortComparator());
+ for (final Object current : manager.getColumnElementsList()) {
+ if (current instanceof IAxis) {
+ final StringValueStyle style = (StringValueStyle) ((IAxis) current).getNamedStyle(NattablestylePackage.eINSTANCE.getStringValueStyle(), NamedStyleConstants.SORT); // $NON-NLS-1$
+ if (style != null) {
+ sortedAxis.put(style, (IAxis) current);
+ }
+ }
+ }
+
+ final StringBuilder builder = new StringBuilder();
+ final Iterator<Entry<StringValueStyle, IAxis>> iter = sortedAxis.entrySet().iterator();
+ while (iter.hasNext()) {
+ Entry<StringValueStyle, IAxis> current = iter.next();
+ int colIndex = manager.getColumnElementsList().indexOf(current.getValue());
+ SortDirectionEnum direction = SortDirectionEnum.valueOf(current.getKey().getStringValue().split(SEPARATOR)[1]);
+ builder.append("column "); //$NON-NLS-1$
+ builder.append(colIndex);
+ if (SortDirectionEnum.DESC.equals(direction)) {
+ builder.append(" reversed"); //$NON-NLS-1$
+ }
+ if (iter.hasNext()) {
+ builder.append(", "); //$NON-NLS-1$
+ }
+ }
+ return builder.toString();
+ }
+
+ /**
+ *
+ * Comparator used to organized the sorted column by sort order
+ *
+ */
+ private static final class SortComparator implements Comparator<StringValueStyle> {
+
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ *
+ * @param o1
+ * @param o2
+ * @return
+ */
+ @Override
+ public int compare(StringValueStyle o1, StringValueStyle o2) {
+ Integer order1 = Integer.valueOf(o1.getStringValue().split(SEPARATOR)[0]);
+ Integer order2 = Integer.valueOf(o2.getStringValue().split(SEPARATOR)[0]);
+ return order1.compareTo(order2);
+ }
+
+ }
+}
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
index 2f7ccd4d59f..e43e1c08855 100644
--- 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
@@ -16,6 +16,8 @@ package org.eclipse.papyrus.infra.nattable.sort;
import java.util.Comparator;
import java.util.List;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
@@ -25,10 +27,12 @@ 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.emf.gmf.command.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.nattable.glazedlists.PapyrusSortingState;
import org.eclipse.papyrus.infra.nattable.manager.refresh.CustomStructuralRefreshEvent;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.sort.copy.NatTableComparatorChooser;
+import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils;
import ca.odell.glazedlists.SortedList;
@@ -50,16 +54,14 @@ public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
*/
protected SortedList<Object> sortedList;
- // TODO : useful
private NatTableComparatorChooser<Object> comparatorChooser;
- // protected SortedList<T> sortedList;
// TODO : useful ?
protected IColumnPropertyResolver columnPropertyResolver;
- // TODO : useful ?
protected ILayer columnHeaderDataLayer;
+ protected PapyrusNatColumnTableFormat<Object> f;
/**
* Constructor.
@@ -76,12 +78,11 @@ public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
- protected PapyrusNatColumnTableFormat<Object> f;
protected NatTableComparatorChooser<Object> getComparatorChooser() {
if (comparatorChooser == null) {
- f = new PapyrusNatColumnTableFormat<>(columnAccessor, getTableManager(), columnHeaderDataLayer);
+ f = new PapyrusNatColumnTableFormat<>(this.columnAccessor, getTableManager(), this.columnHeaderDataLayer);
comparatorChooser = new PapyrusNatTableComparatorChooser(sortedList, f) {
/**
@@ -93,6 +94,7 @@ public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
protected org.eclipse.papyrus.infra.nattable.glazedlists.copy.SortingState createSortingState() {
return new PapyrusSortingState(this, getTableManager());
}
+
};
}
@@ -100,7 +102,7 @@ public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
}
protected IConfigRegistry getConfigRegistry() {
- NatTable nat = (NatTable) getTableManager().getAdapter(NatTable.class);
+ NatTable nat = getTableManager().getAdapter(NatTable.class);
return nat.getConfigRegistry();
}
@@ -130,8 +132,46 @@ public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
}
@Override
- public void sort(int columnIndex, SortDirectionEnum sortDirection, boolean accumulate) {
+ public void sort(int columnIndex, final SortDirectionEnum sortDirection, boolean accumulate) {
+ TransactionalEditingDomain d = TableEditingDomainUtils.getTableEditingDomain(getTableManager().getTable());
+ if (d == null) {
+ d = TableEditingDomainUtils.getTableContextEditingDomain(getTableManager().getTable());
+ }
+ // 1. create the update command
+ final ICommand cmd = new SaveSortedColumnCommand(d, getTableManager(), this.comparatorChooser, getSortedColumnIndexes());
+
+ // 2. do the sort
getComparatorChooser().sort(columnIndex, sortDirection, accumulate);
+
+ // 3. execute the update command
+ /*
+ * the sort generate a GlazedLink event -> so we will ask for a nattable refresh
+ * 1. executing the command in the stack will generate a stack event so we will ask for a nattable refresh
+ *
+ * -> 2 refresh wanted! but thank to the method org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager.refreshNatTable()
+ * only one be done for big model and two observed for small models (probably because the refresh is faster)
+ *
+ *
+ * 2. executing this command with GMFUnsafe generates only 1 refresh, but we don't get he undo...
+ * in addition, it seems the refresh comes quite late, so the user think the action is finished and the UI get a new freeze...
+ * -> worst user experience I think
+ * I get these result with a GenericTreeTable on a model with 3400 classes as child of the root package
+ *
+ * time is equivalent on my computer (35 secondes from 3400 rows (too long of course)
+ *
+ */
+ d.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
+ // worst user experience I think
+ // try {
+ // GMFUnsafe.write(d, cmd);
+ // } catch (ExecutionException e) {
+ // org.eclipse.papyrus.infra.nattable.Activator.log.error(e);
+ // } catch (InterruptedException e) {
+ // org.eclipse.papyrus.infra.nattable.Activator.log.error(e);
+ // } catch (RollbackException e) {
+ // org.eclipse.papyrus.infra.nattable.Activator.log.error(e);
+ // }
+
}
@Override
@@ -147,13 +187,19 @@ public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
}
if (event instanceof StructuralRefreshEvent && ((StructuralRefreshEvent) event).isHorizontalStructureChanged()) {
+ // better rendering (less blinking) keeping this check
String test = getComparatorChooser().toString();
if (test.contains("-")) { //$NON-NLS-1$
// avoid exception moving column where a filter is applied
// the - sign is for negative column index...
return;
}
+
this.comparatorChooser = null;
+
+
+ // required after a table reload
+ test = ColumnSortUtils.buildComparatorValues(getTableManager());
getComparatorChooser().fromString(test);
}
@@ -162,15 +208,28 @@ public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
}
}
+
+
+
+
/**
* @param compositeLayer
*/
- // TODO : try to remove me
- public void setColumnHeaderLayer(ILayer compositeLayer) {
+ public void setColumnHeaderLayer(final ILayer compositeLayer) {
+ if (this.columnHeaderDataLayer != null) {
+ this.columnHeaderDataLayer.removeLayerListener(this);
+ }
this.columnHeaderDataLayer = compositeLayer;
- this.columnHeaderDataLayer.addLayerListener(this);// useful ?
- if (f != null) {
- f.setColumnHeaderDataLayer(columnHeaderDataLayer);
+ this.columnHeaderDataLayer.addLayerListener(this);
+
+ // create/recreate a comparator chooser
+ // this.comparatorChooser = null;
+ final String encodedSort = ColumnSortUtils.buildComparatorValues(getTableManager());
+
+ // to get sort just after a table creation with sorted columns
+ getComparatorChooser().fromString(encodedSort);
+ if (this.comparatorChooser instanceof PapyrusNatTableComparatorChooser) {
+ ((PapyrusNatTableComparatorChooser) this.comparatorChooser).rebuildComparator();
}
}
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
index cbfa8da2aca..d5ab18cb265 100644
--- 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
@@ -1,6 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2015 CEA LIST and others.
- *
+ * Copyright (c) 2015, 2020 CEA LIST and others.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
- *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 486733
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.sort;
@@ -36,4 +36,17 @@ public class PapyrusNatTableComparatorChooser extends NatTableComparatorChooser<
super(sortedList, tableFormat);
}
+
+ /**
+ * We change the visibility from protected to public.
+ * This method is called during the initialization of the {@link PapyrusGlazedListsSortModel}
+ *
+ * @see org.eclipse.papyrus.infra.nattable.glazedlists.copy.AbstractTableComparatorChooser#rebuildComparator()
+ * @since 7.0
+ *
+ */
+ @Override
+ public void rebuildComparator() {
+ super.rebuildComparator();
+ }
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/SaveSortedColumnCommand.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/SaveSortedColumnCommand.java
new file mode 100755
index 00000000000..f9dbc1d0514
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/sort/SaveSortedColumnCommand.java
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) <vincent.lorenzo@cea.fr> - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.sort;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+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.nattablestyle.NattablestyleFactory;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NattablestylePackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.StringValueStyle;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.Style;
+import org.eclipse.papyrus.infra.nattable.sort.copy.NatTableComparatorChooser;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
+
+/**
+ * This command is used to save the sort of the colum
+ *
+ * @since 6.7
+ *
+ */
+public class SaveSortedColumnCommand extends AbstractTransactionalCommand {
+
+ /**
+ * the manager of the edited trable
+ */
+ private final INattableModelManager manager;
+
+ /**
+ * the current comparator chooser
+ */
+ private final NatTableComparatorChooser<?> chooser;
+
+ /**
+ * the indexes representing the previous sorted columns
+ */
+ private final List<Integer> previousSortedColumns;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * the editing domain
+ * @param manager
+ * the table manager
+ * @param chooser
+ * the comparator chooser
+ * @param previousSortedColumns
+ * the indexes of sorted columns before saving the new sorted state
+ */
+ public SaveSortedColumnCommand(final TransactionalEditingDomain domain, final INattableModelManager manager, final NatTableComparatorChooser<?> chooser, final List<Integer> previousSortedColumns) {
+ super(domain, "Save Sorted Columns", null); //$NON-NLS-1$
+ this.manager = manager;
+ this.chooser = chooser;
+ this.previousSortedColumns = previousSortedColumns;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ final List<Integer> currentSortedColumns = this.chooser.getSortingColumns();
+ final List<Integer> columnsToRemove = new ArrayList<>(this.previousSortedColumns);
+ columnsToRemove.removeAll(currentSortedColumns);
+
+ // remove all unecessary sort style
+ for (int columnIndex : columnsToRemove) {
+ final Object column = this.manager.getColumnElement(columnIndex);
+ if (column instanceof IAxis) {
+ final Style style = ((IAxis) column).getNamedStyle(NattablestylePackage.eINSTANCE.getStringValueStyle(), NamedStyleConstants.SORT);
+ if (style != null) {
+ ((IAxis) column).getStyles().remove(style);
+ }
+ }
+ }
+
+ // create or update existing style
+ for (int columnIndex : currentSortedColumns) {
+ final Object column = this.manager.getColumnElement(columnIndex);
+ if (column instanceof IAxis) {
+ StringValueStyle style = (StringValueStyle) ((IAxis) column).getNamedStyle(NattablestylePackage.eINSTANCE.getStringValueStyle(), NamedStyleConstants.SORT);
+ if (style == null) {
+ style = NattablestyleFactory.eINSTANCE.createStringValueStyle();
+ style.setName(NamedStyleConstants.SORT);
+ ((IAxis) column).getStyles().add(style);
+ }
+ style.setStringValue(ColumnSortUtils.buildSortStringValue(chooser, columnIndex));
+ }
+ }
+ return CommandResult.newOKCommandResult();
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java
index b142c5bb705..9db6e85599e 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014, 2017 CEA LIST.
+ * Copyright (c) 2014, 2017, 2020 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -12,10 +12,12 @@
* Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation
* Nicolas FAUVERGUE(ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 504077
* Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220, 515737
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 486733
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.utils;
+import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.BooleanValueStyle;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.StringValueStyle;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.Style;
@@ -151,6 +153,7 @@ public class NamedStyleConstants {
/**
* A default value used to enable the wraptext function in the NatTable.
* It is enabled by default.
+ *
* @since 5.0
*/
public static final boolean ENABLE_WRAP_TEXT = true;
@@ -165,6 +168,7 @@ public class NamedStyleConstants {
/**
* A default value used to enable the auto resize cell height function in the NatTable.
* It is enabled by default.
+ *
* @since 5.0
*/
public static final boolean ENABLE_AUTO_RESIZE_CELL_HEIGHT = true;
@@ -179,7 +183,16 @@ public class NamedStyleConstants {
/**
* A default value used to enable the display list on separated rows function in the NatTable.
* It is disable by default.
+ *
* @since 5.0
*/
public static final boolean ENABLE_DISPLAY_LIST_ON_SEPARATED_ROWS = false;
+
+ /**
+ * A {@link StringValueStyle} used to save the the sort.
+ * The value must be respect this syntax: number_direction, where number is the order sequence of the column and direction is {@link SortDirectionEnum}
+ *
+ * @since 7.0
+ */
+ public static final String SORT = "sort"; //$NON-NLS-1$
}

Back to the top