| 1 | package de.uka.ipd.sdq.pcm.gmf.resource.helper; |
| 2 | |
| 3 | import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; |
| 4 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
| 5 | import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; |
| 6 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
| 7 | import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand; |
| 8 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
| 9 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
| 10 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
| 11 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
| 12 | |
| 13 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentPackage; |
| 14 | |
| 15 | public class AddCommunicationLinkResourceSpecificationEditHelperAdvice extends AbstractEditHelperAdvice implements |
| 16 | IEditHelperAdvice { |
| 17 | |
| 18 | private static final String RESOURCE_COMMUNICATION_LINK_RESOURCE_SPECIFICATION = "de.uka.ipd.sdq.pcm.gmf.resource.CommunicationLinkResourceSpecification_3002"; |
| 19 | |
| 20 | @Override |
| 21 | public ICommand getBeforeConfigureCommand(ConfigureRequest request) { |
| 22 | IElementType elementType = ElementTypeRegistry.getInstance().getType( |
| 23 | RESOURCE_COMMUNICATION_LINK_RESOURCE_SPECIFICATION); |
| 24 | |
| 25 | CreateElementRequest createElementRequest = new CreateElementRequest(request.getElementToConfigure(), elementType); |
| 26 | createElementRequest.setContainmentFeature(ResourceenvironmentPackage.eINSTANCE |
| 27 | .getLinkingResource_CommunicationLinkResourceSpecifications_LinkingResource()); |
| 28 | CreateElementCommand createElementCommand = new CreateElementCommand(createElementRequest); |
| 29 | |
| 30 | // edited object should be a single element |
| 31 | if (request.getElementsToEdit().size() != 1) { |
| 32 | throw new RuntimeException("Did not expect more than one element in request."); |
| 33 | } |
| 34 | |
| 35 | CompositeCommand compositeCommand = new CompositeCommand(""); |
| 36 | compositeCommand.add(createElementCommand); |
| 37 | compositeCommand.add(new SetLatencyThroughputAndLanTypeCommand(request)); |
| 38 | |
| 39 | return compositeCommand; |
| 40 | } |
| 41 | |
| 42 | } |