1
2
3
4
5
6
7
8
9
10
11
12
13 package org.eclipse.papyrus.sysml14.service.types.command;
14
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.emf.common.util.EList;
19 import org.eclipse.gmf.runtime.common.core.command.CommandResult;
20 import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
21 import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
22 import org.eclipse.uml2.uml.Classifier;
23 import org.eclipse.uml2.uml.InstanceSpecification;
24 import org.eclipse.uml2.uml.Property;
25 import org.eclipse.uml2.uml.Slot;
26 import org.eclipse.uml2.uml.UMLPackage;
27
28
29
30
31
32
33
34 public class InstanceSpecificationWithSlotConfigureElementCommand extends ConfigureElementCommand {
35
36 private Classifier classifier;
37
38
39
40
41
42
43
44 public InstanceSpecificationWithSlotConfigureElementCommand(ConfigureRequest request,Classifier classifier) {
45 super(request);
46 this.classifier = classifier;
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60 @Override
61 protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
62 final InstanceSpecification instanceSpecification = (InstanceSpecification) getElementToEdit();
63 if (classifier != null){
64
65 instanceSpecification.getClassifiers().add(classifier);
66 EList<Property> attributes = classifier.getAttributes();
67
68 for (Property property : attributes) {
69 Slot slot = instanceSpecification.createSlot();
70 slot.createValue(property.getName(), property.getType(), UMLPackage.eINSTANCE.getLiteralString());
71 slot.setDefiningFeature(property);
72 }
73 }
74 return CommandResult.newOKCommandResult(instanceSpecification);
75 }
76
77 }