Search in sources :

Example 1 with WorkflowAnnotation

use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.

the class CollapseMetaNodeCommand method create.

/**
 * @param manager
 * @param nodeParts
 * @param annoParts
 * @param encapsulateAsSubnode TODO
 * @return
 */
public static Optional<CollapseMetaNodeCommand> create(final WorkflowManager manager, final NodeContainerEditPart[] nodeParts, final AnnotationEditPart[] annoParts, final boolean encapsulateAsSubnode) {
    NodeID[] nodeIds = new NodeID[nodeParts.length];
    for (int i = 0; i < nodeParts.length; i++) {
        nodeIds[i] = nodeParts[i].getNodeContainer().getID();
    }
    WorkflowAnnotation[] annos = AnnotationEditPart.extractWorkflowAnnotations(annoParts);
    try {
        // before testing anything, let's see if we should reset
        // the selected nodes:
        List<NodeID> resetableIDs = new ArrayList<NodeID>();
        for (NodeID id : nodeIds) {
            if (manager.canResetNode(id)) {
                resetableIDs.add(id);
            }
        }
        if (resetableIDs.size() > 0) {
            // found some: ask if we can reset, otherwise bail
            MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
            mb.setMessage("Executed Nodes will be reset - are you sure?");
            mb.setText("Reset Executed Nodes");
            int dialogreturn = mb.open();
            if (dialogreturn == SWT.CANCEL) {
                return Optional.empty();
            }
        } else {
            // if there are no resetable nodes we can check if
            // we can collapse - otherwise we need to first reset
            // those nodes (which we don't want to do before we
            // have not gathered all info - and allowed the user
            // to cancel the operation!)
            String res = manager.canCollapseNodesIntoMetaNode(nodeIds);
            if (res != null) {
                throw new IllegalArgumentException(res);
            }
        }
        // let the user enter a name
        String name = "Metanode";
        InputDialog idia = new InputDialog(Display.getCurrent().getActiveShell(), "Enter Name of Metanode", "Enter name of Metanode:", name, null);
        int dialogreturn = idia.open();
        if (dialogreturn == Window.CANCEL) {
            return Optional.empty();
        }
        if (dialogreturn == Window.OK) {
            if (resetableIDs.size() > 0) {
                // and skip the ones that were already reset in passing.
                for (NodeID id : resetableIDs) {
                    if (manager.canResetNode(id)) {
                        manager.resetAndConfigureNode(id);
                    }
                }
            }
            // check if there is another reason why we cannot collapse
            String res = manager.canCollapseNodesIntoMetaNode(nodeIds);
            if (res != null) {
                throw new IllegalArgumentException(res);
            }
            name = idia.getValue();
            return Optional.of(new CollapseMetaNodeCommand(manager, nodeIds, annos, name, encapsulateAsSubnode));
        }
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        final String error = "Collapsing to metanode failed: " + e.getMessage();
        LOGGER.error(error, e);
        mb.setMessage(error);
        mb.setText("Collapse failed");
        mb.open();
    }
    return Optional.empty();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with WorkflowAnnotation

use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.

the class ExpandMetaNodeCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    WorkflowManager hostWFM = getHostWFM();
    for (NodeID id : m_pastedNodes) {
        hostWFM.removeNode(id);
    }
    for (WorkflowAnnotation anno : m_pastedAnnotations) {
        hostWFM.removeAnnotation(anno);
    }
    hostWFM.paste(m_undoCopyPersistor);
    m_pastedNodes = null;
    m_pastedAnnotations = null;
    m_undoCopyPersistor = null;
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 3 with WorkflowAnnotation

use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.

the class PasteFromWorkflowPersistorCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    WorkflowManager manager = m_editor.getWorkflowManager().get();
    WorkflowPersistor copyPersistor = m_clipboardObject.getCopyPersistor();
    m_pastedContent = manager.paste(copyPersistor);
    NodeID[] pastedNodes = m_pastedContent.getNodeIDs();
    WorkflowAnnotation[] pastedAnnos = m_pastedContent.getAnnotations();
    // fast lookup below
    Set<NodeID> newIDs = new HashSet<NodeID>();
    List<int[]> insertedElementBounds = new ArrayList<int[]>();
    for (NodeID i : pastedNodes) {
        NodeContainer nc = manager.getNodeContainer(i);
        NodeUIInformation ui = nc.getUIInformation();
        int[] bounds = ui.getBounds();
        insertedElementBounds.add(bounds);
    }
    for (WorkflowAnnotation a : pastedAnnos) {
        int[] bounds = new int[] { a.getX(), a.getY(), a.getWidth(), a.getHeight() };
        insertedElementBounds.add(bounds);
    }
    int[] moveDist = m_shiftCalculator.calculateShift(insertedElementBounds, manager, m_clipboardObject);
    // for redo-operations we need the exact same shift.
    m_shiftCalculator = new FixedShiftCalculator(moveDist);
    for (NodeID id : pastedNodes) {
        newIDs.add(id);
        NodeContainer nc = manager.getNodeContainer(id);
        NodeUIInformation oldUI = nc.getUIInformation();
        NodeUIInformation newUI = NodeUIInformation.builder(oldUI).translate(moveDist).build();
        nc.setUIInformation(newUI);
    }
    for (ConnectionContainer conn : manager.getConnectionContainers()) {
        if (newIDs.contains(conn.getDest()) && newIDs.contains(conn.getSource())) {
            // get bend points and move them
            ConnectionUIInformation oldUI = conn.getUIInfo();
            if (oldUI != null) {
                ConnectionUIInformation newUI = ConnectionUIInformation.builder(oldUI).translate(moveDist).build();
                conn.setUIInfo(newUI);
            }
        }
    }
    for (WorkflowAnnotation a : pastedAnnos) {
        a.shiftPosition(moveDist[0], moveDist[1]);
    }
    EditPartViewer partViewer = m_editor.getViewer();
    partViewer.deselectAll();
    // select the new ones....
    if (partViewer.getRootEditPart().getContents() != null && partViewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
        WorkflowRootEditPart rootEditPart = (WorkflowRootEditPart) partViewer.getRootEditPart().getContents();
        rootEditPart.setFutureSelection(pastedNodes);
        rootEditPart.setFutureAnnotationSelection(Arrays.asList(pastedAnnos));
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) ArrayList(java.util.ArrayList) EditPartViewer(org.eclipse.gef.EditPartViewer) NodeContainer(org.knime.core.node.workflow.NodeContainer) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) HashSet(java.util.HashSet)

