Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-05-03 09:49:38 +0000
committervlorenzo2012-05-03 09:49:38 +0000
commitea2da33ffcbb7e6d94ac8a9dd46a70c177264770 (patch)
tree55b040c358137ba0f9c263a32f1c668998c2e675
parent363991fd8683647836de4e9e16d1892ec5692f6e (diff)
downloadorg.eclipse.papyrus-ea2da33ffcbb7e6d94ac8a9dd46a70c177264770.tar.gz
org.eclipse.papyrus-ea2da33ffcbb7e6d94ac8a9dd46a70c177264770.tar.xz
org.eclipse.papyrus-ea2da33ffcbb7e6d94ac8a9dd46a70c177264770.zip
342163: [Usability] Papyrus merge should use the service edit of Papyrus
https://bugs.eclipse.org/bugs/show_bug.cgi?id=342163 Add the command to add an EObject to a resource
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddToResourceCommand.java102
1 files changed, 102 insertions, 0 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddToResourceCommand.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddToResourceCommand.java
new file mode 100644
index 00000000000..b24bdf111c6
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddToResourceCommand.java
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.commands;
+
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+
+/**
+ *
+ * This command allows to add an EObject to a resource
+ *
+ */
+public class AddToResourceCommand extends AbstractCommand {
+
+ /**
+ * the resource
+ */
+ private final Resource resource;
+
+ /**
+ * the object to add to the resource
+ */
+ private final EObject toAdd;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param resource
+ * the resource
+ * @param toAdd
+ * the objectto add to the resource
+ */
+ public AddToResourceCommand(final Resource resource, final EObject toAdd) {
+ this.resource = resource;
+ this.toAdd = toAdd;
+ setLabel("Add an object to a resource");
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.common.command.Command#execute()
+ *
+ */
+ public void execute() {
+ this.resource.getContents().add(this.toAdd);
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.common.command.Command#redo()
+ *
+ */
+ public void redo() {
+ execute();
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.common.command.AbstractCommand#prepare()
+ *
+ * @return
+ */
+ @Override
+ protected boolean prepare() {
+ return true;
+ };
+
+
+ /**
+ *
+ * @see org.eclipse.emf.common.command.AbstractCommand#undo()
+ *
+ */
+ @Override
+ public void undo() {
+ this.resource.getContents().remove(this.toAdd);
+ };
+
+ /**
+ *
+ * @see org.eclipse.emf.common.command.AbstractCommand#canExecute()
+ *
+ * @return
+ */
+ @Override
+ public boolean canExecute() {
+ return super.canExecute() && this.resource != null;
+ }
+}

Back to the top