Search in sources :

Example 11 with Category

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

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

the class RepositoryFactory method createCategory.

/**
 * Creates a new category object. Throws an exception, if this fails
 *
 * @param root The root to insert the category in
 * @param element Configuration element from the contributing plugin
 * @return Category object to be used within the repository.
 * @throws IllegalArgumentException If the element is not compatible (e.g.
 *             wrong attributes)
 */
public static Category createCategory(final Root root, final IConfigurationElement element) {
    String id = element.getAttribute("level-id");
    // get the id of the contributing plugin
    String pluginID = element.getDeclaringExtension().getNamespaceIdentifier();
    boolean locked = Boolean.parseBoolean(element.getAttribute("locked")) || ((element.getAttribute("locked") == null) && pluginID.matches("^(?:org|com)\\.knime\\..+"));
    Category cat = new Category(id, str(element.getAttribute("name"), "!name is missing!"), pluginID, locked);
    cat.setDescription(str(element.getAttribute("description"), ""));
    cat.setAfterID(str(element.getAttribute("after"), ""));
    String path = str(element.getAttribute("path"), "/");
    cat.setPath(path);
    if (!Boolean.getBoolean("java.awt.headless")) {
        String iconPath = element.getAttribute("icon");
        Image img;
        if (iconPath == null) {
            img = ImageRepository.getIconImage(SharedImages.DefaultCategoryIcon);
        } else {
            img = ImageRepository.getIconImage(pluginID, iconPath);
            if (img == null) {
                LOGGER.coding("Icon '" + element.getAttribute("icon") + "' for category " + cat.getPath() + "/" + cat.getName() + " does not exist");
                img = ImageRepository.getIconImage(SharedImages.DefaultCategoryIcon);
            }
        }
        cat.setIcon(img);
    }
    // 
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    // split the path
    String[] segments = path.split("/");
    // start at root
    IContainerObject container = root;
    for (int i = 0; i < segments.length; i++) {
        IRepositoryObject obj = container.getChildByID(segments[i], false);
        if (obj == null) {
            throw new IllegalArgumentException("The segment '" + segments[i] + "' in path '" + path + "' does not exist!");
        }
        // continue at this level
        container = (IContainerObject) obj;
    }
    String parentPluginId = container.getContributingPlugin();
    if (parentPluginId == null) {
        parentPluginId = "";
    }
    int secondDotIndex = pluginID.indexOf('.', pluginID.indexOf('.') + 1);
    if (secondDotIndex == -1) {
        secondDotIndex = 0;
    }
    if (!container.isLocked() || pluginID.equals(parentPluginId) || pluginID.startsWith("org.knime.") || pluginID.startsWith("com.knime.") || pluginID.regionMatches(0, parentPluginId, 0, secondDotIndex)) {
        // container not locked, or both categories from same plug-in
        // or the vendor is the same (comparing the first two parts of the plug-in ids)
        container.addChild(cat);
    } else {
        LOGGER.error("Locked parent category for category " + cat.getID() + ": " + cat.getPath() + ". Category will NOT be added!");
    }
    return cat;
}
Also used : Category(org.knime.workbench.repository.model.Category) IContainerObject(org.knime.workbench.repository.model.IContainerObject) Image(org.eclipse.swt.graphics.Image) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 13 with Category

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

Example 14 with Category

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

Category (org.knime.workbench.repository.model.Category)14 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)10 MetaNodeTemplate (org.knime.workbench.repository.model.MetaNodeTemplate)8 NodeTemplate (org.knime.workbench.repository.model.NodeTemplate)7 Root (org.knime.workbench.repository.model.Root)7 IContainerObject (org.knime.workbench.repository.model.IContainerObject)5 ArrayList (java.util.ArrayList)4 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)4 Image (org.eclipse.swt.graphics.Image)4 NodeFactory (org.knime.core.node.NodeFactory)4 NodeModel (org.knime.core.node.NodeModel)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 IExtension (org.eclipse.core.runtime.IExtension)3 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 DynamicNodeTemplate (org.knime.workbench.repository.model.DynamicNodeTemplate)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2