Search in sources :

Example 16 with NodeTemplate

use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.

the class NodeDescriptionConverter method processAll.

private boolean processAll(final IRepositoryObject[] elements, final Document nodeToc) throws Exception {
    boolean nodeCreated = false;
    for (IRepositoryObject o : elements) {
        if (o instanceof Category) {
            Category c = (Category) o;
            if (c.getParent() instanceof Root && m_monitor != null) {
                Display d = Display.getDefault();
                d.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        m_monitor.worked(2);
                    }
                });
            }
            // create toc file
            Document topicFile = createNodeTocFile(c);
            boolean hasNodes = processAll(((Category) o).getChildren(), topicFile);
            if (c.getContributingPlugin().equals(m_pluginID)) {
                writeCategoryTocFile(c);
            }
            if (hasNodes) {
                // write toc file
                writeNodeTocFile(topicFile, fileName(getFullPath(c) + NODES));
                writeTocToPluginXML(c, true);
            }
        // TODO: why is nodeToc null?
        } else if (o instanceof NodeTemplate && nodeToc != null) {
            nodeCreated |= processNode((NodeTemplate) o, nodeToc);
        } else if (o instanceof MetaNodeTemplate && nodeToc != null) {
            nodeCreated |= processMetaNode((MetaNodeTemplate) o, nodeToc);
        }
    }
    return nodeCreated;
}
Also used : Category(org.knime.workbench.repository.model.Category) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) Root(org.knime.workbench.repository.model.Root) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) Document(org.w3c.dom.Document) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) Display(org.eclipse.swt.widgets.Display)

Example 17 with NodeTemplate

use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.

the class NodeUsageRegistry method loadLastUsedNodes.

/**
 * Loads the last used nodes from XML memento. Called from
 * FavoriteNodesManager#loadFavoriteNodes.
 *
 * @see #saveLastUsedNodes(IMemento)
 * @param lastUsedNodes the XML memento to load the last used nodes from
 */
public static void loadLastUsedNodes(final IMemento lastUsedNodes) {
    for (IMemento lastNode : lastUsedNodes.getChildren(TAG_FAVORITE)) {
        String id = lastNode.getString(TAG_NODE_ID);
        NodeTemplate node = RepositoryManager.INSTANCE.getNodeTemplate(id);
        if (node != null) {
            addToLastUsedNodes(node);
        }
    }
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) IMemento(org.eclipse.ui.IMemento)

Example 18 with NodeTemplate

use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.

the class DynamicNodeDescriptionCreator method addDescription.

/**
 * Adds the single line description for all nodes contained in the category
 * (and all sub categories) to the StringBuilder. It will separate the lines
 * by a HTML new line tag.
 *
 * @param cat the category to add the descriptions for.
 * @param bld the buffer to add the one line strings to.
 * @param idsDisplayed a set of IDs of categories and templates already
 *            displayed. Items appearing twice will be skipped.
 */
public void addDescription(final Category cat, final StringBuilder bld, final Set<String> idsDisplayed) {
    bld.append("<dl>");
    bld.append("<dt><h2>In <b>");
    bld.append(htmlString(cat.getName()));
    bld.append("</b>:</h2></dt> \n");
    if (!cat.hasChildren()) {
        bld.append("<dd> - contains no nodes - </dd>");
    } else {
        bld.append("<dd><dl>");
        for (IRepositoryObject child : cat.getChildren()) {
            if (child instanceof Category) {
                Category childCat = (Category) child;
                if (!idsDisplayed.contains(childCat.getID())) {
                    idsDisplayed.add(childCat.getID());
                    addDescription(childCat, bld, idsDisplayed);
                }
            } else if (child instanceof NodeTemplate) {
                NodeTemplate templ = (NodeTemplate) child;
                if (!idsDisplayed.contains(templ.getID())) {
                    idsDisplayed.add(templ.getID());
                    addDescription(templ, /* useSingleLine */
                    true, bld);
                }
            } else if (child instanceof MetaNodeTemplate) {
                MetaNodeTemplate templ = (MetaNodeTemplate) child;
                if (!idsDisplayed.contains(templ.getID())) {
                    idsDisplayed.add(templ.getID());
                    NodeContainerUI manager = ((MetaNodeTemplate) child).getManager();
                    addDescription(manager, /* useSingleLine */
                    true, bld);
                }
            } else {
                bld.append(" - contains unknown object (internal err!) -");
            }
        }
        bld.append("</dl></dd>");
    }
    bld.append("</dl>");
}
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) Category(org.knime.workbench.repository.model.Category) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 19 with NodeTemplate

use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.

the class RepositoryStyledLabelProvider method getVendorAndBundle.

/**
 * @param robj
 * @return
 */
private static String getVendorAndBundle(final Object robj) {
    StringBuilder toReturn = new StringBuilder();
    if (robj instanceof NodeTemplate) {
        @SuppressWarnings("rawtypes") final Class<? extends NodeFactory> facClass = ((NodeTemplate) robj).getFactory();
        Bundle bundle = OSGIHelper.getBundle(facClass);
        if (bundle != null) {
            toReturn.append("Vendor: ");
            toReturn.append(bundle.getHeaders().get(Constants.BUNDLE_VENDOR));
            toReturn.append(" - ");
        }
        ((NodeTemplate) robj).getContributingPlugin();
    }
    if (robj instanceof IRepositoryObject) {
        toReturn.append("Plugin: ");
        toReturn.append(((IRepositoryObject) robj).getContributingPlugin());
    }
    return toReturn.toString();
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) Bundle(org.osgi.framework.Bundle) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 20 with NodeTemplate

use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.

the class WorkflowCoachView method hookDoubleClickAction.

/**
 * Inserts a node on double click into the workflow editor.
 */
private void hookDoubleClickAction() {
    m_viewer.addDoubleClickListener(event -> {
        Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (o instanceof NodeRecommendation[]) {
            NodeRecommendation[] nrs = (NodeRecommendation[]) o;
            NodeTemplate tmplt = getNonNullEntry(nrs).getNodeTemplate();
            NodeFactory<? extends NodeModel> nodeFact;
            try {
                nodeFact = tmplt.createFactoryInstance();
            } catch (Exception e) {
                NodeLogger.getLogger(WorkflowCoachView.class).error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
                return;
            }
            boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
            if (added) {
                Display.getDefault().asyncExec(() -> setFocus());
            }
        }
    });
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) NodeRecommendation(org.knime.workbench.workflowcoach.NodeRecommendationManager.NodeRecommendation) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

NodeTemplate (org.knime.workbench.repository.model.NodeTemplate)20 MetaNodeTemplate (org.knime.workbench.repository.model.MetaNodeTemplate)8 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)7 Category (org.knime.workbench.repository.model.Category)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 IMemento (org.eclipse.ui.IMemento)4 NodeFactory (org.knime.core.node.NodeFactory)4 NodeModel (org.knime.core.node.NodeModel)4 Root (org.knime.workbench.repository.model.Root)3 Image (org.eclipse.swt.graphics.Image)2 PartInitException (org.eclipse.ui.PartInitException)2 DynamicNodeTemplate (org.knime.workbench.repository.model.DynamicNodeTemplate)2 IContainerObject (org.knime.workbench.repository.model.IContainerObject)2 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1