Search in sources :

Example 21 with NodeID

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

the class PasteFromWorkflowPersistorCommand method canUndo.

/**
 * {@inheritDoc}
 */
@Override
public boolean canUndo() {
    WorkflowManager manager = m_editor.getWorkflowManager().get();
    NodeID[] pastedNodes = m_pastedContent.getNodeIDs();
    Annotation[] pastedAnnos = m_pastedContent.getAnnotations();
    if ((pastedNodes == null || pastedNodes.length == 0) && (pastedAnnos == null || pastedAnnos.length == 0)) {
        return false;
    }
    for (NodeID id : pastedNodes) {
        if (!manager.canRemoveNode(id)) {
            return false;
        }
    }
    return true;
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) Annotation(org.knime.core.node.workflow.Annotation) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 22 with NodeID

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

the class SearchQueryContributionItem method createNode.

/**
 * Helper to insert a node into the workflow editor.
 *
 * @param event
 */
private void createNode(final Object o) {
    if (o instanceof NodeTemplate) {
        NodeTemplate tmplt = (NodeTemplate) o;
        NodeFactory<? extends NodeModel> nodeFact;
        try {
            nodeFact = tmplt.createFactoryInstance();
        } catch (Exception e) {
            NodeLogger.getLogger(SearchQueryContributionItem.class).error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
            return;
        }
        boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
        if (added) {
            NodeUsageRegistry.addNode(tmplt);
        }
    }
    if (o instanceof MetaNodeTemplate) {
        MetaNodeTemplate mnt = (MetaNodeTemplate) o;
        NodeID metaNode = mnt.getManager().getID();
        NodeProvider.INSTANCE.addMetaNode(WorkflowManager.META_NODE_ROOT, metaNode);
    }
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) NodeID(org.knime.core.node.workflow.NodeID) PartInitException(org.eclipse.ui.PartInitException)

Example 23 with NodeID

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

the class HorizAlignManager method doLayout.

/**
 */
public void doLayout() {
    Map<NodeContainerEditPart, Integer> offsets = HorizAlignmentCenter.doLayout(m_wfm, m_nodeParts);
    // if emtpy - do some other alignement. May be port alignement?
    // preserver the old stuff for undoers
    m_oldBendpoints = new HashMap<ConnectionID, ConnectionUIInformation>();
    m_oldCoordinates = new HashMap<NodeID, NodeUIInformation>();
    if (offsets.isEmpty()) {
        LOGGER.debug("Nodes already aligned. Doing nothing.");
        return;
    }
    // transfer new coordinates into nodes
    for (Map.Entry<NodeContainerEditPart, Integer> e : offsets.entrySet()) {
        NodeContainerEditPart node = e.getKey();
        NodeContainerUI nc = node.getNodeContainer();
        NodeUIInformation uiInfo = nc.getUIInformation();
        int[] b = uiInfo.getBounds();
        NodeUIInformation newCoord = NodeUIInformation.builder().setNodeLocation(b[0], b[1] + e.getValue(), b[2], b[3]).setHasAbsoluteCoordinates(uiInfo.hasAbsoluteCoordinates()).build();
        LOGGER.debug("Node " + nc + " gets alignment coordinates " + newCoord);
        // save old coordinates for undo
        m_oldCoordinates.put(nc.getID(), uiInfo);
        // adjust first bendpoints at port position
        adjustBendPoints(node, e.getValue());
        // triggers gui update
        nc.setUIInformation(newCoord);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionID(org.knime.core.node.workflow.ConnectionID) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with NodeID

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

the class VerticAlignManager method doLayout.

/**
 */
public void doLayout() {
    Map<NodeContainerEditPart, Integer> offsets = VerticAlignmentCenter.doLayout(m_wfm, m_nodeParts);
    // preserver the old stuff for undoers
    m_oldBendpoints = new HashMap<ConnectionID, ConnectionUIInformation>();
    m_oldCoordinates = new HashMap<NodeID, NodeUIInformation>();
    if (offsets.isEmpty()) {
        LOGGER.debug("Nodes already aligned. Doing nothing.");
        return;
    }
    // transfer new coordinates into nodes
    for (Map.Entry<NodeContainerEditPart, Integer> e : offsets.entrySet()) {
        NodeContainerEditPart node = e.getKey();
        NodeContainerUI nc = node.getNodeContainer();
        NodeUIInformation uiInfo = nc.getUIInformation();
        int[] b = uiInfo.getBounds();
        NodeUIInformation newCoord = NodeUIInformation.builder().setNodeLocation(b[0] + e.getValue(), b[1], b[2], b[3]).setHasAbsoluteCoordinates(uiInfo.hasAbsoluteCoordinates()).build();
        LOGGER.debug("Node " + nc + " gets alignment coordinates " + newCoord);
        // save old coordinates for undo
        m_oldCoordinates.put(nc.getID(), uiInfo);
        // triggers gui update
        nc.setUIInformation(newCoord);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionID(org.knime.core.node.workflow.ConnectionID) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) Map(java.util.Map) HashMap(java.util.HashMap)

Example 25 with NodeID

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

the class AutoLayoutCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    Map<NodeID, NodeUIInformation> oldPositions = m_layoutMgr.getOldNodeCoordinates();
    Map<ConnectionID, ConnectionUIInformation> oldBendpoints = m_layoutMgr.getOldBendpoints();
    // re-position nodes
    for (Map.Entry<NodeID, NodeUIInformation> e : oldPositions.entrySet()) {
        NodeContainer nc = m_wfm.getNodeContainer(e.getKey());
        if (nc == null) {
            continue;
        }
        nc.setUIInformation(e.getValue());
    }
    // re-create bendpoints
    for (Map.Entry<ConnectionID, ConnectionUIInformation> e : oldBendpoints.entrySet()) {
        ConnectionContainer cc = m_wfm.getConnection(e.getKey());
        if (cc == null) {
            continue;
        }
        cc.setUIInfo(e.getValue());
    }
}
Also used : ConnectionID(org.knime.core.node.workflow.ConnectionID) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) NodeContainer(org.knime.core.node.workflow.NodeContainer) Map(java.util.Map)

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