| 1 | package de.uka.ipd.sdq.pcm.gmf.resource.helper; |
| 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.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.edithelper.IEditHelperAdvice; |
| 11 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
| 12 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
| 13 | import org.eclipse.jface.dialogs.Dialog; |
| 14 | import org.eclipse.ui.PlatformUI; |
| 15 | |
| 16 | import de.uka.ipd.sdq.pcm.core.CoreFactory; |
| 17 | import de.uka.ipd.sdq.pcm.core.PCMRandomVariable; |
| 18 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
| 19 | import de.uka.ipd.sdq.pcm.dialogs.stoex.StochasticExpressionEditDialog; |
| 20 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentPackage; |
| 21 | import de.uka.ipd.sdq.pcm.resourcetype.ProcessingResourceType; |
| 22 | import de.uka.ipd.sdq.pcm.resourcetype.ResourceRepository; |
| 23 | import de.uka.ipd.sdq.stoex.analyser.visitors.TypeEnum; |
| 24 | |
| 25 | public class ProcessingResourceSpecificationEditHelperAdvice extends AbstractEditHelperAdvice |
| 26 | implements IEditHelperAdvice { |
| 27 | |
| 28 | private static final String DISPLAY_TITLE = "Set Processing Rate"; |
| 29 | private static boolean ongoing = true; |
| 30 | |
| 31 | @Override |
| 32 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
| 33 | PCMRandomVariable rv = CoreFactory.eINSTANCE.createPCMRandomVariable(); |
| 34 | rv.setSpecification(""); |
| 35 | if (ongoing){ |
| 36 | StochasticExpressionEditDialog dialog = new StochasticExpressionEditDialog( |
| 37 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 38 | TypeEnum.DOUBLE, rv); |
| 39 | dialog.setDisplayTitle(DISPLAY_TITLE); |
| 40 | dialog.open(); |
| 41 | |
| 42 | if (dialog.getReturnCode() == Dialog.CANCEL) |
| 43 | return new CanceledCommand(); |
| 44 | |
| 45 | rv.setSpecification(dialog.getResultText()); |
| 46 | } |
| 47 | |
| 48 | ongoing = true; |
| 49 | |
| 50 | ICommand cmd = new SetValueCommand(new SetRequest(request |
| 51 | .getElementToConfigure(), ResourceenvironmentPackage.eINSTANCE.getProcessingResourceSpecification_ProcessingRate_ProcessingResourceSpecification(), |
| 52 | rv)); |
| 53 | |
| 54 | return cmd; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | protected ICommand getBeforeConfigureCommand(ConfigureRequest request) { |
| 59 | EObject resourceType = null; |
| 60 | ArrayList<Object> filterList = new ArrayList<Object>(); // positive filter |
| 61 | // Set types to show and their super types |
| 62 | filterList.add(ProcessingResourceType.class); |
| 63 | filterList.add(ResourceRepository.class); |
| 64 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
| 65 | // set EReference that should be set (in this case: active resource type) |
| 66 | additionalReferences.add(ResourceenvironmentPackage.eINSTANCE.getProcessingResourceSpecification_ActiveResourceType_ActiveResourceSpecification()); |
| 67 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
| 68 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 69 | filterList, |
| 70 | additionalReferences, |
| 71 | request.getElementToConfigure().eResource().getResourceSet()); |
| 72 | dialog.setProvidedService(ProcessingResourceType.class); |
| 73 | dialog.open(); |
| 74 | if (dialog.getResult() == null) { |
| 75 | ongoing = false; //prevents the StoexDialog for the ProcessingRate from being opened |
| 76 | return new CanceledCommand(); |
| 77 | } |
| 78 | |
| 79 | if (!(dialog.getResult() instanceof ProcessingResourceType)){ |
| 80 | ongoing = false; //prevents the StoexDialog for the ProcessingRate from being opened |
| 81 | return new CanceledCommand(); |
| 82 | } |
| 83 | resourceType = (ProcessingResourceType) dialog.getResult(); |
| 84 | |
| 85 | ICommand cmd = new SetValueCommand( |
| 86 | new SetRequest( |
| 87 | request.getElementToConfigure(), |
| 88 | ResourceenvironmentPackage.eINSTANCE.getProcessingResourceSpecification_ActiveResourceType_ActiveResourceSpecification(), |
| 89 | resourceType)); |
| 90 | return cmd; |
| 91 | } |
| 92 | } |