1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.papyrus.sysml14.diagram.common.advices;
13
14
15
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import org.eclipse.core.runtime.OperationCanceledException;
20 import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
21 import org.eclipse.gmf.runtime.common.core.command.ICommand;
22 import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
23 import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
24 import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
25 import org.eclipse.jface.window.Window;
26 import org.eclipse.papyrus.sysml14.diagram.common.command.ConfigurePartCommand;
27 import org.eclipse.papyrus.sysml14.diagram.common.dialog.CreateOrSelectValuePropertyTypeDialog;
28 import org.eclipse.papyrus.sysml14.service.types.advice.AfterConfigureCommandEditHelperAdvice;
29 import org.eclipse.papyrus.uml.diagram.common.dialogs.CreateOrSelectTypeDialog;
30 import org.eclipse.swt.widgets.Display;
31 import org.eclipse.swt.widgets.Shell;
32 import org.eclipse.uml2.uml.Package;
33 import org.eclipse.uml2.uml.Property;
34 import org.eclipse.uml2.uml.Type;
35
36
37
38
39
40
41
42 public class ValueEditHelperAdvice extends AbstractEditHelperAdvice {
43
44
45
46
47
48
49
50 @Override
51 protected ICommand getBeforeConfigureCommand(ConfigureRequest request) {
52 configureRequest(request);
53 return super.getBeforeConfigureCommand(request);
54 }
55
56
57
58
59 protected void configureRequest(ConfigureRequest request) {
60 Map<String, Object> newParameters = new HashMap<String, Object>();
61
62 ICommand configureCommand = null;
63
64 Shell shell = Display.getDefault().getActiveShell();
65 Property property = (Property) request.getElementToConfigure();
66 Package owner = property.getNearestPackage();
67
68 CreateOrSelectTypeDialog dialog = new CreateOrSelectValuePropertyTypeDialog(shell, owner);
69
70 dialog.open();
71 if (dialog.getReturnCode() == Window.OK) {
72
73 final ICommand typeCreationCommand = dialog.getNewTypeCreateCommand();
74 final Type partType = (Type) dialog.getExistingType();
75
76
77 if ((typeCreationCommand != null) && (!typeCreationCommand.canExecute())) {
78 configureCommand = UnexecutableCommand.INSTANCE;
79 } else {
80 configureCommand = CompositeCommand.compose(configureCommand, typeCreationCommand);
81 }
82
83
84 ICommand setTypeCommand = new ConfigurePartCommand(request,partType,typeCreationCommand) ;
85 configureCommand = CompositeCommand.compose(configureCommand, setTypeCommand);
86 } else {
87 throw new OperationCanceledException("Value creation cancelled by user");
88 }
89
90 newParameters.put(AfterConfigureCommandEditHelperAdvice.AFTER_CONFIGURE_COMMAND, configureCommand);
91 request.addParameters(newParameters);
92 }
93 }