use of org.knime.workbench.repository.model.IContainerObject in project knime-core by knime.
the class AbstractRepositoryView method enrichWithAdditionalInfo.
/**
* This methods recursively retrieves and enriches the repository objects with additional information,
* e.g. number of ports, whether the node is streamable and/or distributable, etc.
* Should be called only after the repository content was already loaded with {@link #readRepository(Composite, IProgressMonitor)}.
*/
protected void enrichWithAdditionalInfo(final IRepositoryObject parent, final IProgressMonitor monitor, final boolean updateTreeStructure) {
if (monitor.isCanceled()) {
return;
}
if (!m_additionalInfoAvailable) {
if (parent instanceof IContainerObject) {
IRepositoryObject[] children = ((IContainerObject) parent).getChildren();
for (IRepositoryObject child : children) {
enrichWithAdditionalInfo(child, monitor, updateTreeStructure);
}
} else if (parent instanceof NodeTemplate) {
NodeTemplate nodeTemplate = (NodeTemplate) parent;
try {
NodeFactory<? extends NodeModel> nf = nodeTemplate.createFactoryInstance();
NodeModel nm = nf.createNodeModel();
// check whether the current node model overrides the #createStreamableOperator-method
Method m = nm.getClass().getMethod("createStreamableOperator", PartitionInfo.class, PortObjectSpec[].class);
if (m.getDeclaringClass() != NodeModel.class) {
// method has been overriden -> node is probably streamable or distributable
nodeTemplate.addAdditionalInfo(KEY_INFO_STREAMABLE, "streamable");
}
// possible TODO: parse xml description and get some more additional information (e.g. short description, ...)
// nodeTemplate.addAdditionalInfo(KEY_INFO_SHORT_DESCRIPTION,
// "this could be the short description, number of ports etc.");
} catch (Throwable t) {
LOGGER.error("Unable to instantiate the node " + nodeTemplate.getFactory().getName(), t);
return;
}
if (!updateTreeStructure) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!m_viewer.getControl().isDisposed()) {
m_viewer.update(parent, null);
}
}
});
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!m_viewer.getControl().isDisposed()) {
m_viewer.update(parent, null);
TreeViewerUpdater.update(m_viewer, true, false);
}
}
});
}
}
}
}
use of org.knime.workbench.repository.model.IContainerObject in project knime-core by knime.
the class RepositoryFactory method createCategory.
/**
* Creates a new category object. Throws an exception, if this fails
*
* @param root The root to insert the category in
* @param element Configuration element from the contributing plugin
* @return Category object to be used within the repository.
* @throws IllegalArgumentException If the element is not compatible (e.g.
* wrong attributes)
*/
public static Category createCategory(final Root root, final IConfigurationElement element) {
String id = element.getAttribute("level-id");
// get the id of the contributing plugin
String pluginID = element.getDeclaringExtension().getNamespaceIdentifier();
boolean locked = Boolean.parseBoolean(element.getAttribute("locked")) || ((element.getAttribute("locked") == null) && pluginID.matches("^(?:org|com)\\.knime\\..+"));
Category cat = new Category(id, str(element.getAttribute("name"), "!name is missing!"), pluginID, locked);
cat.setDescription(str(element.getAttribute("description"), ""));
cat.setAfterID(str(element.getAttribute("after"), ""));
String path = str(element.getAttribute("path"), "/");
cat.setPath(path);
if (!Boolean.getBoolean("java.awt.headless")) {
String iconPath = element.getAttribute("icon");
Image img;
if (iconPath == null) {
img = ImageRepository.getIconImage(SharedImages.DefaultCategoryIcon);
} else {
img = ImageRepository.getIconImage(pluginID, iconPath);
if (img == null) {
LOGGER.coding("Icon '" + element.getAttribute("icon") + "' for category " + cat.getPath() + "/" + cat.getName() + " does not exist");
img = ImageRepository.getIconImage(SharedImages.DefaultCategoryIcon);
}
}
cat.setIcon(img);
}
//
if (path.startsWith("/")) {
path = path.substring(1);
}
// split the path
String[] segments = path.split("/");
// start at root
IContainerObject container = root;
for (int i = 0; i < segments.length; i++) {
IRepositoryObject obj = container.getChildByID(segments[i], false);
if (obj == null) {
throw new IllegalArgumentException("The segment '" + segments[i] + "' in path '" + path + "' does not exist!");
}
// continue at this level
container = (IContainerObject) obj;
}
String parentPluginId = container.getContributingPlugin();
if (parentPluginId == null) {
parentPluginId = "";
}
int secondDotIndex = pluginID.indexOf('.', pluginID.indexOf('.') + 1);
if (secondDotIndex == -1) {
secondDotIndex = 0;
}
if (!container.isLocked() || pluginID.equals(parentPluginId) || pluginID.startsWith("org.knime.") || pluginID.startsWith("com.knime.") || pluginID.regionMatches(0, parentPluginId, 0, secondDotIndex)) {
// container not locked, or both categories from same plug-in
// or the vendor is the same (comparing the first two parts of the plug-in ids)
container.addChild(cat);
} else {
LOGGER.error("Locked parent category for category " + cat.getID() + ": " + cat.getPath() + ". Category will NOT be added!");
}
return cat;
}
use of org.knime.workbench.repository.model.IContainerObject 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