Search in sources :

Example 11 with NodeContainerUI

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

the class HelpView method selectionChanged.

/**
 * The method updating the content of the browser. Depending on the type of
 * the selected part(s) it will retrieve the node(s) description and set it
 * in the browser.
 *
 * {@inheritDoc}
 */
@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
    if (m_browser != null && m_browser.isDisposed()) {
        // if someone closed it, unregister as selection listener
        // TODO same for text
        getViewSite().getPage().removeSelectionListener(this);
        return;
    }
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSel = (IStructuredSelection) selection;
        IStructuredSelection lastSel = m_lastSelectionReference == null ? null : m_lastSelectionReference.get();
        // we do not clear our content if nothing is selected.
        if (structSel.size() < 1 || structSel.equals(lastSel)) {
            return;
        }
        m_lastSelectionReference = new WeakReference<>(structSel);
        // we display the full description only if a single node is selected
        boolean useSingleLine;
        if ((structSel.size() > 1) || (structSel.getFirstElement() instanceof Category)) {
            useSingleLine = true;
        } else {
            useSingleLine = false;
        }
        // construct the html page to display
        final StringBuilder content = new StringBuilder();
        if (useSingleLine) {
            // add the prefix to make it a html page
            content.append("<html><head>");
            content.append("<meta http-equiv=\"content-type\" " + "content=\"text/html; charset=UTF-8\"></meta>");
            // include stylesheet
            content.append("<style>");
            content.append(NodeFactoryHTMLCreator.instance.getCss());
            content.append("</style>");
            content.append("</head><body><dl>");
        }
        // Keep a list of already displayed objects (this works as long as
        // the selected items come in an ordered way. Ordered with item
        // containing other selected items coming before the items
        // contained. For the tree view in the repository this is the case.
        HashSet<String> ids = new HashSet<String>();
        for (Iterator<?> selIt = structSel.iterator(); selIt.hasNext(); ) {
            Object sel = selIt.next();
            if (sel instanceof Category) {
                // its a category in the node repository, display a list of
                // contained nodes
                Category cat = (Category) sel;
                if (!ids.contains(cat.getID())) {
                    ids.add(cat.getID());
                    DynamicNodeDescriptionCreator.instance().addDescription(cat, content, ids);
                }
            } else if (sel instanceof NodeTemplate) {
                // its a node selected in the repository
                NodeTemplate templ = (NodeTemplate) sel;
                if (!ids.contains(templ.getID())) {
                    ids.add(templ.getID());
                    DynamicNodeDescriptionCreator.instance().addDescription(templ, useSingleLine, content);
                }
            } else if (sel instanceof NodeContainerEditPart) {
                // if multiple nodes in the editor are selected we should
                // not show description for the same node (if used multiple
                // times) twice. We store the node name in the set.
                NodeContainerUI nc = ((NodeContainerEditPart) sel).getNodeContainer();
                if (!ids.contains(nc.getName())) {
                    ids.add(nc.getName());
                    DynamicNodeDescriptionCreator.instance().addDescription(nc, useSingleLine, content);
                }
            } else if (sel instanceof MetaNodeTemplate) {
                // TODO: add support for MetaNodeTemplates and get the
                // description out of them
                NodeContainerUI manager = ((MetaNodeTemplate) sel).getManager();
                DynamicNodeDescriptionCreator.instance().addDescription(manager, useSingleLine, content);
            }
        }
        if (useSingleLine) {
            // finish the html
            content.append("</dl></body></html>");
        }
        if (m_browser != null) {
            // FG: must always be invoked in SWT UI thread
            m_browser.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (!m_browser.isDisposed()) {
                        m_browser.setText(content.toString());
                    }
                }
            });
        } else if (m_isFallback) {
            m_text.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    m_text.setText(content.toString());
                }
            });
        }
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) Category(org.knime.workbench.repository.model.Category) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) HashSet(java.util.HashSet)

Example 12 with NodeContainerUI

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

the class DynamicNodeDescriptionCreator method addDescription.

/**
 * @param template meta node template
 * @param useSingleLine true if several nodes are selected
 * @param builder gathers the HTML content
 */
