use of org.knime.workbench.repository.model.Category 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.Category in project knime-core by knime.
the class NodeDescriptionConverter method writeCategoryTocFile.
private void writeCategoryTocFile(final Category c) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.newDocument();
doc.appendChild(doc.createProcessingInstruction("NLS", "TYPE=\"org.eclipse.help.toc\""));
Element root = doc.createElement("toc");
if (c.getParent() instanceof Root) {
root.setAttribute("link_to", "../" + "org.knime.workbench.help" + "/toc.xml#" + ROOT_ANCHOR);
root.setAttribute("label", fileName(getFullPath(c)));
/*
* <toc link_to=../org.knime.workbench.help/toc.xml#root
* label=c.getID()
*/
} else {
String parentsPluginID = ((Category) c.getParent()).getContributingPlugin();
String parent = fileName(getFullPath((Category) c.getParent()));
root.setAttribute("link_to", "../" + parentsPluginID + "/" + TOC_DIR + "/" + parent + ".xml#" + parent);
root.setAttribute("label", parent);
/*
* <toc link_to="../c.getParent().getPluginID()/
* c.getParent().getID.xml#c.getID() label=c.getID() >
*/
}
Element topic = doc.createElement("topic");
topic.setAttribute("label", htmlString(c.getName()));
Element anchor = doc.createElement("anchor");
anchor.setAttribute("id", fileName(getFullPath(c)));
topic.appendChild(anchor);
root.appendChild(topic);
doc.appendChild(root);
/*
* <topic label="htmlString(c.getName());> <anchor id=c.getID />
* </topic> </toc>
*/
writeTocToPluginXML(c, false);
/*
* <extension point="org.eclipse.help.toc"> <toc file="toc.xml"> </toc>
* </extension>
*/
writeNodeTocFile(doc, fileName(getFullPath(c)));
}
use of org.knime.workbench.repository.model.Category 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.Category in project knime-core by knime.
the class RepositoryManager method readCategories.
private void readCategories(final IProgressMonitor monitor) {
//
// First, process the contributed categories
//
IExtension[] categoryExtensions = getExtensions(ID_CATEGORY);
ArrayList<IConfigurationElement> allElements = new ArrayList<IConfigurationElement>();
for (IExtension ext : categoryExtensions) {
// iterate through the config elements and create 'Category' objects
IConfigurationElement[] elements = ext.getConfigurationElements();
allElements.addAll(Arrays.asList(elements));
}
// remove duplicated categories
removeDuplicatesFromCategories(allElements);
// sort first by path-depth, so that everything is there in the
// right order
Collections.sort(allElements, new Comparator<IConfigurationElement>() {
@Override
public int compare(final IConfigurationElement o1, final IConfigurationElement o2) {
String element1 = o1.getAttribute("path");
String element2 = o2.getAttribute("path");
if (element1 == element2) {
return 0;
} else if (element1 == null) {
return -1;
} else if (element2 == null) {
return 1;
} else if (element1.equals(element2)) {
return 0;
} else if ("/".equals(element1)) {
return -1;
} else if ("/".equals(element2)) {
return 1;
} else {
int countSlashes1 = 0;
for (int i = 0; i < element1.length(); i++) {
if (element1.charAt(i) == '/') {
countSlashes1++;
}
}
int countSlashes2 = 0;
for (int i = 0; i < element2.length(); i++) {
if (element2.charAt(i) == '/') {
countSlashes2++;
}
}
return countSlashes1 - countSlashes2;
}
}
});
for (IConfigurationElement e : allElements) {
if (monitor.isCanceled()) {
return;
}
try {
Category category = RepositoryFactory.createCategory(m_root, e);
LOGGER.debug("Found category extension '" + category.getID() + "' on path '" + category.getPath() + "'");
for (Listener l : m_loadListeners) {
l.newCategory(m_root, category);
}
} catch (Exception ex) {
String message = "Category '" + e.getAttribute("level-id") + "' from plugin '" + e.getDeclaringExtension().getNamespaceIdentifier() + "' could not be created in parent path '" + e.getAttribute("path") + "'.";
LOGGER.error(message, ex);
}
}
}
use of org.knime.workbench.repository.model.Category 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);
}
}
}
Aggregations