Search in sources :

Example 31 with WorkflowManager

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

the class DropNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // Add node to workflow and get the container
    WorkflowManager hostWFM = getHostWFM();
    try {
        NodeID id = hostWFM.addNodeAndApplyContext(m_factory, m_dropContext);
        m_container = hostWFM.getNodeContainer(id);
        // 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);
        // Open the dialog. Some times.
        if (m_container instanceof SingleNodeContainer && m_container.getNodeContainerState().isIdle() && m_container.hasDialog() && // and has only a variable in port
        m_container.getNrInPorts() == 1) {
            // if not executable and has a dialog and is fully connected
            // This is embedded in a special JFace wrapper dialog
            // 
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        WrappedNodeDialog dlg = new WrappedNodeDialog(Display.getCurrent().getActiveShell(), m_container);
                        dlg.open();
                    } catch (Exception e) {
                    // they need to open it manually then
                    }
                }
            });
        }
    } 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;
    }
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) WrappedNodeDialog(org.knime.workbench.ui.wrapper.WrappedNodeDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 32 with WorkflowManager

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

the class CreateNewConnectedNodeCommand method createNewNode.

/**
 * {@inheritDoc}
 */
@Override
protected NodeID createNewNode() {
    // Add node to workflow and get the container
    NodeID newID = null;
    WorkflowManager hostWFM = getHostWFM();
    try {
        newID = hostWFM.createAndAddNode(m_factory);
        NodeTimer.GLOBAL_TIMER.addNodeCreation(hostWFM.getNodeContainer(newID));
    } 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 node could not be created " + "due to the following reason:\n" + t.getMessage());
        mb.open();
        return null;
    }
    return newID;
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 33 with WorkflowManager

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

the class DeleteCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    // select the new ones....
    if (m_viewer != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
        ((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureSelection(m_nodeIDs);
        m_viewer.deselectAll();
    }
    WorkflowManager hostWFM = getHostWFM();
    if (m_undoPersitor != null) {
        hostWFM.paste(m_undoPersitor);
    }
    for (ConnectionContainer cc : m_connections) {
        ConnectionContainer newCC = hostWFM.addConnection(cc.getSource(), cc.getSourcePort(), cc.getDest(), cc.getDestPort());
        newCC.setUIInfo(cc.getUIInfo());
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 34 with WorkflowManager

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

the class DisconnectSubNodeLinkCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    m_changedIDs = new ArrayList<NodeID>();
    m_oldTemplInfos = new ArrayList<MetaNodeTemplateInformation>();
    WorkflowManager hostWFM = getHostWFM();
    for (NodeID id : m_ids) {
        NodeContainer nc = hostWFM.getNodeContainer(id);
        if (nc instanceof SubNodeContainer) {
            SubNodeContainer snc = (SubNodeContainer) nc;
            MetaNodeTemplateInformation lI = snc.getTemplateInformation();
            if (Role.Link.equals(lI.getRole())) {
                MetaNodeTemplateInformation old = hostWFM.setTemplateInformation(id, MetaNodeTemplateInformation.NONE);
                RECENTLY_USED_URIS.put(snc.getID(), old.getSourceURI());
                m_changedIDs.add(id);
                m_oldTemplInfos.add(old);
            }
        }
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 35 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager 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)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)99 NodeID (org.knime.core.node.workflow.NodeID)38 NodeContainer (org.knime.core.node.workflow.NodeContainer)22 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)19 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)14 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)14 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)10 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)10 MessageBox (org.eclipse.swt.widgets.MessageBox)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 List (java.util.List)8 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)8 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)8