public void addDescription(final MetaNodeTemplate template, final boolean useSingleLine, final StringBuilder builder) {
    WorkflowManagerUI manager = template.getManager();
    if (!useSingleLine) {
        builder.append(getHeader());
        builder.append("<h1>");
        builder.append(manager.getName());
        builder.append("</h1>");
        builder.append("<h2>Description:</h2>");
        builder.append("<p>" + template.getDescription() + "</p>");
        builder.append("<h2>Contained nodes: </h2>");
        for (NodeContainerUI child : manager.getNodeContainers()) {
            addDescription(child, true, builder);
        }
        builder.append("</body></html>");
    } else {
        builder.append("<dt><b>" + manager.getName() + "</b></dt>");
        builder.append("<dd>" + template.getDescription() + "</dd>");
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI)

Example 13 with NodeContainerUI

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

the class WorkflowEditor method getSubEditors.

/**
 * Collects the open editor(s) of the specified (sub-)workflow manager and all sub editor(s) of it. The provided id
 * must be a child of the workflow displayed in this editor.
 *
 * @param id of a child of this editor. Must be a sub/metanode whose editor (and all sub-editors recursively) will
 *            be returned.
 * @return a list of open editors
 */
public List<IEditorPart> getSubEditors(final NodeID id) {
    List<IEditorPart> editors = new ArrayList<IEditorPart>();
    if (m_manager == null) {
        // no workflow, no sub editors
        return editors;
    }
    NodeContainerUI child = null;
    WorkflowManagerUI child_mgr = null;
    try {
        child = m_manager.getNodeContainer(id);
    } catch (IllegalArgumentException iae) {
        // if node doesn't exist - or just got deleted, then there are no sub editors
        return editors;
    }
    if (child instanceof SubNodeContainerUI) {
        child_mgr = ((SubNodeContainerUI) child).getWorkflowManager();
    } else if (child instanceof WorkflowManagerUI) {
        child_mgr = (WorkflowManagerUI) child;
    } else {
        return editors;
    }
    WorkflowManagerInput in = new WorkflowManagerInput(child_mgr, this);
    if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
        for (IWorkbenchPage p : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages()) {
            IEditorPart child_editor = p.findEditor(in);
            if (child_editor != null) {
                editors.add(child_editor);
                if (child_editor instanceof WorkflowEditor) {
                    // recursively add sub editors (to get sub/metanodes in sub/metanodes)
                    for (NodeContainerUI nc : child_mgr.getNodeContainers()) {
                        editors.addAll(((WorkflowEditor) child_editor).getSubEditors(nc.getID()));
                    }
                }
            }
        }
    }
    return editors;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) ArrayList(java.util.ArrayList) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) IEditorPart(org.eclipse.ui.IEditorPart)

Example 14 with NodeContainerUI

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

the class NodeOutPortEditPart method createFigure.

/**
 * {@inheritDoc}
 */
@Override
protected IFigure createFigure() {
    // Create the figure, we need the number of ports from the parent
    // container
    NodeContainerUI container = getNodeContainer();
    NodeOutPortUI port = container.getOutPort(getIndex());
    String tooltip = getTooltipText(port.getPortName(), port);
    boolean isMetaNode = !(container instanceof SingleNodeContainerUI);
    NodeOutPortFigure portFigure = new NodeOutPortFigure(getType(), getIndex(), container.getNrOutPorts(), isMetaNode, tooltip);
    portFigure.setInactive(port.isInactive());
    portFigure.setIsConnected(isConnected());
    return portFigure;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) NodeOutPortUI(org.knime.core.ui.node.workflow.NodeOutPortUI) NodeOutPortFigure(org.knime.workbench.editor2.figures.NodeOutPortFigure)

Example 15 with NodeContainerUI

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

the class MetaNodeOutPortEditPart method createFigure.

/**
 * {@inheritDoc}
 */
@Override
protected IFigure createFigure() {
    NodeContainerUI nc = getNodeContainer();
    LOGGER.debug("returning new sub metanode out port figure " + " with type " + getType() + " index " + getIndex() + " nr outports " + nc.getNrOutPorts() + " and tooltip " + nc.getOutPort(getIndex()).getPortName());
    WorkflowOutPortUI model = (WorkflowOutPortUI) getModel();
    LOGGER.debug("model: " + getModel() + " state: " + model.getNodeState());
    NodeOutPortUI port = nc.getOutPort(getIndex());
    String tooltip = getTooltipText(port.getPortName(), port);
    MetaNodeOutPortFigure f = new MetaNodeOutPortFigure(getType(), getIndex(), nc.getNrOutPorts(), tooltip, model.getNodeState());
    f.setInactive(model.isInactive());
    f.setIsConnected(isConnected());
    return f;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) WorkflowOutPortUI(org.knime.core.ui.node.workflow.WorkflowOutPortUI) NodeOutPortUI(org.knime.core.ui.node.workflow.NodeOutPortUI) MetaNodeOutPortFigure(org.knime.workbench.editor2.figures.MetaNodeOutPortFigure)

Aggregations

NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)59 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)28 SubNodeContainerUI (org.knime.core.ui.node.workflow.SubNodeContainerUI)17 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)16 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)10 NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)9 SingleNodeContainerUI (org.knime.core.ui.node.workflow.SingleNodeContainerUI)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)7 HashMap (java.util.HashMap)5 Point (org.eclipse.draw2d.geometry.Point)5 Image (org.eclipse.swt.graphics.Image)5 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)5 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)5 NodeID (org.knime.core.node.workflow.NodeID)5 ArrayList (java.util.ArrayList)4 EditPart (org.eclipse.gef.EditPart)4 LoopEndNode (org.knime.core.node.workflow.LoopEndNode)4 IContainer (org.eclipse.core.resources.IContainer)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3