Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/Activator.java78
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/ApplyStereotypeAdviceConfigurationFactory.java34
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/ApplyStereotypeAdviceEditHelperAdvice.java216
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/StereotypeFeatureValueUtils.java130
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/settype/SetTypeAdviceEditHelperAdvice.java116
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/settype/SetTypeAdviceFactory.java34
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/AbstractProfilingCommand.java79
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/ApplyProfileCommand.java63
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/ApplyStereotypeCommand.java63
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/SetStereotypeValueCommand.java65
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/UnapplyProfileCommand.java63
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/UnapplyStereotypeCommand.java63
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/edithelper/DefaultUMLEditHelper.java96
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/edithelper/DefaultUMLEditHelperAdvice.java152
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/matchers/stereotype/StereotypeApplicationMatcher.java83
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/matchers/stereotype/StereotypeApplicationMatcherConfigurationFactory.java31
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/AbstractProfileRequest.java90
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/AbstractStereotypeRequest.java88
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/ApplyProfileRequest.java34
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/ApplyStereotypeRequest.java33
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/SetStereotypeValueRequest.java111
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/UnapplyProfileRequest.java26
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/UnapplyStereotypeRequest.java34
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/rules/AbstractUmlRule.java94
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/rules/invariantstereotype/InvariantStereotypeRule.java194
25 files changed, 2070 insertions, 0 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/Activator.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/Activator.java
new file mode 100644
index 00000000000..3c5a84bb8af
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/Activator.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * This is the central singleton for the ApplyStereotypeAdviceConfiguration model plugin.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @generated
+ */
+public final class Activator extends AbstractUIPlugin {
+
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.types.core"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator INSTANCE;
+
+ /** Logging helper */
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ INSTANCE = this;
+ log = new LogHelper(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ log = null;
+ INSTANCE = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return INSTANCE;
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/ApplyStereotypeAdviceConfigurationFactory.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/ApplyStereotypeAdviceConfigurationFactory.java
new file mode 100644
index 00000000000..b2d4d921e2e
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/ApplyStereotypeAdviceConfigurationFactory.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.advices.applystereotype;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.types.AbstractAdviceBindingConfiguration;
+import org.eclipse.papyrus.infra.types.core.factories.impl.AbstractAdviceBindingFactory;
+import org.eclipse.papyrus.infra.types.core.impl.NullEditHelperAdvice;
+
+
+public class ApplyStereotypeAdviceConfigurationFactory extends AbstractAdviceBindingFactory<AbstractAdviceBindingConfiguration> {
+
+
+ @Override
+ protected IEditHelperAdvice getEditHelperAdvice(AbstractAdviceBindingConfiguration adviceConfiguration) {
+ if (adviceConfiguration instanceof ApplyStereotypeAdviceConfiguration) {
+ IEditHelperAdvice editHelperAdvice = new ApplyStereotypeAdviceEditHelperAdvice((ApplyStereotypeAdviceConfiguration) adviceConfiguration);
+ return editHelperAdvice;
+ }
+ return NullEditHelperAdvice.getInstance();
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/ApplyStereotypeAdviceEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/ApplyStereotypeAdviceEditHelperAdvice.java
new file mode 100644
index 00000000000..2537c9d0e69
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/ApplyStereotypeAdviceEditHelperAdvice.java
@@ -0,0 +1,216 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.advices.applystereotype;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
+import org.eclipse.papyrus.uml.types.core.Activator;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyStereotypeRequest;
+import org.eclipse.papyrus.uml.types.core.requests.SetStereotypeValueRequest;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.TypedElement;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ * advice for the {@link ApplyStereotypeAdviceConfiguration}
+ */
+public class ApplyStereotypeAdviceEditHelperAdvice extends AbstractEditHelperAdvice {
+
+
+ protected ApplyStereotypeAdviceConfiguration configuration;
+
+
+ public ApplyStereotypeAdviceEditHelperAdvice(ApplyStereotypeAdviceConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean approveRequest(IEditCommandRequest request) {
+ if (request instanceof CreateElementRequest) {
+ if (configuration == null) {
+ return false;
+ }
+ if (!(((CreateElementRequest) request).getContainer() instanceof Element)) {
+ return false;
+ }
+ Element container = (Element) ((CreateElementRequest) request).getContainer();
+ Package nearestPackage = container.getNearestPackage();
+ if (nearestPackage == null) {
+ return false;
+ }
+ List<Profile> appliedProfiles = nearestPackage.getAllAppliedProfiles();
+ if (appliedProfiles == null) {
+ // no profiles applied, no stereotype can be applied
+ return false;
+ }
+ List<String> appliedProfileNames = new ArrayList<String>();
+ for (Profile profile : appliedProfiles) {
+ appliedProfileNames.add(profile.getQualifiedName());
+ }
+ for (StereotypeToApply stereotypeToApply : configuration.getStereotypesToApply()) {
+ List<String> requiredProfiles = stereotypeToApply.getRequiredProfiles();
+ if (requiredProfiles != null) {
+ for (String requiredProfile : requiredProfiles) {
+ if (!appliedProfileNames.contains(requiredProfile)) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getAfterConfigureCommand(ConfigureRequest request) {
+ if (configuration == null) {
+ return null;
+ }
+ ICommand resultCommand = null;
+ // retrieve eobject
+ EObject elementToConfigure = request.getElementToConfigure();
+ if (!(elementToConfigure instanceof Element)) {
+ return null;
+ }
+
+ TransactionalEditingDomain editingDomain = request.getEditingDomain();
+ if (editingDomain == null) {
+ return null;
+ }
+ // retrieve edit service to get features from configure command
+ IElementEditService service = ElementEditServiceUtils.getCommandProvider(elementToConfigure);
+ if (service == null) {
+ Activator.log.error("Impossible to get edit service from element: " + elementToConfigure, null);
+ return null;
+ }
+
+ // for each stereotype, apply stereotype and apply values
+ for (StereotypeToApply stereotypeToApply : configuration.getStereotypesToApply()) {
+ Stereotype stereotype = ((Element) elementToConfigure).getApplicableStereotype(stereotypeToApply.getStereotypeQualifiedName());
+
+ if (stereotype != null) {
+
+ ICommand applyStereotypeCommand = service.getEditCommand(new ApplyStereotypeRequest((Element) elementToConfigure, stereotype, editingDomain));
+
+ if (resultCommand == null) {
+ resultCommand = applyStereotypeCommand;
+ } else {
+ resultCommand = resultCommand.compose(applyStereotypeCommand);
+ }
+
+ if (stereotypeToApply.isUpdateName() && elementToConfigure instanceof NamedElement) {
+ if (((NamedElement) elementToConfigure).getNamespace() != null) {
+ String newName = NamedElementUtil.getDefaultNameWithIncrementFromBase(stereotype.getName(), ((NamedElement) elementToConfigure).getNamespace().getMembers());
+ ICommand renameCommand = service.getEditCommand(new SetRequest(editingDomain, elementToConfigure, UMLPackage.eINSTANCE.getNamedElement_Name(), newName));
+
+ if (resultCommand == null) {
+ resultCommand = renameCommand;
+ } else {
+ resultCommand = resultCommand.compose(renameCommand);
+ }
+ }
+ }
+
+ // Set values
+ for (FeatureToSet featureToSet : stereotypeToApply.getFeaturesToSet()) {
+ // retrieve feature value
+ ICommand command = getSetStereotypeFeatureValueCommand((Element) elementToConfigure, stereotype, featureToSet.getFeatureName(), featureToSet.getValue(), service, request);
+ if (command != null) {
+ if (resultCommand == null) {
+ resultCommand = command;
+ } else {
+ resultCommand = resultCommand.compose(command);
+ }
+ }
+ }
+ }
+
+ }
+
+ if (resultCommand != null) {
+ return resultCommand.reduce();
+ }
+ return super.getAfterConfigureCommand(request);
+ }
+
+ /**
+ * @param elementToConfigure
+ * the eobject to configure
+ * @param name
+ * the name of the feature to set
+ * @param value
+ * the new value of the feature
+ */
+ protected ICommand getSetStereotypeFeatureValueCommand(Element elementToConfigure, Stereotype stereotype, String name, FeatureValue featureValue, IElementEditService service, ConfigureRequest configureRequest) {
+ if (name == null) {
+ Activator.log.debug("No feature name has been set.");
+ return null;
+ }
+ if (elementToConfigure.eClass() == null) {
+ Activator.log.error("Impossible to find EClass from EObject: " + elementToConfigure, null);
+ return null;
+ }
+
+ if (configureRequest.getEditingDomain() == null) {
+ return null;
+ }
+
+ // retrieve structural feature for the element to configure
+ TypedElement typedElement = (TypedElement) stereotype.getMember(name, true, UMLPackage.eINSTANCE.getTypedElement());
+ if (typedElement == null) {
+ Activator.log.error("Impossible to find feature " + name + " for eobject " + elementToConfigure, null);
+ return null;
+ }
+ Object value = getStereotypeValue(elementToConfigure, stereotype, typedElement.getType(), featureValue);
+
+ return service.getEditCommand(new SetStereotypeValueRequest(configureRequest.getEditingDomain(), stereotype, (Element) elementToConfigure, name, value));
+ }
+
+
+ /**
+ * @param elementToConfigure
+ * @param stereotype
+ * @param feature
+ * @param featureValue
+ * @return
+ */
+ protected Object getStereotypeValue(Element elementToConfigure, Stereotype stereotype, Type type, FeatureValue featureValue) {
+ return StereotypeFeatureValueUtils.getValue(elementToConfigure, stereotype, type, featureValue);
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/StereotypeFeatureValueUtils.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/StereotypeFeatureValueUtils.java
new file mode 100644
index 00000000000..2c2b33fb81f
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/applystereotype/StereotypeFeatureValueUtils.java
@@ -0,0 +1,130 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.advices.applystereotype;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.papyrus.infra.emf.types.converter.ConverterNotfoundException;
+import org.eclipse.papyrus.infra.emf.types.converter.ConverterRegistry;
+import org.eclipse.papyrus.uml.tools.utils.PrimitivesTypesUtils;
+import org.eclipse.papyrus.uml.types.core.Activator;
+import org.eclipse.papyrus.uml.types.core.advices.applystereotype.util.ApplyStereotypeAdviceSwitch;
+import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.Enumeration;
+import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.ValueSpecification;
+
+
+/**
+ * Utility class to get values from a {@link FeatureValue}
+ */
+public class StereotypeFeatureValueUtils {
+
+ protected StereotypeFeatureValueUtils() {
+ // no instanciation, helper class
+ }
+
+ /**
+ * Returns the value to set for a given feature of a given element
+ *
+ * @param elementToConfigure
+ * eobject for which feature is set. This must not be <code>null</code>
+ * @param feature
+ * {@link EStructuralFeature} to set. This must not be <code>null</code>
+ * @param valueModel
+ * configuration of the value, stored in the model
+ * @return the real value that will be set to the object or <code>null</code> if none could be computed
+ */
+ public static Object getValue(final EObject elementToConfigure, final Stereotype stereotype, final Type type, final FeatureValue featureValue) {
+
+ Object result = new ApplyStereotypeAdviceSwitch<Object>() {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object caseConstantValue(ConstantValue object) {
+ ValueSpecification valueSpecification = object.getValueInstance();
+
+ if (valueSpecification == null) {
+ return null;
+ }
+
+ try {
+ if (type instanceof PrimitiveType) {
+ final PrimitiveType pType = (PrimitiveType) type;
+ final String name = pType.getName();
+ if (PrimitivesTypesUtils.UML_BOOLEAN.equals(name)) {
+ return ConverterRegistry.getSingleton().convert(boolean.class, valueSpecification);
+ } else if (PrimitivesTypesUtils.UML_INTEGER.equals(name)) {
+ return ConverterRegistry.getSingleton().convert(int.class, valueSpecification);
+ } else if (PrimitivesTypesUtils.UML_REAL.equals(name)) {
+ return ConverterRegistry.getSingleton().convert(double.class, valueSpecification);
+ } else if (PrimitivesTypesUtils.UML_STRING.equals(name)) {
+ return ConverterRegistry.getSingleton().convert(String.class, valueSpecification);
+ } else if (PrimitivesTypesUtils.UML_UNLIMITED_NATURAL.equals(name)) {
+ return ConverterRegistry.getSingleton().convert(int.class, valueSpecification);
+ } else { // custom PrimitiveType
+ return ConverterRegistry.getSingleton().convert(String.class, valueSpecification);
+ }
+ } else if (type instanceof Enumeration) {
+ return ConverterRegistry.getSingleton().convert(Enumeration.class, valueSpecification);
+ } else if (type instanceof DataType) {// FIXME manage the data type
+ return ConverterRegistry.getSingleton().convert(String.class, valueSpecification);
+ }
+ } catch (ConverterNotfoundException e) {
+ Activator.log.error("Impossible to convert " + valueSpecification + " to fit feature type :" + type, e);
+ }
+ return super.caseConstantValue(object);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object caseQueryExecutionValue(QueryExecutionValue object) {
+ throw new UnsupportedOperationException("Query execution values resolution has not been implemented yet");
+ };
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object caseDynamicValue(DynamicValue object) {
+ throw new UnsupportedOperationException("Dynamic values resolution has not been implemented yet");
+ };
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object caseListValue(ListValue object) {
+ // resolve one by one all features in the values list of this listvalue
+ List<Object> results = new ArrayList<Object>();
+ for (FeatureValue value : object.getValues()) {
+ Object singleResult = getValue(elementToConfigure, stereotype, type, value);
+ results.add(singleResult);
+ }
+ return results;
+ };
+
+ }.doSwitch(featureValue);
+ return result;
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/settype/SetTypeAdviceEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/settype/SetTypeAdviceEditHelperAdvice.java
new file mode 100644
index 00000000000..8f0778012a7
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/settype/SetTypeAdviceEditHelperAdvice.java
@@ -0,0 +1,116 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.advices.settype;
+
+import java.util.Arrays;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.papyrus.uml.properties.modelelement.UMLModelElement;
+import org.eclipse.papyrus.uml.types.core.Activator;
+import org.eclipse.papyrus.uml.types.core.advices.applystereotype.ApplyStereotypeAdviceConfiguration;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * advice for the {@link ApplyStereotypeAdviceConfiguration}
+ */
+public class SetTypeAdviceEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ protected SetTypeAdviceConfiguration configuration;
+
+ public SetTypeAdviceEditHelperAdvice(SetTypeAdviceConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean approveRequest(IEditCommandRequest request) {
+ return super.approveRequest(request);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getBeforeConfigureCommand(ConfigureRequest request) {
+ return super.getBeforeConfigureCommand(request);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getAfterConfigureCommand(ConfigureRequest request) {
+ if (configuration == null) {
+ return null;
+ }
+ ICommand resultCommand = null;
+ // retrieve eobject
+ final EObject elementToConfigure = request.getElementToConfigure();
+ if (!(elementToConfigure instanceof Element)) {
+ return null;
+ }
+
+ final TransactionalEditingDomain editingDomain = request.getEditingDomain();
+ if (editingDomain == null) {
+ return null;
+ }
+ // retrieve edit service to get features from configure command
+ IElementEditService service = ElementEditServiceUtils.getCommandProvider(elementToConfigure);
+ if (service == null) {
+ Activator.log.error("Impossible to get edit service from element: " + elementToConfigure, null);
+ return null;
+ }
+
+ resultCommand = new AbstractTransactionalCommand(editingDomain, "Editing type", Arrays.asList((WorkspaceSynchronizer.getFile(elementToConfigure.eResource())))) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ UMLModelElement umlModelElement = new UMLModelElement(elementToConfigure, editingDomain);
+ ReferenceValueFactory factory = umlModelElement.getValueFactory("type");
+ Object elemObject = factory.edit(Display.getDefault().getFocusControl(), elementToConfigure);
+ return CommandResult.newOKCommandResult(elemObject);
+ }
+ };
+
+ return resultCommand;
+ }
+
+ /**
+ * @return
+ */
+ protected EObject getDefaultTypeContainer(ConfigureRequest request) {
+ if (request.getElementToConfigure() instanceof Element) {
+ return ((Element) request.getElementToConfigure()).getNearestPackage();
+ }
+ return request.getElementToConfigure().eContainer();
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/settype/SetTypeAdviceFactory.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/settype/SetTypeAdviceFactory.java
new file mode 100644
index 00000000000..8e28cd842e8
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/advices/settype/SetTypeAdviceFactory.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.advices.settype;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.papyrus.infra.types.AbstractAdviceBindingConfiguration;
+import org.eclipse.papyrus.infra.types.core.factories.impl.AbstractAdviceBindingFactory;
+import org.eclipse.papyrus.infra.types.core.impl.NullEditHelperAdvice;
+
+
+public class SetTypeAdviceFactory extends AbstractAdviceBindingFactory<AbstractAdviceBindingConfiguration> {
+
+
+ @Override
+ protected IEditHelperAdvice getEditHelperAdvice(AbstractAdviceBindingConfiguration adviceConfiguration) {
+ if (adviceConfiguration instanceof SetTypeAdviceConfiguration) {
+ IEditHelperAdvice editHelperAdvice = new SetTypeAdviceEditHelperAdvice((SetTypeAdviceConfiguration) adviceConfiguration);
+ return editHelperAdvice;
+ }
+ return NullEditHelperAdvice.getInstance();
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/AbstractProfilingCommand.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/AbstractProfilingCommand.java
new file mode 100644
index 00000000000..ff999b80ca8
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/AbstractProfilingCommand.java
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.commands;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+public abstract class AbstractProfilingCommand extends AbstractTransactionalCommand {
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * @param label
+ * @param affectedFiles
+ */
+ public AbstractProfilingCommand(TransactionalEditingDomain domain, String label, List<Object> affectedFiles) {
+ super(domain, label, affectedFiles);
+ }
+
+ protected static List<Object> getAffectedFiles(IEditCommandRequest request) {
+ List<Object> result = new ArrayList<Object>();
+ List<?> elements = request.getElementsToEdit();
+ int size;
+ if (elements != null && ((size = elements.size()) > 0)) {
+ if (size == 1) {
+ Resource resource = ((EObject) elements.get(0)).eResource();
+ if (resource != null) {
+ IFile file = WorkspaceSynchronizer.getFile(resource);
+ if (file != null) {
+ result.add(file);
+ }
+ }
+ } else {
+ Map<Resource, Object> resourcesToFileMap = new HashMap<Resource, Object>();
+ for (int i = 0; i < size; ++i) {
+ Resource resource = ((EObject) elements.get(i)).eResource();
+ if (resource != null) {
+ Object file = resourcesToFileMap.get(resource);
+ // if it is in the Map, then it is in the List already as well
+ if (file == null) {
+ file = WorkspaceSynchronizer.getFile(resource);
+ if (file != null) {
+ resourcesToFileMap.put(resource, file);
+ result.add(file);
+ }
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/ApplyProfileCommand.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/ApplyProfileCommand.java
new file mode 100644
index 00000000000..a8086194c28
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/ApplyProfileCommand.java
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyProfileRequest;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+
+public class ApplyProfileCommand extends AbstractProfilingCommand {
+
+ private ApplyProfileRequest request;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param request
+ * @param domain
+ * @param label
+ */
+ public ApplyProfileCommand(ApplyProfileRequest request, TransactionalEditingDomain domain, String label) {
+ super(domain, label, getAffectedFiles(request));
+ this.request = request;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Package pkg = this.request.getUmlPackage();
+ Profile profile = this.request.getProfile();
+ try {
+ pkg.applyProfile(profile);
+ } catch (IllegalArgumentException e) {
+ return CommandResult.newErrorCommandResult(e);
+ }
+
+
+ return CommandResult.newOKCommandResult();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/ApplyStereotypeCommand.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/ApplyStereotypeCommand.java
new file mode 100644
index 00000000000..7746fdaeac9
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/ApplyStereotypeCommand.java
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyStereotypeRequest;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class ApplyStereotypeCommand extends AbstractProfilingCommand {
+
+ private ApplyStereotypeRequest request;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param request
+ * @param domain
+ * @param label
+ */
+ public ApplyStereotypeCommand(ApplyStereotypeRequest request, TransactionalEditingDomain domain, String label) {
+ super(domain, label, getAffectedFiles(request));
+ this.request = request;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Element element = this.request.getUmlElement();
+ Stereotype stereotype = this.request.getStereotype();
+ try {
+ element.applyStereotype(stereotype);
+ } catch (IllegalArgumentException e) {
+ return CommandResult.newErrorCommandResult(e);
+ }
+
+
+ return CommandResult.newOKCommandResult();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/SetStereotypeValueCommand.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/SetStereotypeValueCommand.java
new file mode 100644
index 00000000000..ee448d48ebe
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/SetStereotypeValueCommand.java
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.uml.types.core.requests.SetStereotypeValueRequest;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class SetStereotypeValueCommand extends AbstractProfilingCommand {
+
+ private SetStereotypeValueRequest request;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param request
+ * @param domain
+ * @param label
+ */
+ public SetStereotypeValueCommand(SetStereotypeValueRequest request, TransactionalEditingDomain domain, String label) {
+ super(domain, label, getAffectedFiles(request));
+ this.request = request;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Element element = this.request.getUmlElement();
+ Stereotype stereotype = this.request.getStereotype();
+ String propertyName = this.request.getPropertyName();
+ Object value = this.request.getValue();
+ try {
+ element.setValue(stereotype, propertyName, value);
+ } catch (IllegalArgumentException e) {
+ return CommandResult.newErrorCommandResult(e);
+ }
+
+
+ return CommandResult.newOKCommandResult();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/UnapplyProfileCommand.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/UnapplyProfileCommand.java
new file mode 100644
index 00000000000..fc1ed93d935
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/UnapplyProfileCommand.java
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyProfileRequest;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+
+public class UnapplyProfileCommand extends AbstractProfilingCommand {
+
+ private UnapplyProfileRequest request;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param request
+ * @param domain
+ * @param label
+ */
+ public UnapplyProfileCommand(UnapplyProfileRequest request, TransactionalEditingDomain domain, String label) {
+ super(domain, label, getAffectedFiles(request));
+ this.request = request;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Package pkg = this.request.getUmlPackage();
+ Profile profile = this.request.getProfile();
+ try {
+ pkg.unapplyProfile(profile);
+ } catch (IllegalArgumentException e) {
+ return CommandResult.newErrorCommandResult(e);
+ }
+
+
+ return CommandResult.newOKCommandResult();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/UnapplyStereotypeCommand.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/UnapplyStereotypeCommand.java
new file mode 100644
index 00000000000..68c69da2839
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/commands/UnapplyStereotypeCommand.java
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyStereotypeRequest;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class UnapplyStereotypeCommand extends AbstractProfilingCommand {
+
+ private UnapplyStereotypeRequest request;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param request
+ * @param domain
+ * @param label
+ */
+ public UnapplyStereotypeCommand(UnapplyStereotypeRequest request, TransactionalEditingDomain domain, String label) {
+ super(domain, label, getAffectedFiles(request));
+ this.request = request;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Element element = this.request.getUmlElement();
+ Stereotype stereotype = this.request.getStereotype();
+ try {
+ element.unapplyStereotype(stereotype);
+ } catch (IllegalArgumentException e) {
+ return CommandResult.newErrorCommandResult(e);
+ }
+
+
+ return CommandResult.newOKCommandResult();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/edithelper/DefaultUMLEditHelper.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/edithelper/DefaultUMLEditHelper.java
new file mode 100644
index 00000000000..e632ec712d2
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/edithelper/DefaultUMLEditHelper.java
@@ -0,0 +1,96 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.edithelper;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.DefaultEditHelper;
+import org.eclipse.papyrus.uml.types.core.commands.ApplyProfileCommand;
+import org.eclipse.papyrus.uml.types.core.commands.ApplyStereotypeCommand;
+import org.eclipse.papyrus.uml.types.core.commands.SetStereotypeValueCommand;
+import org.eclipse.papyrus.uml.types.core.commands.UnapplyProfileCommand;
+import org.eclipse.papyrus.uml.types.core.commands.UnapplyStereotypeCommand;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyProfileRequest;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyStereotypeRequest;
+import org.eclipse.papyrus.uml.types.core.requests.SetStereotypeValueRequest;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyProfileRequest;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyStereotypeRequest;
+
+public class DefaultUMLEditHelper extends DefaultEditHelper {
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.helper.DefaultEditHelper#getInsteadCommand(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ *
+ * @param req
+ * @return
+ */
+ @Override
+ protected ICommand getInsteadCommand(IEditCommandRequest req) {
+
+ if (req instanceof ApplyProfileRequest) {
+ return getApplyProfileCommand((ApplyProfileRequest) req);
+ } else if (req instanceof UnapplyProfileRequest) {
+ return getUnapplyProfileCommand((UnapplyProfileRequest) req);
+ } else if (req instanceof ApplyStereotypeRequest) {
+ return getApplyStereotypeCommand((ApplyStereotypeRequest) req);
+ } else if (req instanceof UnapplyStereotypeRequest) {
+ return getUnapplyStereotypeCommand((UnapplyStereotypeRequest) req);
+ } else if (req instanceof SetStereotypeValueRequest) {
+ return getSetStereotypeValueCommand((SetStereotypeValueRequest) req);
+ }
+
+ return super.getInsteadCommand(req);
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getUnapplyProfileCommand(UnapplyProfileRequest req) {
+ return new UnapplyProfileCommand(req, req.getEditingDomain(), req.getLabel());
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getApplyProfileCommand(ApplyProfileRequest req) {
+ return new ApplyProfileCommand(req, req.getEditingDomain(), req.getLabel());
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getUnapplyStereotypeCommand(UnapplyStereotypeRequest req) {
+ return new UnapplyStereotypeCommand(req, req.getEditingDomain(), req.getLabel());
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getApplyStereotypeCommand(ApplyStereotypeRequest req) {
+ return new ApplyStereotypeCommand(req, req.getEditingDomain(), req.getLabel());
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getSetStereotypeValueCommand(SetStereotypeValueRequest req) {
+ return new SetStereotypeValueCommand(req, req.getEditingDomain(), req.getLabel());
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/edithelper/DefaultUMLEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/edithelper/DefaultUMLEditHelperAdvice.java
new file mode 100644
index 00000000000..f81614f84c4
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/edithelper/DefaultUMLEditHelperAdvice.java
@@ -0,0 +1,152 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.edithelper;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyProfileRequest;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyStereotypeRequest;
+import org.eclipse.papyrus.uml.types.core.requests.SetStereotypeValueRequest;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyProfileRequest;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyStereotypeRequest;
+
+public class DefaultUMLEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeEditCommand(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ public ICommand getBeforeEditCommand(IEditCommandRequest req) {
+ if (req instanceof ApplyProfileRequest) {
+ return getBeforeApplyProfileCommand((ApplyProfileRequest) req);
+ } else if (req instanceof UnapplyStereotypeRequest) {
+ return getBeforeUnapplyProfileCommand((UnapplyStereotypeRequest) req);
+ } else if (req instanceof ApplyStereotypeRequest) {
+ return getBeforeApplyStereotypeCommand((ApplyStereotypeRequest) req);
+ } else if (req instanceof UnapplyProfileRequest) {
+ return getBeforeUnapplyStereotypeCommand((UnapplyProfileRequest) req);
+ } else if (req instanceof SetStereotypeValueRequest) {
+ return getBeforeSetValueCommand((SetStereotypeValueRequest) req);
+ }
+
+ return super.getBeforeEditCommand(req);
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterEditCommand(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ public ICommand getAfterEditCommand(IEditCommandRequest req) {
+ if (req instanceof ApplyProfileRequest) {
+ return getAfterApplyProfileCommand((ApplyProfileRequest) req);
+ } else if (req instanceof UnapplyStereotypeRequest) {
+ return getAfterUnapplyProfileCommand((UnapplyStereotypeRequest) req);
+ } else if (req instanceof ApplyStereotypeRequest) {
+ return getAfterApplyStereotypeCommand((ApplyStereotypeRequest) req);
+ } else if (req instanceof UnapplyProfileRequest) {
+ return getAfterUnapplyStereotypeCommand((UnapplyProfileRequest) req);
+ } else if (req instanceof SetStereotypeValueRequest) {
+ return getAfterSetValueCommand((SetStereotypeValueRequest) req);
+ }
+
+ return super.getAfterEditCommand(req);
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getBeforeUnapplyProfileCommand(UnapplyStereotypeRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getBeforeApplyProfileCommand(ApplyProfileRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getBeforeUnapplyStereotypeCommand(UnapplyProfileRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getBeforeApplyStereotypeCommand(ApplyStereotypeRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getAfterUnapplyProfileCommand(UnapplyStereotypeRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getAfterApplyProfileCommand(ApplyProfileRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getAfterUnapplyStereotypeCommand(UnapplyProfileRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getAfterApplyStereotypeCommand(ApplyStereotypeRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getBeforeSetValueCommand(SetStereotypeValueRequest req) {
+ return null;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ protected ICommand getAfterSetValueCommand(SetStereotypeValueRequest req) {
+ return null;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/matchers/stereotype/StereotypeApplicationMatcher.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/matchers/stereotype/StereotypeApplicationMatcher.java
new file mode 100644
index 00000000000..84ba0644c16
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/matchers/stereotype/StereotypeApplicationMatcher.java
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.matchers.stereotype;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Profile;
+
+
+/**
+ * Matcher for UML elements that should be stereotyped
+ */
+public class StereotypeApplicationMatcher implements IElementMatcher {
+
+ private List<String> stereotypesQualifiedNames;
+ private String profileUri;
+
+ public StereotypeApplicationMatcher(StereotypeApplicationMatcherConfiguration configuration) {
+ this.profileUri = configuration.getProfileUri();
+ this.stereotypesQualifiedNames = configuration.getStereotypesQualifiedNames();
+ }
+
+
+ public boolean matches(EObject eObject) {
+ if (!(eObject instanceof Element)) {
+ return false;
+ }
+
+ Element element = (Element) eObject;
+ if (element.getAppliedStereotypes().isEmpty()) {
+ return false;
+ }
+
+ for (String stereotypeQualifiedName : stereotypesQualifiedNames) {
+ if (element.getAppliedStereotype(stereotypeQualifiedName) == null) {
+ return false;
+ }
+ }
+
+ if (profileUri != null) {
+ Model model = element.getModel();
+ if (model == null) {
+ return false;
+ }
+
+ List<String> appliedProfileByUri = new ArrayList<String>();
+ for (Profile appliedProfile : model.getAllAppliedProfiles()) {
+ appliedProfileByUri.add(appliedProfile.getURI());
+ }
+
+ if (!appliedProfileByUri.contains(profileUri)) {
+ return false;
+ }
+
+ }
+ return true;
+ }
+
+ public List<String> getStereotypesQualifiedNames() {
+ return stereotypesQualifiedNames;
+ }
+
+
+ public void setStereotypesQualifiedNames(List<String> stereotypeQualifiedName) {
+ this.stereotypesQualifiedNames = stereotypeQualifiedName;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/matchers/stereotype/StereotypeApplicationMatcherConfigurationFactory.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/matchers/stereotype/StereotypeApplicationMatcherConfigurationFactory.java
new file mode 100644
index 00000000000..16c619bf473
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/matchers/stereotype/StereotypeApplicationMatcherConfigurationFactory.java
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.matchers.stereotype;
+
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.papyrus.infra.types.core.factories.IMatcherFactory;
+
+
+
+/**
+ * Factory to create matcher based on stereotypes applied on the element
+ */
+public class StereotypeApplicationMatcherConfigurationFactory implements IMatcherFactory<StereotypeApplicationMatcherConfiguration> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public IElementMatcher createElementMatcher(StereotypeApplicationMatcherConfiguration configuration) {
+ return new StereotypeApplicationMatcher(configuration);
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/AbstractProfileRequest.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/AbstractProfileRequest.java
new file mode 100644
index 00000000000..83c2fb1e7ad
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/AbstractProfileRequest.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.requests;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.EditHelperContext;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+
+public abstract class AbstractProfileRequest extends AbstractEditCommandRequest {
+
+ private org.eclipse.uml2.uml.Package umlPackage;
+ private Profile profile;
+
+
+ public AbstractProfileRequest(TransactionalEditingDomain editingDomain, org.eclipse.uml2.uml.Package umlPackage, Profile profile) {
+ super(editingDomain);
+ this.umlPackage = umlPackage;
+ this.profile = profile;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest#getEditHelperContext()
+ *
+ * @return
+ */
+ public Object getEditHelperContext() {
+ IClientContext context = getClientContext();
+
+ if (context == null) {
+ return umlPackage;
+ } else {
+ return new EditHelperContext(umlPackage, context);
+ }
+ }
+
+ /**
+ * @return the umlPackage
+ */
+ public org.eclipse.uml2.uml.Package getUmlPackage() {
+ return umlPackage;
+ }
+
+ /**
+ * @param umlPackage
+ * the umlPackage to set
+ */
+ public void setUmlPackage(org.eclipse.uml2.uml.Package umlPackage) {
+ this.umlPackage = umlPackage;
+ }
+
+ /**
+ * @return the profile
+ */
+ public Profile getProfile() {
+ return profile;
+ }
+
+ /**
+ * @param profile
+ * the profile to set
+ */
+ public void setProfile(Profile profile) {
+ this.profile = profile;
+ }
+
+ public List<Package> getElementsToEdit() {
+ if (umlPackage != null) {
+ return Collections.singletonList(umlPackage);
+ }
+
+ return Collections.emptyList();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/AbstractStereotypeRequest.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/AbstractStereotypeRequest.java
new file mode 100644
index 00000000000..c51be13d0d3
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/AbstractStereotypeRequest.java
@@ -0,0 +1,88 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.requests;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.EditHelperContext;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+public abstract class AbstractStereotypeRequest extends AbstractEditCommandRequest {
+ private Element umlElement;
+ private Stereotype stereotype;
+
+ public AbstractStereotypeRequest(TransactionalEditingDomain editingDomain, Element umlElement, Stereotype stereotype) {
+ super(editingDomain);
+ this.umlElement = umlElement;
+ this.stereotype = stereotype;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest#getEditHelperContext()
+ *
+ * @return
+ */
+ public Object getEditHelperContext() {
+ IClientContext context = getClientContext();
+
+ if (context == null) {
+ return umlElement;
+ } else {
+ return new EditHelperContext(umlElement, context);
+ }
+ }
+
+ /**
+ * @return the umlElement
+ */
+ public Element getUmlElement() {
+ return umlElement;
+ }
+
+ /**
+ * @param umlElement
+ * the umlElement to set
+ */
+ public void setUmlElement(Element umlElement) {
+ this.umlElement = umlElement;
+ }
+
+ /**
+ * @return the stereotype
+ */
+ public Stereotype getStereotype() {
+ return stereotype;
+ }
+
+ /**
+ * @param stereotype
+ * the stereotype to set
+ */
+ public void setStereotype(Stereotype stereotype) {
+ this.stereotype = stereotype;
+ }
+
+ public List<Element> getElementsToEdit() {
+ if (umlElement != null) {
+ return Collections.singletonList(umlElement);
+ }
+
+ return Collections.emptyList();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/ApplyProfileRequest.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/ApplyProfileRequest.java
new file mode 100644
index 00000000000..c80aed577fe
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/ApplyProfileRequest.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.requests;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+
+public class ApplyProfileRequest extends AbstractProfileRequest {
+
+ /**
+ * Constructor.
+ *
+ * @param umlPackage
+ * @param profile
+ * @param editingDomain
+ */
+ public ApplyProfileRequest(TransactionalEditingDomain editingDomain, Package umlPackage, Profile profile) {
+ super(editingDomain, umlPackage, profile);
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/ApplyStereotypeRequest.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/ApplyStereotypeRequest.java
new file mode 100644
index 00000000000..2f670af4163
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/ApplyStereotypeRequest.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.requests;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class ApplyStereotypeRequest extends AbstractStereotypeRequest {
+
+ /**
+ * Constructor.
+ *
+ * @param umlElement
+ * @param stereotype
+ * @param editingDomain
+ */
+ public ApplyStereotypeRequest(Element umlElement, Stereotype stereotype, TransactionalEditingDomain editingDomain) {
+ super(editingDomain, umlElement, stereotype);
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/SetStereotypeValueRequest.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/SetStereotypeValueRequest.java
new file mode 100644
index 00000000000..d18f6f7c299
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/SetStereotypeValueRequest.java
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.requests;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.EditHelperContext;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class SetStereotypeValueRequest extends AbstractEditCommandRequest {
+
+
+ private String propertyName;
+
+ private Element umlElement;
+
+ private Stereotype stereotype;
+
+ private Object value;
+
+
+ public SetStereotypeValueRequest(TransactionalEditingDomain editingDomain, Stereotype stereotype, Element elementToEdit, String propertyName, Object value) {
+ super(editingDomain);
+ this.umlElement = elementToEdit;
+ this.propertyName = propertyName;
+ this.value = value;
+ this.stereotype = stereotype;
+ }
+
+ /**
+ * @return the stereotype
+ */
+ public Stereotype getStereotype() {
+ return stereotype;
+ }
+
+ /**
+ * @param stereotype
+ * the stereotype to set
+ */
+ public void setStereotype(Stereotype stereotype) {
+ this.stereotype = stereotype;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ /**
+ * @param value
+ * the value to set
+ */
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ /**
+ * @param propertyName
+ * the propertyName to set
+ */
+ public void setPropertyName(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+
+ public List<Element> getElementsToEdit() {
+ if (umlElement != null) {
+ return Collections.singletonList(umlElement);
+ }
+
+ return Collections.emptyList();
+ }
+
+
+ public Object getEditHelperContext() {
+ IClientContext context = getClientContext();
+
+ if (context == null) {
+ return umlElement;
+ } else {
+ return new EditHelperContext(umlElement, context);
+ }
+ }
+
+ /**
+ * @return the umlElement
+ */
+ public Element getUmlElement() {
+ return umlElement;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/UnapplyProfileRequest.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/UnapplyProfileRequest.java
new file mode 100644
index 00000000000..3813bb28077
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/UnapplyProfileRequest.java
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.requests;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+
+public class UnapplyProfileRequest extends AbstractProfileRequest {
+
+ public UnapplyProfileRequest(Package umlPackage, Profile profile, TransactionalEditingDomain editingDomain) {
+ super(editingDomain, umlPackage, profile);
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/UnapplyStereotypeRequest.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/UnapplyStereotypeRequest.java
new file mode 100644
index 00000000000..6c37a93c218
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/requests/UnapplyStereotypeRequest.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.types.core.requests;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class UnapplyStereotypeRequest extends AbstractStereotypeRequest {
+
+ /**
+ * Constructor.
+ *
+ * @param umlPackage
+ * @param profile
+ * @param editingDomain
+ */
+ public UnapplyStereotypeRequest(Element umlElement, Stereotype stereotype, TransactionalEditingDomain editingDomain) {
+ super(editingDomain, umlElement, stereotype);
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/rules/AbstractUmlRule.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/rules/AbstractUmlRule.java
new file mode 100644
index 00000000000..1844c6d03be
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/rules/AbstractUmlRule.java
@@ -0,0 +1,94 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.rules;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType;
+import org.eclipse.papyrus.infra.types.rulebased.RuleConfiguration;
+import org.eclipse.papyrus.infra.types.rulebased.core.AbstractRule;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyProfileRequest;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyStereotypeRequest;
+import org.eclipse.papyrus.uml.types.core.requests.SetStereotypeValueRequest;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyProfileRequest;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyStereotypeRequest;
+
+public abstract class AbstractUmlRule<T extends RuleConfiguration> extends AbstractRule<T> {
+ protected T invariantRuleConfiguration;
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.rulebased.core.AbstractRule#approveRequest(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ public boolean approveRequest(IEditCommandRequest request) {
+
+ List<?> elementsToEdit = request.getElementsToEdit();
+ for (Object elementToEdit : elementsToEdit) {
+ if (elementToEdit instanceof EObject) {
+ IElementType[] types = ElementTypeRegistry.getInstance().getAllTypesMatching((EObject) elementToEdit, request.getClientContext());
+
+ for (IElementType type : types) {
+ if (type instanceof ConfiguredHintedSpecializationElementType) {
+ ConfiguredHintedSpecializationElementType configuredHintedSpecializationElementType = (ConfiguredHintedSpecializationElementType) type;
+ if (request instanceof ApplyStereotypeRequest) {
+ if (!approveApplyStereotypeRequest(configuredHintedSpecializationElementType, (ApplyStereotypeRequest) request)) {
+ return false;
+ }
+ } else if (request instanceof UnapplyStereotypeRequest) {
+ if (!approveUnapplyStereotypeRequest(configuredHintedSpecializationElementType, (UnapplyStereotypeRequest) request)) {
+ return false;
+ }
+ } else if (request instanceof ApplyProfileRequest) {
+ if (!approveApplyProfileRequest(configuredHintedSpecializationElementType, (ApplyProfileRequest) request)) {
+ return false;
+ }
+ } else if (request instanceof UnapplyProfileRequest) {
+ if (!approveUnapplyProfileRequest(configuredHintedSpecializationElementType, (UnapplyProfileRequest) request)) {
+ return false;
+ }
+ } else if (request instanceof SetStereotypeValueRequest) {
+ if (!approveSetStereotypeValueRequest(configuredHintedSpecializationElementType, (SetStereotypeValueRequest) request)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return super.approveRequest(request);
+ }
+
+ abstract protected boolean approveApplyStereotypeRequest(ConfiguredHintedSpecializationElementType type, ApplyStereotypeRequest request);
+
+ abstract protected boolean approveUnapplyStereotypeRequest(ConfiguredHintedSpecializationElementType type, UnapplyStereotypeRequest request);
+
+ abstract protected boolean approveApplyProfileRequest(ConfiguredHintedSpecializationElementType type, ApplyProfileRequest request);
+
+ abstract protected boolean approveUnapplyProfileRequest(ConfiguredHintedSpecializationElementType type, UnapplyProfileRequest request);
+
+ abstract protected boolean approveSetStereotypeValueRequest(ConfiguredHintedSpecializationElementType type, SetStereotypeValueRequest request);
+
+ @Override
+ public void init(T invariantRuleConfiguration) {
+ this.invariantRuleConfiguration = invariantRuleConfiguration;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/rules/invariantstereotype/InvariantStereotypeRule.java b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/rules/invariantstereotype/InvariantStereotypeRule.java
new file mode 100644
index 00000000000..66cc66477bc
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.types.core/src/org/eclipse/papyrus/uml/types/core/rules/invariantstereotype/InvariantStereotypeRule.java
@@ -0,0 +1,194 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.types.core.rules.invariantstereotype;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType;
+import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyProfileRequest;
+import org.eclipse.papyrus.uml.types.core.requests.ApplyStereotypeRequest;
+import org.eclipse.papyrus.uml.types.core.requests.SetStereotypeValueRequest;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyProfileRequest;
+import org.eclipse.papyrus.uml.types.core.requests.UnapplyStereotypeRequest;
+import org.eclipse.papyrus.uml.types.core.rules.AbstractUmlRule;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class InvariantStereotypeRule extends AbstractUmlRule<InvariantStereotypeRuleConfiguration> {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.rulebased.core.IRule#matches(org.eclipse.emf.ecore.EObject)
+ *
+ * @param eObject
+ * @return
+ */
+ public boolean matches(EObject eObject) {
+ if (!(eObject instanceof Element)) {
+ return false;
+ }
+
+ String stereotypeQualifiedName = invariantRuleConfiguration.getStereotypeQualifiedName();
+ if (stereotypeQualifiedName == null) { // to avoid null pointers
+ return false;
+ }
+ Stereotype appliedStereotype = ((Element) eObject).getAppliedStereotype(stereotypeQualifiedName);
+ if (appliedStereotype != null) { // one has been found, no need to get further
+ return true;
+ } else if (!invariantRuleConfiguration.isStrict()) { // the stereotype does not match perfectly, but one of the applied stereotypes on the element could match if not strict
+ for (Stereotype stereotype : ((Element) eObject).getAppliedStereotypes()) {
+ for (Stereotype superStereotype : StereotypeUtil.getAllSuperStereotypes(stereotype)) {
+ if (stereotypeQualifiedName.equals(superStereotype.getQualifiedName())) {
+ return true; // there is a match in the super stereotypes. Finish here, element matches
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.rulebased.core.AbstractRule#approveMoveRequest(org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType, org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest)
+ *
+ * @param type
+ * @param request
+ * @return
+ */
+ @Override
+ protected boolean approveMoveRequest(ConfiguredHintedSpecializationElementType type, MoveRequest request) {
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.rulebased.core.AbstractRule#approveSetRequest(org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType, org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest)
+ *
+ * @param type
+ * @param request
+ * @return
+ */
+ @Override
+ protected boolean approveSetRequest(ConfiguredHintedSpecializationElementType type, SetRequest request) {
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.types.rulebased.core.AbstractRule#approveCreationRequest(org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType, org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest)
+ *
+ * @param type
+ * @param request
+ * @return
+ */
+ @Override
+ protected boolean approveCreationRequest(ConfiguredHintedSpecializationElementType type, CreateElementRequest request) {
+ // check that the required profile is present.
+ String requiredProfileName = invariantRuleConfiguration.getRequiredProfile();
+ if (requiredProfileName != null) {
+ // check target
+ EObject container = request.getContainer();
+ if (!(container instanceof Element)) {
+ return false;
+ }
+ Package nearestPackage = ((Element) container).getNearestPackage();
+ if (nearestPackage == null) {
+ return false;
+ }
+ Profile appliedProfile = nearestPackage.getAppliedProfile(requiredProfileName, true);
+ return appliedProfile != null;
+ }
+
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.types.core.rules.AbstractUmlRule#approveApplyStereotypeRequest(org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType, org.eclipse.papyrus.uml.types.core.requests.ApplyStereotypeRequest)
+ *
+ * @param type
+ * @param request
+ * @return
+ */
+ @Override
+ protected boolean approveApplyStereotypeRequest(ConfiguredHintedSpecializationElementType type, ApplyStereotypeRequest request) {
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.types.core.rules.AbstractUmlRule#approveUnapplyStereotypeRequest(org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType, org.eclipse.papyrus.uml.types.core.requests.UnapplyStereotypeRequest)
+ *
+ * @param type
+ * @param request
+ * @return
+ */
+ @Override
+ protected boolean approveUnapplyStereotypeRequest(ConfiguredHintedSpecializationElementType type, UnapplyStereotypeRequest request) {
+
+ if (request.getStereotype().getQualifiedName().equals(this.invariantRuleConfiguration.getStereotypeQualifiedName())) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.types.core.rules.AbstractUmlRule#approveApplyProfileRequest(org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType, org.eclipse.papyrus.uml.types.core.requests.ApplyProfileRequest)
+ *
+ * @param type
+ * @param request
+ * @return
+ */
+ @Override
+ protected boolean approveApplyProfileRequest(ConfiguredHintedSpecializationElementType type, ApplyProfileRequest request) {
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.types.core.rules.AbstractUmlRule#approveUnapplyProfileRequest(org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType, org.eclipse.papyrus.uml.types.core.requests.UnapplyProfileRequest)
+ *
+ * @param type
+ * @param request
+ * @return
+ */
+ @Override
+ protected boolean approveUnapplyProfileRequest(ConfiguredHintedSpecializationElementType type, UnapplyProfileRequest request) {
+ String requiredProfileName = invariantRuleConfiguration.getRequiredProfile();
+
+ if (requiredProfileName.equals(request.getProfile().getQualifiedName())) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.types.core.rules.AbstractUmlRule#approveSetStereotypeValueRequest(org.eclipse.papyrus.infra.types.core.impl.ConfiguredHintedSpecializationElementType, org.eclipse.papyrus.uml.types.core.requests.SetStereotypeValueRequest)
+ *
+ * @param type
+ * @param request
+ * @return
+ */
+ @Override
+ protected boolean approveSetStereotypeValueRequest(ConfiguredHintedSpecializationElementType type, SetStereotypeValueRequest request) {
+ return true;
+ }
+
+}

Back to the top