Search in sources :

Example 1 with DynamicNodeTemplate

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

the class RepositoryManager method readNodeSets.

/**
 * @param isInExpertMode
 */
private void readNodeSets(final IProgressMonitor monitor) {
    // 
    // Process the contributed node sets
    // 
    Iterator<IConfigurationElement> it = Stream.of(RepositoryManager.getExtensions(ID_NODE_SET)).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(elem -> !"true".equalsIgnoreCase(elem.getAttribute("deprecated"))).iterator();
    while (it.hasNext()) {
        IConfigurationElement elem = it.next();
        try {
            Collection<DynamicNodeTemplate> dynamicNodeTemplates = RepositoryFactory.createNodeSet(m_root, elem);
            for (DynamicNodeTemplate node : dynamicNodeTemplates) {
                if (monitor.isCanceled()) {
                    return;
                }
                for (Listener l : m_loadListeners) {
                    l.newNode(m_root, node);
                }
                m_nodesById.put(node.getID(), node);
                String nodeName = node.getID();
                nodeName = nodeName.substring(nodeName.lastIndexOf('.') + 1);
                // Ask the root to lookup the category-container located
                // at
                // the given path
                IContainerObject parentContainer = m_root.findContainer(node.getCategoryPath());
                // the node to the repository root.
                if (parentContainer == null) {
                    LOGGER.warn("Invalid category-path for node " + "contribution: '" + node.getCategoryPath() + "' - adding to root instead");
                    m_root.addChild(node);
                } else {
                    // everything is fine, add the node to its parent
                    // category
                    parentContainer.addChild(node);
                }
            }
        } catch (Throwable t) {
            String message = "Node " + elem.getAttribute("factory-class") + "' from plugin '" + elem.getNamespaceIdentifier() + "' could not be created.";
            Bundle bundle = Platform.getBundle(elem.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 += " The corresponding plugin " + "bundle could not be activated!";
            }
            LOGGER.error(message, t);
        }
    }
}
Also used : Arrays(java.util.Arrays) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FileNativeNodeContainerPersistor(org.knime.core.node.workflow.FileNativeNodeContainerPersistor) Category(org.knime.workbench.repository.model.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Root(org.knime.workbench.repository.model.Root) Bundle(org.osgi.framework.Bundle) IExtension(org.eclipse.core.runtime.IExtension) AbstractContainerObject(org.knime.workbench.repository.model.AbstractContainerObject) NodeFactory(org.knime.core.node.NodeFactory) Iterator(java.util.Iterator) Collection(java.util.Collection) NodeModel(org.knime.core.node.NodeModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) IContainerObject(org.knime.workbench.repository.model.IContainerObject) List(java.util.List) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) Stream(java.util.stream.Stream) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate) Platform(org.eclipse.core.runtime.Platform) Comparator(java.util.Comparator) Collections(java.util.Collections) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Bundle(org.osgi.framework.Bundle) IContainerObject(org.knime.workbench.repository.model.IContainerObject) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate)

Example 2 with DynamicNodeTemplate

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

the class RepositoryFactory method createNodeSet.

/**
 * Creates the set of dynamic node templates.
 *
 * @param root the root to add the missing categories in
 * @param element from the extension points
 * @return the created dynamic node templates
 */
public static Collection<DynamicNodeTemplate> createNodeSet(final Root root, final IConfigurationElement element) {
    String iconPath = element.getAttribute("default-category-icon");
    // Try to load the node set factory class...
    NodeSetFactory nodeSet;
    // this ensures that the class is loaded by the correct eclipse
    // classloaders
    GlobalClassCreator.lock.lock();
    try {
        nodeSet = (NodeSetFactory) element.createExecutableExtension("factory-class");
    } catch (Throwable e) {
        throw new IllegalArgumentException("Can't load factory class for node: " + element.getAttribute("factory-class"), e);
    } finally {
        GlobalClassCreator.lock.unlock();
    }
    Collection<DynamicNodeTemplate> dynamicNodeTemplates = new ArrayList<DynamicNodeTemplate>();
    // for all nodes in the node set
    for (String factoryId : nodeSet.getNodeFactoryIds()) {
        @SuppressWarnings("unchecked") Class<NodeFactory<? extends NodeModel>> factoryClass = (Class<NodeFactory<? extends NodeModel>>) nodeSet.getNodeFactory(factoryId);
        // Try to load the node factory class...
        NodeFactory<? extends NodeModel> factory;
        // this ensures that the class is loaded by the correct eclipse
        // classloaders
        GlobalClassCreator.lock.lock();
        try {
            factory = DynamicNodeTemplate.createFactoryInstance(factoryClass, nodeSet, factoryId);
        } catch (Throwable e) {
            throw new IllegalArgumentException("Can't load factory class for node: " + factoryClass.getName() + "-" + factoryId, e);
        } finally {
            GlobalClassCreator.lock.unlock();
        }
        // DynamicNodeFactory implementations can set deprecation independently from extension
        if (factory.isDeprecated()) {
            continue;
        }
        DynamicNodeTemplate node = new DynamicNodeTemplate(factoryClass, factoryId, nodeSet, factory.getNodeName());
        node.setAfterID(nodeSet.getAfterID(factoryId));
        if (!Boolean.getBoolean("java.awt.headless")) {
            Image icon = ImageRepository.getIconImage(factory);
            node.setIcon(icon);
        }
        node.setCategoryPath(nodeSet.getCategoryPath(factoryId));
        dynamicNodeTemplates.add(node);
        String pluginID = element.getDeclaringExtension().getNamespaceIdentifier();
        // 
        // Insert in proper location, create all categories on
        // the path
        // if not already there
        // 
        String path = node.getCategoryPath();
        if (path.startsWith("/")) {
            path = path.substring(1);
        }
        // split the path
        String[] segments = path.split("/");
        // start at root
        IContainerObject container = root;
        String currentPath = "";
        for (int i = 0; i < segments.length; i++) {
            IRepositoryObject obj = container.getChildByID(segments[i], false);
            currentPath += segments[i];
            if (obj == null) {
                Category cat = createCategory(pluginID, segments[i], "", segments[i], "", iconPath, currentPath);
                // append the newly created category to the container
                container.addChild(cat);
                obj = cat;
            }
            currentPath += "/";
            // continue at this level
            container = (IContainerObject) obj;
        }
    }
    return dynamicNodeTemplates;
}
Also used : Category(org.knime.workbench.repository.model.Category) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) NodeModel(org.knime.core.node.NodeModel) NodeFactory(org.knime.core.node.NodeFactory) DynamicNodeFactory(org.knime.core.node.DynamicNodeFactory) NodeSetFactory(org.knime.core.node.NodeSetFactory) IContainerObject(org.knime.workbench.repository.model.IContainerObject)

Aggregations

ArrayList (java.util.ArrayList)2 NodeFactory (org.knime.core.node.NodeFactory)2 NodeModel (org.knime.core.node.NodeModel)2 Category (org.knime.workbench.repository.model.Category)2 DynamicNodeTemplate (org.knime.workbench.repository.model.DynamicNodeTemplate)2 IContainerObject (org.knime.workbench.repository.model.IContainerObject)2 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Stream (java.util.stream.Stream)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1