Search in sources :

Example 11 with NodeID

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

the class RevealSubNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    List<NodeID> candidateList = new ArrayList<NodeID>();
    List<AbstractExplorerFileStore> templates = new ArrayList<AbstractExplorerFileStore>();
    for (NodeContainerEditPart p : nodes) {
        Object model = p.getModel();
        if (wraps(model, SubNodeContainer.class)) {
            NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
            try {
                SubNodeContainer snc = unwrap((UI) model, SubNodeContainer.class);
                MetaNodeTemplateInformation i = snc.getTemplateInformation();
                if (Role.Link.equals(i.getRole())) {
                    candidateList.add(snc.getID());
                    AbstractExplorerFileStore template = ExplorerFileSystem.INSTANCE.getStore(i.getSourceURI());
                    if (template != null) {
                        templates.add(template);
                    }
                }
            } finally {
                NodeContext.removeLastContext();
            }
        }
    }
    List<Object> treeObjects = ContentDelegator.getTreeObjectList(templates);
    if (treeObjects != null && treeObjects.size() > 0) {
        IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
        for (IViewReference view : views) {
            if (ExplorerView.ID.equals(view.getId())) {
                ExplorerView explorerView = (ExplorerView) view.getView(true);
                explorerView.getViewer().setSelection(new StructuredSelection(treeObjects), true);
            }
        }
    }
}
Also used : ExplorerView(org.knime.workbench.explorer.view.ExplorerView) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IViewReference(org.eclipse.ui.IViewReference) NodeID(org.knime.core.node.workflow.NodeID) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 12 with NodeID

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

the class SaveAsSubNodeTemplateAction method getDefaultSaveLocation.

private ContentObject getDefaultSaveLocation(final WorkflowManager arg) {
    final NodeID id = arg.getID();
    URI uri = DisconnectSubNodeLinkCommand.RECENTLY_USED_URIS.get(id);
    if (uri == null || !ExplorerFileSystem.SCHEME.equals(uri.getScheme())) {
        return null;
    }
    final AbstractExplorerFileStore oldTemplateFileStore = ExplorerFileSystem.INSTANCE.getStore(uri);
    final AbstractExplorerFileStore parent = oldTemplateFileStore == null ? null : oldTemplateFileStore.getParent();
    if (parent != null) {
        return ContentObject.forFile(parent);
    }
    return null;
}
Also used : AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) NodeID(org.knime.core.node.workflow.NodeID) URI(java.net.URI)

Example 13 with NodeID

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

the class CollapseMetaNodeCommand method create.

/**
 * @param manager
 * @param nodeParts
 * @param annoParts
 * @param encapsulateAsSubnode TODO
 * @return
 */
public static Optional<CollapseMetaNodeCommand> create(final WorkflowManager manager, final NodeContainerEditPart[] nodeParts, final AnnotationEditPart[] annoParts, final boolean encapsulateAsSubnode) {
    NodeID[] nodeIds = new NodeID[nodeParts.length];
    for (int i = 0; i < nodeParts.length; i++) {
        nodeIds[i] = nodeParts[i].getNodeContainer().getID();
    }
    WorkflowAnnotation[] annos = AnnotationEditPart.extractWorkflowAnnotations(annoParts);
    try {
        // before testing anything, let's see if we should reset
        // the selected nodes:
        List<NodeID> resetableIDs = new ArrayList<NodeID>();
        for (NodeID id : nodeIds) {
            if (manager.canResetNode(id)) {
                resetableIDs.add(id);
            }
        }
        if (resetableIDs.size() > 0) {
            // found some: ask if we can reset, otherwise bail
            MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
            mb.setMessage("Executed Nodes will be reset - are you sure?");
            mb.setText("Reset Executed Nodes");
            int dialogreturn = mb.open();
            if (dialogreturn == SWT.CANCEL) {
                return Optional.empty();
            }
        } else {
            // if there are no resetable nodes we can check if
            // we can collapse - otherwise we need to first reset
            // those nodes (which we don't want to do before we
            // have not gathered all info - and allowed the user
            // to cancel the operation!)
            String res = manager.canCollapseNodesIntoMetaNode(nodeIds);
            if (res != null) {
                throw new IllegalArgumentException(res);
            }
        }
        // let the user enter a name
        String name = "Metanode";
        InputDialog idia = new InputDialog(Display.getCurrent().getActiveShell(), "Enter Name of Metanode", "Enter name of Metanode:", name, null);
        int dialogreturn = idia.open();
        if (dialogreturn == Window.CANCEL) {
            return Optional.empty();
        }
        if (dialogreturn == Window.OK) {
            if (resetableIDs.size() > 0) {
                // and skip the ones that were already reset in passing.
                for (NodeID id : resetableIDs) {
                    if (manager.canResetNode(id)) {
                        manager.resetAndConfigureNode(id);
                    }
                }
            }
            // check if there is another reason why we cannot collapse
            String res = manager.canCollapseNodesIntoMetaNode(nodeIds);
            if (res != null) {
                throw new IllegalArgumentException(res);
            }
            name = idia.getValue();
            return Optional.of(new CollapseMetaNodeCommand(manager, nodeIds, annos, name, encapsulateAsSubnode));
        }
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        final String error = "Collapsing to metanode failed: " + e.getMessage();
        LOGGER.error(error, e);
        mb.setMessage(error);
        mb.setText("Collapse failed");
        mb.open();
    }
    return Optional.empty();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 14 with NodeID

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

the class DisconnectMetaNodeLinkCommand 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 WorkflowManager) {
            WorkflowManager wm = (WorkflowManager) nc;
            MetaNodeTemplateInformation lI = wm.getTemplateInformation();
            if (Role.Link.equals(lI.getRole())) {
                MetaNodeTemplateInformation old = hostWFM.setTemplateInformation(id, MetaNodeTemplateInformation.NONE);
                RECENTLY_USED_URIS.put(wm.getID(), old.getSourceURI());
                m_changedIDs.add(id);
                m_oldTemplInfos.add(old);
            }
        }
    }
}
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 15 with NodeID

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

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