Search in sources :

Example 6 with MetaNodeTemplate

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

the class AbstractRepositoryView method hookDoubleClickAction.

private void hookDoubleClickAction() {
    m_viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(final DoubleClickEvent event) {
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (o instanceof NodeTemplate) {
                NodeTemplate tmplt = (NodeTemplate) o;
                NodeFactory<? extends NodeModel> nodeFact;
                try {
                    nodeFact = tmplt.createFactoryInstance();
                } catch (Exception e) {
                    LOGGER.error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
                    return;
                }
                boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
                if (added) {
                    NodeUsageRegistry.addNode(tmplt);
                }
            } else if (o instanceof MetaNodeTemplate) {
                MetaNodeTemplate mnt = (MetaNodeTemplate) o;
                NodeID metaNode = mnt.getManager().getID();
                NodeProvider.INSTANCE.addMetaNode(WorkflowManager.META_NODE_ROOT, metaNode);
            } else if (o instanceof Category) {
                m_viewer.setExpandedState(o, !m_viewer.getExpandedState(o));
            }
        }
    });
}
Also used : NodeModel(org.knime.core.node.NodeModel) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) Category(org.knime.workbench.repository.model.Category) NodeFactory(org.knime.core.node.NodeFactory) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) NodeID(org.knime.core.node.workflow.NodeID) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) AbstractRepositoryObject(org.knime.workbench.repository.model.AbstractRepositoryObject) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) IContainerObject(org.knime.workbench.repository.model.IContainerObject) PartInitException(org.eclipse.ui.PartInitException) ConcurrentModificationException(java.util.ConcurrentModificationException)

Example 7 with MetaNodeTemplate

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

the class RepositoryViewFilter method doSelect.

/**
 *  An element is selected if itself, a parent or a
 * child contains the query string in its name.
 * {@inheritDoc}
 */
@Override
protected boolean doSelect(final Object parentElement, final Object element, final boolean recurse) {
    boolean selectThis = false;
    // Node Template : Match against name
    if (element instanceof AbstractNodeTemplate) {
        // check against node name
        selectThis = match(((AbstractNodeTemplate) element).getName());
        if (element instanceof MetaNodeTemplate) {
            // with meta nodes also check the name of the workflow manager
            selectThis |= match(((MetaNodeTemplate) element).getManager().getName());
        }
        if (selectThis) {
            return true;
        }
        // we must also check towards root, as we want to include all
        // children of a selected category
        IRepositoryObject temp = (IRepositoryObject) parentElement;
        while (!(temp instanceof Root)) {
            // check parent category, but do *not* recurse !!!!
            if (doSelect(temp.getParent(), temp, false)) {
                return true;
            }
            temp = temp.getParent();
        }
    } else // Category: Match against name and children
    if (element instanceof Category) {
        // check against node name
        selectThis = match(((Category) element).getName());
        if (selectThis) {
            return true;
        }
        // check recursively against children, if needed
        if (recurse) {
            Category category = (Category) element;
            IRepositoryObject[] children = category.getChildren();
            for (int i = 0; i < children.length; i++) {
                // recursively check. return true on first matching child
                if (doSelect(category, children[i], true)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : AbstractNodeTemplate(org.knime.workbench.repository.model.AbstractNodeTemplate) Category(org.knime.workbench.repository.model.Category) Root(org.knime.workbench.repository.model.Root) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 8 with MetaNodeTemplate

use of org.knime.workbench.repository.model.MetaNodeTemplate 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 9 with MetaNodeTemplate

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

the class RepositoryFactory method createMetaNode.

/**
 * @param configuration content of the extension
 * @return a meta node template
 */
public static MetaNodeTemplate createMetaNode(final IConfigurationElement configuration) {
    String id = configuration.getAttribute("id");
    String name = configuration.getAttribute("name");
    String workflowDir = configuration.getAttribute("workflowDir");
    String after = configuration.getAttribute("after");
    String iconPath = configuration.getAttribute("icon");
    String categoryPath = configuration.getAttribute("category-path");
    String pluginId = configuration.getDeclaringExtension().getNamespaceIdentifier();
    String description = configuration.getAttribute("description");
    WorkflowManagerUI manager = loadMetaNode(pluginId, workflowDir);
    if (manager == null) {
        LOGGER.error("MetaNode  " + name + " could not be loaded. " + "Skipped.");
        return null;
    }
    MetaNodeTemplate template = new MetaNodeTemplate(id, name, categoryPath, configuration.getContributor().getName(), manager);
    if (after != null && !after.isEmpty()) {
        template.setAfterID(after);
    }
    if (description != null) {
        template.setDescription(description);
    }
    if (!Boolean.getBoolean("java.awt.headless")) {
        // Load images from declaring plugin
        Image icon = null;
        if (iconPath != null) {
            icon = ImageRepository.getIconImage(pluginId, iconPath);
        }
        if (icon == null) {
            LOGGER.coding("Icon '" + iconPath + "' for metanode " + categoryPath + "/" + name + " does not exist");
            icon = ImageRepository.getIconImage(SharedImages.DefaultMetaNodeIcon);
        }
        template.setIcon(icon);
    }
    return template;
}
Also used : MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) Image(org.eclipse.swt.graphics.Image)

Example 10 with MetaNodeTemplate

use of org.knime.workbench.repository.model.MetaNodeTemplate 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)

Aggregations

MetaNodeTemplate (org.knime.workbench.repository.model.MetaNodeTemplate)10 Category (org.knime.workbench.repository.model.Category)6 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)5 NodeTemplate (org.knime.workbench.repository.model.NodeTemplate)5 Root (org.knime.workbench.repository.model.Root)3 PartInitException (org.eclipse.ui.PartInitException)2 NodeID (org.knime.core.node.workflow.NodeID)2 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)2 AbstractNodeTemplate (org.knime.workbench.repository.model.AbstractNodeTemplate)2 IContainerObject (org.knime.workbench.repository.model.IContainerObject)2 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashSet (java.util.HashSet)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Image (org.eclipse.swt.graphics.Image)1 Display (org.eclipse.swt.widgets.Display)1 NodeFactory (org.knime.core.node.NodeFactory)1