Search in sources :

Example 1 with ICommand

use of org.eclipse.gmf.runtime.common.core.command.ICommand in project tdi-studio-se by Talend.

the class AssignmentPropertySection method executeDeleteCommand.

private void executeDeleteCommand(IStructuredSelection structuredSelection) {
    UnassignTalendItemsFromBusinessAssignmentCommand command = new UnassignTalendItemsFromBusinessAssignmentCommand(getEditingDomain(), true);
    for (Iterator iter = structuredSelection.iterator(); iter.hasNext(); ) {
        Object object = (Object) iter.next();
        if (object instanceof BusinessAssignment) {
            BusinessAssignment businessAssignment = (BusinessAssignment) object;
            command.addBusinessAssignment(businessAssignment);
        }
    }
    List<ICommand> commands = new ArrayList<ICommand>();
    commands.add(command);
    //$NON-NLS-1$
    executeAsCompositeCommand(Messages.getString("AssignmentPropertySection.DeleteAssignment"), commands);
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) UnassignTalendItemsFromBusinessAssignmentCommand(org.talend.designer.business.diagram.custom.commands.UnassignTalendItemsFromBusinessAssignmentCommand) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 2 with ICommand

use of org.eclipse.gmf.runtime.common.core.command.ICommand in project tdi-studio-se by Talend.

the class BusinessBaseEditHelper method getInsteadCommand.

/**
     * @generated
     */
protected ICommand getInsteadCommand(IEditCommandRequest req) {
    ICommand epCommand = (ICommand) req.getParameter(EDIT_POLICY_COMMAND);
    req.setParameter(EDIT_POLICY_COMMAND, null);
    ICommand ehCommand = super.getInsteadCommand(req);
    if (epCommand == null) {
        return ehCommand;
    }
    if (ehCommand == null) {
        return epCommand;
    }
    CompositeCommand command = new CompositeCommand(null);
    command.add(epCommand);
    command.add(ehCommand);
    return command;
}
Also used : ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) CompositeCommand(org.eclipse.gmf.runtime.common.core.command.CompositeCommand)

Example 3 with ICommand

use of org.eclipse.gmf.runtime.common.core.command.ICommand in project tdi-studio-se by Talend.

the class ClipboardActionHandler method getCommand.

