Search in sources :

Example 6 with NodeTemplate

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

the class NodeDropTargetListener method handleDrop.

/**
 * {@inheritDoc}
 */
@Override
protected void handleDrop() {
    NodeTemplate template = getSelectionNodeTemplate();
    getFactory().setNodeTemplate(template);
    super.handleDrop();
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) AbstractNodeTemplate(org.knime.workbench.repository.model.AbstractNodeTemplate)

Example 7 with NodeTemplate

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

the class SearchQueryContributionItem method createNode.

/**
 * Helper to insert a node into the workflow editor.
 *
 * @param event
 */
private void createNode(final Object o) {
    if (o instanceof NodeTemplate) {
        NodeTemplate tmplt = (NodeTemplate) o;
        NodeFactory<? extends NodeModel> nodeFact;
        try {
            nodeFact = tmplt.createFactoryInstance();
        } catch (Exception e) {
            NodeLogger.getLogger(SearchQueryContributionItem.class).error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
            return;
        }
        boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
        if (added) {
            NodeUsageRegistry.addNode(tmplt);
        }
    }
    if (o instanceof MetaNodeTemplate) {
        MetaNodeTemplate mnt = (MetaNodeTemplate) o;
        NodeID metaNode = mnt.getManager().getID();
        NodeProvider.INSTANCE.addMetaNode(WorkflowManager.META_NODE_ROOT, metaNode);
    }
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) NodeID(org.knime.core.node.workflow.NodeID) PartInitException(org.eclipse.ui.PartInitException)

Example 8 with NodeTemplate

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

the class NodeDocuGenerator method generate.

/**
 * Recursively generates the nodes description documents and the menu entries.
 *
 * @param directory
 * @param current
 * @param parent parent repository object as some nodes pointing to "frequently used"-repository object as a parent
 * @throws Exception
 * @throws TransformerException
 *
 * @return true, if the element was added to the documentation, false if it has been skipped
 */
private boolean generate(final File directory, final IRepositoryObject current, final IRepositoryObject parent) throws TransformerException, Exception {
    // current length of the repository string to be able to revert it to
    // the current state
    int currentLength = m_nodeRepository.length();
    if (current instanceof NodeTemplate) {
        // skip node if not part of the specified plugin
        if (m_pluginId != null && !current.getContributingPlugin().equals(m_pluginId)) {
            return false;
        }
        // as argument
        if (m_catPath.length() > 0) {
            String catIdentifier = getCategoryIdentifier((Category) parent);
            if (!catIdentifier.startsWith(m_catPath)) {
                return false;
            }
        }
        // ((NodeTemplate)current).getID();
        String nodeIdentifier = cleanNodeIdForFileName((NodeTemplate) current);
        // write icon to disc
        URL iconURL = ((NodeTemplate) current).createFactoryInstance().getIcon();
        String nodeIcon;
        if (iconURL != null) {
            writeStreamToFile(iconURL.openStream(), nodeIdentifier + ".png");
            nodeIcon = nodeIdentifier + ".png";
        } else {
            nodeIcon = "knime_default_icon.png";
        }
        // the node repository-like menu
        m_nodeRepository.append("<li style=\"list-style-image: url(");
        m_nodeRepository.append(nodeIcon);
        m_nodeRepository.append(");\" class=\"knime-node\"><span class=\"childs\"><a href=\"");
        m_nodeRepository.append(current.getID());
        m_nodeRepository.append(".html\" target=\"Node Description\">");
        m_nodeRepository.append(((NodeTemplate) current).getName());
        m_nodeRepository.append("</a></span></li>\n");
        // create page with node description and return, as no more
        // children
        // are available
        Writer nodeDoc = createDocumentWriter(cleanNodeIdForFileName((NodeTemplate) current) + ".html", directory);
        String nodeDescription = NodeFactoryHTMLCreator.instance.readFullDescription(((NodeTemplate) current).createFactoryInstance().getXMLDescription());
        // extract the body of the node description html-document
        nodeDescription = nodeDescription.substring(nodeDescription.indexOf("<body>") + 6, nodeDescription.indexOf("</body>"));
        nodeDescription = m_nodeDescriptionTemplate.replace("[NODE_DESCRIPTION]", nodeDescription);
        nodeDoc.write(nodeDescription);
        nodeDoc.flush();
        nodeDoc.close();
        return true;
    } else if (current instanceof Category || current instanceof Root) {
        System.out.println("Processing category " + getPath(current));
        IRepositoryObject[] repoObjs = ((IContainerObject) current).getChildren();
        if (current instanceof Category) {
            String catIdentifier = getCategoryIdentifier((Category) current);
            // write icon to disc and add html-tags
            ImageLoader loader = new ImageLoader();
            Image catImg = ((Category) current).getIcon();
            String catIcon;
            if (catImg != null) {
                loader.data = new ImageData[] { catImg.getImageData() };
                loader.save(directory + File.separator + catIdentifier + ".png", SWT.IMAGE_PNG);
                catIcon = catIdentifier + ".png";
            } else {
                catIcon = "knime_default_icon.png";
            }
            m_nodeRepository.append("<li class=\"knime-category\">");
            m_nodeRepository.append("<img width=\"16px\" src=\"");
            m_nodeRepository.append(catIcon);
            m_nodeRepository.append("\"/>&nbsp;");
            m_nodeRepository.append(((Category) current).getName());
            m_nodeRepository.append("</span><ul>");
        }
        boolean hasChildren = false;
        for (IRepositoryObject repoObj : repoObjs) {
            hasChildren = hasChildren | generate(directory, repoObj, current);
        }
        if (hasChildren) {
            m_nodeRepository.append("</ul></li>");
            return true;
        } else {
            // revert all entries done so far
            m_nodeRepository.setLength(currentLength);
            return false;
        }
    } else {
        // most likely a metanode), we just ignore them for now
        return false;
    }
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) Category(org.knime.workbench.repository.model.Category) Root(org.knime.workbench.repository.model.Root) ImageData(org.eclipse.swt.graphics.ImageData) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 9 with NodeTemplate

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

the class RemoveFavoriteActionDelegate method selectionChanged.

/**
 * {@inheritDoc}
 */
public void selectionChanged(final IAction action, final ISelection selection) {
    action.setEnabled(false);
    if (((IStructuredSelection) selection).getFirstElement() != null && ((IStructuredSelection) selection).getFirstElement() instanceof NodeTemplate) {
        NodeTemplate node = (NodeTemplate) ((IStructuredSelection) selection).getFirstElement();
        if (node.getParent() != null && node.getParent().getID() != null && node.getParent().getID().equals(FavoriteNodesManager.FAV_CAT_ID)) {
            m_node = (NodeTemplate) ((IStructuredSelection) selection).getFirstElement();
            action.setEnabled(true);
        }
    }
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 10 with NodeTemplate

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

the class NodeRecommendationManager method add.

/**
 * Adds a new node recommendation to the map.
 */
private static void add(final Map<String, List<NodeRecommendation>> recommendation, final String key, final NodeInfo ni, final int count) {
    List<NodeRecommendation> p = recommendation.computeIfAbsent(key, k -> new ArrayList<>());
    // create the new node recommendation
    NodeTemplate nt = findNodeTemplate(ni);
    if (nt != null) {
        p.add(new NodeRecommendation(nt, count));
    }
}
Also used : NodeTemplate(org.knime.workbench.repository.model.NodeTemplate)

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