diff options
author | Thanh Liem PHAN | 2017-05-31 07:59:14 +0000 |
---|---|---|
committer | vincent lorenzo | 2017-11-20 12:31:54 +0000 |
commit | 8eca02ee0e11692796d583e3b86df24540f34100 (patch) | |
tree | f213e560615a2917b0e5fe8f8f96653224bf914a /plugins/uml | |
parent | 5afa41f30f3f7a556cb3fdbee14a90733af607a6 (diff) | |
download | org.eclipse.papyrus-8eca02ee0e11692796d583e3b86df24540f34100.tar.gz org.eclipse.papyrus-8eca02ee0e11692796d583e3b86df24540f34100.tar.xz org.eclipse.papyrus-8eca02ee0e11692796d583e3b86df24540f34100.zip |
Bug 515737: [Table] Papyrus Table must be able to display list in cells
with a new line for each object owned by the list and fake line between
values https://bugs.eclipse.org/bugs/show_bug.cgi?id=515737
- Add icon for each element of the list
- Create a new custom table cell painter
- Add menu context and named style for each multiple values column such
as multiple [boolean | integer | real | string | reference | enum]
- Handle generic table, generic tree table, class tree table, generic
stereotype table
- Handle also invert table for the invertable one
- Support wraptext + autoResizeCellHeight for multi string cell
- Add dev doc and user doc for the new feature
- JUnit Test
Note that EOperationAxis column is not supported yet.
Change-Id: If2da613cf6f7c11c31652f6ac4a719faa36e5733
Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins/uml')
13 files changed, 523 insertions, 61 deletions
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml index 940a0a964ae..cc7d56127f3 100755 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml @@ -283,4 +283,71 @@ type="PapyrusUMLGenericTreeTable"> </configuration> </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + allPopups="true" + locationURI="popup:org.eclipse.papyrus.infra.nattable.header.columns.menu?after=general.separator"> + <command + commandId="org.eclipse.papyrus.infra.nattable.displaylist.separatedrows.columnheader" + label="Display List On Separated Rows" + style="toggle"> + <visibleWhen + checkEnabled="true"> + <and> + <with + variable="selection"> + <test + forcePluginActivation="true" + property="org.eclipse.papyrus.infra.nattable.tester.isNattableWidget" + value="true"> + </test> + <test + forcePluginActivation="true" + property="org.eclipse.papyrus.uml.nattable.tester.isOneMultipleValuesAxisSelected" + value="true"> + </test> + </with> + </and> + </visibleWhen> + </command> + </menuContribution> + <menuContribution + allPopups="true" + locationURI="popup:org.eclipse.papyrus.infra.nattable.widget.header.rows.menu?after=general.separator"> + <command + commandId="org.eclipse.papyrus.infra.nattable.displaylist.separatedrows.rowheader" + label="Display List On Separated Rows" + style="toggle"> + <visibleWhen + checkEnabled="true"> + <and> + <with + variable="selection"> + <test + forcePluginActivation="true" + property="org.eclipse.papyrus.infra.nattable.tester.isNattableWidget" + value="true"> + </test> + <test + forcePluginActivation="true" + property="org.eclipse.papyrus.uml.nattable.tester.isOneMultipleValuesAxisSelected" + value="true"> + </test> + </with> + </and> + </visibleWhen> + </command> + </menuContribution> + </extension> + <extension + point="org.eclipse.core.expressions.propertyTesters"> + <propertyTester + class="org.eclipse.papyrus.uml.nattable.tester.UMLNattableWidgetPropertyTester" + id="org.eclipse.papyrus.uml.nattable.tester" + namespace="org.eclipse.papyrus.uml.nattable.tester" + properties="isOneMultipleValuesAxisSelected" + type="org.eclipse.jface.viewers.IStructuredSelection"> + </propertyTester> + </extension> </plugin> diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiBooleanCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiBooleanCellEditorConfiguration.java index c1e66486707..9c79eb45955 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiBooleanCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiBooleanCellEditorConfiguration.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: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; @@ -16,10 +16,8 @@ package org.eclipse.papyrus.uml.nattable.config; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; import org.eclipse.papyrus.infra.emf.utils.EMFContants; import org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration; @@ -28,6 +26,7 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.Table; import org.eclipse.papyrus.infra.nattable.utils.AxisUtils; import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes; import org.eclipse.papyrus.infra.tools.util.TypesConstants; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.editor.MultiBooleanCellEditor; /** @@ -90,9 +89,10 @@ public class MultiBooleanCellEditorConfiguration implements ICellAxisConfigurati */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, configLabel); + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiBooleanCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiBooleanCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); } } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiEEnumCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiEEnumCellEditorConfiguration.java index 7f0b323dd0d..37591061efe 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiEEnumCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiEEnumCellEditorConfiguration.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: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; @@ -16,16 +16,15 @@ package org.eclipse.papyrus.uml.nattable.config; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EEnum; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; 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.NattableConfigAttributes; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.editor.MultiEnumCellEditor; /** @@ -85,9 +84,10 @@ public class MultiEEnumCellEditorConfiguration implements ICellAxisConfiguration */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, configLabel); + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiEnumCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiEnumCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); } } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiIntegerCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiIntegerCellEditorConfiguration.java index 752f1b31739..8578ff3a9d7 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiIntegerCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiIntegerCellEditorConfiguration.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: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; @@ -16,10 +16,8 @@ package org.eclipse.papyrus.uml.nattable.config; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; import org.eclipse.papyrus.infra.emf.utils.EMFContants; import org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration; @@ -28,6 +26,7 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.Table; import org.eclipse.papyrus.infra.nattable.utils.AxisUtils; import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes; import org.eclipse.papyrus.infra.tools.util.TypesConstants; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.editor.MultiIntegerCellEditor; /** @@ -90,9 +89,10 @@ public class MultiIntegerCellEditorConfiguration implements ICellAxisConfigurati */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, configLabel); + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiIntegerCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiIntegerCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); } } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiRealCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiRealCellEditorConfiguration.java index 5758c4587fd..6f69f9eca60 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiRealCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiRealCellEditorConfiguration.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,23 +8,22 @@ * * Contributors: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; 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.NattableConfigAttributes; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.editor.MultiRealCellEditor; import org.eclipse.uml2.types.TypesPackage; @@ -85,9 +84,10 @@ public class MultiRealCellEditorConfiguration implements ICellAxisConfiguration */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, configLabel); + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiRealCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiRealCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); } } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiStringCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiStringCellEditorConfiguration.java index d175d5318b1..ce4c6c18d0d 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiStringCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiStringCellEditorConfiguration.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: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; @@ -16,18 +16,19 @@ package org.eclipse.papyrus.uml.nattable.config; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; import org.eclipse.papyrus.infra.emf.utils.EMFContants; 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; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.editor.MultiStringCellEditor; /** @@ -90,9 +91,20 @@ public class MultiStringCellEditorConfiguration implements ICellAxisConfiguratio */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, 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); + + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel, wrapTextFlag, autoResizeCellHeightFlag); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiStringCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiStringCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); } } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiUMLReferenceCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiUMLReferenceCellEditorConfiguration.java index 69060fe1919..b2e4a365eab 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiUMLReferenceCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiUMLReferenceCellEditorConfiguration.java @@ -8,7 +8,7 @@ * * Contributors: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 517374 + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 517374, 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; @@ -18,7 +18,6 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration; @@ -26,6 +25,7 @@ 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.NattableConfigAttributes; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.converter.MultiUMLReferenceDisplayConverter; import org.eclipse.papyrus.uml.nattable.editor.MultiReferenceCellEditor; import org.eclipse.uml2.uml.UMLPackage; @@ -86,10 +86,11 @@ public class MultiUMLReferenceCellEditorConfiguration implements ICellAxisConfig */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, configLabel); + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiReferenceCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiReferenceCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new MultiUMLReferenceDisplayConverter(), DisplayMode.EDIT, configLabel); } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiUnlimitedNaturalCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiUnlimitedNaturalCellEditorConfiguration.java index 2206cb0cf48..ed2dc6d3184 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiUnlimitedNaturalCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/MultiUnlimitedNaturalCellEditorConfiguration.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,23 +8,22 @@ * * Contributors: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; 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.NattableConfigAttributes; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.editor.MultiUnlimitedNaturalCellEditor; import org.eclipse.uml2.types.TypesPackage; @@ -85,9 +84,10 @@ public class MultiUnlimitedNaturalCellEditorConfiguration implements ICellAxisCo */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, configLabel); + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiUnlimitedNaturalCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiUnlimitedNaturalCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); } } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeMultiDataTypeCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeMultiDataTypeCellEditorConfiguration.java index e463cf7b705..2f7fd2bb7b8 100755 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeMultiDataTypeCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeMultiDataTypeCellEditorConfiguration.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2016 CEA LIST. + * Copyright (c) 2016, 2017 CEA LIST. * * * All rights reserved. This program and the accompanying materials @@ -10,21 +10,20 @@ * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 502533 - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; -import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; 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.NattableConfigAttributes; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.editor.DatatypeDialogCellEditor; import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils; import org.eclipse.uml2.uml.DataType; @@ -34,8 +33,8 @@ import org.eclipse.uml2.uml.Property; import org.eclipse.uml2.uml.Type; /** - * The cell editor for UML Single Datatype declared in the profile. - * + * The cell editor for UML Multi Datatype declared in the profile. + * @since 3.0 */ public class UMLStereotypeMultiDataTypeCellEditorConfiguration implements ICellAxisConfiguration { @@ -60,6 +59,7 @@ public class UMLStereotypeMultiDataTypeCellEditorConfiguration implements ICellA * * @see org.eclipse.papyrus.infra.nattable.configuration.IPapyrusNatTableConfiguration#getConfigurationDescription() */ + @Override public String getConfigurationDescription() { return "This configuration provides a dialog to edit a multi UML datatype"; //$NON-NLS-1$ } @@ -92,9 +92,10 @@ public class UMLStereotypeMultiDataTypeCellEditorConfiguration implements ICellA */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, configLabel); + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new DatatypeDialogCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new DatatypeDialogCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); } } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeMultiUMLEnumerationCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeMultiUMLEnumerationCellEditorConfiguration.java index 7c5e40a92cb..c9c1d3b6a2f 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeMultiUMLEnumerationCellEditorConfiguration.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeMultiUMLEnumerationCellEditorConfiguration.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,21 +8,20 @@ * * Contributors: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.config; -import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; -import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; 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.NattableConfigAttributes; +import org.eclipse.papyrus.uml.nattable.config.utils.CellEditorConfigurationUtils; import org.eclipse.papyrus.uml.nattable.editor.MultiEnumCellEditor; import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils; import org.eclipse.uml2.uml.Enumeration; @@ -86,9 +85,10 @@ public class UMLStereotypeMultiUMLEnumerationCellEditorConfiguration implements */ @Override public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.NORMAL, configLabel); + final Object axisElement = AxisUtils.getRepresentedElement(axis); + CellEditorConfigurationUtils.configureCellPainter(configRegistry, axis, configLabel); final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiEnumCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new MultiEnumCellEditor(axisElement, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); } } diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/utils/CellEditorConfigurationUtils.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/utils/CellEditorConfigurationUtils.java new file mode 100644 index 00000000000..c13d3d066f6 --- /dev/null +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/utils/CellEditorConfigurationUtils.java @@ -0,0 +1,94 @@ +/***************************************************************************** + * 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 515737 + *****************************************************************************/ +package org.eclipse.papyrus.uml.nattable.config.utils; + +import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; +import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; +import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator; +import org.eclipse.nebula.widgets.nattable.style.DisplayMode; +import org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; +import org.eclipse.papyrus.infra.nattable.painter.CustomImagePainter; +import org.eclipse.papyrus.infra.nattable.painter.CustomizedCellPainter; +import org.eclipse.papyrus.infra.nattable.painter.PapyrusTableCellPainter; +import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants; +import org.eclipse.papyrus.infra.nattable.utils.StyleUtils; + +/** + * Common methods for cell editor configuration. + * + * @since 4.0 + */ +public class CellEditorConfigurationUtils { + + /** + * Private constructor to prevent instantiation. + */ + private CellEditorConfigurationUtils() { + } + + /** + * Configure the cell painter based on the named style displayListOnSeparatedRows of the input axis. + * If the named style is <code>true</code>, use table cell painter to display list elements in separated rows. + * Otherwise, use the default cell painter to display list elements in one single row. + * + * @param configRegistry + * The config registry + * @param axis + * The input axis + * @param configLabel + * The config label + */ + public static void configureCellPainter(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { + + // wrapText and autoResizeCellHeight are disabled by default + configureCellPainter(configRegistry, axis, configLabel, false, false); + } + + /** + * Configure the cell painter based on the named style displayListOnSeparatedRows of the input axis. + * If the named style is <code>true</code>, use table cell painter to display list elements in separated rows. + * Otherwise, use the default cell painter to display list elements in one single row. + * + * @param configRegistry + * The config registry + * @param axis + * The input axis + * @param configLabel + * The config label + * @param wrapText + * Split text over multiple lines + * @param autoResizeCellHeight + * Tell the text painter to calculate the cell border by + * containing text height + */ + public static void configureCellPainter(final IConfigRegistry configRegistry, final Object axis, final String configLabel, final boolean wrapText, final boolean autoResizeCellHeight) { + + if (null != configRegistry && axis instanceof IAxis) { + final boolean displayListOnRowsFlag = StyleUtils.getBooleanNamedStyleValue((IAxis) axis, NamedStyleConstants.DISPLAY_LIST_ON_SEPARATED_ROWS, NamedStyleConstants.ENABLE_DISPLAY_LIST_ON_SEPARATED_ROWS); + + if (displayListOnRowsFlag) { + PapyrusTableCellPainter tableCellPainter = new PapyrusTableCellPainter(new CellPainterDecorator(new CustomizedCellPainter(wrapText, autoResizeCellHeight), CellEdgeEnum.LEFT, new CustomImagePainter())); + if (autoResizeCellHeight) { + // Call the method setFixedSubCellHeight to trigger the method CustomizedCellPainter.getPreferredHeight + // Workaround for the bug 516783 in NatTable, thanks to Dirk Fauth for the temporary solution + tableCellPainter.setFixedSubCellHeight(-1); + } + configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, tableCellPainter, DisplayMode.NORMAL, configLabel); + } else { + configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CustomizedCellPainter(wrapText, autoResizeCellHeight), DisplayMode.NORMAL, configLabel); + } + } else { + configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CustomizedCellPainter(wrapText, autoResizeCellHeight), DisplayMode.NORMAL, configLabel); + } + } +} diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/tester/UMLNattableWidgetPropertyTester.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/tester/UMLNattableWidgetPropertyTester.java new file mode 100644 index 00000000000..df26ef42c8e --- /dev/null +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/tester/UMLNattableWidgetPropertyTester.java @@ -0,0 +1,72 @@ +/***************************************************************************** + * Copyright (c) 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: + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515737 + *****************************************************************************/ +package org.eclipse.papyrus.uml.nattable.tester; + +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.nattableaxis.FeatureIdAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider; +import org.eclipse.papyrus.infra.nattable.utils.AxisUtils; +import org.eclipse.papyrus.infra.nattable.utils.NattableWidgetPropertyTester; +import org.eclipse.papyrus.uml.nattable.utils.UMLNattableStereotypeUtils; +import org.eclipse.uml2.uml.Property; + +/** + * Property testers for UML NatTable widgets. + * Check if an axis corresponding to a stereotype property is multiple values or not. + * + * @since 4.0 + */ +public class UMLNattableWidgetPropertyTester extends NattableWidgetPropertyTester { + + @Override + public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { + final INattableModelManager manager = getNattableModelManager(); + + if (null != manager && expectedValue instanceof Boolean && IS_ONE_MULTIPLE_VALUES_AXIS_SELECTED.equals(property)) { + + // Get the selected axis index + final int axisIndex = AxisUtils.getUniqueSelectedAxisIndex(manager); + + // Always get the column axis provider for invert or non-invert table + final AbstractAxisProvider axisProvider = manager.getTable().getCurrentColumnAxisProvider(); + + // If the index is in range + if (null != axisProvider && null != axisProvider.getAxis() && 0 <= axisIndex && axisIndex < axisProvider.getAxis().size()) { + final IAxis selectedAxis = axisProvider.getAxis().get(axisIndex); + // Get the selected axis element + final Object axisElement = selectedAxis.getElement(); + + // Check if the selected axis defined by properties of a stereotype + // we need to find the corresponding property defined in stereotype + if (selectedAxis instanceof FeatureIdAxis) { + + final FeatureIdAxis selectedFeatureAxis = (FeatureIdAxis) selectedAxis; + + final String propertyStereotypeID = axisElement.toString(); + + // Get the corresponding property defined in the stereotype and check its upper bound + if (propertyStereotypeID.startsWith(UMLNattableStereotypeUtils.PROPERTY_OF_STEREOTYPE_PREFIX) && null != selectedFeatureAxis.eContainer() && selectedFeatureAxis.eContainer().eContainer() instanceof Table) { + final Table table = (Table) selectedFeatureAxis.eContainer().eContainer(); + final Property propertyStereotype = UMLNattableStereotypeUtils.getRealStereotypeProperty(table.getOwner(), propertyStereotypeID); + if (null != propertyStereotype) { + return expectedValue.equals(isMultipleValues(propertyStereotype.getUpper())); + } + } + } + } + } + + return false; + } +} diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLNattableStereotypeUtils.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLNattableStereotypeUtils.java new file mode 100644 index 00000000000..ef3144f3034 --- /dev/null +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLNattableStereotypeUtils.java @@ -0,0 +1,215 @@ +/***************************************************************************** + * 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 515737 + *****************************************************************************/ +package org.eclipse.papyrus.uml.nattable.utils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.papyrus.infra.nattable.utils.Constants; +import org.eclipse.papyrus.uml.nattable.paste.StereotypeApplicationStructure; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Namespace; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Profile; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * This class provides useful methods to manage stereotypes in the table. + * Methods in this class are duplicated from those in oep.uml.tools.utils.StereotypeUtil. + * + * @since 4.0 + */ +public class UMLNattableStereotypeUtils { + + public static final String PROPERTY_OF_STEREOTYPE_PREFIX = "property_of_stereotype:/"; //$NON-NLS-1$ + + /** + * Private constructor to prevent instantiation. + */ + private UMLNattableStereotypeUtils() { + } + + /** + * @param eobject + * an element of the model (currently, if it is not an UML::Element, we can't find the property) + * @param id + * the id used to identify the property of the stereotype + * + * @return + * the UML::Property or <code>null</code> if we can't resolve it (the required profile is not applied) + */ + public static Property getRealStereotypeProperty(final EObject eobject, final String id) { + return getRealStereotypeProperty(eobject, id, null); + } + + /** + * @param packages + * a list of package + * @param propertyQN + * the qualified name of the wanted property + * @return + * the property or <code>null</code> if not found + */ + protected static Property getProperty(Collection<Package> packages, String propertyQN) { + final String propertyName = getNameFromQualifiedName(propertyQN); + final String stereotypeQN = getParentQualifiedName(propertyQN); + final String stereotypeName = getNameFromQualifiedName(stereotypeQN); + final String profileQN = getParentQualifiedName(stereotypeQN); + for (Package package1 : packages) { + for (Profile prof : package1.getAppliedProfiles()) { + if (prof.getQualifiedName().equals(profileQN)) { + NamedElement ste = prof.getMember(stereotypeName); + if (ste instanceof Stereotype) { + NamedElement prop = ((Stereotype) ste).getMember(propertyName); + if (prop instanceof Property && prop.getQualifiedName().equals(propertyQN)) { + return (Property) prop; + } + } + } + Property p = getProperty(package1.getNestedPackages(), propertyQN); + if (null != p) { + return p; + } + } + } + return null; + } + + /** + * @param eobject + * an element of the model (currently, if it is not an UML::Element, we can't find the property) + * @param id + * the id used to identify the property of the stereotype + * @param sharedMap + * a map owning interesting information, like {@link StereotypeApplicationStructure} which can be used to find stereotype, stereotype + * application and so on + * @return + * the UML::Property or <code>null</code> if we can't resolve it (the required profile is not applied) + */ + public static Property getRealStereotypeProperty(final EObject eobject, final String id, final Map<?, ?> sharedMap) { + Property result = null; + + Assert.isTrue(id.startsWith(PROPERTY_OF_STEREOTYPE_PREFIX)); + if (eobject instanceof Element) { + final Element element = (Element) eobject; + final String propertyQN = id.replace(UMLNattableStereotypeUtils.PROPERTY_OF_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$ + + Package nearestPackage = null; + if (null != sharedMap) { + final Element context = (Element) sharedMap.get(Constants.PASTED_ELEMENT_CONTAINER_KEY); + nearestPackage = context.getNearestPackage(); + } else { + nearestPackage = element.getNearestPackage(); + } + + if (null != nearestPackage) { + // Search the properties by their qualified name instead of search by its stereotypes first + // This allows to manage the inherit properties and the stereotypes in packages + final Iterator<Profile> appliedProfilesIterator = nearestPackage.getAllAppliedProfiles().iterator(); + while (appliedProfilesIterator.hasNext() && null == result) { + final Profile appliedProfile = appliedProfilesIterator.next(); + + // Loop on all stereotypes (check in sub packages) + final Iterator<Stereotype> stereotypesIterator = getAllStereotypes(appliedProfile).iterator(); + while (stereotypesIterator.hasNext() && null == result) { + final Stereotype ownedStereotype = stereotypesIterator.next(); + final Iterator<Property> propertiesIterator = ownedStereotype.getAllAttributes().iterator(); + while (propertiesIterator.hasNext() && null == result) { + final Property property = propertiesIterator.next(); + if (property.getQualifiedName().equals(propertyQN)) { + result = property; + } + } + } + } + + // If the property is still not found , the profile could be applied on a sub-package of the nearest package + // The table can show element which are not children of its context, so the profile could not be available in its context + if (null == result) { + result = getProperty(element.getNearestPackage().getNestedPackages(), propertyQN); + } + } + } + return result; + } + + /** + * This allows to get all stereotypes of a profile (check in sub packages). + * + * @param profile + * the profile + * @return The list of stereotypes corresponding to the profile + */ + public static List<Stereotype> getAllStereotypes(final Profile profile) { + final List<Stereotype> stereotypes = new ArrayList<>(profile.getOwnedStereotypes()); + stereotypes.addAll(getStereotypeInMembers(profile.getOwnedMembers())); + return stereotypes; + } + + /** + * @param members + * The owned members of an element + * @return The list of all stereotypes in sub packages + */ + protected static List<Stereotype> getStereotypeInMembers(final List<NamedElement> members) { + final List<Stereotype> stereotypes = new ArrayList<>(); + + // Loop on members + final Iterator<NamedElement> membersIterator = members.iterator(); + while (membersIterator.hasNext()) { + NamedElement member = membersIterator.next(); + + // Get stereotypes in packages + if (member instanceof Package) { + stereotypes.addAll(((Package) member).getOwnedStereotypes()); + } + + // Loop recursively in members + if (member instanceof Namespace) { + stereotypes.addAll(getStereotypeInMembers(((Namespace) member).getOwnedMembers())); + } + } + + return stereotypes; + } + + /** + * Return the name of an element, given its qualified name. + * + * @param qualifiedName + * the qualified name of the element + * @return the name of the element, must not be <code>null</code> + */ + public static String getNameFromQualifiedName(String qualifiedName) { + String name = qualifiedName.substring(qualifiedName.lastIndexOf(NamedElement.SEPARATOR) + NamedElement.SEPARATOR.length()); + return (null != name) ? name : ""; //$NON-NLS-1$ + } + + /** + * @param childQualifiedName + * the qualifiedName of an element + * @return + * the qualified name of its parent + */ + public static String getParentQualifiedName(final String childQualifiedName) { + final String childName = getNameFromQualifiedName(childQualifiedName); + final String parentQualifiedName = childQualifiedName.substring(0, childQualifiedName.length() - (NamedElement.SEPARATOR.length() + childName.length())); + return (null != parentQualifiedName) ? parentQualifiedName : ""; //$NON-NLS-1$ + } +} |