Search in sources :

Example 31 with NodeContainer

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

the class DefaultOpenViewAction method runOnNodes.

/**
 * This opens the first view of all the selected nodes.
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    LOGGER.debug("Creating open default view job for " + nodeParts.length + " node(s)...");
    for (NodeContainerEditPart p : nodeParts) {
        final NodeContainer cont = unwrapNC(p.getNodeContainer());
        final InteractiveWebViewsResult webViewsResult = cont.getInteractiveWebViews();
        boolean hasView = cont.getNrViews() > 0;
        hasView |= cont.hasInteractiveView() || webViewsResult.size() > 0;
        hasView |= OpenSubnodeWebViewAction.hasContainerView(cont);
        if (cont.getNodeContainerState().isExecuted() && hasView) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        final IAction action;
                        if (cont.hasInteractiveView()) {
                            action = new OpenInteractiveViewAction(cont);
                        } else if (cont instanceof SubNodeContainer) {
                            action = new OpenSubnodeWebViewAction((SubNodeContainer) cont);
                        } else if (webViewsResult.size() > 0) {
                            action = new OpenInteractiveWebViewAction(cont, webViewsResult.get(0));
                        } else {
                            action = new OpenViewAction(cont, 0);
                        }
                        action.run();
                    } catch (Throwable t) {
                        MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
                        mb.setText("View cannot be opened");
                        mb.setMessage("The view cannot be opened for the " + "following reason:\n" + t.getMessage());
                        mb.open();
                        LOGGER.error("The view for node '" + cont.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an " + "implementation error.", t);
                    }
                }
            });
        }
    }
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) MessageBox(org.eclipse.swt.widgets.MessageBox) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) InteractiveWebViewsResult(org.knime.core.node.workflow.action.InteractiveWebViewsResult)

Example 32 with NodeContainer

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

the class SubNodeReconfigureAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of <code>WorkflowManager</code>, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    NodeContainer nc = Wrapper.unwrapOptionalNC(nodes[0].getNodeContainer()).orElse(null);
    if (nc instanceof SubNodeContainer) {
        return !((SubNodeContainer) nc).isWriteProtected();
    }
    return false;
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer)

Example 33 with NodeContainer

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

the class AbstractCreateNewConnectedNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    m_newNode = createNewNode();
    if (m_newNode != null) {
        if (m_connectTo != null) {
            autoConnectNewNode();
        }
        NodeContainer newNode = getHostWFM().getNodeContainer(m_newNode);
        NodeUIInformation uiInfo = newNode.getUIInformation();
        // create extra info and set it
        if (uiInfo == null) {
            uiInfo = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).build();
        } else {
            uiInfo = NodeUIInformation.builder(uiInfo).setNodeLocation(m_location.x, m_location.y, uiInfo.getBounds()[2], uiInfo.getBounds()[3]).build();
        }
        newNode.setUIInformation(uiInfo);
    }
    // make sure the new node is selected and visible
    m_viewer.deselectAll();
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeContainer(org.knime.core.node.workflow.NodeContainer)

Example 34 with NodeContainer

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

the class AbstractCreateNewConnectedNodeCommand method autoConnectNewNode.

private void autoConnectNewNode() {
    if (m_newNode == null) {
        return;
    }
    if (m_connectTo == null) {
        return;
    }
    WorkflowManager hostWFM = getHostWFM();
    NodeContainer sourceNode = hostWFM.getNodeContainer(m_connectTo);
    NodeContainer nc = hostWFM.getNodeContainer(m_newNode);
    Map<Integer, Integer> matchingPorts = getMatchingPorts(sourceNode, nc);
    if (matchingPorts.size() == 0) {
        LOGGER.info("Can't auto-connect new node (" + m_newNode + "): " + "no matching port type found at node " + sourceNode.getNameWithID());
        return;
    }
    for (Map.Entry<Integer, Integer> entry : matchingPorts.entrySet()) {
        Integer leftPort = entry.getKey();
        Integer rightPort = entry.getValue();
        LOGGER.info("Autoconnect: Connecting new node " + m_newNode + " port " + rightPort + " with existing node " + sourceNode + " port " + leftPort);
        try {
            hostWFM.addConnection(m_connectTo, leftPort, m_newNode, rightPort).getID();
            NodeTimer.GLOBAL_TIMER.addConnectionCreation(sourceNode, nc);
        } catch (Exception e) {
            String from = sourceNode.getNameWithID();
            String to = nc.getNameWithID();
            String msg = "Unable to add connection from " + from + " port " + leftPort + " to " + to + "port " + rightPort + ": " + e.getMessage();
            LOGGER.error(msg);
        }
    }
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 35 with NodeContainer

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

the class ChangeNodeBoundsCommand method undo.

/**
 * Sets the old bounds.
 *
 * @see org.eclipse.gef.commands.Command#execute()
 */
@Override
public void undo() {
    if (!Arrays.equals(m_oldBounds, m_newBounds)) {
        NodeUIInformation information = NodeUIInformation.builder().setNodeLocation(m_oldBounds[0], m_oldBounds[1], m_oldBounds[2], m_oldBounds[3]).build();
        NodeContainer container = getHostWFM().getNodeContainer(m_nodeID);
        container.setUIInformation(information);
    }
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeContainer(org.knime.core.node.workflow.NodeContainer)

Aggregations

NodeContainer (org.knime.core.node.workflow.NodeContainer)51 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)21 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)20 NodeID (org.knime.core.node.workflow.NodeID)18 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)13 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)11 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)9 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)9 Map (java.util.Map)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)6 ConnectionID (org.knime.core.node.workflow.ConnectionID)6 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)6 File (java.io.File)5 List (java.util.List)5 GridData (org.eclipse.swt.layout.GridData)5 ReferencedFile (org.knime.core.internal.ReferencedFile)5 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)5