Search in sources :

Example 51 with NodeID

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

the class CreateNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    WorkflowManager hostWFM = getHostWFM();
    // Add node to workflow and get the container
    try {
        NodeID id = hostWFM.createAndAddNode(m_factory);
        m_container = hostWFM.getNodeContainer(id);
        NodeTimer.GLOBAL_TIMER.addNodeCreation(m_container);
    } catch (Throwable t) {
        // if fails notify the user
        LOGGER.debug("Node cannot be created.", t);
        MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
        mb.setText("Node cannot be created.");
        mb.setMessage("The selected node could not be created " + "due to the following reason:\n" + t.getMessage());
        mb.open();
        return;
    }
    // create extra info and set it
    NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(m_snapToGrid).setIsDropLocation(true).build();
    m_container.setUIInformation(info);
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 52 with NodeID

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

the class DisconnectMetaNodeLinkCommand method canExecute.

/**
 * We can execute, if all components were 'non-null' in the constructor.
 * {@inheritDoc}
 */
@Override
public boolean canExecute() {
    if (!super.canExecute()) {
        return false;
    }
    if (m_ids == null) {
        return false;
    }
    for (NodeID id : m_ids) {
        NodeContainer nc = getHostWFM().getNodeContainer(id);
        if (nc instanceof WorkflowManager) {
            WorkflowManager wm = (WorkflowManager) nc;
            MetaNodeTemplateInformation lI = wm.getTemplateInformation();
            if (Role.Link.equals(lI.getRole())) {
                return true;
            }
        }
    }
    return false;
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 53 with NodeID

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

the class DisconnectMetaNodeLinkCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    LOGGER.debug("Undo: Reconnecting metanode links (" + m_changedIDs.size() + " metanode(s))");
    for (int i = 0; i < m_changedIDs.size(); i++) {
        NodeID id = m_changedIDs.get(i);
        MetaNodeTemplateInformation old = m_oldTemplInfos.get(i);
        getHostWFM().setTemplateInformation(id, old);
    }
    m_changedIDs = null;
    m_oldTemplInfos = null;
}
Also used : NodeID(org.knime.core.node.workflow.NodeID) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 54 with NodeID

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

the class ExpandSubNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    try {
        WorkflowManager hostWFM = getHostWFM();
        // close editor of subnode and children
        NodeID wfmID = ((SubNodeContainer) hostWFM.getNodeContainer(m_id)).getWorkflowManager().getID();
        for (IEditorPart child : m_editor.getSubEditors(m_id)) {
            child.getEditorSite().getPage().closeEditor(child, false);
        }
        m_expandResult = hostWFM.expandSubWorkflow(m_id);
        WorkflowAnnotation[] annotations = m_expandResult.getExpandedCopyContent().getAnnotations();
        NodeID[] nodeIDs = m_expandResult.getExpandedCopyContent().getNodeIDs();
        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(nodeIDs);
            rootEditPart.setFutureAnnotationSelection(Arrays.asList(annotations));
        }
    } catch (Exception e) {
        String error = "Expanding Wrapped Metanode failed: " + e.getMessage();
        LOGGER.error(error, e);
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Expand failed", error);
    }
}
Also used : WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) EditPartViewer(org.eclipse.gef.EditPartViewer) IEditorPart(org.eclipse.ui.IEditorPart) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 55 with NodeID

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

the class DeleteCommand method canExecute.

/**
 * {@inheritDoc}
 */
@Override
public boolean canExecute() {
    if (!super.canExecute()) {
        return false;
    }
    boolean foundValid = false;
    WorkflowManager hostWFM = getHostWFM();
    for (NodeID id : m_nodeIDs) {
        foundValid = true;
        if (!hostWFM.canRemoveNode(id)) {
            return false;
        }
    }
    for (ConnectionContainer cc : m_connections) {
        foundValid = true;
        if (!hostWFM.canRemoveConnection(cc)) {
            return false;
        }
    }
    return foundValid || m_annotations.length > 0;
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID)

Aggregations

NodeID (org.knime.core.node.workflow.NodeID)71 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)30 NodeContainer (org.knime.core.node.workflow.NodeContainer)17 ArrayList (java.util.ArrayList)12 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)11 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)11 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)10 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)10 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)10 Map (java.util.Map)9 ConnectionID (org.knime.core.node.workflow.ConnectionID)9 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)9 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)7 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)6 MessageBox (org.eclipse.swt.widgets.MessageBox)5 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)5 File (java.io.File)4 IOException (java.io.IOException)4 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)4 NodeContainerTemplate (org.knime.core.node.workflow.NodeContainerTemplate)4