| 1 | package de.uka.ipd.sdq.pcm.gmf.seff.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.ICommand; |
| 12 | import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand; |
| 13 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
| 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.jface.dialogs.Dialog; |
| 17 | import org.eclipse.ui.PlatformUI; |
| 18 | |
| 19 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
| 20 | import de.uka.ipd.sdq.pcm.dialogs.stoex.StochasticExpressionEditDialog; |
| 21 | import de.uka.ipd.sdq.pcm.resourcetype.ProcessingResourceType; |
| 22 | import de.uka.ipd.sdq.pcm.resourcetype.ResourceRepository; |
| 23 | import de.uka.ipd.sdq.pcm.seff.seff_performance.ParametricResourceDemand; |
| 24 | import de.uka.ipd.sdq.pcm.seff.seff_performance.Seff_performancePackage; |
| 25 | import de.uka.ipd.sdq.stoex.StoexPackage; |
| 26 | import de.uka.ipd.sdq.stoex.analyser.visitors.TypeEnum; |
| 27 | |
| 28 | /** @author roman */ |
| 29 | public class ParametricResourceDemandConfigureCommand extends |
| 30 | ConfigureElementCommand { |
| 31 | |
| 32 | private ConfigureRequest request = null; |
| 33 | |
| 34 | public ParametricResourceDemandConfigureCommand(ConfigureRequest request){ |
| 35 | super(request); |
| 36 | this.request = request; |
| 37 | } |
| 38 | |
| 39 | /* (non-Javadoc) |
| 40 | * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
| 41 | */ |
| 42 | @Override |
| 43 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
| 44 | IAdaptable info) throws ExecutionException { |
| 45 | |
| 46 | CommandResult commandResult = setRequiredResource_ParametricResourceDemand( |
| 47 | monitor, info); |
| 48 | if (!isOK(commandResult)) { |
| 49 | return CommandResult |
| 50 | .newErrorCommandResult("Set RequiredResource for the ParametricResourceDemand failed!"); |
| 51 | } |
| 52 | commandResult = setSpecification_ParametricResourceDemand(monitor, info); |
| 53 | if (!isOK(commandResult)) { |
| 54 | return CommandResult |
| 55 | .newErrorCommandResult("Set Action for the ParametricResourceDemand failed!"); |
| 56 | } |
| 57 | return CommandResult.newOKCommandResult(); |
| 58 | } |
| 59 | |
| 60 | private CommandResult setRequiredResource_ParametricResourceDemand( |
| 61 | IProgressMonitor monitor, IAdaptable info) |
| 62 | throws ExecutionException { |
| 63 | |
| 64 | EObject resource = null; |
| 65 | ArrayList<Object> filterList = new ArrayList<Object>(); |
| 66 | filterList.add(ResourceRepository.class); |
| 67 | filterList.add(ProcessingResourceType.class); |
| 68 | |
| 69 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
| 70 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
| 71 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 72 | filterList, additionalReferences, request.getEditingDomain() |
| 73 | .getResourceSet()); |
| 74 | dialog.setProvidedService(ProcessingResourceType.class); |
| 75 | dialog.open(); |
| 76 | if (dialog.getResult() == null) |
| 77 | return CommandResult.newCancelledCommandResult(); |
| 78 | if (!(dialog.getResult() instanceof ProcessingResourceType)) |
| 79 | return CommandResult.newCancelledCommandResult(); |
| 80 | resource = (ProcessingResourceType) dialog.getResult(); |
| 81 | |
| 82 | ICommand cmd = new SetValueCommand( |
| 83 | new SetRequest( |
| 84 | request.getElementToConfigure(), |
| 85 | Seff_performancePackage.eINSTANCE |
| 86 | .getParametricResourceDemand_RequiredResource_ParametricResourceDemand(), |
| 87 | resource)); |
| 88 | cmd.execute(monitor, info); |
| 89 | |
| 90 | return cmd.getCommandResult(); |
| 91 | } |
| 92 | |
| 93 | private CommandResult setSpecification_ParametricResourceDemand( |
| 94 | IProgressMonitor monitor, IAdaptable info) |
| 95 | throws ExecutionException { |
| 96 | |
| 97 | StochasticExpressionEditDialog dialog = new StochasticExpressionEditDialog( |
| 98 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 99 | TypeEnum.DOUBLE, request.getElementToConfigure()); |
| 100 | dialog.open(); |
| 101 | |
| 102 | if (dialog.getReturnCode() == Dialog.CANCEL) |
| 103 | return CommandResult.newCancelledCommandResult(); |
| 104 | |
| 105 | ICommand cmd = new SetValueCommand( |
| 106 | new SetRequest(((ParametricResourceDemand)request |
| 107 | .getElementToConfigure()).getSpecification_ParametericResourceDemand(), |
| 108 | StoexPackage.eINSTANCE |
| 109 | .getRandomVariable_Specification(), |
| 110 | dialog.getResultText())); |
| 111 | cmd.execute(monitor, info); |
| 112 | |
| 113 | return cmd.getCommandResult(); |
| 114 | } |
| 115 | } |