Search in sources :

Example 1 with IRepositoryObject

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

the class RepositoryManager method removeEmptyCategories.

private static void removeEmptyCategories(final AbstractContainerObject treeNode) {
    for (IRepositoryObject object : treeNode.getChildren()) {
        if (object instanceof AbstractContainerObject) {
            AbstractContainerObject cat = (AbstractContainerObject) object;
            removeEmptyCategories(cat);
            if (!cat.hasChildren() && (cat.getParent() != null)) {
                cat.getParent().removeChild((AbstractContainerObject) object);
            }
        }
    }
}
Also used : AbstractContainerObject(org.knime.workbench.repository.model.AbstractContainerObject) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 2 with IRepositoryObject

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

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

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

the class NodeDocuGenerator method generate.

/**
 * Starts generating the node reference documents.
 *
 * @throws Exception
 */
private void generate() throws Exception {
    // copy static html files
    copyFiles(FILES_TO_COPY);
    m_nodeRepository.setLength(0);
    // write css file
    Writer css = createDocumentWriter("style.css", m_directory);
    css.write(NodeFactoryHTMLCreator.instance.getCss());
    css.close();
    System.out.println("Reading node repository");
    IRepositoryObject root = RepositoryManager.INSTANCE.getRoot();
    // replace '/' with points and remove leading '/'
    if (m_catPath.startsWith("/")) {
        m_catPath = m_catPath.substring(1);
    }
    m_catPath = m_catPath.replaceAll("/", ".");
    // recursively generate the node reference and the node description
    // pages
    generate(m_directory, root, null);
    // complete and write repository template
    String nodeRepo = m_nodeRepositoryTemplate.replace("[NODE_REPOSITORY]", m_nodeRepository.toString());
    Writer out = createDocumentWriter("node_repository.html", m_directory);
    out.write(nodeRepo);
    out.close();
    String header = readFile(HEADER_TEMPLATE);
    header = header.replace("[KNIME_VERSION]", KNIMEConstants.MAJOR + "." + KNIMEConstants.MINOR + "." + KNIMEConstants.REV);
    out = createDocumentWriter("header.html", m_directory);
    out.write(header);
    out.close();
}
Also used : BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 5 with IRepositoryObject

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

the class FavoriteNodesManager method saveFavoriteNodes.

private void saveFavoriteNodes(final XMLMemento memento) {
    // personal favorites
    IMemento favNodes = memento.createChild(TAG_PERSONAL_FAVS);
    for (IRepositoryObject reposObj : m_favNodes.getChildren()) {
        IMemento item = favNodes.createChild(TAG_FAVORITE);
        item.putString(TAG_NODE_ID, ((NodeTemplate) reposObj).getID());
    }
    // most frequent
    IMemento freqNodes = memento.createChild(TAG_MOST_FREQUENT);
    NodeUsageRegistry.saveFrequentNodes(freqNodes);
    // last used
    IMemento lastUsedNodes = memento.createChild(TAG_LAST_USED);
    NodeUsageRegistry.saveLastUsedNodes(lastUsedNodes);
}
Also used : IMemento(org.eclipse.ui.IMemento) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Aggregations

IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)13 Category (org.knime.workbench.repository.model.Category)7 MetaNodeTemplate (org.knime.workbench.repository.model.MetaNodeTemplate)5 NodeTemplate (org.knime.workbench.repository.model.NodeTemplate)5 IContainerObject (org.knime.workbench.repository.model.IContainerObject)4 Root (org.knime.workbench.repository.model.Root)4 Image (org.eclipse.swt.graphics.Image)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Writer (java.io.Writer)2 NodeFactory (org.knime.core.node.NodeFactory)2 NodeModel (org.knime.core.node.NodeModel)2 AbstractNodeTemplate (org.knime.workbench.repository.model.AbstractNodeTemplate)2 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 StyledString (org.eclipse.jface.viewers.StyledString)1 ImageData (org.eclipse.swt.graphics.ImageData)1 ImageLoader (org.eclipse.swt.graphics.ImageLoader)1 Display (org.eclipse.swt.widgets.Display)1