1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.helper; |
5 | |
6 | import java.util.ArrayList; |
7 | |
8 | import org.eclipse.emf.ecore.EObject; |
9 | import org.eclipse.emf.ecore.EReference; |
10 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
11 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
13 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
14 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
16 | import org.eclipse.ui.PlatformUI; |
17 | |
18 | import com.sun.corba.se.spi.activation.Repository; |
19 | |
20 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
21 | import de.uka.ipd.sdq.pcm.repository.BasicComponent; |
22 | import de.uka.ipd.sdq.pcm.repository.PassiveResource; |
23 | import de.uka.ipd.sdq.pcm.seff.SeffPackage; |
24 | |
25 | /** |
26 | * @author admin |
27 | * |
28 | */ |
29 | public class AcquireActionEditHelperAdvice extends AbstractEditHelperAdvice |
30 | implements IEditHelperAdvice { |
31 | |
32 | /* (non-Javadoc) |
33 | * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest) |
34 | */ |
35 | @Override |
36 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
37 | EObject resource = null; |
38 | ArrayList<Object> filterList = new ArrayList<Object>(); |
39 | filterList.add(Repository.class); |
40 | filterList.add(BasicComponent.class); |
41 | filterList.add(PassiveResource.class); |
42 | |
43 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
44 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
45 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
46 | filterList, |
47 | additionalReferences, |
48 | searchBasicComponent(request.getElementToConfigure())); |
49 | dialog.setProvidedService(PassiveResource.class); |
50 | dialog.open(); |
51 | if (dialog.getResult() == null) |
52 | return new CanceledCommand(); |
53 | if (!(dialog.getResult() instanceof PassiveResource)) |
54 | return new CanceledCommand(); |
55 | resource = (PassiveResource) dialog.getResult(); |
56 | |
57 | ICommand cmd = new SetValueCommand( |
58 | new SetRequest( |
59 | request.getElementToConfigure(), |
60 | SeffPackage.eINSTANCE.getAcquireAction_Passiveresource_AcquireAction(), |
61 | resource)); |
62 | return cmd; |
63 | } |
64 | |
65 | private EObject searchBasicComponent(EObject elementToConfigure) { |
66 | EObject o = elementToConfigure; |
67 | while (!(o instanceof BasicComponent)) |
68 | o = o.eContainer(); |
69 | return o; |
70 | } |
71 | |
72 | } |