use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class HelpView method selectionChanged.
/**
* The method updating the content of the browser. Depending on the type of
* the selected part(s) it will retrieve the node(s) description and set it
* in the browser.
*
* {@inheritDoc}
*/
@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (m_browser != null && m_browser.isDisposed()) {
// if someone closed it, unregister as selection listener
// TODO same for text
getViewSite().getPage().removeSelectionListener(this);
return;
}
if (selection instanceof IStructuredSelection) {
IStructuredSelection structSel = (IStructuredSelection) selection;
IStructuredSelection lastSel = m_lastSelectionReference == null ? null : m_lastSelectionReference.get();
// we do not clear our content if nothing is selected.
if (structSel.size() < 1 || structSel.equals(lastSel)) {
return;
}
m_lastSelectionReference = new WeakReference<>(structSel);
// we display the full description only if a single node is selected
boolean useSingleLine;
if ((structSel.size() > 1) || (structSel.getFirstElement() instanceof Category)) {
useSingleLine = true;
} else {
useSingleLine = false;
}
// construct the html page to display
final StringBuilder content = new StringBuilder();
if (useSingleLine) {
// add the prefix to make it a html page
content.append("<html><head>");
content.append("<meta http-equiv=\"content-type\" " + "content=\"text/html; charset=UTF-8\"></meta>");
// include stylesheet
content.append("<style>");
content.append(NodeFactoryHTMLCreator.instance.getCss());
content.append("</style>");
content.append("</head><body><dl>");
}
// Keep a list of already displayed objects (this works as long as
// the selected items come in an ordered way. Ordered with item
// containing other selected items coming before the items
// contained. For the tree view in the repository this is the case.
HashSet<String> ids = new HashSet<String>();
for (Iterator<?> selIt = structSel.iterator(); selIt.hasNext(); ) {
Object sel = selIt.next();
if (sel instanceof Category) {
// its a category in the node repository, display a list of
// contained nodes
Category cat = (Category) sel;
if (!ids.contains(cat.getID())) {
ids.add(cat.getID());
DynamicNodeDescriptionCreator.instance().addDescription(cat, content, ids);
}
} else if (sel instanceof NodeTemplate) {
// its a node selected in the repository
NodeTemplate templ = (NodeTemplate) sel;
if (!ids.contains(templ.getID())) {
ids.add(templ.getID());
DynamicNodeDescriptionCreator.instance().addDescription(templ, useSingleLine, content);
}
} else if (sel instanceof NodeContainerEditPart) {
// if multiple nodes in the editor are selected we should
// not show description for the same node (if used multiple
// times) twice. We store the node name in the set.
NodeContainerUI nc = ((NodeContainerEditPart) sel).getNodeContainer();
if (!ids.contains(nc.getName())) {
ids.add(nc.getName());
DynamicNodeDescriptionCreator.instance().addDescription(nc, useSingleLine, content);
}
} else if (sel instanceof MetaNodeTemplate) {
// TODO: add support for MetaNodeTemplates and get the
// description out of them
NodeContainerUI manager = ((MetaNodeTemplate) sel).getManager();
DynamicNodeDescriptionCreator.instance().addDescription(manager, useSingleLine, content);
}
}
if (useSingleLine) {
// finish the html
content.append("</dl></body></html>");
}
if (m_browser != null) {
// FG: must always be invoked in SWT UI thread
m_browser.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!m_browser.isDisposed()) {
m_browser.setText(content.toString());
}
}
});
} else if (m_isFallback) {
m_text.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
m_text.setText(content.toString());
}
});
}
}
}
use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class NodeUsageRegistry method saveLastUsedNodes.
/**
* Saves last used nodes to XML memento. Called from
* FavoriteNodesManager#saveFavoriteNodes.
*
* @see #loadLastUsedNodes(IMemento)
* @param lastUsedNodes XML memento to save last used nodes to
*/
public static void saveLastUsedNodes(final IMemento lastUsedNodes) {
for (NodeTemplate node : LAST_USED) {
IMemento item = lastUsedNodes.createChild(TAG_FAVORITE);
item.putString(TAG_NODE_ID, node.getID());
}
}
use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class NodeUsageRegistry method loadFrequentNodes.
/**
* Loads the most frequently used nodes from XML memento. Called from
* FavoriteNodesManager#loadFavoriteNodes.
*
* @see #saveFrequentNodes(IMemento)
* @param freqNodes the XML memento containing the most frequently used
* nodes
*/
public static void loadFrequentNodes(final IMemento freqNodes) {
for (IMemento freqNode : freqNodes.getChildren(TAG_FAVORITE)) {
String id = freqNode.getString(TAG_NODE_ID);
int frequency = freqNode.getInteger(TAG_FREQUENCY);
NodeTemplate node = RepositoryManager.INSTANCE.getNodeTemplate(id);
if (node != null) {
NodeTemplateFrequency nodeFreq = new NodeTemplateFrequency(node);
nodeFreq.m_frequency = frequency;
FREQUENCIES.put(nodeFreq, nodeFreq);
}
}
}
use of org.knime.workbench.repository.model.NodeTemplate 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
}
use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class RepositoryFactory method createNode.
/**
* Creates a new node repository object. Throws an exception, if this fails
*
* @param element Configuration element from the contributing plugin
* @return NodeTemplate object to be used within the repository.
* @throws IllegalArgumentException If the element is not compatible (e.g.
* wrong attributes, or factory class not found)
*/
@SuppressWarnings("unchecked")
public static NodeTemplate createNode(final IConfigurationElement element) {
// 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 = (NodeFactory<? extends NodeModel>) 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();
}
if (factory instanceof DynamicNodeFactory) {
throw new IllegalArgumentException("Dynamic node factory '" + element.getAttribute("factory-class") + "'" + " registered as normal node factory.");
}
String pluginID = element.getDeclaringExtension().getNamespaceIdentifier();
NodeTemplate node = new NodeTemplate((Class<NodeFactory<? extends NodeModel>>) factory.getClass(), factory.getNodeName(), pluginID);
node.setAfterID(str(element.getAttribute("after"), ""));
node.setType(factory.getType());
if (!Boolean.valueOf(System.getProperty("java.awt.headless", "false"))) {
// Load images from declaring plugin
Image icon = ImageRepository.getIconImage(factory);
node.setIcon(icon);
}
node.setCategoryPath(str(element.getAttribute("category-path"), "/"));
return node;
}
Aggregations