Search in sources :

Example 46 with NodeID

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

the class RevealMetaNodeTemplateAction 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 (model instanceof WorkflowManagerUI) {
            NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
            try {
                WorkflowManager wm = Wrapper.unwrapWFM((UI) model);
                MetaNodeTemplateInformation i = wm.getTemplateInformation();
                if (Role.Link.equals(i.getRole())) {
                    candidateList.add(wm.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) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) 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 47 with NodeID

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

the class SaveAsMetaNodeTemplateAction method getDefaultSaveLocation.

private ContentObject getDefaultSaveLocation(final WorkflowManager arg) {
    final NodeID id = arg.getID();
    URI uri = DisconnectMetaNodeLinkCommand.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 48 with NodeID

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

the class CreateMetaNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // Add node to workflow and get the container
    try {
        WorkflowManager wfm = getHostWFM();
        m_copyContent = wfm.paste(m_persistor);
        NodeID[] nodeIDs = m_copyContent.getNodeIDs();
        if (nodeIDs.length > 0) {
            NodeID first = nodeIDs[0];
            m_container = wfm.getNodeContainer(first);
            // 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);
        }
    } catch (Throwable t) {
        // if fails notify the user
        String error = "Metanode cannot be created";
        LOGGER.debug(error + ": " + t.getMessage(), t);
        MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
        mb.setText(error);
        mb.setMessage("The metanode 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) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 49 with NodeID

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

the class CreateMetaNodeCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    NodeID[] ids = m_copyContent.getNodeIDs();
    if (LOGGER.isDebugEnabled()) {
        String debug = "Removing node";
        if (ids.length == 1) {
            debug = debug + " " + ids[0];
        } else {
            debug = debug + "s " + Arrays.asList(ids);
        }
        LOGGER.debug(debug);
    }
    WorkflowManager wm = getHostWFM();
    if (canUndo()) {
        for (NodeID id : ids) {
            wm.removeNode(id);
        }
        for (WorkflowAnnotation anno : m_copyContent.getAnnotations()) {
            wm.removeAnnotation(anno);
        }
    } else {
        MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Operation no allowed", "The node(s) " + Arrays.asList(ids) + " can currently not be removed");
    }
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 50 with NodeID

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

the class CreateNewConnectedMetaNodeCommand method createNewNode.

/**
 * {@inheritDoc}
 */
@Override
protected NodeID createNewNode() {
    WorkflowCopyContent.Builder content = WorkflowCopyContent.builder();
    content.setNodeIDs(m_sourceID);
    WorkflowManager hostWFM = getHostWFM();
    NodeID[] copied = hostWFM.copyFromAndPasteHere(m_source, content.build()).getNodeIDs();
    assert copied.length == 1;
    return copied[0];
}
Also used : WorkflowCopyContent(org.knime.core.node.workflow.WorkflowCopyContent) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID)

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