Example 4 with WorkflowAnnotation

use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.

the class ExpandSubnodeResult method undo.

public void undo() {
    WorkflowManager hostWFM = m_hostWFM;
    for (NodeID id : m_expandedCopyContent.getNodeIDs()) {
        hostWFM.removeNode(id);
    }
    for (WorkflowAnnotation anno : m_expandedCopyContent.getAnnotations()) {
        hostWFM.removeAnnotation(anno);
    }
    hostWFM.paste(m_undoCopyPersistor);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 5 with WorkflowAnnotation

use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.

the class CopyAction method runInSWT.

/**
 * {@inheritDoc}
 */
@Override
public void runInSWT() {
    m_nodeParts = getSelectedParts(NodeContainerEditPart.class);
    m_annotationParts = getSelectedParts(AnnotationEditPart.class);
    NodeID[] ids = new NodeID[m_nodeParts.length];
    for (int i = 0; i < m_nodeParts.length; i++) {
        NodeContainerEditPart nodeEP = m_nodeParts[i];
        ids[i] = nodeEP.getNodeContainer().getID();
    }
    WorkflowAnnotation[] annotations = AnnotationEditPart.extractWorkflowAnnotations(m_annotationParts);
    WorkflowCopyContent.Builder content = WorkflowCopyContent.builder();
    content.setNodeIDs(ids);
    content.setAnnotation(annotations);
    WorkflowPersistor copyPersistor = getManager().copy(false, content.build());
    // the information about the nodes is stored in the config XML format
    // also used to store workflow information in the kflow files
    getEditor().setClipboardContent(new ClipboardObject(copyPersistor));
    // update the actions
    getEditor().updateActions();
    // Give focus to the editor again. Otherwise the actions (selection)
    // is not updated correctly.
    getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) WorkflowCopyContent(org.knime.core.node.workflow.WorkflowCopyContent) ClipboardObject(org.knime.workbench.editor2.ClipboardObject) NodeID(org.knime.core.node.workflow.NodeID) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Aggregations

WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)11 NodeID (org.knime.core.node.workflow.NodeID)8 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)7 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)3 ArrayList (java.util.ArrayList)2 EditPartViewer (org.eclipse.gef.EditPartViewer)2 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)2 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)2 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)2 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)2 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)2 WorkflowPersistor (org.knime.core.node.workflow.WorkflowPersistor)2 HashSet (java.util.HashSet)1 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 IEditorPart (org.eclipse.ui.IEditorPart)1 Annotation (org.knime.core.node.workflow.Annotation)1