| 1 | package de.uka.ipd.sdq.pcm.gmf.repository.helper; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | |
| 5 | import org.eclipse.core.commands.ExecutionException; |
| 6 | import org.eclipse.core.runtime.IAdaptable; |
| 7 | import org.eclipse.core.runtime.IProgressMonitor; |
| 8 | import org.eclipse.emf.ecore.EObject; |
| 9 | import org.eclipse.emf.ecore.EReference; |
| 10 | import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
| 11 | import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; |
| 12 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
| 13 | import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand; |
| 14 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
| 15 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
| 16 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
| 17 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
| 18 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
| 19 | import org.eclipse.ui.PlatformUI; |
| 20 | |
| 21 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
| 22 | import de.uka.ipd.sdq.pcm.repository.Interface; |
| 23 | import de.uka.ipd.sdq.pcm.repository.ProvidedRole; |
| 24 | import de.uka.ipd.sdq.pcm.repository.RepositoryPackage; |
| 25 | import de.uka.ipd.sdq.pcm.repository.Signature; |
| 26 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF; |
| 27 | import de.uka.ipd.sdq.pcm.seff.SeffFactory; |
| 28 | import de.uka.ipd.sdq.pcm.seff.SeffPackage; |
| 29 | import de.uka.ipd.sdq.pcm.seff.StartAction; |
| 30 | import de.uka.ipd.sdq.pcm.seff.StopAction; |
| 31 | |
| 32 | class ConfigureSEFFCommand extends ConfigureElementCommand { |
| 33 | private ConfigureRequest myRequest; |
| 34 | |
| 35 | public ConfigureSEFFCommand(ConfigureRequest request) { |
| 36 | super(request); |
| 37 | myRequest = request; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
| 42 | IAdaptable info) throws ExecutionException { |
| 43 | |
| 44 | ResourceDemandingSEFF seff = (ResourceDemandingSEFF) myRequest.getElementToConfigure(); |
| 45 | StartAction start = SeffFactory.eINSTANCE.createStartAction(); |
| 46 | SetRequest setter2 = new SetRequest(seff, |
| 47 | SeffPackage.eINSTANCE.getResourceDemandingBehaviour_Steps_Behaviour(), |
| 48 | start); |
| 49 | SetValueCommand setCommand2 = new SetValueCommand(setter2); |
| 50 | setCommand2.execute(monitor, info); |
| 51 | CommandResult result = setCommand2.getCommandResult(); |
| 52 | if (!isOK(result)) |
| 53 | { |
| 54 | return CommandResult.newErrorCommandResult("Create SEFF failed!"); |
| 55 | } |
| 56 | StopAction stop = SeffFactory.eINSTANCE.createStopAction(); |
| 57 | SetRequest setter3 = new SetRequest(seff, |
| 58 | SeffPackage.eINSTANCE.getResourceDemandingBehaviour_Steps_Behaviour(), |
| 59 | stop); |
| 60 | SetValueCommand setCommand3 = new SetValueCommand(setter3); |
| 61 | setCommand3.execute(monitor, info); |
| 62 | result = setCommand3.getCommandResult(); |
| 63 | if (!isOK(result)) |
| 64 | { |
| 65 | return CommandResult.newErrorCommandResult("Create SEFF failed!"); |
| 66 | } |
| 67 | SetRequest setter4 = new SetRequest(start, |
| 68 | SeffPackage.eINSTANCE.getAbstractAction_Successor_AbstractAction(), |
| 69 | stop); |
| 70 | SetValueCommand setCommand4 = new SetValueCommand(setter4); |
| 71 | setCommand4.execute(monitor, info); |
| 72 | result = setCommand4.getCommandResult(); |
| 73 | if (!isOK(result)) |
| 74 | { |
| 75 | return CommandResult.newErrorCommandResult("Create SEFF failed!"); |
| 76 | } |
| 77 | return CommandResult.newOKCommandResult(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public class RepositoryEditorSeffEditHelperAdvice extends AbstractEditHelperAdvice implements |
| 82 | IEditHelperAdvice { |
| 83 | |
| 84 | @Override |
| 85 | /** |
| 86 | * Sets signature of a provided role |
| 87 | */ |
| 88 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
| 89 | EObject signature = null; |
| 90 | ArrayList<Object> filterList = new ArrayList<Object>(); // positive filter |
| 91 | // Set types to show and their super types |
| 92 | filterList.add(ProvidedRole.class); |
| 93 | filterList.add(Interface.class); |
| 94 | filterList.add(Signature.class); |
| 95 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
| 96 | // set EReference that should be set (in this case: provided role) |
| 97 | additionalReferences.add(RepositoryPackage.eINSTANCE.getOperationProvidedRole_ProvidedInterface__OperationProvidedRole()); |
| 98 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
| 99 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 100 | filterList, |
| 101 | additionalReferences, |
| 102 | request.getElementToConfigure().eContainer()); |
| 103 | dialog.setProvidedService(Signature.class); |
| 104 | dialog.open(); |
| 105 | if (dialog.getResult() == null) |
| 106 | return new CanceledCommand(); |
| 107 | if (!(dialog.getResult() instanceof Signature)) |
| 108 | return new CanceledCommand(); |
| 109 | signature = (Signature) dialog.getResult(); |
| 110 | |
| 111 | ICommand cmd = new SetValueCommand( |
| 112 | new SetRequest( |
| 113 | request.getElementToConfigure(), |
| 114 | SeffPackage.eINSTANCE.getServiceEffectSpecification_DescribedService__SEFF(), |
| 115 | signature)); |
| 116 | CompositeCommand cc = new CompositeCommand("Configure SEFF"); |
| 117 | cc.add(cmd); |
| 118 | cc.add(new ConfigureSEFFCommand(request)); |
| 119 | return cc; |
| 120 | } |
| 121 | |
| 122 | } |