use of org.knime.workbench.repository.model.MetaNodeTemplate 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.MetaNodeTemplate 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;
}
use of org.knime.workbench.repository.model.MetaNodeTemplate 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;
}
use of org.knime.workbench.repository.model.MetaNodeTemplate in project knime-core by knime.
the class RepositoryFactory method createMetaNode.
/**
* @param configuration content of the extension
* @return a meta node template
*/
public static MetaNodeTemplate createMetaNode(final IConfigurationElement configuration) {
String id = configuration.getAttribute("id");
String name = configuration.getAttribute("name");
String workflowDir = configuration.getAttribute("workflowDir");
String after = configuration.getAttribute("after");
String iconPath = configuration.getAttribute("icon");
String categoryPath = configuration.getAttribute("category-path");
String pluginId = configuration.getDeclaringExtension().getNamespaceIdentifier();
String description = configuration.getAttribute("description");
WorkflowManagerUI manager = loadMetaNode(pluginId, workflowDir);
if (manager == null) {
LOGGER.error("MetaNode " + name + " could not be loaded. " + "Skipped.");
return null;
}
MetaNodeTemplate template = new MetaNodeTemplate(id, name, categoryPath, configuration.getContributor().getName(), manager);
if (after != null && !after.isEmpty()) {
template.setAfterID(after);
}
if (description != null) {
template.setDescription(description);
}
if (!Boolean.getBoolean("java.awt.headless")) {
// Load images from declaring plugin
Image icon = null;
if (iconPath != null) {
icon = ImageRepository.getIconImage(pluginId, iconPath);
}
if (icon == null) {
LOGGER.coding("Icon '" + iconPath + "' for metanode " + categoryPath + "/" + name + " does not exist");
icon = ImageRepository.getIconImage(SharedImages.DefaultMetaNodeIcon);
}
template.setIcon(icon);
}
return template;
}
use of org.knime.workbench.repository.model.MetaNodeTemplate 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>");
}
Aggregations