@Override
public ICommand getCommand(IGlobalActionContext cntxt) {
    IWorkbenchPart part = cntxt.getActivePart();
    if (!(part instanceof IDiagramWorkbenchPart)) {
        return null;
    }
    IDiagramWorkbenchPart workbenchPart = (IDiagramWorkbenchPart) part;
    DiagramEditPart diagramEditPart = workbenchPart.getDiagramEditPart();
    ICommand command = null;
    String actionId = cntxt.getActionId();
    if (actionId.equals(GlobalActionId.COPY)) {
        command = getCopyCommand(cntxt, workbenchPart, false);
        transfer(cntxt.getSelection());
        isCut = false;
        older = workbenchPart;
        orginalCopyFrom = workbenchPart;
        clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
    } else if (actionId.equals(GlobalActionId.CUT) && cntxt.getSelection() != null) {
        saveCut(cntxt.getSelection());
        command = getCutCommand(cntxt, workbenchPart);
        transfer(cntxt.getSelection());
        isCut = true;
        older = workbenchPart;
        clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
    } else if (actionId.equals(GlobalActionId.SAVE)) {
        if (workbenchPart instanceof IEditorPart) {
            IEditorPart editorPart = (IEditorPart) workbenchPart;
            if (editorPart.isDirty()) {
                IWorkbenchPage page = editorPart.getSite().getPage();
                page.saveEditor(editorPart, false);
            }
        }
    }
    if (actionId.equals(GlobalActionId.PASTE)) {
        // diagramPart.getDiagramGraphicalViewer().setSelection(new
        // StructuredSelection(diagramPart.getDiagramEditPart()));
        PasteViewRequest pasteReq = createPasteViewRequest();
        CommandStack cs = workbenchPart.getDiagramEditDomain().getDiagramCommandStack();
        IStructuredSelection selection = (IStructuredSelection) cntxt.getSelection();
        if (!(selection.getFirstElement() instanceof BusinessProcessEditPart)) {
            selection = new StructuredSelection(workbenchPart.getDiagramEditPart());
        }
        Object[] objects = selection.toArray();
        Collection returnValues = null;
        if (objects.length == 1) {
            Command paste = ((EditPart) objects[0]).getCommand(pasteReq);
            if (paste != null) {
                cs.execute(paste);
                workbenchPart.getDiagramEditPart().getFigure().invalidate();
                workbenchPart.getDiagramEditPart().getFigure().validate();
                returnValues = DiagramCommandStack.getReturnValues(paste);
            // selectAddedObject(diagramPart.getDiagramGraphicalViewer(), returnValues);
            }
        }
        Object elements = TemplateTransfer.getInstance().getObject();
        if (elements instanceof List) {
            List<BusinessItem> list = (List<BusinessItem>) elements;
            boolean inEditors = false;
            if (older != workbenchPart) {
                inEditors = true;
            } else if (!this.isCut && orginalCopyFrom != workbenchPart) {
                // bug 16065 fixed, by xtan. to resolve the copy(A)/parse(B)/parse(B)/parse(B)... problem.
                inEditors = true;
            }
            // always keep the last one as the current selection.
            older = workbenchPart;
            GmfPastCommand pastBusiness = new GmfPastCommand((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement(), list, diagramEditPart, this.cutItemIds, this.isCut | inEditors);
            pastBusiness.setClonedSourceProcessItemsList(clonedSourceProcessItemsList);
            try {
                pastBusiness.execute(null, null);
            } catch (ExecutionException e) {
                ExceptionHandler.process(e);
            }
        }
        if (returnValues != null) {
            selectAddedObject(workbenchPart.getDiagramGraphicalViewer(), returnValues);
        }
        return null;
    }
    return command;
}
Also used : PasteViewRequest(org.eclipse.gmf.runtime.diagram.ui.requests.PasteViewRequest) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) BusinessProcessEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(org.eclipse.core.commands.ExecutionException) GmfPastCommand(org.talend.designer.business.diagram.custom.commands.GmfPastCommand) DiagramCommandStack(org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack) CommandStack(org.eclipse.gef.commands.CommandStack) IDiagramWorkbenchPart(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) BusinessProcessEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart) EditPart(org.eclipse.gef.EditPart) IEditorPart(org.eclipse.ui.IEditorPart) Diagram(org.eclipse.gmf.runtime.notation.Diagram) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) GmfPastCommand(org.talend.designer.business.diagram.custom.commands.GmfPastCommand) Command(org.eclipse.gef.commands.Command) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) BusinessItem(org.talend.designer.business.model.business.BusinessItem) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 4 with ICommand

use of org.eclipse.gmf.runtime.common.core.command.ICommand in project tdi-studio-se by Talend.

the class BusinessBaseItemSemanticEditPolicy method getSemanticCommand.

/**
     * @generated
     */
