Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanh Liem PHAN2016-12-21 15:02:23 +0000
committerGerrit Code Review @ Eclipse.org2017-04-26 15:13:59 +0000
commita66c06dc2549cbd65aaa248ea8d105a07486c043 (patch)
treeb73b7c3fc1780b812e31dd2e6891aec0d2b6b7dd /plugins/infra/nattable
parent8fc4e5d8dbfa9611b1a3c7160d1a1db888854e7f (diff)
downloadorg.eclipse.papyrus-a66c06dc2549cbd65aaa248ea8d105a07486c043.tar.gz
org.eclipse.papyrus-a66c06dc2549cbd65aaa248ea8d105a07486c043.tar.xz
org.eclipse.papyrus-a66c06dc2549cbd65aaa248ea8d105a07486c043.zip
Bug 459220: [Table 2] Papyrus should support automatic text wrap in
table cells https://bugs.eclipse.org/bugs/show_bug.cgi?id=459220 - Add wrap text and auto resize cell height functionalities for string columns in table - Enable/disable wrap text and auto resize cell height by the context menu - WrapText and AutoResizeCellHeight values are saved for each table using the named styles mechanism - Undo/Redo could be done in both regular table and generic table - Update userDoc and devDoc Change-Id: I26ec7dff15470a73843848f17fcfaf9656d14b2f Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
Diffstat (limited to 'plugins/infra/nattable')
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/SingleStringCellEditorConfiguration.java28
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java50
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/plugin.xml71
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/command/CommandIds.java171
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusRowResizeBindingsConfiguration.java121
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/SetAutoResizeCellHeightHandler.java54
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/SetWrapTextHandler.java75
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java66
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java65
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java27
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigAttributes.java16
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/StyleUtils.java379
12 files changed, 751 insertions, 372 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/SingleStringCellEditorConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/SingleStringCellEditorConfiguration.java
index 82c83fdfc6c..546ce326c7d 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/SingleStringCellEditorConfiguration.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/SingleStringCellEditorConfiguration.java
@@ -1,6 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2015 CEA LIST and others.
- *
+ * Copyright (c) 2015, 2017 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
@@ -8,7 +8,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
- *
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
*****************************************************************************/
package org.eclipse.papyrus.infra.emf.nattable.celleditor.config;
@@ -24,8 +24,12 @@ import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.papyrus.infra.emf.utils.EMFContants;
import org.eclipse.papyrus.infra.nattable.celleditor.MultiLineTextCellEditorEx;
import org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.utils.StyleUtils;
import org.eclipse.papyrus.infra.tools.util.TypesConstants;
/**
@@ -91,7 +95,23 @@ public class SingleStringCellEditorConfiguration implements ICellAxisConfigurati
*/
@Override
public void configureCellEditor(IConfigRegistry configRegistry, Object axis, String configLabel) {
- configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.EDIT, configLabel);
+ final INattableModelManager nattableManager = configRegistry.getConfigAttribute(
+ NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE,
+ DisplayMode.NORMAL,
+ NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+
+ final Table table = nattableManager.getTable();
+
+ final boolean wrapTextFlag = StyleUtils.getBooleanNamedStyleValue(table, NamedStyleConstants.WRAP_TEXT);
+ final boolean autoResizeCellHeightFlag = StyleUtils.getBooleanNamedStyleValue(table, NamedStyleConstants.AUTO_RESIZE_CELL_HEIGHT);
+
+ // Note that the width of the affected column will not be changed
+ TextPainter textPainter = new TextPainter(wrapTextFlag, true, 2, false, autoResizeCellHeightFlag);
+
+ // TODO: using wordWrapping when upgrade to the new NatTable version
+ // textPainter.setWordWrapping(true);
+
+ configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, textPainter, DisplayMode.NORMAL, configLabel);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiLineTextCellEditorEx(true), DisplayMode.EDIT, configLabel);
// I believe that we don't need converters because we are working with the standard type --String.
// configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, null, DisplayMode.EDIT, configLabel);
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
index 9cbebb91a6a..00112572b60 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2009, 2014 CEA LIST, LIFL, and others.
- *
+ * Copyright (c) 2009, 2017 CEA LIST, LIFL, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -13,7 +12,7 @@
* Christian W. Damus (CEA) - bug 430880
* Christian W. Damus (CEA) - bug 437217
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905
- *
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.common.editor;
@@ -58,10 +57,7 @@ import org.eclipse.ui.part.EditorPart;
/**
- * Abstract class for TableEditor
- *
- *
- *
+ * Abstract class for TableEditor.
*/
public abstract class AbstractEMFNattableEditor extends EditorPart implements NavigationTarget, IInternationalizationEditor {
@@ -262,22 +258,24 @@ public abstract class AbstractEMFNattableEditor extends EditorPart implements Na
/**
* this method is used dispose the existing nattable widget and recreate a new one.
* It has been created to be able to reload a table when a bug broke the table after a user action.
- *
+ *
* see bug 466447: [TreeTable] Missing method to reload a (hierarchic) table
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=466447
*/
public void reloadNattableModelManager() {
- if (TableHelper.isTreeTable(tableManager)) {
- reloadTreeNattableModelManager();
- } else {
- Table rawModel = this.tableManager.getTable();
- // we dispose the previous nattable widget
- NatTable nattable = this.tableManager.getAdapter(NatTable.class);
- Composite parent = nattable.getParent();
- this.tableManager.dispose();
- this.tableManager = NattableModelManagerFactory.INSTANCE.createNatTableModelManager(rawModel, new EObjectSelectionExtractor());
- nattable = this.tableManager.createNattable(parent, SWT.NONE, getSite());
- nattable.getParent().layout();
+ if (null != this.tableManager) {
+ if (TableHelper.isTreeTable(tableManager)) {
+ reloadTreeNattableModelManager();
+ } else {
+ Table rawModel = this.tableManager.getTable();
+ // we dispose the previous nattable widget
+ NatTable nattable = this.tableManager.getAdapter(NatTable.class);
+ Composite parent = nattable.getParent();
+ this.tableManager.dispose();
+ this.tableManager = NattableModelManagerFactory.INSTANCE.createNatTableModelManager(rawModel, new EObjectSelectionExtractor());
+ nattable = this.tableManager.createNattable(parent, SWT.NONE, getSite());
+ nattable.getParent().layout();
+ }
}
}
@@ -420,7 +418,7 @@ public abstract class AbstractEMFNattableEditor extends EditorPart implements Na
}
/**
- *
+ *
* @return
* the table model displayed by the editor
*/
@@ -429,7 +427,7 @@ public abstract class AbstractEMFNattableEditor extends EditorPart implements Na
}
/**
- *
+ *
* @return
* the table editing domain
*/
@@ -438,7 +436,7 @@ public abstract class AbstractEMFNattableEditor extends EditorPart implements Na
}
/**
- *
+ *
* @return
* the table context editing domain
*/
@@ -448,21 +446,21 @@ public abstract class AbstractEMFNattableEditor extends EditorPart implements Na
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.papyrus.infra.internationalization.common.editor.IInternationalizationEditor#modifyPartName(java.lang.String)
*/
@Override
public void modifyPartName(final String name) {
setPartName(name);
}
-
+
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.papyrus.infra.internationalization.common.editor.IInternationalizationEditor#refreshEditorPart()
*/
@Override
- public void refreshEditorPart(){
+ public void refreshEditorPart() {
// We don't need to refresh the editor part, the table is refreshed alone
}
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/plugin.xml b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/plugin.xml
index e95f504da74..c06c7b24ef4 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/plugin.xml
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/plugin.xml
@@ -1734,4 +1734,75 @@
type="java.lang.Object">
</propertyTester>
</extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.infra.nattable.category"
+ description="Wrap Text"
+ id="org.eclipse.papyrus.infra.nattable.wraptext"
+ name="Wrap Text">
+ <state
+ class="org.eclipse.ui.handlers.RegistryToggleState"
+ id="org.eclipse.ui.commands.toggleState">
+ </state>
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.infra.nattable.category"
+ description="Auto Resize Cell Height"
+ id="org.eclipse.papyrus.infra.nattable.autoresize.cellheight"
+ name="Auto Resize Cell Height">
+ <state
+ class="org.eclipse.ui.handlers.RegistryToggleState"
+ id="org.eclipse.ui.commands.toggleState">
+ </state>
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.papyrus.infra.nattable.widget.menu?endof=general.separator">
+ <command
+ commandId="org.eclipse.papyrus.infra.nattable.wraptext"
+ label="Wrap Text"
+ style="toggle">
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.infra.nattable.autoresize.cellheight"
+ label="Auto Resize Cell Height"
+ style="toggle">
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.infra.nattable.handler.SetWrapTextHandler"
+ commandId="org.eclipse.papyrus.infra.nattable.wraptext">
+ <activeWhen>
+ <with
+ variable="selection">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.nattable.tester.isNattableWidget"
+ value="true">
+ </test>
+ </with>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.infra.nattable.handler.SetAutoResizeCellHeightHandler"
+ commandId="org.eclipse.papyrus.infra.nattable.autoresize.cellheight">
+ <activeWhen>
+ <with
+ variable="selection">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.nattable.tester.isNattableWidget"
+ value="true">
+ </test>
+ </with>
+ </activeWhen>
+ </handler>
+ </extension>
</plugin>
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/command/CommandIds.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/command/CommandIds.java
index 065c9ec75b2..944487f5e8d 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/command/CommandIds.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/command/CommandIds.java
@@ -1,84 +1,87 @@
-/*****************************************************************************
- * 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.command;
-
-/**
- * This class references the ids of the commands declared for tables
- *
- * @author vl222926
- *
- */
-public class CommandIds {
-
- private CommandIds() {
- // to prevent instanciation
- }
-
- public static final String COMMAND_COLUMN_DISPLAY_INDEX_ID = "org.eclipse.papyrus.infra.nattable.column.display.index"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_DISPLAY_LABEL_ID = "org.eclipse.papyrus.infra.nattable.column.display.label"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_DISPLAY_FILTER_ID = "org.eclipse.papyrus.infra.nattable.column.display.filter"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_DISPLAY_INDEX_STYLE_ID = "org.eclipse.papyrus.infra.nattable.column.index.style"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_DISPLAY_INDEX_ID = "org.eclipse.papyrus.infra.nattable.row.display.index"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_DISPLAY_LABEL_ID = "org.eclipse.papyrus.infra.nattable.row.display.label"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_DISPLAY_INDEX_STYLE_ID = "org.eclipse.papyrus.infra.nattable.row.index.style"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_LABEL_DISPLAY_ICON = "org.eclipse.papyrus.infra.nattable.column.label.display.icon"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_LABEL_DISPLAY_ICON = "org.eclipse.papyrus.infra.nattable.row.label.display.icon"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_LABEL_DISPLAY_LABEL = "org.eclipse.papyrus.infra.nattable.column.label.display.label"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_LABEL_DISPLAY_LABEL = "org.eclipse.papyrus.infra.nattable.row.label.display.label"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_LABEL_FEATURE_DISPLAY_IS_DERIVED = "org.eclipse.papyrus.infra.nattable.row.label.feature.display.isderived"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_LABEL_FEATURE_DISPLAY_MULTIPLICITY = "org.eclipse.papyrus.infra.nattable.row.label.feature.display.multiplicity"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_LABEL_FEATURE_DISPLAY_TYPE = "org.eclipse.papyrus.infra.nattable.row.label.feature.display.type"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_LABEL_FEATURE_DISPLAY_IS_DERIVED = "org.eclipse.papyrus.infra.nattable.column.label.feature.display.isderived"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_LABEL_FEATURE_DISPLAY_MULTIPLICITY = "org.eclipse.papyrus.infra.nattable.column.label.feature.display.multiplicity"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_LABEL_FEATURE_DISPLAY_TYPE = "org.eclipse.papyrus.infra.nattable.column.label.feature.display.type"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_LABEL_FEATURE_DISPLAY_NAME = "org.eclipse.papyrus.infra.nattable.row.label.feature.display.name"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_LABEL_FEATURE_DISPLAY_NAME = "org.eclipse.papyrus.infra.nattable.column.label.feature.display.name"; //$NON-NLS-1$
-
- public static final String COMMAND_ROW_DISCONNECT_SLAVE = "org.eclipse.papyrus.infra.nattable.row.disconnect.slave"; //$NON-NLS-1$
-
- public static final String COMMAND_COLUMN_DISCONNECT_SLAVE = "org.eclipse.papyrus.infra.nattable.column.disconnect.slave"; //$NON-NLS-1$
-
- public static final String COMMAND_INVERT_AXIS = "org.eclipse.papyrus.infra.nattable.invert.axis"; //$NON-NLS-1$
-
- public static final String COMMAND_MERGE_ROWS = "org.eclipse.papyrus.infra.nattable.mergeRows"; //$NON-NLS-1$
-
- public static final String COMMAND_MERGE_COLUMNS = "org.eclipse.papyrus.infra.nattable.mergeColumns"; //$NON-NLS-1$
-
- public static final String COMMAND_MERGE_SELECTED_ROWS = "org.eclipse.papyrus.infra.nattable.mergeSelectedRows"; //$NON-NLS-1$
-
- public static final String COMMAND_MERGE_SELECTED_COLUMNS = "org.eclipse.papyrus.infra.nattable.mergeSelectedColumns"; //$NON-NLS-1$
-
- // public static final String COMMAND_MERGE_TABLE = "org.eclipse.papyrus.infra.nattable.mergeTable"; //$NON-NLS-1$
-
- public static final String COMMAND_HIERARCHIC_DISPLAY_STYLE = "org.eclipse.papyrus.infra.nattable.table.hierarchic.style";////$NON-NLS-1$
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013, 2017 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
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.command;
+
+/**
+ * This class references the ids of the commands declared for tables.
+ *
+ * @author vl222926
+ *
+ */
+public class CommandIds {
+
+ private CommandIds() {
+ // to prevent instanciation
+ }
+
+ public static final String COMMAND_COLUMN_DISPLAY_INDEX_ID = "org.eclipse.papyrus.infra.nattable.column.display.index"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_DISPLAY_LABEL_ID = "org.eclipse.papyrus.infra.nattable.column.display.label"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_DISPLAY_FILTER_ID = "org.eclipse.papyrus.infra.nattable.column.display.filter"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_DISPLAY_INDEX_STYLE_ID = "org.eclipse.papyrus.infra.nattable.column.index.style"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_DISPLAY_INDEX_ID = "org.eclipse.papyrus.infra.nattable.row.display.index"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_DISPLAY_LABEL_ID = "org.eclipse.papyrus.infra.nattable.row.display.label"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_DISPLAY_INDEX_STYLE_ID = "org.eclipse.papyrus.infra.nattable.row.index.style"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_LABEL_DISPLAY_ICON = "org.eclipse.papyrus.infra.nattable.column.label.display.icon"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_LABEL_DISPLAY_ICON = "org.eclipse.papyrus.infra.nattable.row.label.display.icon"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_LABEL_DISPLAY_LABEL = "org.eclipse.papyrus.infra.nattable.column.label.display.label"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_LABEL_DISPLAY_LABEL = "org.eclipse.papyrus.infra.nattable.row.label.display.label"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_LABEL_FEATURE_DISPLAY_IS_DERIVED = "org.eclipse.papyrus.infra.nattable.row.label.feature.display.isderived"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_LABEL_FEATURE_DISPLAY_MULTIPLICITY = "org.eclipse.papyrus.infra.nattable.row.label.feature.display.multiplicity"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_LABEL_FEATURE_DISPLAY_TYPE = "org.eclipse.papyrus.infra.nattable.row.label.feature.display.type"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_LABEL_FEATURE_DISPLAY_IS_DERIVED = "org.eclipse.papyrus.infra.nattable.column.label.feature.display.isderived"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_LABEL_FEATURE_DISPLAY_MULTIPLICITY = "org.eclipse.papyrus.infra.nattable.column.label.feature.display.multiplicity"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_LABEL_FEATURE_DISPLAY_TYPE = "org.eclipse.papyrus.infra.nattable.column.label.feature.display.type"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_LABEL_FEATURE_DISPLAY_NAME = "org.eclipse.papyrus.infra.nattable.row.label.feature.display.name"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_LABEL_FEATURE_DISPLAY_NAME = "org.eclipse.papyrus.infra.nattable.column.label.feature.display.name"; //$NON-NLS-1$
+
+ public static final String COMMAND_ROW_DISCONNECT_SLAVE = "org.eclipse.papyrus.infra.nattable.row.disconnect.slave"; //$NON-NLS-1$
+
+ public static final String COMMAND_COLUMN_DISCONNECT_SLAVE = "org.eclipse.papyrus.infra.nattable.column.disconnect.slave"; //$NON-NLS-1$
+
+ public static final String COMMAND_INVERT_AXIS = "org.eclipse.papyrus.infra.nattable.invert.axis"; //$NON-NLS-1$
+
+ public static final String COMMAND_MERGE_ROWS = "org.eclipse.papyrus.infra.nattable.mergeRows"; //$NON-NLS-1$
+
+ public static final String COMMAND_MERGE_COLUMNS = "org.eclipse.papyrus.infra.nattable.mergeColumns"; //$NON-NLS-1$
+
+ public static final String COMMAND_MERGE_SELECTED_ROWS = "org.eclipse.papyrus.infra.nattable.mergeSelectedRows"; //$NON-NLS-1$
+
+ public static final String COMMAND_MERGE_SELECTED_COLUMNS = "org.eclipse.papyrus.infra.nattable.mergeSelectedColumns"; //$NON-NLS-1$
+
+ // public static final String COMMAND_MERGE_TABLE = "org.eclipse.papyrus.infra.nattable.mergeTable"; //$NON-NLS-1$
+
+ public static final String COMMAND_HIERARCHIC_DISPLAY_STYLE = "org.eclipse.papyrus.infra.nattable.table.hierarchic.style";////$NON-NLS-1$
+
+ public static final String COMMAND_WRAP_TEXT = "org.eclipse.papyrus.infra.nattable.wraptext"; //$NON-NLS-1$
+
+ public static final String COMMAND_AUTO_RESIZE_CELL_HEIGHT = "org.eclipse.papyrus.infra.nattable.autoresize.cellheight"; //$NON-NLS-1$
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusRowResizeBindingsConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusRowResizeBindingsConfiguration.java
index d71c5739798..1491b475cd4 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusRowResizeBindingsConfiguration.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusRowResizeBindingsConfiguration.java
@@ -1,56 +1,65 @@
-/*****************************************************************************
- * 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.config.AbstractUiBindingConfiguration;
-import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
-import org.eclipse.nebula.widgets.nattable.resize.action.RowResizeCursorAction;
-import org.eclipse.nebula.widgets.nattable.resize.event.RowResizeEventMatcher;
-import org.eclipse.nebula.widgets.nattable.resize.mode.RowResizeDragMode;
-import org.eclipse.nebula.widgets.nattable.ui.action.ClearCursorAction;
-import org.eclipse.nebula.widgets.nattable.ui.action.NoOpMouseAction;
-import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
-import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
-import org.eclipse.swt.SWT;
-
-/**
- * Adapted code from DefaultRowResizeBindings. Allow to resize the rows on all regions of the table (corner, body, row header, column header)
- *
- * @author vl222926
- *
- */
-public class PapyrusRowResizeBindingsConfiguration extends AbstractUiBindingConfiguration {
-
- @Override
- public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
- // Mouse move - Show resize cursor
- uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 0), new RowResizeCursorAction());
- uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 0), new RowResizeCursorAction());
- uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.CORNER, 0), new RowResizeCursorAction());
- uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.BODY, 0), new RowResizeCursorAction());
-
- uiBindingRegistry.registerMouseMoveBinding(new MouseEventMatcher(), new ClearCursorAction());
-
- // Row resize
- uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 1), new RowResizeDragMode());
- uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 1), new RowResizeDragMode());
- uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, GridRegion.CORNER, 1), new RowResizeDragMode());
- uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, GridRegion.BODY, 1), new RowResizeDragMode());
-
- // uiBindingRegistry.registerDoubleClickBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 1), new AutoResizeRowAction());
- uiBindingRegistry.registerSingleClickBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 1), new NoOpMouseAction());
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013, 2017 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
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.configuration;
+
+import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
+import org.eclipse.nebula.widgets.nattable.resize.action.RowResizeCursorAction;
+import org.eclipse.nebula.widgets.nattable.resize.event.RowResizeEventMatcher;
+import org.eclipse.nebula.widgets.nattable.resize.mode.RowResizeDragMode;
+import org.eclipse.nebula.widgets.nattable.ui.action.ClearCursorAction;
+import org.eclipse.nebula.widgets.nattable.ui.action.NoOpMouseAction;
+import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
+import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.swt.SWT;
+
+/**
+ * Adapted code from DefaultRowResizeBindings. Allow to resize the rows on all regions of the table (corner, body, row header, column header).
+ *
+ * @author vl222926
+ *
+ */
+public class PapyrusRowResizeBindingsConfiguration extends AbstractUiBindingConfiguration {
+
+ @Override
+ public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
+ // Mouse move - Show resize cursor
+ uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 0), new RowResizeCursorAction());
+ uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 0), new RowResizeCursorAction());
+ uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.CORNER, 0), new RowResizeCursorAction());
+ uiBindingRegistry.registerFirstMouseMoveBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.BODY, 0), new RowResizeCursorAction());
+
+ uiBindingRegistry.registerMouseMoveBinding(new MouseEventMatcher(), new ClearCursorAction());
+
+ // Row resize
+ uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 1), new RowResizeDragMode());
+ uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 1), new RowResizeDragMode());
+ uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, GridRegion.CORNER, 1), new RowResizeDragMode());
+ uiBindingRegistry.registerFirstMouseDragMode(new RowResizeEventMatcher(SWT.NONE, GridRegion.BODY, 1), new RowResizeDragMode());
+
+ // uiBindingRegistry.registerDoubleClickBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 1), new AutoResizeRowAction());
+ uiBindingRegistry.registerSingleClickBinding(new RowResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 1), new NoOpMouseAction());
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void configureRegistry(final IConfigRegistry configRegistry) {
+ configRegistry.registerConfigAttribute(NattableConfigAttributes.REINITIALISE_ROW_HEIGHT, new Boolean(false));
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/SetAutoResizeCellHeightHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/SetAutoResizeCellHeightHandler.java
new file mode 100644
index 00000000000..4bfb8b036f1
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/SetAutoResizeCellHeightHandler.java
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * Copyright (c) 2017 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:
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.handler;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.BooleanValueStyle;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NattablestylePackage;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
+import org.eclipse.papyrus.infra.nattable.utils.StyleUtils;
+
+/**
+ * Handler to enable or disable the auto-resizing of cell height of the active table.
+ */
+public class SetAutoResizeCellHeightHandler extends AbstractTableHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TransactionalEditingDomain editingDomain = getTableEditingDomain();
+ Table table = getTable();
+
+ if (null != editingDomain && null != table) {
+
+ // Get the auto resize cell height named style from the table
+ BooleanValueStyle autoResizeValue = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.AUTO_RESIZE_CELL_HEIGHT);
+
+ // If the auto resize value exists
+ if (null != autoResizeValue) {
+ // Inverse the auto resize cell boolean value and save it to the table
+ StyleUtils.setBooleanNamedStyle(editingDomain, table, NamedStyleConstants.AUTO_RESIZE_CELL_HEIGHT, !autoResizeValue.isBooleanValue());
+
+ } else {
+ // Otherwise, initialise the auto resize cell height named value in the disable mode by default
+ StyleUtils.initBooleanNamedStyle(editingDomain, table, NamedStyleConstants.AUTO_RESIZE_CELL_HEIGHT, false);
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/SetWrapTextHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/SetWrapTextHandler.java
new file mode 100644
index 00000000000..d76d9a9cb74
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/SetWrapTextHandler.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * Copyright (c) 2017 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:
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.handler;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.BooleanValueStyle;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NattablestylePackage;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.utils.StyleUtils;
+
+/**
+ * Handler to enable or disable wrap text in cells of the active table.
+ */
+public class SetWrapTextHandler extends AbstractTableHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TransactionalEditingDomain editingDomain = getTableEditingDomain();
+ Table table = getTable();
+
+ if (null != editingDomain && null != table) {
+ // Get the wrap text named style from the table
+ BooleanValueStyle wrapTextValue = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.WRAP_TEXT);
+
+ // If the wrap text value exists
+ if (null != wrapTextValue) {
+ boolean oldWrapTextValue = wrapTextValue.isBooleanValue();
+
+ // Inverse the wrap text boolean value and save it to the table
+ StyleUtils.setBooleanNamedStyle(editingDomain, table, NamedStyleConstants.WRAP_TEXT, !oldWrapTextValue);
+
+ // If wrap text value is changing from enable to disable and if the set auto resize cell height is currently enabled,
+ // the row's height must be reset to the default value
+ if (oldWrapTextValue) {
+ // Get the auto resize cell height named style from the table
+ BooleanValueStyle autoResizeValue = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.AUTO_RESIZE_CELL_HEIGHT);
+
+ // NB: Rows resizing must be done in NattableModelManager after the cell editors are reconfigured
+ // So, an auto resize rows config attribute flag is used here, which allows the rows resizing to be done later
+ if (null != autoResizeValue && autoResizeValue.isBooleanValue()) {
+ NatEventData natEventData = getNatEventData();
+ if (null != natEventData && null != natEventData.getNatTable()) {
+ final NatTable natTable = natEventData.getNatTable();
+ // Enable the rows resizing to be done later in NattableModelManager
+ natTable.getConfigRegistry().registerConfigAttribute(NattableConfigAttributes.REINITIALISE_ROW_HEIGHT, true);
+ }
+ }
+ }
+ } else {
+ // Otherwise, initialise the wrap text named value in the disable mode by default
+ StyleUtils.initBooleanNamedStyle(editingDomain, table, NamedStyleConstants.WRAP_TEXT, false);
+ }
+ }
+
+ return null;
+ }
+}
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 41229012fb6..59a084ec458 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
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012, 2016 CEA LIST and others.
- *
+ * Copyright (c) 2012, 2017 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
@@ -14,7 +13,7 @@
* Dirk Fauth <dirk.fauth@googlemail.com> - Bug 488234
* Nicolas FAUVERGUE(ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 504077
* Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 502560: add drag to diagram support
- *
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.manager.table;
@@ -146,6 +145,7 @@ import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
import org.eclipse.papyrus.infra.nattable.utils.PapyrusTableSizeCalculation;
import org.eclipse.papyrus.infra.nattable.utils.PercentageCalculationUtils;
+import org.eclipse.papyrus.infra.nattable.utils.StyleUtils;
import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils;
import org.eclipse.papyrus.infra.nattable.utils.TableGridRegion;
import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
@@ -264,7 +264,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* the composite layer providing the filter row in the column header
- *
+ *
* @since 2.0
*/
protected FilterRowHeaderComposite<?> filterColumnHeaderComposite;
@@ -303,14 +303,14 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* The CTabFolder.
- *
+ *
* @since 2.1
*/
private CTabFolder cTabFolder;
/**
* The CTabFolder selection listener.
- *
+ *
* @since 2.1
*/
private SelectionListener cTabFolderSelectionListener;
@@ -473,9 +473,9 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* Get the parent CTabFolder if exists.
- *
+ *
* @return The parent CTabFolder or <code>null</code>.
- *
+ *
* @since 3.0
*/
protected CTabFolder getParentCTabFolder() {
@@ -493,9 +493,9 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* Get the CTabFolder selection listener created if doesn't exists.
- *
+ *
* @return The CTabFolder selection listener.
- *
+ *
* @since 3.0
*/
protected SelectionListener getCTabFolderSelectionListener() {
@@ -531,9 +531,9 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* Get the display of the top composite of nattable editor.
- *
+ *
* @return The display of the top composite.
- *
+ *
* @since 3.0
*/
protected Control getNattableTopParentComposite() {
@@ -836,7 +836,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* Instantiate a new {@link NatTableDropListener}.
- *
+ *
* @return The Drop Listener.
*/
protected NatTableDropListener createDropListener() {
@@ -845,7 +845,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* Instantiate a new {@link DragSourceListener}.
- *
+ *
* @return The Drag Listener.
*/
protected DragSourceListener createDragListener() {
@@ -952,14 +952,20 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
// the process is the same for this event
else if (event instanceof RowResizeEvent) {
- int resizedRowPosition = getRangeStart(event);
- int newRowSize = rowHeaderLayerStack.getRowHeightByPosition(resizedRowPosition);
- ICommand cmd = createSetRowSizeCommand(resizedRowPosition, newRowSize);
- if (cmd != null && cmd.canExecute()) {
- resizeCommand.add(cmd);
+ final boolean autoResizeCellHeightFlag = StyleUtils.getBooleanNamedStyleValue(table, NamedStyleConstants.AUTO_RESIZE_CELL_HEIGHT);
+
+ // The set row size command is performed only if the auto resize cell height flag is turned off
+ // When this flag is turned on, all rows will be resized. So there's no need to do it here
+ if (!autoResizeCellHeightFlag) {
+ int resizedRowPosition = getRangeStart(event);
+ int newRowSize = rowHeaderLayerStack.getRowHeightByPosition(resizedRowPosition);
+ ICommand cmd = createSetRowSizeCommand(resizedRowPosition, newRowSize);
+ if (cmd != null && cmd.canExecute()) {
+ resizeCommand.add(cmd);
+ }
}
-
}
+
if (!resizeCommand.isEmpty()) {
tableDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(resizeCommand));
}
@@ -974,7 +980,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* This allows to calculate the initial width percentage for a column without 'axisWidth' named style.
- *
+ *
* @return The percentage for a column without 'axisWidth' named style.
* @since 3.0
*/
@@ -1013,14 +1019,14 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* Create the set column size command for the column resizing.
- *
+ *
* @param columnIndex
* the column where we edit the width.
* @param newColumnWidth
* the new width for the given column.
* @return
* the command to set the new column width when the column is saved as IAxis and <code>null</code> in others cases
- *
+ *
* @since 2.0
*/
private ICommand createSetColumnSizeCommand(final int resizedColumnPosition, final int newColumnWidth) {
@@ -1069,14 +1075,14 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* Create the set row size command for the row resizing.
- *
+ *
* @param columnIndex
* the row where we edit the height.
* @param newRowHeight
* the new height for the given row.
* @return
* the command to set the new row height when the row is saved as IAxis and <code>null</code> in others cases
- *
+ *
* @since 2.0
*/
private ICommand createSetRowSizeCommand(final int resizedRowPosition, final int newRowHeight) {
@@ -1490,7 +1496,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager#exportToFile()
*/
@Override
@@ -1515,7 +1521,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.ui.services.IDisposable#dispose()
*/
@Override
@@ -1778,10 +1784,10 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
}
}
}
-
+
/**
* This allows to manage the fill columns size named style by managing the width of columns to fill all the parent space.
- *
+ *
* @since 2.0
*/
protected void doFillColumnsSize() {
@@ -1814,7 +1820,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
/**
* Get the column width as percentage management value.
- *
+ *
* @return <code>true</code> if columns width are managed as percentage, <code>false</code> otherwise.
* @since 3.0
*/
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 d316ec8d7f3..805b59e07d4 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
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012, 2016 CEA LIST, Esterel Technologies SAS and others.
- *
+ * Copyright (c) 2012, 2017 CEA LIST, Esterel Technologies SAS and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -12,7 +11,7 @@
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 476618, 504077, 496905, 508175
* Nicolas Boulay (Esterel Technologies SAS) - Bug 497467
* Sebastien Bordes (Esterel Technologies SAS) - Bug 497738
- *
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.manager.table;
@@ -55,6 +54,7 @@ import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.window.Window;
import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
@@ -62,6 +62,7 @@ import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.filterrow.IFilterStrategy;
import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
+import org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeRowsCommand;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand;
import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand;
@@ -69,6 +70,7 @@ import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand
import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand;
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.internationalization.utils.utils.LabelInternationalization;
import org.eclipse.papyrus.infra.nattable.Activator;
@@ -111,8 +113,10 @@ import org.eclipse.papyrus.infra.nattable.sort.PapyrusCompositeGlazedListSortMod
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.CellMapKey;
import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
import org.eclipse.papyrus.infra.nattable.utils.StringComparator;
+import org.eclipse.papyrus.infra.nattable.utils.StyleUtils;
import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
@@ -144,9 +148,7 @@ import ca.odell.glazedlists.event.ListEvent;
import ca.odell.glazedlists.event.ListEventListener;
/**
- * All the code concerning tree table is in the subclass {@link TreeNattableModelManager}
- *
- *
+ * All the code concerning tree table is in the subclass {@link TreeNattableModelManager}.
*/
public class NattableModelManager extends AbstractNattableWidgetManager implements INattableModelManager, FocusListener {
@@ -246,7 +248,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
}
/**
- *
+ *
* Constructor.
*
* @param rawModel
@@ -392,7 +394,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
this.listEventListener = new ListEventListener<Object>() {
/**
- *
+ *
* @param listChanges
*/
@Override
@@ -408,7 +410,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
}
/**
- *
+ *
* @param listChanges
* manage the list events
*/
@@ -453,7 +455,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
protected SortedList<Object> columnSortedList;
/**
- *
+ *
* @return
* the new list to use for vertical element
*/
@@ -467,7 +469,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
}
/**
- *
+ *
* @return
* the new list to use for horizontal element
*/
@@ -538,7 +540,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
nattable.addFocusListener(this.focusListener);
// registering to focusService allows to declare properties tester on "activeFocusControl" and "activeFocusControlId" variables
- focusService = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);
+ focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
String id = null;
if (getTable().getTableConfiguration() != null) {
@@ -705,8 +707,13 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
// updateToggleCommandState(command, false);
// }
+ // Update the wrap text command state
+ command = commandService.getCommand(CommandIds.COMMAND_WRAP_TEXT);
+ updateToggleCommandState(command, StyleUtils.getBooleanNamedStyleValue(getTable(), NamedStyleConstants.WRAP_TEXT));
-
+ // Update the auto resize cell height state
+ command = commandService.getCommand(CommandIds.COMMAND_AUTO_RESIZE_CELL_HEIGHT);
+ updateToggleCommandState(command, StyleUtils.getBooleanNamedStyleValue(getTable(), NamedStyleConstants.AUTO_RESIZE_CELL_HEIGHT));
} else {
throw new RuntimeException(String.format("The Eclipse service %s has not been found", ICommandService.class)); //$NON-NLS-1$
@@ -1151,6 +1158,9 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
// Refresh the nattable columns size in the case of named style
doFillColumnsSize();
+ // Resize all rows if necessary
+ reinitialiseRowHeight();
+
// Keep the selection after the refresh of the table
if (null != selectedCells && !selectedCells.isEmpty()) {
Collection<Integer> selectedColumns = new ArrayList<Integer>();
@@ -1450,7 +1460,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager#getAddRowElementCommand(java.util.Collection, int)
*/
@Override
@@ -1475,7 +1485,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager#getAddColumnElementCommand(java.util.Collection, int)
*/
@Override
@@ -1798,7 +1808,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager#setTableLabel(java.lang.String)
*/
@Override
@@ -2128,7 +2138,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
}
/**
- *
+ *
* @return
* a new decoration service listener
*/
@@ -2136,7 +2146,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
if (this.decoractionServiceObserver == null) {
this.decoractionServiceObserver = new Observer() {
/**
- *
+ *
* @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*
* @param o
@@ -2150,4 +2160,23 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
}
return this.decoractionServiceObserver;
}
+
+ /**
+ * Method to resize rows of the NatTable if the reinitialise row height attribute is <code>true</true>.
+ */
+ protected void reinitialiseRowHeight() {
+ IConfigRegistry configRegistry = this.natTable.getConfigRegistry();
+
+ final Boolean isAutoResizeRowsEnabled = configRegistry.getConfigAttribute(NattableConfigAttributes.REINITIALISE_ROW_HEIGHT, DisplayMode.NORMAL);
+
+ if (isAutoResizeRowsEnabled) {
+ // Loop to resize all rows of the NatTable
+ for (int rowIndex = 0; rowIndex < natTable.getRowCount(); rowIndex++) {
+ natTable.doCommand(new InitializeAutoResizeRowsCommand(natTable, rowIndex, natTable.getConfigRegistry(), new GCFactory(natTable)));
+ }
+
+ // Once it is done, reset the resize row height flag to false
+ configRegistry.registerConfigAttribute(NattableConfigAttributes.REINITIALISE_ROW_HEIGHT, false);
+ }
+ }
}
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 1eaf2b3e34f..aa0490e3540 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,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
+ * Copyright (c) 2014, 2017 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,7 +9,7 @@
* Contributors:
* 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
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.utils;
@@ -99,8 +98,8 @@ public class NamedStyleConstants {
/**
* key used to save a filter configuration id state when the system use a filter choosen by the user
* It is only used as name for a {@link StringValueStyle}, we use a specific key in order to not destroyed it when we unapply filter on a column where filter has been definied by the user
- *
- *
+ *
+ *
*/
public static final String FILTER_FORCED_BY_USER_ID = "filterForcedByUserId"; //$NON-NLS-1$
@@ -111,7 +110,7 @@ public class NamedStyleConstants {
/**
* This allows to manage the fill columns size to take all the container space.
- *
+ *
* @deprecated since 3.0
*/
@Deprecated
@@ -120,7 +119,7 @@ public class NamedStyleConstants {
/**
* This allows to determinate if the columns width must be managed as percentage.
* This named style is not compatible with 'fillColumnsSize'.
- *
+ *
* @since 3.0
*/
public static final String COLUMNS_WIDTH_AS_PERCENTAGE = "columnsWidthAsPercentage"; //$NON-NLS-1$
@@ -128,15 +127,25 @@ public class NamedStyleConstants {
/**
* This allows to determinate if the columns width must be saved or not.
* This named style is not compatible with 'fillColumnsSize'.
- *
+ *
* @since 3.0
*/
public static final String SAVE_COLUMNS_WIDTH = "saveColumnsWidth"; //$NON-NLS-1$
/**
* Enable the drag behavior regions from the natTable to an other widget/editor (diagram, table, ...) which can accept it.
- *
+ *
* @since 3.0
*/
public static final String DRAG_REGIONS = "dragRegions"; //$NON-NLS-1$
+
+ /**
+ * A {@link BooleanValueStyle} used to enable wrap text in the NatTable.
+ */
+ public static final String WRAP_TEXT = "wrapText"; //$NON-NLS-1$
+
+ /**
+ * A {@link BooleanValueStyle} used to enable auto-resize cell height in the NatTable.
+ */
+ public static final String AUTO_RESIZE_CELL_HEIGHT = "autoResizeCellHeight"; //$NON-NLS-1$
}
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 22ca596501f..d4b235af106 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
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
+ * Copyright (c) 2013, 2017 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,7 +8,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.utils;
@@ -26,7 +25,7 @@ import org.eclipse.papyrus.infra.services.decoration.DecorationService;
import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
/**
- * This class references the keys registered in the ConfigRegistry of the table to facilitate access to these objects
+ * This class references the keys registered in the ConfigRegistry of the table to facilitate access to these objects.
*
* @author Vincent Lorenzo
*
@@ -69,7 +68,7 @@ public class NattableConfigAttributes {
*/
public static final ConfigAttribute<DecorationService> DECORATION_SERVICE_CONFIG_ATTRIBUTE = new ConfigAttribute<DecorationService>();
-
+
/**
* Id used to register the label provider service
*/
@@ -80,7 +79,7 @@ public class NattableConfigAttributes {
*/
public static final String DECORATION_SERVICE_ID = "decoration_service_id"; //$NON-NLS-1$
-
+
/**
* Id used to register the table model manager
*/
@@ -126,4 +125,9 @@ public class NattableConfigAttributes {
*/
public static final ConfigAttribute<ISortModel> ROW_SORT_MODEl = new ConfigAttribute<ISortModel>();
+ /**
+ * The config attribute used to reinitialise the height of rows in the table.
+ */
+ public static final ConfigAttribute<Boolean> REINITIALISE_ROW_HEIGHT = new ConfigAttribute<Boolean>();
+
} \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/StyleUtils.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/StyleUtils.java
index 21ab7c2ef1d..43d3e200836 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/StyleUtils.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/StyleUtils.java
@@ -1,139 +1,240 @@
-/*****************************************************************************
- * 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.utils;
-
-import java.util.Collections;
-import java.util.List;
-
-import javax.swing.text.StyledDocument;
-
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.IntListValueStyle;
-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.model.nattable.nattablestyle.Style;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.StyledElement;
-
-/**
- * @author VL222926
- *
- */
-public class StyleUtils {
-
- /**
- *
- * @param table
- * a table
- * @return
- * a list with the hidden depth in the table. The returned values in never <code>null</code>;
- */
- public static final List<Integer> getHiddenDepths(final Table table) {
- IntListValueStyle style = getHiddenDepthsValueStyle(table);
- if (style == null) {
- return Collections.emptyList();
- }
- return Collections.unmodifiableList(style.getIntListValue());
- }
-
- /**
- *
- * @param table
- * a table
- * @return
- * a list with the hidden depth in the table. The returned values in never <code>null</code>;
- */
- public static final List<Integer> getHiddenDepths(final INattableModelManager manager) {
- return getHiddenDepths(manager.getTable());
- }
-
- /**
- *
- * @param manager
- * the table
- * @return
- * the style referencing the hidden category
- */
-
- public static final IntListValueStyle getHiddenDepthsValueStyle(final Table table) {
- return (IntListValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getIntListValueStyle(), NamedStyleConstants.HIDDEN_CATEGORY_FOR_DEPTH);
- }
-
- /**
- *
- * @param manager
- * the table manager
- * @return
- * the style referencing the hidden category
- */
- public static final IntListValueStyle getHiddenDepthsValueStyle(final INattableModelManager manager) {
- return getHiddenDepthsValueStyle(manager.getTable());
- }
-
- /**
- *
- * @param manager
- * a table manager
- * @param depth
- * a depth
- * @return
- * <code>true</code> if the category must be hidden
- */
- public static final boolean isHiddenDepth(final INattableModelManager manager, final int depth) {
- return isHiddenDepth(manager.getTable(), depth);
- }
-
- /**
- *
- * @param table
- * a table
- * @param depth
- * a depth
- * @return
- * <code>true</code> if the category must be hidden
- */
- public static final boolean isHiddenDepth(final Table table, final int depth) {
- List<Integer> hidden = getHiddenDepths(table);
- if (hidden.contains(depth)) {
- return true;
- }
- return false;
- }
-
- /**
- *
- * @param manager
- * the table manager
- * @return
- * <code>true</code> if at least one filter is register on the currents columns
- */
- public static final boolean hasAppliedFilter(final INattableModelManager manager) {
- for (Object current : manager.getColumnElementsList()) {
- if (current instanceof StyledElement) {
- StyledElement element = (StyledElement) current;
- NamedStyle style = element.getNamedStyle(NattablestylePackage.eINSTANCE.getStringValueStyle(), NamedStyleConstants.FILTER_SYSTEM_ID);
- if (style != null) {
- return true;
- }
- style = element.getNamedStyle(NattablestylePackage.eINSTANCE.getStringValueStyle(), NamedStyleConstants.FILTER_FORCED_BY_USER_ID);
- if (style != null) {
- return true;
- }
-
- }
- }
- return false;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014, 2017 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
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 459220
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.utils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.BooleanValueStyle;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.IntListValueStyle;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NamedStyle;
+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.Style;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.StyledElement;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+
+/**
+ * @author VL222926
+ *
+ */
+public class StyleUtils {
+
+ /**
+ *
+ * @param table
+ * a table
+ * @return
+ * a list with the hidden depth in the table. The returned values in never <code>null</code>;
+ */
+ public static final List<Integer> getHiddenDepths(final Table table) {
+ IntListValueStyle style = getHiddenDepthsValueStyle(table);
+ if (style == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableList(style.getIntListValue());
+ }
+
+ /**
+ *
+ * @param table
+ * a table
+ * @return
+ * a list with the hidden depth in the table. The returned values in never <code>null</code>;
+ */
+ public static final List<Integer> getHiddenDepths(final INattableModelManager manager) {
+ return getHiddenDepths(manager.getTable());
+ }
+
+ /**
+ *
+ * @param manager
+ * the table
+ * @return
+ * the style referencing the hidden category
+ */
+
+ public static final IntListValueStyle getHiddenDepthsValueStyle(final Table table) {
+ return (IntListValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getIntListValueStyle(), NamedStyleConstants.HIDDEN_CATEGORY_FOR_DEPTH);
+ }
+
+ /**
+ *
+ * @param manager
+ * the table manager
+ * @return
+ * the style referencing the hidden category
+ */
+ public static final IntListValueStyle getHiddenDepthsValueStyle(final INattableModelManager manager) {
+ return getHiddenDepthsValueStyle(manager.getTable());
+ }
+
+ /**
+ *
+ * @param manager
+ * a table manager
+ * @param depth
+ * a depth
+ * @return
+ * <code>true</code> if the category must be hidden
+ */
+ public static final boolean isHiddenDepth(final INattableModelManager manager, final int depth) {
+ return isHiddenDepth(manager.getTable(), depth);
+ }
+
+ /**
+ *
+ * @param table
+ * a table
+ * @param depth
+ * a depth
+ * @return
+ * <code>true</code> if the category must be hidden
+ */
+ public static final boolean isHiddenDepth(final Table table, final int depth) {
+ List<Integer> hidden = getHiddenDepths(table);
+ if (hidden.contains(depth)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param manager
+ * the table manager
+ * @return
+ * <code>true</code> if at least one filter is register on the currents columns
+ */
+ public static final boolean hasAppliedFilter(final INattableModelManager manager) {
+ for (Object current : manager.getColumnElementsList()) {
+ if (current instanceof StyledElement) {
+ StyledElement element = (StyledElement) current;
+ NamedStyle style = element.getNamedStyle(NattablestylePackage.eINSTANCE.getStringValueStyle(), NamedStyleConstants.FILTER_SYSTEM_ID);
+ if (style != null) {
+ return true;
+ }
+ style = element.getNamedStyle(NattablestylePackage.eINSTANCE.getStringValueStyle(), NamedStyleConstants.FILTER_FORCED_BY_USER_ID);
+ if (style != null) {
+ return true;
+ }
+
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get the value of a boolean named style in a given table.
+ *
+ * @param table
+ * The given papyrus table
+ * @param namedStyleString
+ * The named style string
+ * @return The boolean value of the named style
+ */
+ public static boolean getBooleanNamedStyleValue(final Table table, final String namedStyleString) {
+ boolean resultValue = false;
+
+ if (null != table && null != namedStyleString) {
+ // Get the relevant boolean named style from the table
+ BooleanValueStyle booleanNamedStyle = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), namedStyleString);
+
+ if (null == booleanNamedStyle) {
+ final TableConfiguration config = table.getTableConfiguration();
+ booleanNamedStyle = (BooleanValueStyle) config.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), namedStyleString);
+ }
+
+ resultValue = null != booleanNamedStyle && booleanNamedStyle.isBooleanValue();
+ }
+
+ return resultValue;
+ }
+
+ /**
+ * Set the value of a boolean named style in a given table.
+ *
+ * @param editingDomain
+ * The editing domain
+ * @param table
+ * The given papyrus table
+ * @param namedStyleString
+ * The named style string
+ * @param value
+ * The boolean value to be set
+ */
+ public static void setBooleanNamedStyle(final TransactionalEditingDomain editingDomain, final Table table, final String namedStyleString, final boolean value) {
+ if (null != editingDomain && null != table && null != namedStyleString) {
+ // Get the relevant boolean named style from the table
+ BooleanValueStyle booleanNamedStyle = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), namedStyleString);
+
+ if (null != booleanNamedStyle) {
+ IElementEditService editService = ElementEditServiceUtils.getCommandProvider(booleanNamedStyle);
+ SetRequest request = new SetRequest(editingDomain, booleanNamedStyle, NattablestylePackage.eINSTANCE.getBooleanValueStyle_BooleanValue(), value);
+
+ if (editService.canEdit(request)) {
+ Command command = GMFtoEMFCommandWrapper.wrap(editService.getEditCommand(request));
+ editingDomain.getCommandStack().execute(command);
+ }
+ }
+ }
+ }
+
+ /**
+ * Initialize the given named style if it is not created.
+ * If the named style has been already created, do nothing.
+ *
+ * @param editingDomain
+ * The editing domain
+ * @param table
+ * The given papyrus table
+ * @param namedStyleString
+ * The named style string
+ * @param defaultValue
+ * The default value to be set
+ */
+ public static void initBooleanNamedStyle(final TransactionalEditingDomain editingDomain, final Table table, final String namedStyleString, final boolean defaultValue) {
+ if (null != editingDomain && null != table && null != namedStyleString) {
+ // Get the relevant named style
+ BooleanValueStyle namedStyle = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), namedStyleString);
+
+ // If it does not exist, initialize it, otherwise do nothing
+ if (null == namedStyle) {
+ namedStyle = NattablestyleFactory.eINSTANCE.createBooleanValueStyle();
+ namedStyle.setName(namedStyleString);
+ namedStyle.setBooleanValue(defaultValue);
+
+ // Add the new boolean style
+ List<Style> styleList = new ArrayList<Style>(table.getStyles());
+ styleList.add(namedStyle);
+
+ IElementEditService editService = ElementEditServiceUtils.getCommandProvider(table);
+ SetRequest request = new SetRequest(editingDomain, table, NattablestylePackage.eINSTANCE.getStyledElement_Styles(), styleList);
+ if (editService.canEdit(request)) {
+ Command command = GMFtoEMFCommandWrapper.wrap(editService.getEditCommand(request));
+ editingDomain.getCommandStack().execute(command);
+ }
+ }
+ }
+ }
+}

Back to the top