Search in sources :

Example 1 with CreateElementRequest

use of org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest in project statecharts by Yakindu.

the class CreateTransitionCommand method doExecuteWithResult.

@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    Vertex source = (Vertex) getRequest().getSource();
    Vertex target = (Vertex) getRequest().getTarget();
    if (source != null && target != null) {
        Transition transition = SGraphFactory.eINSTANCE.createTransition();
        source.getOutgoingTransitions().add(transition);
        transition.setSource(source);
        transition.setTarget(target);
        source.getOutgoingTransitions().add(transition);
        target.getIncomingTransitions().add(transition);
        ((CreateElementRequest) getRequest()).setNewElement(transition);
    }
    return CommandResult.newOKCommandResult();
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Transition(org.yakindu.sct.model.sgraph.Transition) CreateElementRequest(org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest)

Example 2 with CreateElementRequest

use of org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest in project statecharts by Yakindu.

the class CompartmentLayoutEditPolicy method getCreateCommand.

@SuppressWarnings("unchecked")
@Override
protected Command getCreateCommand(CreateRequest request) {
    if (request instanceof CreateViewAndElementRequest) {
        TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
        CompositeTransactionalCommand cc = new CompositeTransactionalCommand(editingDomain, DiagramUIMessages.AddCommand_Label);
        Iterator<?> descriptors = ((CreateViewRequest) request).getViewDescriptors().iterator();
        while (descriptors.hasNext()) {
            CreateViewRequest.ViewDescriptor descriptor = (CreateViewRequest.ViewDescriptor) descriptors.next();
            int feedBackIndex = getFeedbackIndexFor(request);
            // obtain CreateElementRequest and add initial region feedback
            // index to request map. This index is needed to add the
            // semantic element at the correct listIndex
            CreateElementRequest createElementRequest = (CreateElementRequest) ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter().getAdapter(CreateElementRequest.class);
            if (createElementRequest != null) {
                createElementRequest.getParameters().put(RequestParameterKeys.RegionFeedbackIndex, feedBackIndex);
            }
            CreateCommand createCommand = new CompartmentChildCreateCommand(editingDomain, descriptor, (View) (getHost().getModel()), feedBackIndex);
            cc.compose(createCommand);
        }
        return new ICommandProxy(cc.reduce());
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) CompartmentChildCreateCommand(org.yakindu.base.gmf.runtime.commands.CompartmentChildCreateCommand) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) CompartmentChildCreateCommand(org.yakindu.base.gmf.runtime.commands.CompartmentChildCreateCommand) CreateCommand(org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand) CreateElementRequest(org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) CreateViewAndElementRequest(org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest) CreateViewRequest(org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CompositeTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand)

Aggregations

CreateElementRequest (org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest)2 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 CreateCommand (org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand)1 ICommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 CreateViewAndElementRequest (org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest)1 CreateViewRequest (org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest)1 CompositeTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand)1 CompartmentChildCreateCommand (org.yakindu.base.gmf.runtime.commands.CompartmentChildCreateCommand)1 Transition (org.yakindu.sct.model.sgraph.Transition)1 Vertex (org.yakindu.sct.model.sgraph.Vertex)1