Search in sources :

Example 16 with NodeContainer

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

Example 17 with NodeContainer

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

the class ParallelizedChunkContentMaster method cleanupChunks.

/**
 * Clean up chunks (and containing WFM).
 */
public void cleanupChunks() {
    synchronized (m_chunks) {
        for (int i = 0; i < m_chunks.length; i++) {
            ParallelizedChunkContent pbc = m_chunks[i];
            if (pbc != null) {
                pbc.removeLoopEndStateChangeListener(this);
                m_chunks[i] = null;
            }
        }
        if ((m_manager != null) && m_manager.getParent().containsNodeContainer(m_manager.getID())) {
            NodeContainer nc = m_manager.getParent().getNodeContainer(m_manager.getID());
            if (m_manager == nc) {
                // need to make sure that this is not just another node
                // with the same ID (in rare cases this can happen if
                // the metanode was cleared but the StartNode did not
                // get notified and calls this function again.)
                m_manager.getParent().removeNode(m_manager.getID());
            }
        }
    }
}
Also used : NodeContainer(org.knime.core.node.workflow.NodeContainer)

Example 18 with NodeContainer

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

the class DeleteAction method closeOpenWorkflows.

private void closeOpenWorkflows(final List<IContainer> allWorkflows) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (IContainer wf : allWorkflows) {
        NodeContainer wfm = ProjectWorkflowMap.getWorkflow(wf.getLocationURI());
        if (wfm != null) {
            for (IEditorReference editRef : page.getEditorReferences()) {
                IEditorPart editor = editRef.getEditor(false);
                if (editor == null) {
                    // got closed in the mean time
                    continue;
                }
                WorkflowEditorAdapter wea = (WorkflowEditorAdapter) editor.getAdapter(WorkflowEditorAdapter.class);
                NodeContainer editWFM = null;
                if (wea != null) {
                    editWFM = wea.getWorkflowManager();
                }
                if (wfm == editWFM) {
                    page.closeEditor(editor, false);
                }
            }
        }
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) WorkflowEditorAdapter(org.knime.workbench.ui.navigator.WorkflowEditorAdapter) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NodeContainer(org.knime.core.node.workflow.NodeContainer) IEditorPart(org.eclipse.ui.IEditorPart) IContainer(org.eclipse.core.resources.IContainer)

Example 19 with NodeContainer

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

the class WorkflowCoachView method updateInput.

