Search in sources :

Example 1 with IContainerObject

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

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

the class RepositoryManager method readNodes.

/**
 * @param isInExpertMode
 */
private void readNodes(final IProgressMonitor monitor) {
    // 
    // Second, process the contributed nodes
    // 
    IContainerObject uncategorized = m_root.findContainer("/uncategorized");
    if (uncategorized == null) {
        // this should never happen, but who knows...
        uncategorized = m_root;
    }
    Iterator<IConfigurationElement> it = Stream.of(RepositoryManager.getExtensions(ID_NODE)).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(elem -> !"true".equalsIgnoreCase(elem.getAttribute("deprecated"))).iterator();
    while (it.hasNext()) {
        IConfigurationElement elem = it.next();
        if (monitor.isCanceled()) {
            return;
        }
        try {
            NodeTemplate node = RepositoryFactory.createNode(elem);
            LOGGER.debug("Found node extension '" + node.getID() + "': " + node.getName());
            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.coding("Unknown category for node " + node.getID() + " (plugin: " + node.getContributingPlugin() + "): " + node.getCategoryPath() + ". Node will be added to 'Uncategorized' instead");
                uncategorized.addChild(node);
            } else {
                String nodePluginId = elem.getNamespaceIdentifier();
                String categoryPluginId = parentContainer.getContributingPlugin();
                if (categoryPluginId == null) {
                    categoryPluginId = "";
                }
                int secondDotIndex = nodePluginId.indexOf('.', nodePluginId.indexOf('.') + 1);
                if (secondDotIndex == -1) {
                    secondDotIndex = 0;
                }
                if (!parentContainer.isLocked() || nodePluginId.equals(categoryPluginId) || nodePluginId.startsWith("org.knime.") || nodePluginId.startsWith("com.knime.") || nodePluginId.regionMatches(0, categoryPluginId, 0, secondDotIndex)) {
                    // container not locked, or node and category from same plug-in
                    // or the vendor is the same (comparing the first two parts of the plug-in ids)
                    parentContainer.addChild(node);
                } else {
                    LOGGER.coding("Locked category for node " + node.getID() + ": " + node.getCategoryPath() + ". Node will be added to 'Uncategorized' instead");
                    uncategorized.addChild(node);
                }
            }
        } catch (Throwable t) {
            String message = "Node " + elem.getAttribute("factory-class") + "' from plugin '" + elem.getNamespaceIdentifier() + "' could not be created: " + t.getMessage();
            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);
        }
    }
// for configuration elements
}
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) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) Bundle(org.osgi.framework.Bundle) IContainerObject(org.knime.workbench.repository.model.IContainerObject) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 3 with IContainerObject

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

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

the class RepositoryStyledLabelProvider method getCategoryString.

private static String getCategoryString(final IRepositoryObject obj) {
    StringBuilder builder = new StringBuilder();
    IContainerObject curr = obj.getParent();
    while (curr != null && curr.getParent() != null) {
        builder.insert(0, "/" + curr.getName());
        curr = curr.getParent();
    }
    return builder.toString();
}
Also used : IContainerObject(org.knime.workbench.repository.model.IContainerObject)

Example 5 with IContainerObject

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

the class NodeDocuGenerator method getCategoryIdentifier.

/*
     * Helper to compose the category names/identifier of the super-categories
     * and the current one
     */
private static String getCategoryIdentifier(final Category cat) {
    IContainerObject parent = cat.getParent();
    String identifier = cat.getID();
    while (!(parent instanceof Root)) {
        identifier = parent.getID() + "." + identifier;
        parent = parent.getParent();
    }
    return identifier;
}
Also used : Root(org.knime.workbench.repository.model.Root) IContainerObject(org.knime.workbench.repository.model.IContainerObject)

Aggregations

IContainerObject (org.knime.workbench.repository.model.IContainerObject)8 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)5 NodeFactory (org.knime.core.node.NodeFactory)4 NodeModel (org.knime.core.node.NodeModel)4 Category (org.knime.workbench.repository.model.Category)4 MetaNodeTemplate (org.knime.workbench.repository.model.MetaNodeTemplate)4 ArrayList (java.util.ArrayList)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 IExtension (org.eclipse.core.runtime.IExtension)3 DynamicNodeTemplate (org.knime.workbench.repository.model.DynamicNodeTemplate)3 NodeTemplate (org.knime.workbench.repository.model.NodeTemplate)3 Root (org.knime.workbench.repository.model.Root)3 Bundle (org.osgi.framework.Bundle)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2