Search in sources :

Example 66 with NodeID

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

the class UpdateMetaNodeLinkCommand 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;
    }
    boolean containsUpdateableMN = false;
    WorkflowManager hostWFM = getHostWFM();
    for (NodeID id : m_ids) {
        NodeContainer nc = hostWFM.findNodeContainer(id);
        if (nc instanceof NodeContainerTemplate) {
            NodeContainerTemplate tnc = (NodeContainerTemplate) nc;
            final WorkflowManager parent = tnc.getParent();
            if (parent.hasUpdateableMetaNodeLink(id)) {
                containsUpdateableMN = true;
            }
            if (!parent.canUpdateMetaNodeLink(id)) {
                return false;
            }
        }
    }
    return containsUpdateableMN;
}
Also used : NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer)

Example 67 with NodeID

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

the class ReplaceHelper method reconnect.

/**
 * Connects new node with connection of the old node.
 *
 * @param container new node container
 */
public void reconnect(final NodeContainer container) {
    // reset node location
    NodeUIInformation uiInformation = m_oldNode.getUIInformation();
    int[] bounds = uiInformation.getBounds();
    NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(bounds[0], bounds[1], -1, -1).setHasAbsoluteCoordinates(true).setSnapToGrid(uiInformation.getSnapToGrid()).setIsDropLocation(false).build();
    container.setUIInformation(info);
    int inShift;
    int outShift;
    if (m_oldNode instanceof WorkflowManager && !(container instanceof WorkflowManager)) {
        inShift = 0;
        // replacing a metanode (no opt. flow var ports) with a "normal" node (that has optional flow var ports)
        if (m_oldNode.getNrInPorts() > 0 && container.getNrInPorts() > 1) {
            // shift ports one index - unless we need to use the invisible optional flow var port of new node
            if (!m_oldNode.getInPort(0).getPortType().equals(FlowVariablePortObject.TYPE)) {
                inShift = 1;
            } else if (container.getInPort(1).getPortType().equals(FlowVariablePortObject.TYPE)) {
                inShift = 1;
            }
        }
        outShift = 0;
        if (m_oldNode.getNrOutPorts() > 0 && container.getNrOutPorts() > 1) {
            if (!m_oldNode.getOutPort(0).getPortType().equals(FlowVariablePortObject.TYPE)) {
                outShift = 1;
            } else if (container.getOutPort(1).getPortType().equals(FlowVariablePortObject.TYPE)) {
                outShift = 1;
            }
        }
    } else if (!(m_oldNode instanceof WorkflowManager) && container instanceof WorkflowManager) {
        // replacing a "normal" node with a metanode
        inShift = -1;
        for (ConnectionContainer cc : m_incomingConnections) {
            if (cc.getDestPort() == 0) {
                inShift = 0;
                break;
            }
        }
        outShift = -1;
        for (ConnectionContainer cc : m_outgoingConnections) {
            if (cc.getSourcePort() == 0) {
                outShift = 0;
                break;
            }
        }
    } else {
        inShift = 0;
        outShift = 0;
    }
    // set incoming connections
    NodeID newId = container.getID();
    for (ConnectionContainer c : m_incomingConnections) {
        if (m_wfm.canAddConnection(c.getSource(), c.getSourcePort(), newId, c.getDestPort() + inShift)) {
            m_wfm.addConnection(c.getSource(), c.getSourcePort(), newId, c.getDestPort() + inShift);
        } else {
            break;
        }
    }
    // set outgoing connections
    for (ConnectionContainer c : m_outgoingConnections) {
        if (m_wfm.canAddConnection(newId, c.getSourcePort() + outShift, c.getDest(), c.getDestPort())) {
            m_wfm.addConnection(newId, c.getSourcePort() + outShift, c.getDest(), c.getDestPort());
        } else {
            break;
        }
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID)

Example 68 with NodeID

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

the class SetupSubnodeWizard method addPages.

/**
 * {@inheritDoc}
 */
@Override
public void addPages() {
    setWindowTitle("Setup Wrapped Metanode Wizard");
    setDefaultPageImageDescriptor(ImageDescriptor.createFromImage(ImageRepository.getImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/meta/meta_node_wizard2.png")));
    WorkflowManager wfManager = m_subNode.getWorkflowManager();
    Map<NodeID, NodeModel> allNodes = wfManager.findNodes(NodeModel.class, false);
    LinkedHashMap<NodeID, NodeModel> usageNodes = new LinkedHashMap<NodeID, NodeModel>();
    List<NodeID> nodeIDs = new ArrayList<NodeID>();
    nodeIDs.addAll(allNodes.keySet());
    Collections.sort(nodeIDs);
    for (NodeID id : nodeIDs) {
        NodeModel model = allNodes.get(id);
        if (considerNodeForUsage(model)) {
            usageNodes.put(id, model);
        }
    }
    m_portsPage = new ConfigureMetaNodePortsPage("Change the Wrapped Metanode configuration");
    m_portsPage.setSubNode(m_subNode);
    m_portsPage.setTemplate(null);
    addPage(m_portsPage);
}
Also used : NodeModel(org.knime.core.node.NodeModel) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList) ConfigureMetaNodePortsPage(org.knime.workbench.editor2.meta.ConfigureMetaNodePortsPage) LinkedHashMap(java.util.LinkedHashMap)

Example 69 with NodeID

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

the class SubnodeLayoutPage method createControl.

/**
 * {@inheritDoc}
 */
@Override
public void createControl(final Composite parent) {
    ScrolledComposite scrollPane = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    scrollPane.setExpandHorizontal(true);
    scrollPane.setExpandVertical(true);
    Composite composite = new Composite(scrollPane, SWT.NONE);
    scrollPane.setContent(composite);
    scrollPane.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    composite.setLayout(new GridLayout(4, false));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    Label titleLabel = new Label(composite, SWT.LEFT);
    FontData fontData = titleLabel.getFont().getFontData()[0];
    Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
    titleLabel.setText("Node");
    titleLabel.setFont(boldFont);
    Label xLabel = new Label(composite, SWT.LEFT);
    xLabel.setText("X");
    xLabel.setFont(boldFont);
    Label yLabel = new Label(composite, SWT.LEFT);
    yLabel.setText("Y");
    yLabel.setFont(boldFont);
    Label paddingLabel = new Label(composite, SWT.LEFT);
    paddingLabel.setText("Padding");
    paddingLabel.setFont(boldFont);
    for (final NodeID nodeID : m_viewNodes) {
        NodeContainer nodeContainer = m_wfManager.getNodeContainer(nodeID);
        WizardNodeLayoutInfo layoutInfo = null;
        if (m_subNodeContainer != null && m_subNodeContainer.getLayoutInfo() != null) {
            layoutInfo = m_subNodeContainer.getLayoutInfo().get(nodeID.getIndex());
            if (layoutInfo != null) {
                m_layoutMap.put(nodeID.getIndex(), layoutInfo);
            }
        }
        Composite labelComposite = new Composite(composite, SWT.NONE);
        labelComposite.setLayout(new GridLayout(2, false));
        labelComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        Label iconLabel = new Label(labelComposite, SWT.CENTER);
        iconLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        try (InputStream iconURLStream = FileLocator.resolve(nodeContainer.getIcon()).openStream()) {
            iconLabel.setImage(new Image(Display.getCurrent(), iconURLStream));
        } catch (IOException e) {
        /* do nothing */
        }
        Label nodeLabel = new Label(labelComposite, SWT.LEFT);
        nodeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        String nodeName = nodeContainer.getName();
        String annotation = nodeContainer.getNodeAnnotation().getText();
        nodeLabel.setText(nodeName + "\nID: " + nodeID.getIndex() + "\n" + annotation);
        GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
        gridData.widthHint = 80;
        final Text xText = new Text(composite, SWT.SINGLE | SWT.BORDER);
        xText.setLayoutData(gridData);
        xText.setText(layoutInfo == null ? "" : layoutInfo.getX());
        xText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                editX(nodeID, xText);
            }
        });
        final Text yText = new Text(composite, SWT.SINGLE | SWT.BORDER);
        yText.setLayoutData(gridData);
        yText.setText(layoutInfo == null ? "" : layoutInfo.getY());
        yText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                editY(nodeID, yText);
            }
        });
        final Text paddingText = new Text(composite, SWT.SINGLE | SWT.BORDER);
        paddingText.setLayoutData(gridData);
        paddingText.setText(layoutInfo == null || layoutInfo.getPadding() == null ? "" : layoutInfo.getPadding());
        paddingText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                editPadding(nodeID, paddingText);
            }
        });
    }
    scrollPane.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    setControl(scrollPane);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) InputStream(java.io.InputStream) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) NodeID(org.knime.core.node.workflow.NodeID) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) WizardNodeLayoutInfo(org.knime.core.node.wizard.WizardNodeLayoutInfo)

Example 70 with NodeID

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

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