use of org.knime.core.node.NodeSetFactory 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