Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-09-19 07:50:25 +0000
committercletavernie2012-09-19 07:50:25 +0000
commit7c71eb917aaae478ad8a7c8ca4dfdf3f9a503b0a (patch)
tree6762d86a67998ec5f317b54c38e1e77e43450c3e
parentf2093f1c9f2613a9bc7b402b3a4289364ece753a (diff)
downloadorg.eclipse.papyrus-7c71eb917aaae478ad8a7c8ca4dfdf3f9a503b0a.tar.gz
org.eclipse.papyrus-7c71eb917aaae478ad8a7c8ca4dfdf3f9a503b0a.tar.xz
org.eclipse.papyrus-7c71eb917aaae478ad8a7c8ca4dfdf3f9a503b0a.zip
389865: [Profiles] Invalid implementation of the profile/stereotype application commands
https://bugs.eclipse.org/bugs/show_bug.cgi?id=389865
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/model/ProfileApplicationModel.java22
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeApplicationObservableList.java9
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java37
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyStereotypeCommand.java33
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyProfileCommand.java37
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyStereotypeCommand.java33
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java9
7 files changed, 69 insertions, 111 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/model/ProfileApplicationModel.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/model/ProfileApplicationModel.java
index 43915ad3065..b6abff25bd8 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/model/ProfileApplicationModel.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/model/ProfileApplicationModel.java
@@ -14,13 +14,16 @@ package org.eclipse.papyrus.uml.profile.model;
import java.util.Collection;
import java.util.Map;
+import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.infra.core.resource.IModelSetSnippet;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.infra.core.resource.uml.UmlModel;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.uml.profile.Activator;
import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
import org.eclipse.papyrus.uml.tools.utils.ProfileUtil;
import org.eclipse.swt.widgets.Display;
@@ -42,6 +45,9 @@ public class ProfileApplicationModel implements IModelSetSnippet {
public void start(ModelSet modelsManager) {
UmlModel umlModel = (UmlModel)modelsManager.getModel(UmlModel.MODEL_ID);
+ if(umlModel == null) {
+ return;
+ }
rootPackage = getRootPackage(umlModel);
@@ -50,6 +56,7 @@ public class ProfileApplicationModel implements IModelSetSnippet {
}
checkAndRefreshProfiles(rootPackage);
+
}
protected Package getRootPackage(UmlModel umlModel) {
@@ -90,11 +97,20 @@ public class ProfileApplicationModel implements IModelSetSnippet {
public void run() {
Map<Package, Collection<Profile>> profilesToReapply = dialog.getProfilesToReapply();
- for(Map.Entry<Package, Collection<Profile>> profiles : profilesToReapply.entrySet()) {
- ApplyProfileCommand command = new ApplyProfileCommand(profiles.getKey(), profiles.getValue());
- EditingDomain domain = EMFHelper.resolveEditingDomain(rootPackage);
+ EditingDomain domain = EMFHelper.resolveEditingDomain(rootPackage);
+
+ if(domain instanceof TransactionalEditingDomain) {
+ CompoundCommand command = new CompoundCommand();
+
+ for(Map.Entry<Package, Collection<Profile>> profiles : profilesToReapply.entrySet()) {
+ command.append(new ApplyProfileCommand(profiles.getKey(), profiles.getValue(), (TransactionalEditingDomain)domain));
+ }
+
domain.getCommandStack().execute(command);
+ } else {
+ Activator.log.error(new IllegalArgumentException("Cannot reapply profiles on Package " + rootPackage.getQualifiedName() + ". The EditingDomain cannot be found"));
}
+
}
};
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeApplicationObservableList.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeApplicationObservableList.java
index 46ab8c8e72d..49e65474e3a 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeApplicationObservableList.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeApplicationObservableList.java
@@ -22,6 +22,7 @@ import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
import org.eclipse.papyrus.uml.tools.commands.ApplyStereotypeCommand;
@@ -196,7 +197,7 @@ public class StereotypeApplicationObservableList extends WritableList implements
return false;
}
Stereotype stereotype = (Stereotype)o;
- Command command = new ApplyStereotypeCommand(umlSource, stereotype);
+ Command command = new ApplyStereotypeCommand(umlSource, stereotype, (TransactionalEditingDomain)domain);
commands.add(command);
@@ -211,7 +212,7 @@ public class StereotypeApplicationObservableList extends WritableList implements
}
final Stereotype stereotype = (Stereotype)o;
- Command command = new UnapplyStereotypeCommand(umlSource, stereotype);
+ Command command = new UnapplyStereotypeCommand(umlSource, stereotype, (TransactionalEditingDomain)domain);
commands.add(command);
@@ -224,7 +225,7 @@ public class StereotypeApplicationObservableList extends WritableList implements
//We only apply the stereotypes that are not applied yet (To avoid removing them when undo is called)
c.removeAll(wrappedList);
- Command command = new ApplyStereotypeCommand(umlSource, c);
+ Command command = new ApplyStereotypeCommand(umlSource, c, (TransactionalEditingDomain)domain);
commands.add(command);
@@ -233,7 +234,7 @@ public class StereotypeApplicationObservableList extends WritableList implements
@Override
public boolean removeAll(Collection c) {
- Command command = new UnapplyStereotypeCommand(umlSource, c);
+ Command command = new UnapplyStereotypeCommand(umlSource, c, (TransactionalEditingDomain)domain);
commands.add(command);
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java
index 82e27e03b97..45e402d2edf 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java
@@ -14,7 +14,8 @@ package org.eclipse.papyrus.uml.tools.commands;
import java.util.Collection;
import java.util.Collections;
-import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Profile;
@@ -23,7 +24,7 @@ import org.eclipse.uml2.uml.Profile;
*
* @author Camille Letavernier
*/
-public class ApplyProfileCommand extends AbstractCommand {
+public class ApplyProfileCommand extends RecordingCommand {
private Package umlPackage;
@@ -37,8 +38,11 @@ public class ApplyProfileCommand extends AbstractCommand {
* The UML Package on which the profiles will be applied
* @param profiles
* The list of profiles to apply
+ * @param editingDomain
+ * The EditingDomain
*/
- public ApplyProfileCommand(Package umlPackage, Collection<Profile> profiles) {
+ public ApplyProfileCommand(Package umlPackage, Collection<Profile> profiles, TransactionalEditingDomain editingDomain) {
+ super(editingDomain);
this.umlPackage = umlPackage;
this.profiles = profiles;
}
@@ -51,37 +55,20 @@ public class ApplyProfileCommand extends AbstractCommand {
* The UML Package on which the profile will be applied
* @param profile
* The profile to apply
+ * @param editingDomain
+ * The EditingDomain
*/
- public ApplyProfileCommand(Package umlPackage, Profile profile) {
+ public ApplyProfileCommand(Package umlPackage, Profile profile, TransactionalEditingDomain editingDomain) {
+ super(editingDomain);
this.umlPackage = umlPackage;
this.profiles = Collections.singletonList(profile);
}
@Override
- public boolean canExecute() {
- return true;
- }
-
- public void execute() {
+ protected void doExecute() {
for(Profile profile : profiles) {
umlPackage.applyProfile(profile);
}
}
- @Override
- public boolean canUndo() {
- return true;
- }
-
- @Override
- public void undo() {
- for(Profile profile : profiles) {
- umlPackage.unapplyProfile(profile);
- }
- }
-
- public void redo() {
- execute();
- }
-
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyStereotypeCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyStereotypeCommand.java
index ff9a4d83039..f0d38ffa1ae 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyStereotypeCommand.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyStereotypeCommand.java
@@ -14,7 +14,8 @@ package org.eclipse.papyrus.uml.tools.commands;
import java.util.Collection;
import java.util.Collections;
-import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Stereotype;
@@ -23,7 +24,7 @@ import org.eclipse.uml2.uml.Stereotype;
*
* @author Camille Letavernier
*/
-public class ApplyStereotypeCommand extends AbstractCommand {
+public class ApplyStereotypeCommand extends RecordingCommand {
private Element element;
@@ -38,7 +39,8 @@ public class ApplyStereotypeCommand extends AbstractCommand {
* @param stereotypes
* The stereotypes to apply
*/
- public ApplyStereotypeCommand(Element element, Collection<Stereotype> stereotypes) {
+ public ApplyStereotypeCommand(Element element, Collection<Stereotype> stereotypes, TransactionalEditingDomain domain) {
+ super(domain);
this.element = element;
this.stereotypes = stereotypes;
}
@@ -52,36 +54,17 @@ public class ApplyStereotypeCommand extends AbstractCommand {
* @param stereotype
* The stereotypes to apply
*/
- public ApplyStereotypeCommand(Element element, Stereotype stereotype) {
+ public ApplyStereotypeCommand(Element element, Stereotype stereotype, TransactionalEditingDomain domain) {
+ super(domain);
this.element = element;
this.stereotypes = Collections.singletonList(stereotype);
}
@Override
- public boolean canExecute() {
- return true;
- }
-
- public void execute() {
+ protected void doExecute() {
for(Stereotype stereotype : stereotypes) {
element.applyStereotype(stereotype);
}
}
- @Override
- public boolean canUndo() {
- return true;
- }
-
- @Override
- public void undo() {
- for(Stereotype stereotype : stereotypes) {
- element.unapplyStereotype(stereotype);
- }
- }
-
- public void redo() {
- execute();
- }
-
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyProfileCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyProfileCommand.java
index d6a23fa0c1c..eeef5a84ff6 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyProfileCommand.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyProfileCommand.java
@@ -14,7 +14,8 @@ package org.eclipse.papyrus.uml.tools.commands;
import java.util.Collection;
import java.util.Collections;
-import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Profile;
@@ -23,7 +24,7 @@ import org.eclipse.uml2.uml.Profile;
*
* @author Camille Letavernier
*/
-public class UnapplyProfileCommand extends AbstractCommand {
+public class UnapplyProfileCommand extends RecordingCommand {
private Package umlPackage;
@@ -37,8 +38,11 @@ public class UnapplyProfileCommand extends AbstractCommand {
* The UML Package from which the profiles will be unapplied
* @param profiles
* The list of profiles to unapply
+ * @param domain
+ * The EditingDomain
*/
- public UnapplyProfileCommand(Package umlPackage, Collection<Profile> profiles) {
+ public UnapplyProfileCommand(Package umlPackage, Collection<Profile> profiles, TransactionalEditingDomain domain) {
+ super(domain);
this.umlPackage = umlPackage;
this.profiles = profiles;
}
@@ -51,36 +55,19 @@ public class UnapplyProfileCommand extends AbstractCommand {
* The UML Package from which the profile will be unapplied
* @param profile
* The profile to unapply
+ * @param domain
+ * The EditingDomain
*/
- public UnapplyProfileCommand(Package umlPackage, Profile profile) {
+ public UnapplyProfileCommand(Package umlPackage, Profile profile, TransactionalEditingDomain domain) {
+ super(domain);
this.umlPackage = umlPackage;
this.profiles = Collections.singletonList(profile);
}
@Override
- public boolean canExecute() {
- return true;
- }
-
- public void execute() {
+ protected void doExecute() {
for(Profile profile : profiles) {
umlPackage.unapplyProfile(profile);
}
}
-
- @Override
- public boolean canUndo() {
- return true;
- }
-
- @Override
- public void undo() {
- for(Profile profile : profiles) {
- umlPackage.applyProfile(profile);
- }
- }
-
- public void redo() {
- execute();
- }
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyStereotypeCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyStereotypeCommand.java
index cc7cd53a5ca..7132dfa015f 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyStereotypeCommand.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UnapplyStereotypeCommand.java
@@ -14,7 +14,8 @@ package org.eclipse.papyrus.uml.tools.commands;
import java.util.Collection;
import java.util.Collections;
-import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Stereotype;
@@ -23,7 +24,7 @@ import org.eclipse.uml2.uml.Stereotype;
*
* @author Camille Letavernier
*/
-public class UnapplyStereotypeCommand extends AbstractCommand {
+public class UnapplyStereotypeCommand extends RecordingCommand {
private Element element;
@@ -38,7 +39,8 @@ public class UnapplyStereotypeCommand extends AbstractCommand {
* @param stereotypes
* The stereotypes to unapply
*/
- public UnapplyStereotypeCommand(Element element, Collection<Stereotype> stereotypes) {
+ public UnapplyStereotypeCommand(Element element, Collection<Stereotype> stereotypes, TransactionalEditingDomain domain) {
+ super(domain);
this.element = element;
this.stereotypes = stereotypes;
}
@@ -52,36 +54,17 @@ public class UnapplyStereotypeCommand extends AbstractCommand {
* @param stereotype
* The stereotype to unapply
*/
- public UnapplyStereotypeCommand(Element element, Stereotype stereotype) {
+ public UnapplyStereotypeCommand(Element element, Stereotype stereotype, TransactionalEditingDomain domain) {
+ super(domain);
this.element = element;
this.stereotypes = Collections.singletonList(stereotype);
}
@Override
- public boolean canExecute() {
- return true;
- }
-
- public void execute() {
+ protected void doExecute() {
for(Stereotype stereotype : stereotypes) {
element.unapplyStereotype(stereotype);
}
}
- @Override
- public boolean canUndo() {
- return true;
- }
-
- @Override
- public void undo() {
- for(Stereotype stereotype : stereotypes) {
- element.applyStereotype(stereotype);
- }
- }
-
- public void redo() {
- execute();
- }
-
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java
index 4aaa16ff532..ebebb793dfc 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java
@@ -22,6 +22,7 @@ import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
@@ -209,7 +210,7 @@ public class ProfileApplicationObservableList extends WritableList implements IC
}
Profile profile = (Profile)o;
- Command command = new ApplyProfileCommand(umlSource, profile);
+ Command command = new ApplyProfileCommand(umlSource, profile, (TransactionalEditingDomain)domain);
commands.add(command);
@@ -227,7 +228,7 @@ public class ProfileApplicationObservableList extends WritableList implements IC
}
final Profile profile = (Profile)o;
- Command command = new UnapplyProfileCommand(umlSource, profile);
+ Command command = new UnapplyProfileCommand(umlSource, profile, (TransactionalEditingDomain)domain);
commands.add(command);
@@ -242,7 +243,7 @@ public class ProfileApplicationObservableList extends WritableList implements IC
//We only apply the profiles that are not applied yet (To avoid removing them when undo is called)
c.removeAll(wrappedList);
- Command command = new ApplyProfileCommand(umlSource, c);
+ Command command = new ApplyProfileCommand(umlSource, c, (TransactionalEditingDomain)domain);
commands.add(command);
@@ -254,7 +255,7 @@ public class ProfileApplicationObservableList extends WritableList implements IC
*/
@Override
public boolean removeAll(Collection c) {
- Command command = new UnapplyProfileCommand(umlSource, c);
+ Command command = new UnapplyProfileCommand(umlSource, c, (TransactionalEditingDomain)domain);
commands.add(command);

Back to the top