private void updateInput(final ISelection selection) {
    if (NodeRecommendationManager.getInstance().getNumLoadedProviders() == 0) {
        // if there is at least one enabled triple provider then the statistics might need to be download first
        if (NodeRecommendationManager.getInstance().getNodeTripleProviders().stream().anyMatch(ntp -> ntp.isEnabled())) {
            if (m_loadState.get() == LoadState.Disposed) {
                return;
            }
            m_loadState.set(LoadState.LoadingNodes);
            updateInput("Loading recommendations ...");
            // try updating the triple provider that are enabled and require an update
            updateTripleProviders(e -> {
                m_loadState.set(LoadState.Initizalized);
                if (e.isPresent()) {
                    updateInputNoProvider();
                } else {
                    try {
                        NodeRecommendationManager.getInstance().loadRecommendations();
                        if (NodeRecommendationManager.getInstance().getNumLoadedProviders() == 0) {
                            // if there are still no triple provider, show link
                            updateInputNoProvider();
                        } else {
                            updateInput("Statistics successfully loaded. Select a node...");
                        }
                    } catch (Exception e1) {
                        updateInputNoProvider();
                    }
                }
            }, true, false);
        } else {
            // no triple provider enabled -> needs to be configured
            updateInputNoProvider();
            return;
        }
    }
    IStructuredSelection structSel = (IStructuredSelection) selection;
    if (structSel.size() > 1) {
        updateInput("No recommendation for multiple selected nodes.");
        return;
    }
    // retrieve first (and only!) selection:
    Iterator<?> selIt = structSel.iterator();
    boolean nodeSelected = selIt.hasNext();
    NodeContainer nc = null;
    if (nodeSelected) {
        Object sel = selIt.next();
        nodeSelected &= (sel instanceof NodeContainerEditPart);
        if (nodeSelected) {
            NodeContainerUI uinc = ((NodeContainerEditPart) sel).getNodeContainer();
            if (!Wrapper.wraps(uinc, NodeContainer.class)) {
                updateInput("Worklfow coach only supports native nodes, so far.\nBut the selected one is of type '" + uinc.getClass().getSimpleName() + "'.");
                return;
            } else {
                nc = Wrapper.unwrapNC(uinc);
                nodeSelected &= nc instanceof NativeNodeContainer;
            }
        }
    }
    // -> in that case no redraw is required
    if (nodeSelected) {
        if (m_lastSelection.equals(nc.getNameWithID())) {
            return;
        } else {
            m_lastSelection = nc.getNameWithID();
        }
    } else {
        if (m_lastSelection.equals("no node selected")) {
            return;
        } else {
            m_lastSelection = "no node selected";
        }
    }
    List<NodeRecommendation>[] recommendations;
    if (nodeSelected) {
        // retrieve node recommendations if exactly one node is selected
        recommendations = NodeRecommendationManager.getInstance().getNodeRecommendationFor((NativeNodeContainer) nc);
    } else if (nc == null) {
        // retrieve node recommendations if no node is selected (most likely the source nodes etc.)
        recommendations = NodeRecommendationManager.getInstance().getNodeRecommendationFor();
    } else {
        Display.getDefault().syncExec(() -> {
            m_viewer.setInput("");
            m_viewer.refresh();
        });
        return;
    }
    if (recommendations == null) {
        // something went wrong with loading the node recommendations, show the configure link
        updateInputNoProvider();
        return;
    }
    // TODO: cache node recommendations??
    int maxSize = 0;
    for (List<NodeRecommendation> l : recommendations) {
        maxSize = Math.max(maxSize, l.size());
    }
    List<NodeRecommendation[]> recommendationsJoined = joinRecommendations(recommendations, maxSize);
    // remove duplicates from list
    Set<String> duplicates = new HashSet<>();
    List<NodeRecommendation[]> recommendationsWithoutDups = new ArrayList<>(recommendationsJoined.size());
    for (NodeRecommendation[] nrs : recommendationsJoined) {
        int idx = getNonNullIdx(nrs);
        if (duplicates.add(nrs[idx].toString())) {
            recommendationsWithoutDups.add(nrs);
        }
    }
    // update viewer
    changeViewerStateTo(ViewerState.RECOMMENDATIONS);
    Display.getDefault().syncExec(() -> {
        m_viewer.setInput(recommendationsWithoutDups);
        m_viewer.refresh();
        m_recommendationsAvailable = true;
        // scroll to the very top
        if (!recommendationsWithoutDups.isEmpty()) {
            m_viewer.getTable().setTopIndex(0);
        }
    });
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeRecommendation(org.knime.workbench.workflowcoach.NodeRecommendationManager.NodeRecommendation) ArrayList(java.util.ArrayList) NodeContainer(org.knime.core.node.workflow.NodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) List(java.util.List) ArrayList(java.util.ArrayList) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) HashSet(java.util.HashSet)

Example 20 with NodeContainer

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

the class WorkflowExportPage method handleSingleSelection.

private IContainer handleSingleSelection(final IStructuredSelection selection) {
    Object obj = selection.getFirstElement();
    IContainer resultContainer = null;
    // prepare default export file name
    if (obj instanceof IContainer) {
        resultContainer = (IContainer) obj;
    } else if (obj instanceof IResource) {
        resultContainer = ((IResource) obj).getParent();
    }
    if (obj instanceof NodeContainer) {
        resultContainer = getContainerForWorkflow((NodeContainer) obj);
    }
    if (obj instanceof IContainer) {
        IContainer container = (IContainer) obj;
        // check whether it is a workflow group -> list all workflows
        if (KnimeResourceUtil.isWorkflowGroup(container) || container instanceof IWorkspaceRoot) {
            // get all contained containers and list them recursively
            m_treeViewer.setInput(container);
            m_treeViewer.getTree().setVisible(true);
            m_treeViewer.expandAll();
            // all
            if (selection.size() <= 1) {
                /*
                     * Since the tree is expanded before the deprecated method
                     * should work. Reason why it is deprecated:
                     * "this method only checks or unchecks visible items" but
                     * CheckboxTreeViewer#setSubtreeChecked(Object, boolean)
                     * does not work.
                     */
                m_treeViewer.setAllChecked(true);
            }
        } else if (KnimeResourceUtil.isWorkflow(container)) {
            // or a workflow -> list nothing
            m_treeViewer.getTree().setVisible(false);
        }
    }
    return resultContainer;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) NodeContainer(org.knime.core.node.workflow.NodeContainer) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

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