protected Command getSemanticCommand(IEditCommandRequest request) {
    IEditCommandRequest completedRequest = completeRequest(request);
    Object editHelperContext = completedRequest.getEditHelperContext();
    if (editHelperContext instanceof View || (editHelperContext instanceof IEditHelperContext && ((IEditHelperContext) editHelperContext).getEObject() instanceof View)) {
        // no semantic commands are provided for pure design elements
        return null;
    }
    if (editHelperContext == null) {
        editHelperContext = ViewUtil.resolveSemanticElement((View) getHost().getModel());
    }
    IElementType elementType = ElementTypeRegistry.getInstance().getElementType(editHelperContext);
    if (elementType == ElementTypeRegistry.getInstance().getType("org.eclipse.gmf.runtime.emf.type.core.default")) {
        //$NON-NLS-1$ 
        elementType = null;
    }
    Command epCommand = getSemanticCommandSwitch(completedRequest);
    if (epCommand != null) {
        ICommand command = epCommand instanceof ICommandProxy ? ((ICommandProxy) epCommand).getICommand() : new CommandProxy(epCommand);
        completedRequest.setParameter(BusinessBaseEditHelper.EDIT_POLICY_COMMAND, command);
    }
    Command ehCommand = null;
    if (elementType != null) {
        ICommand command = elementType.getEditCommand(completedRequest);
        if (command != null) {
            if (!(command instanceof CompositeTransactionalCommand)) {
                TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
                command = new CompositeTransactionalCommand(editingDomain, null).compose(command);
            }
            ehCommand = new ICommandProxy(command);
        }
    }
    boolean shouldProceed = true;
    if (completedRequest instanceof DestroyRequest) {
        shouldProceed = shouldProceed((DestroyRequest) completedRequest);
    }
    if (shouldProceed) {
        if (completedRequest instanceof DestroyRequest) {
            TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
            Command deleteViewCommand = new ICommandProxy(new DeleteCommand(editingDomain, (View) getHost().getModel()));
            ehCommand = ehCommand == null ? deleteViewCommand : ehCommand.chain(deleteViewCommand);
        }
        return ehCommand;
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) DestroyRequest(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyRequest) IEditCommandRequest(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest) View(org.eclipse.gmf.runtime.notation.View) IElementType(org.eclipse.gmf.runtime.emf.type.core.IElementType) DeleteCommand(org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) CommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy) IEditHelperContext(org.eclipse.gmf.runtime.emf.type.core.IEditHelperContext) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CompositeTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) CompositeTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) DeleteCommand(org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand) Command(org.eclipse.gef.commands.Command) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) EObject(org.eclipse.emf.ecore.EObject)

Example 5 with ICommand

use of org.eclipse.gmf.runtime.common.core.command.ICommand in project Palladio-Editors-Sirius by PalladioSimulator.

the class AddLatencyAndThroughputRecordingCommand method doExecute.

@Override
protected void doExecute() {
    // Throughput
    PCMRandomVariable rv = CoreFactory.eINSTANCE.createPCMRandomVariable();
    rv.setSpecification("");
    StochasticExpressionEditDialog dialog = new StochasticExpressionEditDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), TypeEnum.ANY, rv);
    dialog.open();
    rv.setSpecification(dialog.getResultText());
    ICommand cmd = new MySetValueCommand(new SetRequest(communicationLinkResourceSpecification, ResourceenvironmentPackage.eINSTANCE.getCommunicationLinkResourceSpecification_Throughput_CommunicationLinkResourceSpecification(), rv));
    cmd.setLabel("Throughput");
    // Latency
    rv = CoreFactory.eINSTANCE.createPCMRandomVariable();
    rv.setSpecification("");
    dialog = new StochasticExpressionEditDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), TypeEnum.ANY, rv);
    dialog.open();
    rv.setSpecification(dialog.getResultText());
    cmd = new SetValueCommand(new SetRequest(communicationLinkResourceSpecification, ResourceenvironmentPackage.eINSTANCE.getCommunicationLinkResourceSpecification_Latency_CommunicationLinkResourceSpecification(), rv));
}
Also used : SetRequest(org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest) SetValueCommand(org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) StochasticExpressionEditDialog(org.palladiosimulator.editors.commons.dialogs.stoex.StochasticExpressionEditDialog) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable)

Aggregations

ICommand (org.eclipse.gmf.runtime.common.core.command.ICommand)7 EObject (org.eclipse.emf.ecore.EObject)3 Command (org.eclipse.gef.commands.Command)3 ArrayList (java.util.ArrayList)2 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)2 ICommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy)2 CompositeTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 PointList (org.eclipse.draw2d.geometry.PointList)1 EditPart (org.eclipse.gef.EditPart)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 UnexecutableCommand (org.eclipse.gef.commands.UnexecutableCommand)1 AbstractEditPart (org.eclipse.gef.editparts.AbstractEditPart)1 CompositeCommand (org.eclipse.gmf.runtime.common.core.command.CompositeCommand)1 DeleteCommand (org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand)1 CommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy)1 DiagramEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart)1