Search in sources :

Example 1 with DeleteCommand

use of org.knime.workbench.editor2.commands.DeleteCommand in project knime-core by knime.

the class CutAction method runInSWT.

/**
 * Invokes the copy action followed by the delete command.
 * {@inheritDoc}
 */
@Override
public void runInSWT() {
    LOGGER.debug("Clipboard cut action invoked...");
    // invoke copy action
    CopyAction copy = new CopyAction(getEditor());
    copy.runInSWT();
    NodeContainerEditPart[] nodeParts = copy.getNodeParts();
    AnnotationEditPart[] annotationParts = copy.getAnnotationParts();
    Collection<EditPart> coll = new ArrayList<EditPart>();
    coll.addAll(Arrays.asList(nodeParts));
    coll.addAll(Arrays.asList(annotationParts));
    DeleteCommand delete = new DeleteCommand(coll, getEditor().getWorkflowManager().get());
    // enable undo
    getCommandStack().execute(delete);
    getEditor().updateActions();
    // Give focus to the editor again. Otherwise the actions (selection)
    // is not updated correctly.
    getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
}
Also used : DeleteCommand(org.knime.workbench.editor2.commands.DeleteCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList)

Example 2 with DeleteCommand

use of org.knime.workbench.editor2.commands.DeleteCommand in project knime-core by knime.

the class NodeConnectionContainerDeleteAction method createDeleteCommand.

/**
 * Create one command to remove the selected objects.
 *
 * @param objects The objects to be deleted.
 * @return The command to remove the selected objects.
 */
@Override
public Command createDeleteCommand(final List objects) {
    if (objects.isEmpty()) {
        return null;
    }
    if (!(objects.get(0) instanceof EditPart)) {
        return null;
    }
    VerifyingCompoundCommand compoundCmd = new VerifyingCompoundCommand(GEFMessages.DeleteAction_ActionDeleteCommandName);
    // will contain nodes -- just used for marking
    NodeContainerEditPart[] nodeParts = AbstractNodeAction.filterObjects(NodeContainerEditPart.class, objects);
    Optional<WorkflowManager> manager = ((WorkflowEditor) getWorkbenchPart()).getWorkflowManager();
    if (manager.isPresent()) {
        DeleteCommand cmd = new DeleteCommand(objects, manager.get());
        int nodeCount = cmd.getNodeCount();
        int connCount = cmd.getConnectionCount();
        int annoCount = cmd.getAnnotationCount();
        StringBuilder dialogText = new StringBuilder("Do you really want to delete ");
        if (nodeCount > 0) {
            dialogText.append(nodeCount).append(" node");
            dialogText.append(nodeCount > 1 ? "s" : "");
            if (annoCount > 0 && connCount > 0) {
                dialogText.append(" , ");
            } else if (annoCount > 0 || connCount > 0) {
                dialogText.append(" and ");
            }
        }
        if (connCount > 0) {
            dialogText.append(connCount).append(" connection");
            dialogText.append(connCount > 1 ? "s" : "");
            dialogText.append(annoCount > 0 ? " and " : "");
        }
        if (annoCount > 0) {
            dialogText.append(annoCount).append(" annotation");
            dialogText.append(annoCount > 1 ? "s" : "");
        }
        dialogText.append("?");
        compoundCmd.setDialogDisplayText(dialogText.toString());
        // set the parts into the compound command (for unmarking after cancel)
        compoundCmd.setNodeParts(Arrays.asList(nodeParts));
        compoundCmd.add(cmd);
    }
    return compoundCmd;
}
Also used : VerifyingCompoundCommand(org.knime.workbench.editor2.commands.VerifyingCompoundCommand) WorkflowEditor(org.knime.workbench.editor2.WorkflowEditor) DeleteCommand(org.knime.workbench.editor2.commands.DeleteCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart)

Aggregations

EditPart (org.eclipse.gef.EditPart)2 DeleteCommand (org.knime.workbench.editor2.commands.DeleteCommand)2 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)2 ArrayList (java.util.ArrayList)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 WorkflowEditor (org.knime.workbench.editor2.WorkflowEditor)1 VerifyingCompoundCommand (org.knime.workbench.editor2.commands.VerifyingCompoundCommand)1 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)1 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)1