Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2020-03-16 14:59:27 +0000
committerVincent Lorenzo2020-03-23 13:41:58 +0000
commit98e535560236ce864b2187d42fef8d04ba201ea2 (patch)
tree1b233c6c0f59efa237b652bced210ef112d0d03a
parent0205f0239a9f243c1a10ba812276399313251608 (diff)
downloadorg.eclipse.papyrus-98e535560236ce864b2187d42fef8d04ba201ea2.tar.gz
org.eclipse.papyrus-98e535560236ce864b2187d42fef8d04ba201ea2.tar.xz
org.eclipse.papyrus-98e535560236ce864b2187d42fef8d04ba201ea2.zip
Bug 561096: [Table] The framework must support columns representing stereotype properties
- manage Stereotype Operation columns Change-Id: I02a5bfbb9649c306671ad9968fc72f121c55b598 Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/pom.xml2
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/LabelOperationConfigurationManagementUtils.java177
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF2
-rwxr-xr-xplugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml28
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/pom.xml2
-rwxr-xr-xplugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/UMLStereotypeOperationAxisManager.java279
-rwxr-xr-xplugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypeOperationCellManager.java242
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/UMLOperationValueCellManager.java23
-rwxr-xr-xplugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/StereotypeOperationCellLabelProvider.java58
-rwxr-xr-xplugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/StereotypeOperationHeaderLabelProvider.java168
-rwxr-xr-xplugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedOperationContentProvider.java296
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java111
-rwxr-xr-x[-rw-r--r--]plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/Constants.java0
-rwxr-xr-xplugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/StereotypeOperationUtils.java148
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF2
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml2
-rwxr-xr-xplugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/IOperationContentProvider.java53
-rwxr-xr-xplugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypeOperationContentProvider.java260
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypePropertyContentProvider.java13
-rwxr-xr-xplugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/StereotypeUtil.java95
21 files changed, 1837 insertions, 126 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
index 66ecf5b283c..e1ff560a35b 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
@@ -77,7 +77,7 @@ Require-Bundle: org.eclipse.gmf.runtime.emf.type.core;bundle-version="[1.9.0,2.0
javax.inject;bundle-version="[1.0.0,2.0.0)"
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 6.6.0.qualifier
+Bundle-Version: 6.7.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Activator: org.eclipse.papyrus.infra.nattable.Activator
Bundle-ManifestVersion: 2
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/pom.xml b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/pom.xml
index 50aae1d3d21..ab4b91a1b92 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/pom.xml
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/pom.xml
@@ -9,6 +9,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.nattable</artifactId>
- <version>6.6.0-SNAPSHOT</version>
+ <version>6.7.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/LabelOperationConfigurationManagementUtils.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/LabelOperationConfigurationManagementUtils.java
new file mode 100755
index 00000000000..ec173ea677a
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/LabelOperationConfigurationManagementUtils.java
@@ -0,0 +1,177 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.utils;
+
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AbstractHeaderAxisConfiguration;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.ILabelProviderConfiguration;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.OperationLabelProviderConfiguration;
+
+/**
+ * Utils class for Label Operation Configuration management
+ *
+ * TODO : merge me with {@link LabelConfigurationManagementUtils} in Papyrus 5.0 (bug 561258)
+ * see bug 561258 for remove of this class
+ *
+ * @author Vincent Lorenzo
+ * @since 6.7
+ *
+ */
+public class LabelOperationConfigurationManagementUtils {
+
+ private LabelOperationConfigurationManagementUtils() {
+ // to prevent instanciation
+ }
+
+ /**
+ *
+ * @param table
+ * a table
+ * @return
+ * the OperationLabelProviderConfiguration for rows defined in the table, managing the inversion of the axis or <code>null</code>
+ */
+ public static final OperationLabelProviderConfiguration getRowOperationLabelConfigurationInTable(final Table table) {
+ AbstractHeaderAxisConfiguration config = table.getLocalRowHeaderAxisConfiguration();
+ if (table.isInvertAxis()) {
+ config = table.getLocalColumnHeaderAxisConfiguration();
+ }
+ if (config != null) {
+ for (final ILabelProviderConfiguration current : config.getOwnedLabelConfigurations()) {
+ if (current instanceof OperationLabelProviderConfiguration) {
+ return (OperationLabelProviderConfiguration) current;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param table
+ * a table
+ * @return
+ * the OperationLabelProviderConfiguration for rows defined in the configuration, managing the inversion of the axis or <code>null</code>
+ */
+ public static final OperationLabelProviderConfiguration getRowOperationLabelConfigurationInTableConfiguration(final Table table) {
+ AbstractHeaderAxisConfiguration config = table.getTableConfiguration().getRowHeaderAxisConfiguration();
+ if (table.isInvertAxis()) {
+ config = table.getTableConfiguration().getColumnHeaderAxisConfiguration();
+ }
+ // can be null according to the metamodel
+ for (final ILabelProviderConfiguration current : config.getOwnedLabelConfigurations()) {
+ if (current instanceof OperationLabelProviderConfiguration) {
+ return (OperationLabelProviderConfiguration) current;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param table
+ * a table
+ * @return
+ * <code>true</code> if a OperationLabelProviderConfiguration is defined for rows for the table, managing the inversion of the axis
+ */
+ public static final boolean hasRowOperationLabelConfiguration(final Table table) {
+ return getRowOperationLabelConfigurationInTable(table) != null || getRowOperationLabelConfigurationInTableConfiguration(table) != null;
+ }
+
+ /**
+ *
+ * @param table
+ * a table
+ * @return
+ * the OperationLabelProviderConfiguration for columns defined in the table, managing the inversion of the axis or <code>null</code>
+ */
+ public static final OperationLabelProviderConfiguration getColumnOperationLabelConfigurationInTable(final Table table) {
+ AbstractHeaderAxisConfiguration config = table.getLocalRowHeaderAxisConfiguration();
+ if (!table.isInvertAxis()) {
+ config = table.getLocalColumnHeaderAxisConfiguration();
+ }
+ if (config != null) {
+ for (final ILabelProviderConfiguration current : config.getOwnedLabelConfigurations()) {
+ if (current instanceof OperationLabelProviderConfiguration) {
+ return (OperationLabelProviderConfiguration) current;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param table
+ * a table
+ * @return
+ * the OperationLabelProviderConfiguration for columns defined in the configuration, managing the inversion of the axis or <code>null</code>
+ */
+ public static final OperationLabelProviderConfiguration getColumnOperationLabelConfigurationInTableConfiguration(final Table table) {
+ AbstractHeaderAxisConfiguration config = table.getTableConfiguration().getRowHeaderAxisConfiguration();
+ if (!table.isInvertAxis()) {
+ config = table.getTableConfiguration().getColumnHeaderAxisConfiguration();
+ }
+ // can be null according to the metamodel
+ for (final ILabelProviderConfiguration current : config.getOwnedLabelConfigurations()) {
+ if (current instanceof OperationLabelProviderConfiguration) {
+ return (OperationLabelProviderConfiguration) current;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param table
+ * a table
+ * @return
+ * <code>true</code> if a OperationLabelProviderConfiguration is defined for columns for the table, managing the inversion of the axis
+ */
+ public static final boolean hasColumnOperationLabelConfiguration(final Table table) {
+ return getColumnOperationLabelConfigurationInTable(table) != null || getColumnOperationLabelConfigurationInTableConfiguration(table) != null;
+ }
+
+ /**
+ *
+ * @param table
+ * the table
+ * @return
+ * the object label configuration currently used in the table
+ */
+ public static final OperationLabelProviderConfiguration getUsedColumnOperationLabelConfiguration(final Table table) {
+ OperationLabelProviderConfiguration conf = getColumnOperationLabelConfigurationInTable(table);
+ if (conf == null) {
+ conf = getColumnOperationLabelConfigurationInTableConfiguration(table);
+ }
+ return conf;
+ }
+
+ /**
+ *
+ * @param table
+ * the table
+ * @return
+ * the object label configuration currently used in the table
+ */
+ public static final OperationLabelProviderConfiguration getUsedRowOperationLabelConfiguration(final Table table) {
+ OperationLabelProviderConfiguration conf = getRowOperationLabelConfigurationInTable(table);
+ if (conf == null) {
+ conf = getRowOperationLabelConfigurationInTableConfiguration(table);
+ }
+ return conf;
+ }
+
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF
index 69d6897d754..b578b4f0422 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF
@@ -20,7 +20,7 @@ Require-Bundle: org.eclipse.papyrus.uml.tools;bundle-version="[4.0.0,5.0.0)";vis
org.eclipse.papyrus.infra.properties.ui;bundle-version="[3.0.0,4.0.0)"
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 5.3.0.qualifier
+Bundle-Version: 5.4.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Localization: plugin
Bundle-Activator: org.eclipse.papyrus.uml.nattable.Activator
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 cc7d56127f3..e88aa1fa601 100755
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml
@@ -185,6 +185,23 @@
context="org.eclipse.papyrus.infra.nattable.body.labelprovider">
</labelProviderContext>
</labelProvider>
+ <labelProvider
+ priority="1105"
+ provider="org.eclipse.papyrus.uml.nattable.provider.StereotypeOperationHeaderLabelProvider">
+ <labelProviderContext
+ context="org.eclipse.papyrus.infra.nattable.header.operation.labelprovider">
+ </labelProviderContext>
+ <labelProviderContext
+ context="org.eclipse.papyrus.infra.nattable.header.labelprovider">
+ </labelProviderContext>
+ </labelProvider>
+ <labelProvider
+ priority="1107"
+ provider="org.eclipse.papyrus.uml.nattable.provider.StereotypeOperationCellLabelProvider">
+ <labelProviderContext
+ context="org.eclipse.papyrus.infra.nattable.body.labelprovider">
+ </labelProviderContext>
+ </labelProvider>
</extension>
<extension
point="org.eclipse.papyrus.infra.nattable.axismanager">
@@ -208,6 +225,10 @@
id="org.eclipse.papyrus.uml.nattable.operation.axis.manager"
manager="org.eclipse.papyrus.uml.nattable.manager.axis.UMLOperationAxisManager">
</axisManager>
+ <axisManager
+ id="org.eclipse.papyrus.uml.nattable.stereotype.operation.axis.manager"
+ manager="org.eclipse.papyrus.uml.nattable.manager.axis.UMLStereotypeOperationAxisManager">
+ </axisManager>
</extension>
<extension
point="org.eclipse.papyrus.infra.nattable.cellmanager">
@@ -222,10 +243,15 @@
order="500">
</cellManager>
<cellManager
- id="org.eclipse.papyrus.infra.emf.nattable.cell.operation.manager"
+ id="org.eclipse.papyrus.uml.nattable.cell.operation.manager"
manager="org.eclipse.papyrus.uml.nattable.manager.cell.UMLOperationValueCellManager"
order="1150">
</cellManager>
+ <cellManager
+ id="org.eclipse.papyrus.uml.nattable.uml.stereotype.operation.cell.manager"
+ manager="org.eclipse.papyrus.uml.nattable.manager.cell.StereotypeOperationCellManager"
+ order="502">
+ </cellManager>
</extension>
<extension
point="org.eclipse.papyrus.infra.nattable.tester">
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/pom.xml b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/pom.xml
index e05f6525fa0..7a93f9d19ad 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/pom.xml
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/pom.xml
@@ -9,6 +9,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.nattable</artifactId>
- <version>5.3.0-SNAPSHOT</version>
+ <version>5.4.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/UMLStereotypeOperationAxisManager.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/UMLStereotypeOperationAxisManager.java
new file mode 100755
index 00000000000..0f8ff5a299e
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/UMLStereotypeOperationAxisManager.java
@@ -0,0 +1,279 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.nattable.manager.axis;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.nattable.manager.axis.IIdAxisManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.OperationIdAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider;
+import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization;
+import org.eclipse.papyrus.uml.nattable.provider.UMLStereotypeRestrictedOperationContentProvider;
+import org.eclipse.papyrus.uml.nattable.utils.StereotypeOperationUtils;
+import org.eclipse.papyrus.uml.tools.util.StereotypeUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * Axis Manager for operations of stereotypes
+ *
+ * @since 5.4
+ */
+public class UMLStereotypeOperationAxisManager extends UMLOperationAxisManager implements IIdAxisManager {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.nattable.manager.axis.UMLFeatureAxisManager#isAllowedContents(java.lang.Object)
+ *
+ * @param object
+ * @return
+ */
+ @Override
+ public boolean isAllowedContents(Object object) {
+ boolean result = false;
+ if (object instanceof Operation) {
+ final Operation operation = (Operation) object;
+ Element owner = operation.getOwner();
+ if (owner instanceof Stereotype) {
+ while (owner.getOwner() instanceof Package && !result) {
+ owner = owner.getOwner();
+ result = owner instanceof Profile;
+ }
+ if (result) {
+ result = EMFHelper.isReadOnly(operation);
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param objectToAdd
+ * @return
+ */
+ @Override
+ public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
+ final Set<Object> operationsToAdd = getOperationToAdd(objectToAdd);
+ if (!operationsToAdd.isEmpty()) {
+ return getAddAxisCommand(domain, operationsToAdd);
+ }
+ return null;
+ }
+
+ /**
+ * Get the properties to add.
+ *
+ * @param objectToAdd
+ * The initial objects to add.
+ * @return The properties to add.
+ */
+ protected Set<Object> getOperationToAdd(final Collection<Object> objectToAdd) {
+ final Set<Stereotype> appliedStereotypes = new HashSet<>();
+ for (final Object current : objectToAdd) {
+ if (current instanceof Element) {
+ appliedStereotypes.addAll(((Element) current).getAppliedStereotypes());
+ }
+ }
+ final Set<Object> operationToAdd = new HashSet<>();
+
+ for (final Stereotype stereotype : appliedStereotypes) {
+ operationToAdd.addAll(StereotypeUtil.getAllStereotypeOperations(stereotype, true, true, true));
+
+ }
+ return operationToAdd;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param objectToAdd
+ * @return
+ */
+ @Override
+ public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
+ Collection<IAxis> toAdd = getAxisToAdd(objectToAdd);
+ if (!toAdd.isEmpty()) {
+ return new AddCommandWrapper(AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd), objectToAdd);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.nattable.manager.axis.EStructuralFeatureAxisManager#getAddAxisCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.util.Collection, int)
+ *
+ * @param domain
+ * @param objectToAdd
+ * @param index
+ * @return
+ */
+ @Override
+ public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd, final int index) {
+ Collection<IAxis> toAdd = getAxisToAdd(objectToAdd);
+ if (!toAdd.isEmpty()) {
+ return new AddCommandWrapper(AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd, index), objectToAdd);
+ }
+ return null;
+ }
+
+ /**
+ * Get the axis to add from the objects to add.
+ *
+ * @param objectToAdd
+ * The objects to add.
+ * @return The axis to add.
+ */
+ @Override
+ protected Collection<IAxis> getAxisToAdd(final Collection<Object> objectToAdd) {
+ final Collection<IAxis> toAdd = new ArrayList<>();
+ final List<String> allOperationQN = new ArrayList<>();
+ for (Object object : objectToAdd) {
+ if (isAllowedContents(object)) {
+ allOperationQN.add(StereotypeOperationUtils.OPERATION_OF_STEREOTYPE_PREFIX + ((NamedElement) object).getQualifiedName());
+ }
+ }
+ allOperationQN.removeAll(getElements());
+ if (!allOperationQN.isEmpty()) {
+ for (String operationQN : allOperationQN) {
+ final IdAxis newAxis = NattableaxisFactory.eINSTANCE.createOperationIdAxis();
+ newAxis.setElement(operationQN);
+ newAxis.setManager(this.representedAxisManager);
+ toAdd.add(newAxis);
+ }
+ }
+ return toAdd;
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.nattable.manager.axis.UMLOperationAxisManager#createPossibleAxisContentProvider(boolean)
+ *
+ * @param isRestricted
+ * @return
+ */
+ @Override
+ public IRestrictedContentProvider createPossibleAxisContentProvider(boolean isRestricted) {
+ return new UMLStereotypeRestrictedOperationContentProvider(this, isRestricted);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisCommand(TransactionalEditingDomain, java.util.Collection)
+ *
+ * @param domain
+ * @param umlProperties
+ * the UML Property for which we want destroy axis
+ * @return
+ */
+ @Override
+ public Command getDestroyAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> umlProperties) {
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getRepresentedContentProvider());
+ final CompositeCommand compositeCommand = new CompositeCommand("Destroy IAxis Command"); //$NON-NLS-1$
+ final List<String> propIdToDestroy = new ArrayList<>();
+ for (final Object current : umlProperties) {
+ if (current instanceof Operation && ((Operation) current).eContainer() instanceof Stereotype) {
+ propIdToDestroy.add(StereotypeOperationUtils.OPERATION_OF_STEREOTYPE_PREFIX + ((NamedElement) current).getQualifiedName());
+ } else if (current instanceof String) {
+ propIdToDestroy.add((String) current);
+ } else if (current instanceof IAxis) {
+ propIdToDestroy.add(((IAxis) current).getElement().toString());
+ }
+ }
+
+ for (final IAxis current : getRepresentedContentProvider().getAxis()) {
+ if (current instanceof IdAxis) {
+ String propId = AxisUtils.getPropertyId(current);
+ if (propIdToDestroy.contains(propId)) {
+ DestroyElementRequest request = new DestroyElementRequest(domain, current, false);
+ compositeCommand.add(provider.getEditCommand(request));
+ }
+ }
+ }
+
+ if (!compositeCommand.isEmpty()) {
+ return new RemoveCommandWrapper(new GMFtoEMFCommandWrapper(compositeCommand), umlProperties);
+ }
+ return null;
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.IIdAxisManager#resolvedPath(java.lang.String)
+ *
+ * @param path
+ * @return
+ */
+ @Override
+ public Object resolvedPath(final String path) {
+ if (path.startsWith(StereotypeOperationUtils.OPERATION_OF_STEREOTYPE_PREFIX)) {
+ return StereotypeOperationUtils.getRealStereotypeOperation(getTableContext(), path);
+ }
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.emf.nattable.manager.axis.EStructuralFeatureAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
+ */
+ @Override
+ public String getElementAxisName(final IAxis axis) {
+ String returnedValue = null; // $NON-NLS-1$
+ if (axis instanceof OperationIdAxis) {
+ String elementId = ((OperationIdAxis) axis).getElement();
+ final Object resolvedElement = resolvedPath(elementId);
+ if (resolvedElement instanceof NamedElement) {
+ returnedValue = UMLLabelInternationalization.getInstance().getLabel((NamedElement) resolvedElement);
+ } else {
+ elementId = elementId.replace(StereotypeOperationUtils.OPERATION_OF_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$
+ final String[] splitedElementId = elementId.split("::"); //$NON-NLS-1$
+ returnedValue = splitedElementId[splitedElementId.length - 1];
+ }
+
+ }
+ return null != returnedValue ? returnedValue : super.getElementAxisName(axis);
+ }
+
+
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypeOperationCellManager.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypeOperationCellManager.java
new file mode 100755
index 00000000000..30a07508c9f
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypeOperationCellManager.java
@@ -0,0 +1,242 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.nattable.manager.cell;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.util.ECollections;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.emf.nattable.manager.cell.EMFOperationValueCellManager;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.CellHelper;
+import org.eclipse.papyrus.infra.ui.converter.AbstractStringValueConverter;
+import org.eclipse.papyrus.uml.nattable.Activator;
+import org.eclipse.papyrus.uml.nattable.utils.StereotypeOperationUtils;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * Cell Manager which allows to get the value of an operation provided by a stereotype for a stereotyped element.
+ *
+ * @since 5.4
+ *
+ */
+public class StereotypeOperationCellManager extends EMFOperationValueCellManager {
+
+ /**
+ * the error message when several stereotypes with the same operation are applied
+ * TODO : externalize me in Papyrus 5.0 (bug 561258)
+ */
+ public static final String SEVERAL_STEREOTYPES_WITH_THIS_OPERATION_ARE_APPLIED = "Several stereotypes with this operation are applied -> not yet managed"; //$NON-NLS-1$
+
+ /**
+ * the error message when the called operation is not implemented
+ * TODO : externalize me in Papyrus 5.0 (bug 561258)
+ */
+ private static final String OPERATION_NOT_IMPLEMENTED = "Not Implemented";
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.nattable.manager.cell.UMLFeatureCellManager#handles(java.lang.Object, java.lang.Object, INattableModelManager)
+ *
+ * @param columnElement
+ * @param rowElement
+ * @return
+ */
+ @Override
+ public boolean handles(final Object columnElement, final Object rowElement, INattableModelManager tableManager) {
+ return organizeAndResolvedObjects(columnElement, rowElement, null) != null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.nattable.manager.cell.EMFFeatureValueCellManager#doGetValue(java.lang.Object, java.lang.Object, org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager)
+ *
+ * @param columnElement
+ * @param rowElement
+ * @param tableManager
+ * @return
+ */
+ @Override
+ protected Object doGetValue(final Object columnElement, final Object rowElement, final INattableModelManager tableManager) {
+ final List<Object> umlObjects = organizeAndResolvedObjects(columnElement, rowElement, null);
+ if (umlObjects.size() == 2) {
+ final Element el = (Element) umlObjects.get(0);
+ final String id = (String) umlObjects.get(1);
+ final Operation operation = (Operation) StereotypeOperationUtils.getRealStereotypeOperation(el, id);
+ final List<Stereotype> stereotypesWithThisOperation = StereotypeOperationUtils.getAppliedStereotypesWithThisOperation(el, id);
+ if (stereotypesWithThisOperation.size() == 1) {
+ final EObject steAppl = el.getStereotypeApplication(stereotypesWithThisOperation.get(0));
+ final Collection<EOperation> operations = steAppl.eClass().getEAllOperations();
+ EOperation eOp = null;
+ while (eOp == null) {
+ for (final EOperation current : operations) {
+ if (current.getName().equalsIgnoreCase(operation.getName())) {
+ eOp = current;
+ }
+
+ }
+ }
+
+ try {
+ Object result = steAppl.eInvoke(eOp, ECollections.emptyEList());
+ return result;
+ } catch (UnsupportedOperationException e) {
+ return OPERATION_NOT_IMPLEMENTED;
+ } catch (InvocationTargetException e) {
+ Activator.log.error(e);
+ }
+ } else if (stereotypesWithThisOperation.size() > 1) {
+ return SEVERAL_STEREOTYPES_WITH_THIS_OPERATION_ARE_APPLIED;
+ }
+ }
+ return CellHelper.getUnsupportedCellContentsText();
+ }
+
+ /**
+ *
+ * @param columnElement
+ * @param rowElement
+ * @return
+ * a list with 2 elements : the first one is the Element and the second one the string representing the property of stereotypes
+ */
+ @Override
+ protected List<Object> organizeAndResolvedObjects(final Object columnElement, final Object rowElement, final Map<?, ?> sharedMap) {
+ List<Object> objects = null;
+ final Object column = AxisUtils.getRepresentedElement(columnElement);
+ final Object row = AxisUtils.getRepresentedElement(rowElement);
+ if (column instanceof String && ((String) column).startsWith(StereotypeOperationUtils.OPERATION_OF_STEREOTYPE_PREFIX) && row instanceof Element) {
+ objects = new ArrayList<>();
+ objects.add(row);
+ objects.add(column);
+ }
+ if (row instanceof String && ((String) row).startsWith(StereotypeOperationUtils.OPERATION_OF_STEREOTYPE_PREFIX) && column instanceof Element) {
+ objects = new ArrayList<>();
+ objects.add(column);
+ objects.add(row);
+ }
+ return objects;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.nattable.manager.cell.UMLFeatureCellManager#isCellEditable(java.lang.Object, java.lang.Object, INattableModelManager)
+ *
+ * @param columnElement
+ * @param rowElement
+ * @return
+ */
+ @Override
+ public boolean isCellEditable(final Object columnElement, final Object rowElement, INattableModelManager tableManager) {
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.cell.AbstractCellManager#isCellEditable(java.lang.Object, java.lang.Object, java.util.Map, INattableModelManager)
+ *
+ * @param columnElement
+ * @param rowElement
+ * @param sharedMap
+ * @return
+ */
+ @Override
+ public boolean isCellEditable(final Object columnElement, final Object rowElement, final Map<?, ?> sharedMap, INattableModelManager tableManager) {
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.nattable.manager.cell.EMFFeatureValueCellManager#getSetValueCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.Object, java.lang.Object, java.lang.Object,
+ * org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager)
+ *
+ * @param domain
+ * @param columnElement
+ * @param rowElement
+ * @param newValue
+ * @param tableManager
+ * @return
+ */
+ @Override
+ public Command getSetValueCommand(final TransactionalEditingDomain domain, final Object columnElement, final Object rowElement, final Object newValue, final INattableModelManager tableManager) {
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.nattable.manager.cell.EMFFeatureValueCellManager#getSetStringValueCommand(org.eclipse.emf.edit.domain.EditingDomain, EObject, java.lang.Object, java.lang.Object, java.lang.String, java.util.Map)
+ *
+ * @param domain
+ * @param columnElement
+ * @param rowElement
+ * @param newValue
+ * @param stringResolvers
+ * @return
+ */
+ @Override
+ public Command getSetStringValueCommand(final TransactionalEditingDomain domain, final Object columnElement, final Object rowElement, final String newValue, final AbstractStringValueConverter valueSolver, final INattableModelManager tableManager) {
+ return null;
+ }
+
+ /**
+ * This method is used when we are pasting elements in detached mode
+ *
+ * @param columnElement
+ * the column element
+ * @param rowElement
+ * the row element
+ * @param valueAsString
+ * the value as string
+ * @param valueConverter
+ * the value converter to use
+ * @param sharedMap
+ * a map with shared elements. The method may read/add elements to the shared map. These contributions will be managed by a paste post
+ * action or by the paste manager itself
+ * @param tableManager
+ * the table manager
+ */
+ @Override
+ public void setStringValue(Object columnElement, Object rowElement, String valueAsString, AbstractStringValueConverter valueSolver, Map<?, ?> sharedMap, INattableModelManager tableManager) {
+
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.emf.nattable.manager.cell.EMFFeatureValueCellManager#getUnsetCellValueCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.Object, java.lang.Object,
+ * org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager)
+ *
+ * @param domain
+ * @param columnElement
+ * @param rowElement
+ * @param tableManager
+ * @return
+ */
+ @Override
+ public Command getUnsetCellValueCommand(TransactionalEditingDomain domain, Object columnElement, Object rowElement, INattableModelManager tableManager) {
+ return null;
+ }
+
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/UMLOperationValueCellManager.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/UMLOperationValueCellManager.java
index 0c7be7d0585..22e435adae7 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/UMLOperationValueCellManager.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/UMLOperationValueCellManager.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* Copyright (c) 2016 CEA LIST and others.
- *
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,7 @@
*
* Contributors:
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.nattable.manager.cell;
@@ -28,33 +28,34 @@ import org.eclipse.uml2.uml.UMLPackage;
/**
* Cell Manager which allows to get the value of an UML {@link EOperation} for an {@link EObject}.
+ *
* @since 3.0
*/
public class UMLOperationValueCellManager extends EMFOperationValueCellManager {
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.papyrus.infra.emf.nattable.manager.cell.EMFOperationValueCellManager#doGetValue(java.lang.Object, java.lang.Object, org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager)
*/
@Override
protected Object doGetValue(final Object columnElement, final Object rowElement, final INattableModelManager tableManager) {
Object result = null;
-
+
final List<Object> objects = organizeAndResolvedObjects(columnElement, rowElement, null);
final EObject eobject = (EObject) objects.get(0);
final EOperation operation = (EOperation) objects.get(1);
-
+
// If the operation called if the 'getLabel' from UML, call the papyrus internationalization 'getLabel'
- if(eobject instanceof NamedElement && operation.equals(UMLPackage.eINSTANCE.getNamedElement__GetLabel())){
- result = UMLLabelInternationalization.getInstance().getLabel((NamedElement)eobject);
+ if (eobject instanceof NamedElement && operation.equals(UMLPackage.eINSTANCE.getNamedElement__GetLabel())) {
+ result = UMLLabelInternationalization.getInstance().getLabel((NamedElement) eobject);
// If the operation called if the 'getKeyword' from UML, call the papyrus internationalization 'getKeyword'
- }else if(eobject instanceof Stereotype && operation.equals(UMLPackage.eINSTANCE.getStereotype__GetKeyword())){
- result = UMLLabelInternationalization.getInstance().getKeyword((Stereotype)eobject);
- }else{
+ } else if (eobject instanceof Stereotype && operation.equals(UMLPackage.eINSTANCE.getStereotype__GetKeyword())) {
+ result = UMLLabelInternationalization.getInstance().getKeyword((Stereotype) eobject);
+ } else {
result = super.doGetValue(columnElement, rowElement, tableManager);
}
return result;
}
-
+
}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/StereotypeOperationCellLabelProvider.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/StereotypeOperationCellLabelProvider.java
new file mode 100755
index 00000000000..5a2f5ac2b7f
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/StereotypeOperationCellLabelProvider.java
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.nattable.provider;
+
+import java.util.List;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderCellContextElementWrapper;
+import org.eclipse.uml2.uml.Operation;
+
+/**
+ * This label provider provides the label for cells representing a stereotype operation call
+ *
+ * @since 5.4
+ *
+ */
+public class StereotypeOperationCellLabelProvider extends AbstractUMLNattableCellLabelProvider {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.provider.GenericCellLabelProvider#accept(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public boolean accept(Object element) {
+ if (element instanceof ILabelProviderCellContextElementWrapper) {
+ final ILabelProviderCellContextElementWrapper cellWrapperContextElement = (ILabelProviderCellContextElementWrapper) element;
+
+ final IConfigRegistry registry = cellWrapperContextElement.getConfigRegistry();
+
+ // now it is possible that we accepts the element
+ final Object rowObject = getRowObject(cellWrapperContextElement, registry);
+ final Object columnObject = getColumnObject(cellWrapperContextElement, registry);
+
+ final List<Object> objects = getUMLObjects(rowObject, columnObject);
+ if (objects.size() == 2) {
+ final Object feature = objects.get(1);
+ return feature instanceof Operation;
+ }
+ }
+ return false;
+ }
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/StereotypeOperationHeaderLabelProvider.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/StereotypeOperationHeaderLabelProvider.java
new file mode 100755
index 00000000000..af356894f78
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/StereotypeOperationHeaderLabelProvider.java
@@ -0,0 +1,168 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.nattable.provider;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.papyrus.infra.emf.nattable.provider.EMFEOperationHeaderLabelProvider;
+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.IAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.OperationIdAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.ILabelProviderConfiguration;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.ObjectLabelProviderConfiguration;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.OperationLabelProviderConfiguration;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderCellContextElementWrapper;
+import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderContextElementWrapper;
+import org.eclipse.papyrus.infra.nattable.utils.LabelOperationConfigurationManagementUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization;
+import org.eclipse.papyrus.uml.nattable.utils.StereotypeOperationUtils;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Operation;
+
+/**
+ * This label provider provides the label for operations of stereotypes displayed in header area
+ *
+ * @since 5.4
+ *
+ */
+public class StereotypeOperationHeaderLabelProvider extends EMFEOperationHeaderLabelProvider {
+
+ /**
+ * @see org.eclipse.papyrus.infra.emf.nattable.provider.EMFEOperationHeaderLabelProvider#accept(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public boolean accept(Object element) {
+ if (element instanceof ILabelProviderContextElementWrapper) {
+ final Object object = ((ILabelProviderContextElementWrapper) element).getObject();
+ if (object instanceof OperationIdAxis) {
+ final String id = ((OperationIdAxis) object).getElement();
+ return id != null && id.startsWith(StereotypeOperationUtils.OPERATION_OF_STEREOTYPE_PREFIX);
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.nattable.provider.EMFFeatureHeaderLabelProvider#getText(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public String getText(Object element) {
+ final ILabelProviderContextElementWrapper wrapper = (ILabelProviderContextElementWrapper) element;
+ final IConfigRegistry configRegistry = wrapper.getConfigRegistry();
+ final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+ final Table table = modelManager.getTable();
+ final EObject tableContext = table.getContext();
+ final Object value = getWrappedValue(wrapper);
+ String alias = ""; //$NON-NLS-1$
+ if (value instanceof IAxis) {
+ alias = ((IAxis) value).getAlias();
+ }
+
+ ILabelProviderConfiguration conf = null;
+ if (wrapper instanceof ILabelProviderCellContextElementWrapper) {
+ conf = getLabelConfiguration((ILabelProviderCellContextElementWrapper) wrapper);
+ }
+
+ String returnedValue = null;
+ if (conf instanceof ObjectLabelProviderConfiguration && !((ObjectLabelProviderConfiguration) conf).isDisplayLabel()) {
+ returnedValue = ""; //$NON-NLS-1$
+ } else {
+ String id = AxisUtils.getPropertyId(value);
+ final Operation operation = (Operation) StereotypeOperationUtils.getRealStereotypeOperation(tableContext, id);
+ if (operation == null) {
+ id = id.replace(StereotypeOperationUtils.OPERATION_OF_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$
+ returnedValue = id + " " + "Required Profile not available"; //$NON-NLS-1$
+ return returnedValue;
+ }
+ if (alias != null && !alias.isEmpty()) {
+ returnedValue = alias;
+ } else {
+ returnedValue = UMLLabelInternationalization.getInstance().getLabel(operation);// getLabelProviderService(configRegistry).getLabelProvider(prop).getText(prop);
+ }
+ if (conf != null) {
+ if (alias != null && !alias.equals("")) { //$NON-NLS-1$
+ returnedValue = alias;
+ }
+ returnedValue = getText((OperationLabelProviderConfiguration) conf, configRegistry, returnedValue, operation.getType(), operation.getLower(), operation.getUpper());
+ }
+ }
+ return returnedValue;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.nattable.provider.AbstractNattableCellLabelProvider#getLabelConfiguration(org.eclipse.papyrus.infra.nattable.utils.ILabelProviderCellContextElementWrapper)
+ */
+ @Override
+ protected ILabelProviderConfiguration getLabelConfiguration(ILabelProviderCellContextElementWrapper wrapper) {
+ ILabelProviderConfiguration conf = null;
+ final IConfigRegistry configRegistry = wrapper.getConfigRegistry();
+ final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+ final Table table = modelManager.getTable();
+ if (wrapper instanceof ILabelProviderCellContextElementWrapper) {
+ LabelStack labels = wrapper.getConfigLabels();
+ if (labels.hasLabel(GridRegion.COLUMN_HEADER)) {
+ conf = LabelOperationConfigurationManagementUtils.getUsedColumnOperationLabelConfiguration(table);
+ } else if (labels.hasLabel(GridRegion.ROW_HEADER)) {
+ conf = LabelOperationConfigurationManagementUtils.getUsedRowOperationLabelConfiguration(table);
+ }
+ }
+ return conf;
+ };
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.nattable.provider.EMFFeatureHeaderLabelProvider#getImage(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Image getImage(Object element) {
+ final Object value = getWrappedValue((ILabelProviderContextElementWrapper) element);
+ final IConfigRegistry configRegistry = ((ILabelProviderContextElementWrapper) element).getConfigRegistry();
+ final INattableModelManager modelManager = getAxisContentProvider(configRegistry);
+ ILabelProviderConfiguration conf = getLabelConfiguration((ILabelProviderCellContextElementWrapper) element);
+ if (conf instanceof ObjectLabelProviderConfiguration && !((ObjectLabelProviderConfiguration) conf).isDisplayIcon()) {
+ return null;
+ }
+
+ final EObject tableContext = modelManager.getTable().getContext();
+ final String id = AxisUtils.getPropertyId(value);
+ final Operation operation = (Operation) StereotypeOperationUtils.getRealStereotypeOperation(tableContext, id);
+ final ILabelProvider p = getLabelProviderService(configRegistry).getLabelProvider(operation);
+ if (p != null) {
+ return p.getImage(operation);
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedOperationContentProvider.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedOperationContentProvider.java
new file mode 100755
index 00000000000..6bac5666b30
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedOperationContentProvider.java
@@ -0,0 +1,296 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.nattable.provider;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider;
+import org.eclipse.papyrus.uml.nattable.manager.axis.UMLStereotypeOperationAxisManager;
+import org.eclipse.papyrus.uml.tools.providers.UMLStereotypeOperationContentProvider;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * Restricted Content Provider for the operations of Stereotypes
+ *
+ * @since 5.4
+ */
+public class UMLStereotypeRestrictedOperationContentProvider extends UMLStereotypeOperationContentProvider implements IRestrictedContentProvider {
+
+ /**
+ * we show the value according to the table content
+ * if <code>true</code> -> the properties of stereotypes which are not applied on elements visible on the table aren't returned
+ */
+ private boolean isRestricted;
+
+ /**
+ * the stereotype axis manager
+ */
+ private UMLStereotypeOperationAxisManager umlStereotypePropertyManager;
+
+ /**
+ * the list of the allowed contents (Profile and Stereotype) when we are in restricted mode
+ */
+ private Collection<Element> restrictedElements;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param umlStereotypePropertyManager
+ * the UML stereotype axis manager
+ * @param isRestricted
+ * restrict mode
+ */
+ public UMLStereotypeRestrictedOperationContentProvider(final UMLStereotypeOperationAxisManager umlStereotypePropertyManager, final boolean isRestricted) {
+ super();
+ setIgnoredOperationsWithParameters(true);
+ setIgnoreVoidOperations(true);
+ setIgnoreInheritedElements(true);
+ this.isRestricted = isRestricted;
+ this.umlStereotypePropertyManager = umlStereotypePropertyManager;
+ init();
+ }
+
+ /**
+ * inits the fields of the table
+ */
+ protected void init() {
+ setProfiles(new ArrayList<>(getAllAvailableProfiles()));
+ this.restrictedElements = calculusOfAllowedElements();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.tools.providers.UMLStereotypePropertyContentProvider#getElements()
+ *
+ * @return
+ */
+ @Override
+ public Object[] getElements() {
+ if (this.isRestricted) {
+ final boolean isColumnManager = umlStereotypePropertyManager.isUsedAsColumnManager();
+ final List<?> elements;
+ if (isColumnManager) {
+ elements = this.umlStereotypePropertyManager.getTableManager().getRowElementsList();
+ } else {
+ elements = this.umlStereotypePropertyManager.getTableManager().getColumnElementsList();
+ }
+ if (elements.isEmpty()) {
+ return new Object[0];
+ } else {
+ List<Object> values = Arrays.asList(super.getElements());
+ values = new ArrayList<>(values);
+ values.retainAll(restrictedElements);
+ return values.toArray();
+ }
+ } else {
+ return super.getElements();
+ }
+ }
+
+ /**
+ *
+ * @return
+ * the list of the allowed profiles and stereotypes
+ */
+ protected Collection<Element> calculusOfAllowedElements() {
+ final Collection<Element> restrictedElements = new HashSet<>();
+ // we are restricted so we show only the elements available for the current contents of the table
+ final Set<Stereotype> restrictedStereotypes = new HashSet<>();
+ final boolean isColumnManager = umlStereotypePropertyManager.isUsedAsColumnManager();
+ final List<?> elementsList;
+ if (isColumnManager) {
+ elementsList = this.umlStereotypePropertyManager.getTableManager().getRowElementsList();
+ } else {
+ elementsList = this.umlStereotypePropertyManager.getTableManager().getColumnElementsList();
+ }
+ for (Object object : elementsList) {
+ Object representedElement = AxisUtils.getRepresentedElement(object);
+ if (representedElement instanceof Element) {
+ restrictedStereotypes.addAll(((Element) representedElement).getAppliedStereotypes());
+ }
+ }
+
+ final Collection<Namespace> stereotypesNamespace = new HashSet<>();
+ stereotypesNamespace.addAll(restrictedStereotypes);
+ for (Stereotype stereotype : restrictedStereotypes) {
+ stereotypesNamespace.addAll(stereotype.allNamespaces());
+ }
+
+ restrictedElements.addAll(restrictedStereotypes);
+ restrictedElements.addAll(stereotypesNamespace);
+ return restrictedElements;
+ }
+
+ /**
+ *
+ * @param profile
+ * a profile
+ * @param availableProfiles
+ * the list of available profile
+ * @return
+ * the root applied profile
+ */
+ protected Profile getTopRootProfile(final Profile profile, final Collection<Profile> availableProfiles) {
+ EObject container = profile.eContainer();
+ Profile topProfile = profile;
+ while (container != null) {
+ if (container instanceof Profile) {
+ if (availableProfiles.contains(container)) {
+ topProfile = (Profile) container;
+ }
+ }
+ container = container.eContainer();
+ }
+
+ return topProfile;
+ }
+
+ /**
+ *
+ * @return
+ * the list of all the profiles applied somewhere in the model
+ */
+ protected Set<Profile> getAllAvailableProfiles() {
+ final Set<Profile> coll = new HashSet<>();
+ final EObject context = umlStereotypePropertyManager.getTableManager().getTableContext();
+ if (context instanceof Element) {
+ final EObject container = EcoreUtil.getRootContainer(context);
+ if (container instanceof Package) {
+ // get the list of all profile applied in the model
+ final Collection<Profile> allAppliedProfiles = getAppliedProfilesInWholePackage((Package) container);
+
+
+ for (Profile profile : allAppliedProfiles) {
+ coll.add(getTopRootProfile(profile, allAppliedProfiles));
+ }
+ }
+ }
+ return coll;
+ }
+
+
+ /**
+ *
+ * @param pack
+ * a package
+ * @return
+ * a collection with all profiles applied in the package and its subpackage
+ * //TODO : should be moved in an upper plugin
+ */
+ private static final Collection<Profile> getAppliedProfilesInWholePackage(final Package pack) {
+ final Collection<Profile> appliedProfiles = new HashSet<>();
+ final List<ProfileApplication> result = getInstancesFilteredByType(pack, ProfileApplication.class, null);
+ for (ProfileApplication profileApplication : result) {
+ if (EcoreUtil.getRootContainer((profileApplication.getApplyingPackage())) == pack) {// restriction to avoid to find profile application from an imported model
+ appliedProfiles.add(profileApplication.getAppliedProfile());
+ }
+ }
+ return appliedProfiles;
+ }
+
+ /**
+ * Retrieve an list of all instances in the model that are instances of
+ * the java.lang.Class metaType or with a stereotype applied
+ *
+ * @param <T>
+ *
+ * @param metaType
+ * selected classes
+ * @param model
+ * to check
+ * @param appliedStereotype
+ * may be null, metatype is ignored if not null
+ * @return a list containing the selected instances
+ */
+ private static final <T extends EObject> List<T> getInstancesFilteredByType(final Package topPackage, final java.lang.Class<T> metaType, final Stereotype appliedStereotype) {
+ return org.eclipse.papyrus.uml.tools.utils.ElementUtil.getInstancesFilteredByType(topPackage, metaType, appliedStereotype);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider#setRestriction(boolean)
+ *
+ * @param isRestricted
+ * Setter for {@link #isRestricted}
+ */
+ @Override
+ public void setRestriction(boolean isRestricted) {
+ this.isRestricted = isRestricted;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.tools.providers.UMLStereotypePropertyContentProvider#getChildren(java.lang.Object)
+ *
+ * @param parentElement
+ * @return
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (!(parentElement instanceof Package || parentElement instanceof Stereotype)) {
+ return new Object[0];
+ }
+ final Object[] children = super.getChildren(parentElement);
+ if (!isRestricted || !(parentElement instanceof Package)) {
+ return children;
+ } else {
+ // we are restricted so we show only the elements available for the current contents of the table
+ final Collection<Object> returnedValues = new ArrayList<>();
+ returnedValues.addAll(Arrays.asList(children));
+ returnedValues.retainAll(this.restrictedElements);
+ return returnedValues.toArray();
+ }
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.tools.providers.UMLStereotypePropertyContentProvider#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ this.umlStereotypePropertyManager = null;
+ this.restrictedElements.clear();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider#isRestricted()
+ *
+ * @return
+ */
+ @Override
+ public boolean isRestricted() {
+ return isRestricted;
+ }
+
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java
index 503811bf52d..1b7f18a3305 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java
@@ -17,7 +17,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -28,11 +27,8 @@ import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider;
import org.eclipse.papyrus.uml.nattable.manager.axis.UMLStereotypePropertyAxisManager;
import org.eclipse.papyrus.uml.tools.providers.UMLStereotypePropertyContentProvider;
import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.PackageImport;
-import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.ProfileApplication;
import org.eclipse.uml2.uml.Stereotype;
@@ -121,7 +117,7 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
/**
*
* @return
- * the list of the allowed profiles and stereotypes
+ * the list of the allowed profiles and stereotypes
*/
protected Collection<Element> calculusOfAllowedElements() {
final Collection<Element> restrictedElements = new HashSet<>();
@@ -170,7 +166,7 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
/**
*
* @return
- * the list of all the profiles applied somewhere in the model
+ * the list of all the profiles applied somewhere in the model
*/
protected Set<Profile> getAllAvailableProfiles() {
final Set<Profile> coll = new HashSet<>();
@@ -214,7 +210,7 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
* @param pack
* a package
* @return
- * a collection with all profiles applied in the package and its subpackage
+ * a collection with all profiles applied in the package and its subpackage
* //TODO : should be moved in an upper plugin
*/
private static final Collection<Profile> getAppliedProfilesInWholePackage(final Package pack) {
@@ -242,107 +238,8 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
* may be null, metatype is ignored if not null
* @return a list containing the selected instances
*/
- // TODO : replace me by ElementUtils.getInstance...
- @SuppressWarnings("unchecked")
private static final <T extends EObject> List<T> getInstancesFilteredByType(final Package topPackage, final java.lang.Class<T> metaType, final Stereotype appliedStereotype) {
- // retrieve parent element
- // Package topPackage = Util.topPackage(element);
- // Assert.isNotNull(topPackage,
- // "Top package should not be null for element " + element);
- Iterator<EObject> iter = topPackage.eAllContents();
- List<T> filteredElements = new ArrayList<>();
-
- while (iter.hasNext()) {
- EObject currentElt = iter.next();
-
- // If currentElt is an ElementImport, it is replaced by the imported
- // Element.
- if (currentElt instanceof ElementImport) {
- ElementImport elementImport = (ElementImport) currentElt;
- currentElt = elementImport.getImportedElement();
- }
-
- /* package imports treatment */
- else if (currentElt instanceof PackageImport) {
- Package imported = ((PackageImport) currentElt).getImportedPackage();
- if (imported != null) {
- Iterator<EObject> piIter = imported.eAllContents();
- while (piIter.hasNext()) {
- EObject piCurrentElt = piIter.next();
- if (piCurrentElt instanceof Element) {
- if (appliedStereotype != null) {
-
- Iterator<Stereotype> appStIter = ((Element) piCurrentElt).getAppliedStereotypes().iterator();
- while (appStIter.hasNext()) {
- Stereotype currentSt = appStIter.next();
-
- if (currentSt.conformsTo(appliedStereotype)) {
- filteredElements.add((T) piCurrentElt);
- }
- }
-
- } else { // if (appliedStereotype == null)
- if (metaType.isInstance(piCurrentElt)) {
- filteredElements.add((T) piCurrentElt);
- }
-
- /** add imported meta elements */
- else if (piCurrentElt instanceof ElementImport) {
- PackageableElement importedElement = ((ElementImport) piCurrentElt).getImportedElement();
- if (importedElement != null) {
- Iterator<EObject> eIter = importedElement.eAllContents();
- while (eIter.hasNext()) {
- EObject currentEIelt = eIter.next();
- if (metaType.isInstance(currentEIelt)) {
- filteredElements.add((T) currentEIelt);
- }
- }
- }
- }
- }
- }
-
- }
- }
- }
-
- // Filtering elements
- if (currentElt instanceof Element) {
-
- if (appliedStereotype != null) {
-
- Iterator<Stereotype> appStIter = ((Element) currentElt).getAppliedStereotypes().iterator();
- while (appStIter.hasNext()) {
- Stereotype currentSt = appStIter.next();
-
- if (currentSt.conformsTo(appliedStereotype)) {
- filteredElements.add((T) currentElt);
- }
- }
-
- } else { // if (appliedStereotype == null)
- if (metaType.isInstance(currentElt)) {
- filteredElements.add((T) currentElt);
- }
-
- /** add imported meta elements */
- else if (currentElt instanceof ElementImport) {
- PackageableElement importedElement = ((ElementImport) currentElt).getImportedElement();
- if (importedElement != null) {
- Iterator<EObject> eIter = importedElement.eAllContents();
- while (eIter.hasNext()) {
- EObject currentEIelt = eIter.next();
- if (metaType.isInstance(currentEIelt)) {
- filteredElements.add((T) currentEIelt);
- }
- }
- }
- }
- }
- }
- }
-
- return filteredElements;
+ return org.eclipse.papyrus.uml.tools.utils.ElementUtil.getInstancesFilteredByType(topPackage, metaType, appliedStereotype);
}
/**
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/Constants.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/Constants.java
index a260cbe375f..a260cbe375f 100644..100755
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/Constants.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/Constants.java
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/StereotypeOperationUtils.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/StereotypeOperationUtils.java
new file mode 100755
index 00000000000..ba3914470a7
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/StereotypeOperationUtils.java
@@ -0,0 +1,148 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.nattable.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * This class provides useful methods for operations of stereotypes
+ *
+ * @since 5.4
+ *
+ */
+public class StereotypeOperationUtils {
+
+ /**
+ * The prefix used to identify the operations of stereotype in the table axis
+ */
+ public static final String OPERATION_OF_STEREOTYPE_PREFIX = "operation_of_stereotype:/"; //$NON-NLS-1$
+
+
+ /**
+ *
+ * @param tableContext
+ * the context of the table
+ * @param id
+ * the id of the operation
+ * @return
+ * the stereotype operation
+ */
+ public static Object getRealStereotypeOperation(final EObject tableContext, final String id) {
+ Operation result = null;
+ Assert.isTrue(id.startsWith(OPERATION_OF_STEREOTYPE_PREFIX));
+ if (tableContext instanceof Element) {
+ final Element element = (Element) tableContext;
+ final String operationQN = id.replace(OPERATION_OF_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$
+
+ final Package nearestPackage = element.getNearestPackage();
+ if (null != nearestPackage) {
+
+ result = UMLUtil.<Operation> findNamedElements(nearestPackage.eResource().getResourceSet(), operationQN, false, UMLPackage.eINSTANCE.getOperation())
+ .stream()
+ .findFirst()
+ .orElse(null);
+
+
+ // TODO should we still keep that? FindNamedElement browse all the resourceSet.
+ // 2. if not, 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 = getOperation(element.getNearestPackage().getNestedPackages(), operationQN);
+ }
+ }
+
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param packages
+ * a collection of packages
+ * @param operationQN
+ * the qualified name of the operation
+ * @return
+ * the first found operation with the expected qualified name
+ */
+ public static Operation getOperation(final Collection<Package> packages, final String operationQN) {
+ final String operationName = NamedElementUtil.getNameFromQualifiedName(operationQN);
+ final String stereotypeQN = NamedElementUtil.getParentQualifiedName(operationQN);
+ final String stereotypeName = NamedElementUtil.getNameFromQualifiedName(stereotypeQN);
+ final String profileQN = NamedElementUtil.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(operationName);
+ if (prop instanceof Operation && prop.getQualifiedName().equals(operationQN)) {
+ return (Operation) prop;
+ }
+ }
+ }
+ Operation p = getOperation(package1.getNestedPackages(), operationQN);
+ if (p != null) {
+ return p;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @param element
+ * the UML::Element on which we are looking for applied Stereotype with the operation identified by its id
+ * @param id
+ * the id used to identify the operation of the stereotype
+ *
+ * @return
+ * the list of UML::Stereotype which have the operation identified by this id and which are applied on the Element or <code>null</code> if
+ * we can't resolve it (the required profile is not applied)
+ */
+ public static final List<Stereotype> getAppliedStereotypesWithThisOperation(final Element element, final String id) {
+ Assert.isTrue(id.startsWith(OPERATION_OF_STEREOTYPE_PREFIX));
+ final List<Stereotype> stereotypes = new ArrayList<>();
+ if (element.eResource() != null) {
+ final Object operation = getRealStereotypeOperation(element, id);
+ if (operation instanceof Operation) {
+ for (final Stereotype current : element.getAppliedStereotypes()) {
+ if (current.getAllOperations().contains(operation)) {
+ stereotypes.add(current);
+ }
+ }
+ }
+ }
+ return stereotypes;
+ }
+
+
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
index 973c9143ef5..456c59c16af 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
@@ -33,7 +33,7 @@ Require-Bundle: org.eclipse.uml2.uml;bundle-version="[5.3.0,6.0.0)";visibility:=
org.eclipse.papyrus.infra.services.decoration;bundle-version="[2.0.0,3.0.0)"
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 4.2.100.qualifier
+Bundle-Version: 4.3.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Activator: org.eclipse.papyrus.uml.tools.Activator
Bundle-ManifestVersion: 2
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
index f4f6f0012e9..969f040759f 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
@@ -9,7 +9,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.tools</artifactId>
- <version>4.2.100-SNAPSHOT</version>
+ <version>4.3.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<description>This plugin contributes a set of common tools for UML</description>
</project>
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/IOperationContentProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/IOperationContentProvider.java
new file mode 100755
index 00000000000..2d66692bb43
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/IOperationContentProvider.java
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.providers;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+
+/**
+ * StructuredContentProvider dedicated to Operations
+ *
+ * @since 4.3
+ */
+public interface IOperationContentProvider extends IStructuredContentProvider {
+
+ /**
+ * @param ignoreOperationsWithParameters
+ * if <code>true</code> the content provider must not include the operation with parameters
+ */
+ void setIgnoredOperationsWithParameters(final boolean ignoreOperationsWithParameters);
+
+ /**
+ *
+ * @param ignoreVoidOperation
+ * if <code>true</code> the concent provider must not include the operation returning void
+ */
+ void setIgnoreVoidOperations(final boolean ignoreVoidOperation);
+
+ /**
+ *
+ * @return
+ * <code>true</code> if the content provider is ignoring operations with parameters
+ */
+ boolean isIgnoringOperationsWithParameters();
+
+ /**
+ *
+ * @return
+ * <code>true</code> if the content provider is ignoring operations returning void
+ */
+ boolean isIgnoringVoidOperations();
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypeOperationContentProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypeOperationContentProvider.java
new file mode 100755
index 00000000000..dccccde6bd8
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypeOperationContentProvider.java
@@ -0,0 +1,260 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.providers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IInheritedElementContentProvider;
+import org.eclipse.papyrus.uml.tools.util.StereotypeUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ *
+ * This content providers is used to get the operations of stereotypes
+ *
+ * @since 4.3
+ *
+ */
+public class UMLStereotypeOperationContentProvider implements IHierarchicContentProvider, IInheritedElementContentProvider, IOperationContentProvider {
+
+ /**
+ * the profiles
+ */
+ protected List<Profile> profiles;
+
+ /**
+ * if <code>true</code> we don't return the inherited properties
+ */
+ private boolean ignoreInheritedOperation;
+
+ private boolean ignoreVoidOperations;
+
+ private boolean ignoreOperationsWithParameters;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param profiles
+ * the profiles to navigate
+ *
+ * the boolean fields are initialized to false
+ */
+ public UMLStereotypeOperationContentProvider(final List<Profile> profiles) {
+ this.profiles = profiles;
+ this.ignoreInheritedOperation = false;
+ this.ignoreOperationsWithParameters = false;
+ this.ignoreVoidOperations = false;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public UMLStereotypeOperationContentProvider() {
+ this(null);
+ }
+
+
+ /**
+ *
+ * @return
+ */
+ public Object[] getElements() {
+ return this.profiles.toArray();
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ *
+ * @param inputElement
+ * @return
+ */
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return getElements();
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ *
+ * @param parentElement
+ * @return
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ List<Object> children = new ArrayList<>();
+ if (hasChildren(parentElement)) {
+ if (parentElement instanceof Package) {
+ for (final EObject current : ((Package) parentElement).getOwnedMembers()) {
+ if (hasChildren(current)) {
+ children.add(current);
+ }
+ }
+ } else if (parentElement instanceof Stereotype) {
+ children.addAll(StereotypeUtil.getAllStereotypeOperations((Stereotype) parentElement, this.ignoreVoidOperations, this.ignoreOperationsWithParameters, this.ignoreInheritedOperation));
+ }
+ }
+ return children.toArray();
+ }
+
+
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Object getParent(Object element) {
+ if (element instanceof EObject) {
+ return ((EObject) element).eContainer();
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof Element) {
+ final TreeIterator<EObject> iter = ((EObject) element).eAllContents();
+ while (iter.hasNext()) {
+ if (isValidValue(iter.next())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void dispose() {
+ profiles.clear();
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider#isValidValue(java.lang.Object)
+ *
+ * @param element
+ * an element
+ * @return
+ * <code>true</code> if the element is a Property owned by a Stereotype
+ */
+ @Override
+ public boolean isValidValue(Object element) {
+ if (element instanceof Element) {
+ return element instanceof Operation && ((Element) element).eContainer() instanceof Stereotype;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param profiles
+ * the list of the profiles to navigate
+ */
+ public void setProfiles(final List<Profile> profiles) {
+ this.profiles = profiles;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.widgets.providers.IInheritedElementContentProvider#setIgnoreInheritedElements(boolean)
+ *
+ * @param ignoreInheritedElements
+ */
+ @Override
+ public void setIgnoreInheritedElements(final boolean ignoreInheritedElements) {
+ this.ignoreInheritedOperation = ignoreInheritedElements;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.widgets.providers.IInheritedElementContentProvider#isIgnoringInheritedElements()
+ *
+ * @return
+ */
+ @Override
+ public boolean isIgnoringInheritedElements() {
+ return this.ignoreInheritedOperation;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.tools.providers.IOperationContentProvider#setIgnoredOperationsWithParameters(boolean)
+ *
+ * @param ignoreOperationsWithParameters
+ */
+ @Override
+ public void setIgnoredOperationsWithParameters(boolean ignoreOperationsWithParameters) {
+ this.ignoreOperationsWithParameters = ignoreOperationsWithParameters;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.tools.providers.IOperationContentProvider#setIgnoreVoidOperations(boolean)
+ *
+ * @param ignoreVoidOperation
+ */
+ @Override
+ public void setIgnoreVoidOperations(boolean ignoreVoidOperation) {
+ this.ignoreVoidOperations = ignoreVoidOperation;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.tools.providers.IOperationContentProvider#isIgnoringOperationsWithParameters()
+ *
+ * @return
+ */
+ @Override
+ public boolean isIgnoringOperationsWithParameters() {
+ return this.ignoreOperationsWithParameters;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.tools.providers.IOperationContentProvider#isIgnoringVoidOperations()
+ *
+ * @return
+ */
+ @Override
+ public boolean isIgnoringVoidOperations() {
+ return this.ignoreVoidOperations;
+ }
+
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypePropertyContentProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypePropertyContentProvider.java
index 6567bbf95f1..9fb49ef765b 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypePropertyContentProvider.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLStereotypePropertyContentProvider.java
@@ -94,6 +94,7 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
* @param inputElement
* @return
*/
+ @Override
public Object[] getElements(Object inputElement) {
return getElements();
}
@@ -105,8 +106,9 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
* @param parentElement
* @return
*/
+ @Override
public Object[] getChildren(Object parentElement) {
- List<Object> children = new ArrayList<Object>();
+ List<Object> children = new ArrayList<>();
if (hasChildren(parentElement)) {
if (parentElement instanceof Package) {
for (final EObject current : ((Package) parentElement).getOwnedMembers()) {
@@ -144,6 +146,7 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
* @param element
* @return
*/
+ @Override
public Object getParent(Object element) {
if (element instanceof EObject) {
return ((EObject) element).eContainer();
@@ -158,6 +161,7 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
* @param element
* @return
*/
+ @Override
public boolean hasChildren(Object element) {
if (element instanceof Element) {
final TreeIterator<EObject> iter = ((EObject) element).eAllContents();
@@ -170,10 +174,12 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
return false;
}
+ @Override
public void dispose() {
profiles.clear();
}
+ @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@@ -186,6 +192,7 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
* @return
* <code>true</code> if the element is a Property owned by a Stereotype
*/
+ @Override
public boolean isValidValue(Object element) {
if (element instanceof Element) {
boolean result = element instanceof Property && ((Element) element).eContainer() instanceof Stereotype;
@@ -211,6 +218,7 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
*
* @param ignoreBaseProperty
*/
+ @Override
public void setIgnoreBaseProperty(boolean ignoreBaseProperty) {
this.ignoreBaseProperty = ignoreBaseProperty;
}
@@ -222,6 +230,7 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
*
* @param ignoreInheritedElements
*/
+ @Override
public void setIgnoreInheritedElements(final boolean ignoreInheritedElements) {
this.ignoreInheritedProperties = ignoreInheritedElements;
}
@@ -232,6 +241,7 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
*
* @return
*/
+ @Override
public boolean isIgnoringInheritedElements() {
return this.ignoreInheritedProperties;
}
@@ -242,6 +252,7 @@ public class UMLStereotypePropertyContentProvider implements IHierarchicContentP
*
* @return
*/
+ @Override
public boolean isIgnoringBaseProperty() {
return this.ignoreBaseProperty;
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/StereotypeUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/StereotypeUtil.java
new file mode 100755
index 00000000000..03004f109d0
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/StereotypeUtil.java
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.ParameterDirectionKind;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * Utils class for stereotype
+ *
+ * @since 4.3
+ *
+ */
+public class StereotypeUtil {
+
+ private StereotypeUtil() {
+ // to prevent instanciation
+ }
+
+ /**
+ *
+ * @param stereotype
+ * a stereotype
+ * @param ignoreVoidOperations
+ * if <code>true</code>, void operations won't be included in the result
+ * @param ignoreOperationsWithParameters
+ * if <code>true</code>, operations with parameters won't be included in the result
+ * @param inheritedOperation
+ * if <code>true</code> inherited operations will be included in the result
+ * @return
+ * a collection of operations of the stereotypes, matching the values of the parameters
+ */
+ public static final Collection<Operation> getAllStereotypeOperations(final Stereotype stereotype, final boolean ignoreVoidOperations, final boolean ignoreOperationsWithParameters, final boolean inheritedOperation) {
+ if (inheritedOperation) {
+ return filterOperations(stereotype.getAllOperations(), ignoreVoidOperations, ignoreOperationsWithParameters);
+ }
+ return filterOperations(stereotype.getOwnedOperations(), ignoreVoidOperations, ignoreOperationsWithParameters);
+ }
+
+ /**
+ *
+ * @param operations
+ * a collection of operations
+ * @param ignoreVoidOperations
+ * if <code>true</code>, void operations won't be included in the result
+ * @param ignoreOperationsWithParameters
+ * * if <code>true</code>, operations with parameters won't be included in the result
+ *
+ * @return
+ * a collection of operations of the stereotypes, matching the values of the parameters
+ */
+ private static final Collection<Operation> filterOperations(final Collection<Operation> operations, final boolean ignoreVoidOperations, final boolean ignoreOperationsWithParameters) {
+ if (!ignoreOperationsWithParameters && !ignoreVoidOperations) {
+ return Collections.unmodifiableCollection(operations);
+ }
+ final Collection<Operation> filteredOperation = new HashSet<>();
+ for (Operation current : operations) {
+ final Collection<Parameter> returnParameters = new ArrayList<>();
+ final Collection<Parameter> othersParameters = new ArrayList<>();
+ for (final Parameter p : current.getOwnedParameters()) {
+ if (p.getDirection() == ParameterDirectionKind.RETURN_LITERAL) {
+ returnParameters.add(p);
+ } else {
+ othersParameters.add(p);
+ }
+ }
+ if ((ignoreVoidOperations && !returnParameters.isEmpty())
+ && (ignoreOperationsWithParameters && othersParameters.isEmpty())) {
+ filteredOperation.add(current);
+ }
+ }
+ return filteredOperation;
+ }
+
+}

Back to the top