use of org.knime.workbench.repository.model.DynamicNodeTemplate in project knime-core by knime.
the class RepositoryManager method readNodeSets.
/**
* @param isInExpertMode
*/
private void readNodeSets(final IProgressMonitor monitor) {
//
// Process the contributed node sets
//
Iterator<IConfigurationElement> it = Stream.of(RepositoryManager.getExtensions(ID_NODE_SET)).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(elem -> !"true".equalsIgnoreCase(elem.getAttribute("deprecated"))).iterator();
while (it.hasNext()) {
IConfigurationElement elem = it.next();
try {
Collection<DynamicNodeTemplate> dynamicNodeTemplates = RepositoryFactory.createNodeSet(m_root, elem);
for (DynamicNodeTemplate node : dynamicNodeTemplates) {
if (monitor.isCanceled()) {
return;
}
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.warn("Invalid category-path for node " + "contribution: '" + node.getCategoryPath() + "' - adding to root instead");
m_root.addChild(node);
} else {
// everything is fine, add the node to its parent
// category
parentContainer.addChild(node);
}
}
} catch (Throwable t) {
String message = "Node " + elem.getAttribute("factory-class") + "' from plugin '" + elem.getNamespaceIdentifier() + "' could not be created.";
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);
}
}
}
use of org.knime.workbench.repository.model.DynamicNodeTemplate 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;
}
Aggregations