Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/deprecated-plugins/uml.deprecated/org.eclipse.papyrus.diagram.sequence/src/org/eclipse/papyrus/diagram/sequence/edit/commands/ElementOwnedCommentCreateCommand.java')
-rw-r--r--extraplugins/deprecated-plugins/uml.deprecated/org.eclipse.papyrus.diagram.sequence/src/org/eclipse/papyrus/diagram/sequence/edit/commands/ElementOwnedCommentCreateCommand.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/extraplugins/deprecated-plugins/uml.deprecated/org.eclipse.papyrus.diagram.sequence/src/org/eclipse/papyrus/diagram/sequence/edit/commands/ElementOwnedCommentCreateCommand.java b/extraplugins/deprecated-plugins/uml.deprecated/org.eclipse.papyrus.diagram.sequence/src/org/eclipse/papyrus/diagram/sequence/edit/commands/ElementOwnedCommentCreateCommand.java
new file mode 100644
index 00000000000..9d7273d1795
--- /dev/null
+++ b/extraplugins/deprecated-plugins/uml.deprecated/org.eclipse.papyrus.diagram.sequence/src/org/eclipse/papyrus/diagram/sequence/edit/commands/ElementOwnedCommentCreateCommand.java
@@ -0,0 +1,104 @@
+package org.eclipse.papyrus.diagram.sequence.edit.commands;
+
+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.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Model;
+
+import org.eclipse.papyrus.diagram.sequence.edit.policies.UMLBaseItemSemanticEditPolicy;
+
+/**
+ * @generated
+ */
+public class ElementOwnedCommentCreateCommand extends EditElementCommand {
+
+ /**
+ * @generated
+ */
+ private final EObject source;
+
+ /**
+ * @generated
+ */
+ private final EObject target;
+
+ /**
+ * @generated
+ */
+ public ElementOwnedCommentCreateCommand(CreateRelationshipRequest request,
+ EObject source, EObject target) {
+ super(request.getLabel(), null, request);
+ this.source = source;
+ this.target = target;
+ }
+
+ /**
+ * @generated
+ */
+ @Override
+ public boolean canExecute() {
+ if (source == null && target == null) {
+ return false;
+ }
+ if (source != null && false == source instanceof Element) {
+ return false;
+ }
+ if (target != null && false == target instanceof Comment) {
+ return false;
+ }
+ if (getSource() == null) {
+ return true; // link creation is in progress; source is not defined yet
+ }
+ // target may be null here but it's possible to check constraint
+ return UMLBaseItemSemanticEditPolicy.LinkConstraints
+ .canCreateElementOwnedComment_3007(getSource(), getTarget());
+ }
+
+ /**
+ * @generated not
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
+ IAdaptable info) throws ExecutionException {
+ if (!canExecute()) {
+ throw new ExecutionException(
+ "Invalid arguments in create link command"); //$NON-NLS-1$
+ }
+ if (getSource() != null && getTarget() != null) {
+ getSource().getOwnedComments().add(getTarget());
+
+ // add the Element to the annotatedElement relation of the Comment
+ getTarget().getAnnotatedElements().add(getSource());
+
+ // check the parent of the comment. If has not elements in
+ // annotatedElement relation, the parent will be this Element; if
+ // has more than one element, the parent will be the model
+ if (getTarget().getAnnotatedElements().size() > 1) {
+ Model root = (Model) getSource().eResource().getContents().get(
+ 0);
+ root.getOwnedComments().add(getTarget());
+ }
+ }
+ return CommandResult.newOKCommandResult();
+ }
+
+ /**
+ * @generated
+ */
+ protected Element getSource() {
+ return (Element) source;
+ }
+
+ /**
+ * @generated
+ */
+ protected Comment getTarget() {
+ return (Comment) target;
+ }
+}

Back to the top