use of org.knime.workbench.repository.model.Category in project knime-core by knime.
the class RepositoryFactory method createCategory.
/* Little helper to create a category */
private static Category createCategory(final String pluginID, final String categoryID, final String description, final String name, final String afterID, final String icon, final String categoryPath) {
Category cat = new Category(categoryID, str(name, "!name is missing!"), pluginID);
cat.setDescription(str(description, ""));
cat.setAfterID(str(afterID, ""));
String path = str(categoryPath, "/");
cat.setPath(path);
if (!Boolean.getBoolean("java.awt.headless")) {
Image img;
if (icon == null) {
img = ImageRepository.getIconImage(SharedImages.DefaultCategoryIcon);
} else {
img = ImageRepository.getIconImage(pluginID, icon);
if (img == null) {
LOGGER.coding("Icon '" + icon + "' for category " + cat.getPath() + "/" + cat.getName() + " does not exist");
img = ImageRepository.getIconImage(SharedImages.DefaultCategoryIcon);
}
}
cat.setIcon(img);
}
return cat;
}
use of org.knime.workbench.repository.model.Category 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;
}
use of org.knime.workbench.repository.model.Category 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("\"/> ");
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;
}
}
use of org.knime.workbench.repository.model.Category in project knime-core by knime.
the class AbstractRepositoryView method hookDoubleClickAction.
private void hookDoubleClickAction() {
m_viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(final DoubleClickEvent event) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (o instanceof NodeTemplate) {
NodeTemplate tmplt = (NodeTemplate) o;
NodeFactory<? extends NodeModel> nodeFact;
try {
nodeFact = tmplt.createFactoryInstance();
} catch (Exception e) {
LOGGER.error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
return;
}
boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
if (added) {
NodeUsageRegistry.addNode(tmplt);
}
} else if (o instanceof MetaNodeTemplate) {
MetaNodeTemplate mnt = (MetaNodeTemplate) o;
NodeID metaNode = mnt.getManager().getID();
NodeProvider.INSTANCE.addMetaNode(WorkflowManager.META_NODE_ROOT, metaNode);
} else if (o instanceof Category) {
m_viewer.setExpandedState(o, !m_viewer.getExpandedState(o));
}
}
});
}
use of org.knime.workbench.repository.model.Category in project knime-core by knime.
the class RepositoryViewFilter method doSelect.
/**
* An element is selected if itself, a parent or a
* child contains the query string in its name.
* {@inheritDoc}
*/
@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;
}
Aggregations