1 | package de.uka.ipd.sdq.pcm.gmf.allocation.helper; |
2 | |
3 | import java.util.ArrayList; |
4 | |
5 | import org.eclipse.emf.ecore.EReference; |
6 | import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; |
7 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
8 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
9 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
10 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
11 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
12 | import org.eclipse.ui.PlatformUI; |
13 | |
14 | import de.uka.ipd.sdq.pcm.allocation.AllocationPackage; |
15 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
16 | import de.uka.ipd.sdq.pcm.core.entity.EntityPackage; |
17 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
18 | |
19 | public class AllocationContextEditHelperAdvice |
20 | extends AbstractEditHelperAdvice { |
21 | |
22 | @Override |
23 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
24 | AssemblyContext resource = null; |
25 | |
26 | ArrayList<Object> filterList = new ArrayList<Object>(); |
27 | filterList.add(de.uka.ipd.sdq.pcm.system.System.class); |
28 | filterList.add(AssemblyContext.class); |
29 | |
30 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
31 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
32 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
33 | filterList, |
34 | additionalReferences, |
35 | request.getElementToConfigure().eResource().getResourceSet()); |
36 | dialog.setProvidedService(AssemblyContext.class); |
37 | dialog.open(); |
38 | if (dialog.getResult() == null) |
39 | return new CanceledCommand(); |
40 | if (!(dialog.getResult() instanceof AssemblyContext)) |
41 | return new CanceledCommand(); |
42 | resource = (AssemblyContext) dialog.getResult(); |
43 | |
44 | ICommand cmd = new SetValueCommand( |
45 | new SetRequest( |
46 | request.getElementToConfigure(), |
47 | AllocationPackage.eINSTANCE.getAllocationContext_AssemblyContext_AllocationContext(), |
48 | resource)); |
49 | |
50 | String allocationName = "Allocation_"+resource.getEntityName(); |
51 | if (resource.getEncapsulatedComponent__AssemblyContext() != null) |
52 | allocationName += " <"+resource.getEncapsulatedComponent__AssemblyContext().getEntityName()+">"; |
53 | |
54 | ICommand cmd2 = new SetValueCommand( |
55 | new SetRequest( |
56 | request.getElementToConfigure(), |
57 | EntityPackage.eINSTANCE.getNamedElement_EntityName(), |
58 | allocationName)); |
59 | |
60 | CompositeCommand cc = new CompositeCommand("Configure Allocation Context"); |
61 | cc.add(cmd); |
62 | cc.add(cmd2); |
63 | |
64 | return cc; |
65 | } |
66 | } |