blob: dd326bf19aaf09391a75fe28a16911535c03df82 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*****************************************************************************
* Copyright (c) 2010 CEA
*
*
* 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:
* Soyatec - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.command;
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.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.uml.diagram.sequence.edit.commands.InteractionUseCreateCommand;
import org.eclipse.papyrus.uml.diagram.sequence.providers.ElementInitializers;
import org.eclipse.uml2.uml.Interaction;
import org.eclipse.uml2.uml.InteractionOperand;
import org.eclipse.uml2.uml.InteractionUse;
import org.eclipse.uml2.uml.UMLFactory;
/**
* @author Jin Liu (jin.liu@soyatec.com)
*/
public class CustomInteractionUseCreateCommand extends InteractionUseCreateCommand {
/**
* Constructor.
*
* @param req
* @param eObject
*/
public CustomInteractionUseCreateCommand(CreateElementRequest req, EObject eObject, Diagram diagram) {
super(req, eObject, diagram);
}
/**
* Constructor.
*
* @param req
*/
public CustomInteractionUseCreateCommand(CreateElementRequest req, Diagram diagram) {
super(req, diagram);
}
/**
* The creation command can only be executed if the elementToEdit (i.e the container) is an Interaction or an InteractionOperand
*
* @Override
*/
@Override
public boolean canExecute() {
return getElementToEdit() instanceof Interaction || getElementToEdit() instanceof InteractionOperand;
}
/**
* Handle creation on InteractionOperand
*
* @Override
*/
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
InteractionUse newElement = UMLFactory.eINSTANCE.createInteractionUse();
EObject elementToEdit = getElementToEdit();
if(elementToEdit instanceof InteractionOperand) {
InteractionOperand owner = (InteractionOperand)elementToEdit;
owner.getFragments().add(newElement);
} else {
Interaction owner = (Interaction)elementToEdit;
owner.getFragments().add(newElement);
}
ElementInitializers.getInstance().init_InteractionUse_3002(newElement);
doConfigure(newElement, monitor, info);
((CreateElementRequest)getRequest()).setNewElement(newElement);
return CommandResult.newOKCommandResult(newElement);
}
}
|