diff options
author | Pauline DEVILLE | 2017-01-19 13:19:45 +0000 |
---|---|---|
committer | Florian Noyrit | 2017-04-19 09:22:47 +0000 |
commit | f45a1c318287940a1aa794e1ca5bf4803f643666 (patch) | |
tree | fcb8bdfa15787de037a29f1a1f914b3da9ead7eb /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org | |
parent | d3739fa7daaed31c87750b64ce89ca9177a4f09a (diff) | |
download | org.eclipse.papyrus-f45a1c318287940a1aa794e1ca5bf4803f643666.tar.gz org.eclipse.papyrus-f45a1c318287940a1aa794e1ca5bf4803f643666.tar.xz org.eclipse.papyrus-f45a1c318287940a1aa794e1ca5bf4803f643666.zip |
Bug 509073 - [ActivityDiagram] Pin of ValueSpecificationAction should be
create and update automatically
Change-Id: Idcccff4b412ab74ec858a7e23733949190680b39
Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org')
10 files changed, 418 insertions, 30 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/InstanceSpecificationEditHelperAdvice.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/InstanceSpecificationEditHelperAdvice.java new file mode 100644 index 00000000000..2ef345e737f --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/InstanceSpecificationEditHelperAdvice.java @@ -0,0 +1,79 @@ +/***************************************************************************** + * Copyright (c) 2017 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.activity.edit.advices; + +import java.util.List; + +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.SetRequest; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.uml.diagram.activity.edit.commands.util.PinUpdateCommand; +import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.IPinUpdater; +import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.PinUpdaterFactory; +import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.preferences.AutomatedModelCompletionPreferencesInitializer; +import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.preferences.IAutomatedModelCompletionPreferencesConstants; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.tools.utils.ElementUtil; +import org.eclipse.papyrus.uml.tools.utils.PackageUtil; +import org.eclipse.uml2.uml.InstanceSpecification; +import org.eclipse.uml2.uml.InstanceValue; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.ValueSpecificationAction; + +/** + * + * Pin of ValueSpecificationAction should be create and update automatically + * + */ +public class InstanceSpecificationEditHelperAdvice extends AbstractEditHelperAdvice { + + /** + * @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 getAfterSetCommand(SetRequest request) { + // 1] check if the setFeature is classifier + if (request.getFeature().equals(UMLPackage.eINSTANCE.getInstanceSpecification_Classifier())) { + final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore(); + boolean synchronizePin = false; + InstanceSpecification instanceSpecification = (InstanceSpecification) request.getElementToEdit(); + // 1] get the preference for ValueSpecificationAction + synchronizePin = (prefStore.getString(IAutomatedModelCompletionPreferencesConstants.VALUE_SPECIFICATION_ACTION).equals(AutomatedModelCompletionPreferencesInitializer.PIN_SYNCHRONIZATION)); + // 2] check preference + if (synchronizePin) { + Package root = PackageUtil.getRootPackage(instanceSpecification); + if (root != null) { + // 3] get all ValueSpecificationAction + List<ValueSpecificationAction> allValueSpecificationAction = ElementUtil.getInstancesFilteredByType(root, ValueSpecificationAction.class, null); + // 4] loop into the list of ValueSpecificationAction + for (ValueSpecificationAction valueSpecificationAction : allValueSpecificationAction) { + if (valueSpecificationAction.getValue() instanceof InstanceValue) { + if (((InstanceValue) valueSpecificationAction.getValue()).getInstance() == instanceSpecification) { + // 5] call the command for the ValueSpecificationAction whose value is an instanceValue which referenced the instance specification + IPinUpdater<ValueSpecificationAction> updater = PinUpdaterFactory.getInstance().instantiate(valueSpecificationAction); + return new PinUpdateCommand<ValueSpecificationAction>("Update value specification action pins", updater, valueSpecificationAction); //$NON-NLS-1$ + } + } + } + } + } + } + return super.getAfterSetCommand(request); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/InstanceValueEditHelperAdvice.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/InstanceValueEditHelperAdvice.java new file mode 100644 index 00000000000..85cafa5c7bb --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/InstanceValueEditHelperAdvice.java @@ -0,0 +1,78 @@ +/***************************************************************************** + * Copyright (c) 2017 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.activity.edit.advices; + +import java.util.List; + +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.SetRequest; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.uml.diagram.activity.edit.commands.util.PinUpdateCommand; +import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.IPinUpdater; +import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.PinUpdaterFactory; +import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.preferences.AutomatedModelCompletionPreferencesInitializer; +import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.preferences.IAutomatedModelCompletionPreferencesConstants; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.tools.utils.ElementUtil; +import org.eclipse.papyrus.uml.tools.utils.PackageUtil; +import org.eclipse.uml2.uml.InstanceValue; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.ValueSpecificationAction; + +/** + * + * Pin of ValueSpecificationAction should be create and update automatically + * + */ +public class InstanceValueEditHelperAdvice extends AbstractEditHelperAdvice { + + /** + * @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 getAfterSetCommand(SetRequest request) { + // 1] check if the setFeature is instance + if (request.getFeature().equals(UMLPackage.eINSTANCE.getInstanceValue_Instance())) { + final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore(); + boolean synchronizePin = false; + // 2] get the preference for ValueSpecificationAction + synchronizePin = (prefStore.getString(IAutomatedModelCompletionPreferencesConstants.VALUE_SPECIFICATION_ACTION).equals(AutomatedModelCompletionPreferencesInitializer.PIN_SYNCHRONIZATION)); + // 3] check preference + if (synchronizePin) { + InstanceValue instanceValue = (InstanceValue) request.getElementToEdit(); + Package root = PackageUtil.getRootPackage(instanceValue); + if (root != null) { + // 4] get all ValueSpecificationAction + List<ValueSpecificationAction> allValueSpecificationAction = ElementUtil.getInstancesFilteredByType(root, ValueSpecificationAction.class, null); + // 5] loop into the list of ValueSpecificationAction + for (ValueSpecificationAction valueSpecificationAction : allValueSpecificationAction) { + if (valueSpecificationAction.getValue() instanceof InstanceValue) { + if (valueSpecificationAction.getValue() == instanceValue) { + // 6] call the command for the ValueSpecificationAction whose value is the instanceValue + IPinUpdater<ValueSpecificationAction> updater = PinUpdaterFactory.getInstance().instantiate(valueSpecificationAction); + return new PinUpdateCommand<ValueSpecificationAction>("Update value specification action pins", updater, valueSpecificationAction); //$NON-NLS-1$ + } + } + } + } + } + } + return super.getAfterSetCommand(request); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/ValueSpecificationActionEditHelperAdvice.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/ValueSpecificationActionEditHelperAdvice.java new file mode 100644 index 00000000000..00570308b4c --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/ValueSpecificationActionEditHelperAdvice.java @@ -0,0 +1,112 @@ +/*****************************************************************************
+ * 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.diagram.activity.edit.advices;
+
+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.SetRequest;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.uml.diagram.activity.edit.commands.util.ImportUMLPrimitiveTypePackageCommand;
+import org.eclipse.papyrus.uml.diagram.activity.edit.commands.util.PinUpdateCommand;
+import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.IPinUpdater;
+import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.PinUpdaterFactory;
+import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.UpdaterPinUtils;
+import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.preferences.AutomatedModelCompletionPreferencesInitializer;
+import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.preferences.IAutomatedModelCompletionPreferencesConstants;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.ValueSpecificationAction;
+
+/**
+ *
+ * Pin of ValueSpecificationAction should be create and update automatically
+ *
+ */
+public class ValueSpecificationActionEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeSetCommand(org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ protected ICommand getBeforeConfigureCommand(ConfigureRequest request) {
+ // 1] get the preference for ValueSpecificationAction
+ final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
+ boolean synchronizePin = (prefStore.getString(IAutomatedModelCompletionPreferencesConstants.VALUE_SPECIFICATION_ACTION).equals(AutomatedModelCompletionPreferencesInitializer.PIN_SYNCHRONIZATION));
+ // 2] check preference
+ if (synchronizePin) {
+ Package root = PackageUtil.getRootPackage((Element) request.getElementToConfigure());
+ if (!UpdaterPinUtils.isPrimitiveTypeLibraryImported(root)) {
+ // 3] call the command to import the UML primitive types package
+ return new ImportUMLPrimitiveTypePackageCommand("Import UML primitive type package", root); //$NON-NLS-1$
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterSetCommand(org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ protected ICommand getAfterSetCommand(SetRequest request) {
+ // 1] check if the setFeature is value
+ if (request.getFeature().equals(UMLPackage.eINSTANCE.getValueSpecificationAction_Value())) {
+ // 2] get the preference for ValueSpecificationAction
+ final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
+ boolean synchronizePin = (prefStore.getString(IAutomatedModelCompletionPreferencesConstants.VALUE_SPECIFICATION_ACTION).equals(AutomatedModelCompletionPreferencesInitializer.PIN_SYNCHRONIZATION));
+ // 3] check preference
+ if (synchronizePin) {
+ ValueSpecificationAction valueSpecificationAction = (ValueSpecificationAction) request.getElementToEdit();
+ if (valueSpecificationAction != null && request.getFeature() == UMLPackage.eINSTANCE.getValueSpecificationAction_Value()) {
+ // 4] call the command for the ValueSpecificationAction
+ IPinUpdater<ValueSpecificationAction> updater = PinUpdaterFactory.getInstance().instantiate(valueSpecificationAction);
+ return new PinUpdateCommand<ValueSpecificationAction>("Update value specification action pins", updater, valueSpecificationAction); //$NON-NLS-1$
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ protected ICommand getAfterConfigureCommand(ConfigureRequest request) {
+ // 1] get the preference for ValueSpecificationAction
+ final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
+ boolean synchronizePin = (prefStore.getString(IAutomatedModelCompletionPreferencesConstants.VALUE_SPECIFICATION_ACTION).equals(AutomatedModelCompletionPreferencesInitializer.PIN_SYNCHRONIZATION));
+ // 2] check preference
+ if (synchronizePin) {
+ ValueSpecificationAction valueSpecificationAction = (ValueSpecificationAction) request.getElementToConfigure();
+ if (valueSpecificationAction != null) {
+ // 3] call the command for the ValueSpecificationAction
+ return new PinUpdateCommand<ValueSpecificationAction>("Update value specification action pins", PinUpdaterFactory.getInstance().instantiate(valueSpecificationAction), valueSpecificationAction); //$NON-NLS-1$
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/AbstractActionPinUpdater.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/AbstractActionPinUpdater.java index 45d0d8b69f2..c36e5b42178 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/AbstractActionPinUpdater.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/AbstractActionPinUpdater.java @@ -14,19 +14,25 @@ package org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; +import org.eclipse.papyrus.uml.diagram.common.util.Util; import org.eclipse.uml2.uml.Action; import org.eclipse.uml2.uml.Activity; import org.eclipse.uml2.uml.ActivityEdge; import org.eclipse.uml2.uml.ActivityPartition; +import org.eclipse.uml2.uml.Classifier; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Model; import org.eclipse.uml2.uml.Package; import org.eclipse.uml2.uml.Pin; import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.uml2.uml.SignalEvent; import org.eclipse.uml2.uml.StructuredActivityNode; +import org.eclipse.uml2.uml.Trigger; import org.eclipse.uml2.uml.Type; /** @@ -93,4 +99,40 @@ public abstract class AbstractActionPinUpdater<NodeType extends Action> implemen } } } + + /** + * This method search the first classifier which is common of all classifiers + * + * @param classifiers + * @return return the first classifier which is common of all classifiers + */ + protected static Classifier getFirstCommonSuperClassifier(List<Classifier> classifiers) { + // 1] get super class of the first classifier of the list + List<Classifier> commonSuperClassifier = new ArrayList<>(Util.getAllSuperClasses(null, classifiers.get(0))); + commonSuperClassifier.add(classifiers.get(0)); + Set<Classifier> nonCommonClassifier = new HashSet<Classifier>(); + // 2] loop into classifiers + for (Classifier c : classifiers) { + // 3] loop into the list of the commonSuperClass + // put into nonCommonClassifier list all super classifier of c which is not in the commonSuperClass list + for (Classifier c2 : commonSuperClassifier) { + if (!(Util.getAllSuperClasses(null, c).contains(c2)) && (c != c2)) { + nonCommonClassifier.add(c2); + } + } + } + + // 4] remove all nonCommonClassifier from commonSuperClass + commonSuperClassifier.removeAll(nonCommonClassifier); + + // 5] Get the classifier which inherited of all common super class + for (Classifier classifier : commonSuperClassifier) { + List<Classifier> inheritedClassifier = new ArrayList<>(Util.getAllSuperClasses(null, classifier)); + inheritedClassifier.add(classifier); + if (inheritedClassifier.containsAll(commonSuperClassifier)) { + return classifier; + } + } + return null; + } }
\ No newline at end of file diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/PinUpdaterFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/PinUpdaterFactory.java index a4cb8cc8754..d2fca723e26 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/PinUpdaterFactory.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/PinUpdaterFactory.java @@ -19,6 +19,7 @@ import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.intermediatea import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.intermediateactions.AddStructuralFeatureValueActionPinUpdater;
import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.intermediateactions.CreateObjectActionPinUpdater;
import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.intermediateactions.ReadStructuralFeatureActionPinUpdater;
+import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.intermediateactions.ValueSpecificationActionPinUpdater;
import org.eclipse.uml2.uml.AcceptCallAction;
import org.eclipse.uml2.uml.AcceptEventAction;
import org.eclipse.uml2.uml.ActivityNode;
@@ -28,6 +29,7 @@ import org.eclipse.uml2.uml.CallOperationAction; import org.eclipse.uml2.uml.CreateObjectAction;
import org.eclipse.uml2.uml.ReadStructuralFeatureAction;
import org.eclipse.uml2.uml.SendSignalAction;
+import org.eclipse.uml2.uml.ValueSpecificationAction;
public class PinUpdaterFactory {
@@ -83,6 +85,8 @@ public class PinUpdaterFactory { updater = (IPinUpdater<T>) new AddStructuralFeatureValueActionPinUpdater();
} else if (node instanceof CreateObjectAction) {
updater = (IPinUpdater<T>) new CreateObjectActionPinUpdater();
+ } else if (node instanceof ValueSpecificationAction) {
+ updater = (IPinUpdater<T>) new ValueSpecificationActionPinUpdater();
}
return updater;
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/intermediateactions/AcceptEventActionPinUpdater.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/intermediateactions/AcceptEventActionPinUpdater.java index 005cdfbf1b8..70bb6877b47 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/intermediateactions/AcceptEventActionPinUpdater.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/intermediateactions/AcceptEventActionPinUpdater.java @@ -14,12 +14,9 @@ package org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.intermediateactions; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.AbstractActionPinUpdater; -import org.eclipse.papyrus.uml.diagram.common.util.Util; import org.eclipse.uml2.uml.AcceptEventAction; import org.eclipse.uml2.uml.Classifier; import org.eclipse.uml2.uml.Event; @@ -187,41 +184,22 @@ public class AcceptEventActionPinUpdater extends AbstractActionPinUpdater<Accept } /** - * Get the common ancestor supposing all triggers referenced a signalEvent + * Get the common ancestor * * @param triggers * @return */ private Classifier getTypeForMultipleTriggers(List<Trigger> triggers) { - if (!triggers.isEmpty()) { - // 1] get super class of the signal referencing by the first trigger - List<Classifier> commonSuperClass = new ArrayList<>(Util.getAllSuperClasses(null, ((SignalEvent) triggers.get(0).getEvent()).getSignal())); - commonSuperClass.add(((SignalEvent) triggers.get(0).getEvent()).getSignal()); - Set<Classifier> nonCommonClassifier = new HashSet<Classifier>(); - // 2] loop into triggers + List<Classifier> listOfClassifier = new ArrayList<>(); + // 1] check if all triggers reference a SignalEvent + if(!triggers.isEmpty()){ for (Trigger t : triggers) { - // 3] loop into the list of the commonSuperClass - // put into nonCommonClassifier list all super classifier of the signal referenced by the trigger - // which is not in the commonSuperClass list - for (Classifier c : commonSuperClass) { - if (!(Util.getAllSuperClasses(null, ((SignalEvent) t.getEvent()).getSignal()).contains(c)) && ((SignalEvent) t.getEvent()).getSignal() != c) { - nonCommonClassifier.add(c); - } - } - } - - // 4] remove all nonCommonClassifier from commonSuperClass - commonSuperClass.removeAll(nonCommonClassifier); - - // 5] Get the classifier which inherited of all common super class - for (Classifier classifier : commonSuperClass) { - List<Classifier> inheritedClassifier = new ArrayList<>(Util.getAllSuperClasses(null, classifier)); - inheritedClassifier.add(classifier); - if (inheritedClassifier.containsAll(commonSuperClass)) { - return classifier; + if (t.getEvent() instanceof SignalEvent) { + listOfClassifier.add(((SignalEvent) t.getEvent()).getSignal()); } } - + // 2] get common super classifier + return getFirstCommonSuperClassifier(listOfClassifier); } return null; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/intermediateactions/ValueSpecificationActionPinUpdater.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/intermediateactions/ValueSpecificationActionPinUpdater.java new file mode 100644 index 00000000000..df6968a622c --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/intermediateactions/ValueSpecificationActionPinUpdater.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.diagram.activity.edit.utils.updater.intermediateactions;
+
+import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.AbstractActionPinUpdater;
+import org.eclipse.uml2.uml.EnumerationLiteral;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.InstanceValue;
+import org.eclipse.uml2.uml.LiteralBoolean;
+import org.eclipse.uml2.uml.LiteralInteger;
+import org.eclipse.uml2.uml.LiteralReal;
+import org.eclipse.uml2.uml.LiteralString;
+import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
+import org.eclipse.uml2.uml.OutputPin;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.ValueSpecification;
+import org.eclipse.uml2.uml.ValueSpecificationAction;
+
+/**
+ *
+ * Pin of ValueSpecificationAction should be create and update automatically
+ *
+ */
+public class ValueSpecificationActionPinUpdater extends AbstractActionPinUpdater<ValueSpecificationAction> {
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.IPinUpdater#updatePins(org.eclipse.uml2.uml.ActivityNode)
+ *
+ * @param node
+ */
+ @Override
+ public void updatePins(ValueSpecificationAction node) {
+ // 1] create result pin if it is not created yet
+ if (node != null) {
+ OutputPin result = node.getResult();
+ if (result == null) {
+ result = UMLFactory.eINSTANCE.createOutputPin();
+ result.setLower(1);
+ result.setUpper(1);
+ result.setName("result"); //$NON-NLS-1$
+ }
+ // 2] type the result pin according to the value type
+ ValueSpecification valueSpecification = node.getValue();
+ if (valueSpecification != null) {
+ if (valueSpecification instanceof LiteralInteger) {
+ result.setType(this.getUMLPrimitiveType("Integer", valueSpecification.getModel())); //$NON-NLS-1$
+ } else if (valueSpecification instanceof LiteralUnlimitedNatural) {
+ result.setType(this.getUMLPrimitiveType("UnlimitedNatural", valueSpecification.getModel())); //$NON-NLS-1$
+ } else if (valueSpecification instanceof LiteralReal) {
+ result.setType(this.getUMLPrimitiveType("Real", valueSpecification.getModel())); //$NON-NLS-1$
+ } else if (valueSpecification instanceof LiteralString) {
+ result.setType(this.getUMLPrimitiveType("String", valueSpecification.getModel())); //$NON-NLS-1$
+ } else if (valueSpecification instanceof LiteralBoolean) {
+ result.setType(this.getUMLPrimitiveType("Boolean", valueSpecification.getModel())); //$NON-NLS-1$
+ } else if (valueSpecification instanceof InstanceValue) {
+ InstanceSpecification specification = ((InstanceValue) valueSpecification).getInstance();
+ if (specification != null) {
+ // 3] case EnumerationLiteral
+ // the result pin is typed by the enumeration owning the EnumerationLiteral
+ if (specification instanceof EnumerationLiteral) {
+ result.setType(((EnumerationLiteral) specification).getEnumeration());
+ } else {
+ // 4] case InstanceSpecification
+ // the result pin is typed by the classifier of the InstanceSpecification
+ // if there is more than one classifier the pin is typed by the common super classifer
+ if (specification.getClassifiers().size() == 1) {
+ result.setType(specification.getClassifiers().iterator().next());
+ } else if (specification.getClassifiers().size() > 1) {
+ result.setType(getFirstCommonSuperClassifier(specification.getClassifiers()));
+ }
+ }
+ }
+ }
+ }
+ node.setResult(result);
+ }
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/ActivityAutomatedModelCompletionPreferencePage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/ActivityAutomatedModelCompletionPreferencePage.java index 2d6797cc952..5ff9453f032 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/ActivityAutomatedModelCompletionPreferencePage.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/ActivityAutomatedModelCompletionPreferencePage.java @@ -24,6 +24,7 @@ import org.eclipse.uml2.uml.ActivityNode; import org.eclipse.uml2.uml.AddStructuralFeatureValueAction; import org.eclipse.uml2.uml.CreateObjectAction; import org.eclipse.uml2.uml.ReadStructuralFeatureAction; +import org.eclipse.uml2.uml.ValueSpecificationAction; /** * @@ -76,6 +77,7 @@ public class ActivityAutomatedModelCompletionPreferencePage extends AbstractAuto actionList.add(AddStructuralFeatureValueAction.class); actionList.add(CreateObjectAction.class); actionList.add(ReadStructuralFeatureAction.class); + actionList.add(ValueSpecificationAction.class); return actionList; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/AutomatedModelCompletionPreferencesInitializer.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/AutomatedModelCompletionPreferencesInitializer.java index f1efcedc320..e77d4a0ba30 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/AutomatedModelCompletionPreferencesInitializer.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/AutomatedModelCompletionPreferencesInitializer.java @@ -49,6 +49,7 @@ public class AutomatedModelCompletionPreferencesInitializer extends AbstractPref store.setDefault(IAutomatedModelCompletionPreferencesConstants.ADD_STRUCTURAL_FEATURE_VALUE_ACTION_ACCELERATOR, PIN_SYNCHRONIZATION); store.setDefault(IAutomatedModelCompletionPreferencesConstants.CREATE_OBJECT_ACTION_ACCELERATOR, PIN_SYNCHRONIZATION); store.setDefault(IAutomatedModelCompletionPreferencesConstants.READ_STRUCTURAL_FEATURE_ACTION_ACCELERATOR, PIN_SYNCHRONIZATION); + store.setDefault(IAutomatedModelCompletionPreferencesConstants.VALUE_SPECIFICATION_ACTION, PIN_SYNCHRONIZATION); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/IAutomatedModelCompletionPreferencesConstants.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/IAutomatedModelCompletionPreferencesConstants.java index 922ee7ed72b..ca39d698616 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/IAutomatedModelCompletionPreferencesConstants.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/utils/updater/preferences/IAutomatedModelCompletionPreferencesConstants.java @@ -29,4 +29,6 @@ public interface IAutomatedModelCompletionPreferencesConstants { final public String CREATE_OBJECT_ACTION_ACCELERATOR = "org.eclipse.papyrus.uml.diagram.activity.preferences.createObjectAction"; final public String READ_STRUCTURAL_FEATURE_ACTION_ACCELERATOR = "org.eclipse.papyrus.uml.diagram.activity.preferences.readStructuralFeatureAction"; + + final public String VALUE_SPECIFICATION_ACTION = "org.eclipse.papyrus.uml.diagram.activity.preferences.valueSpecificationAction"; } |