1 | package de.uka.ipd.sdq.pcm.dialogs.resource; |
2 | |
3 | import java.util.ArrayList; |
4 | |
5 | import org.eclipse.emf.ecore.EObject; |
6 | import org.eclipse.emf.ecore.EReference; |
7 | import org.eclipse.emf.ecore.resource.ResourceSet; |
8 | import org.eclipse.gef.Request; |
9 | import org.eclipse.gef.commands.Command; |
10 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
11 | import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; |
12 | import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; |
13 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
14 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy; |
15 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
17 | import org.eclipse.gmf.runtime.notation.View; |
18 | import org.eclipse.ui.PlatformUI; |
19 | |
20 | import de.uka.ipd.sdq.pcm.core.PCMRandomVariable; |
21 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
22 | import de.uka.ipd.sdq.pcm.resourceenvironment.ProcessingResourceSpecification; |
23 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentPackage; |
24 | import de.uka.ipd.sdq.pcm.resourceenvironment.impl.ProcessingResourceSpecificationImpl; |
25 | import de.uka.ipd.sdq.pcm.resourcetype.ProcessingResourceType; |
26 | import de.uka.ipd.sdq.pcm.resourcetype.ResourceRepository; |
27 | |
28 | public class OpenActiveResourceSpecificationDialog extends OpenEditPolicy{ |
29 | |
30 | |
31 | @Override |
32 | protected Command getOpenCommand(Request request) { |
33 | ProcessingResourceSpecification specification = (ProcessingResourceSpecification)(((View) ((IGraphicalEditPart) getHost()).getModel()).getElement()); |
34 | ResourceSet set = (specification.getResourceContainer_ProcessingResourceSpecification()).eResource().getResourceSet(); |
35 | EObject resourceType = null; |
36 | ArrayList<Object> filterList = new ArrayList<Object>(); // positive filter |
37 | // Set types to show and their super types |
38 | filterList.add(ProcessingResourceType.class); |
39 | filterList.add(ResourceRepository.class); |
40 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
41 | // set EReference that should be set (in this case: active resource type) |
42 | additionalReferences.add(ResourceenvironmentPackage.eINSTANCE.getProcessingResourceSpecification_ActiveResourceType_ActiveResourceSpecification()); |
43 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
44 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
45 | filterList, |
46 | additionalReferences, |
47 | set); |
48 | dialog.setProvidedService(ProcessingResourceType.class); |
49 | dialog.open(); |
50 | if (dialog.getResult() == null) { |
51 | return null; |
52 | } |
53 | |
54 | if (!(dialog.getResult() instanceof ProcessingResourceType)){ |
55 | return null; |
56 | } |
57 | resourceType = (ProcessingResourceType) dialog.getResult(); |
58 | |
59 | |
60 | ICommand icmd = new SetValueCommand( |
61 | new SetRequest( |
62 | specification, |
63 | ResourceenvironmentPackage.eINSTANCE.getProcessingResourceSpecification_ActiveResourceType_ActiveResourceSpecification(), |
64 | resourceType)); |
65 | return new ICommandProxy(icmd); |
66 | } |
67 | |
68 | } |