Search in sources :

Example 1 with MetaNodeTemplate

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

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

the class RepositoryManager method readMetanodes.

private void readMetanodes(final IProgressMonitor monitor) {
    // iterate over the meta node config elements
    // and create meta node templates
    IExtension[] metanodeExtensions = getExtensions(ID_META_NODE);
    for (IExtension mnExt : metanodeExtensions) {
        IConfigurationElement[] mnConfigElems = mnExt.getConfigurationElements();
        for (IConfigurationElement mnConfig : mnConfigElems) {
            if (monitor.isCanceled()) {
                return;
            }
            try {
                MetaNodeTemplate metaNode = RepositoryFactory.createMetaNode(mnConfig);
                LOGGER.debug("Found meta node definition '" + metaNode.getID() + "': " + metaNode.getName());
                for (Listener l : m_loadListeners) {
                    l.newMetanode(m_root, metaNode);
                }
                IContainerObject parentContainer = m_root.findContainer(metaNode.getCategoryPath());
                // append the node to the repository root.
                if (parentContainer == null) {
                    LOGGER.warn("Invalid category-path for node " + "contribution: '" + metaNode.getCategoryPath() + "' - adding to root instead");
                    m_root.addChild(metaNode);
                } else {
                    // everything is fine, add the node to its parent
                    // category
                    parentContainer.addChild(metaNode);
                }
            } catch (Throwable t) {
                String message = "MetaNode " + mnConfig.getAttribute("id") + "' from plugin '" + mnConfig.getNamespaceIdentifier() + "' could not be created: " + t.getMessage();
                Bundle bundle = Platform.getBundle(mnConfig.getNamespaceIdentifier());
                if ((bundle == null) || (bundle.getState() != Bundle.ACTIVE)) {
                    // if the plugin is null, the plugin could not
                    // be activated maybe due to a not
                    // activateable plugin
                    // (plugin class cannot be found)
                    message = message + " The corresponding plugin " + "bundle could not be activated!";
                }
                LOGGER.error(message, t);
            }
        }
    }
}
Also used : MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) IExtension(org.eclipse.core.runtime.IExtension) Bundle(org.osgi.framework.Bundle) IContainerObject(org.knime.workbench.repository.model.IContainerObject) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with MetaNodeTemplate

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

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

the class TanimotoTextualViewFilter method doSelect.

/**
 * Copied from {@link TextualViewFilter}.
 */
@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 5 with MetaNodeTemplate

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

the class MetaNodeDropTargetListener method handleDrop.

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

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