use of org.knime.core.ui.node.workflow.NodeContainerUI 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.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class DynamicNodeDescriptionCreator method addDescription.
/**
* @param template meta node template
* @param useSingleLine true if several nodes are selected
* @param builder gathers the HTML content
*/
public void addDescription(final MetaNodeTemplate template, final boolean useSingleLine, final StringBuilder builder) {
WorkflowManagerUI manager = template.getManager();
if (!useSingleLine) {
builder.append(getHeader());
builder.append("<h1>");
builder.append(manager.getName());
builder.append("</h1>");
builder.append("<h2>Description:</h2>");
builder.append("<p>" + template.getDescription() + "</p>");
builder.append("<h2>Contained nodes: </h2>");
for (NodeContainerUI child : manager.getNodeContainers()) {
addDescription(child, true, builder);
}
builder.append("</body></html>");
} else {
builder.append("<dt><b>" + manager.getName() + "</b></dt>");
builder.append("<dd>" + template.getDescription() + "</dd>");
}
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class WorkflowEditor method getSubEditors.
/**
* Collects the open editor(s) of the specified (sub-)workflow manager and all sub editor(s) of it. The provided id
* must be a child of the workflow displayed in this editor.
*
* @param id of a child of this editor. Must be a sub/metanode whose editor (and all sub-editors recursively) will
* be returned.
* @return a list of open editors
*/
public List<IEditorPart> getSubEditors(final NodeID id) {
List<IEditorPart> editors = new ArrayList<IEditorPart>();
if (m_manager == null) {
// no workflow, no sub editors
return editors;
}
NodeContainerUI child = null;
WorkflowManagerUI child_mgr = null;
try {
child = m_manager.getNodeContainer(id);
} catch (IllegalArgumentException iae) {
// if node doesn't exist - or just got deleted, then there are no sub editors
return editors;
}
if (child instanceof SubNodeContainerUI) {
child_mgr = ((SubNodeContainerUI) child).getWorkflowManager();
} else if (child instanceof WorkflowManagerUI) {
child_mgr = (WorkflowManagerUI) child;
} else {
return editors;
}
WorkflowManagerInput in = new WorkflowManagerInput(child_mgr, this);
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
for (IWorkbenchPage p : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages()) {
IEditorPart child_editor = p.findEditor(in);
if (child_editor != null) {
editors.add(child_editor);
if (child_editor instanceof WorkflowEditor) {
// recursively add sub editors (to get sub/metanodes in sub/metanodes)
for (NodeContainerUI nc : child_mgr.getNodeContainers()) {
editors.addAll(((WorkflowEditor) child_editor).getSubEditors(nc.getID()));
}
}
}
}
}
return editors;
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class NodeOutPortEditPart method createFigure.
/**
* {@inheritDoc}
*/
@Override
protected IFigure createFigure() {
// Create the figure, we need the number of ports from the parent
// container
NodeContainerUI container = getNodeContainer();
NodeOutPortUI port = container.getOutPort(getIndex());
String tooltip = getTooltipText(port.getPortName(), port);
boolean isMetaNode = !(container instanceof SingleNodeContainerUI);
NodeOutPortFigure portFigure = new NodeOutPortFigure(getType(), getIndex(), container.getNrOutPorts(), isMetaNode, tooltip);
portFigure.setInactive(port.isInactive());
portFigure.setIsConnected(isConnected());
return portFigure;
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class MetaNodeOutPortEditPart method createFigure.
/**
* {@inheritDoc}
*/
@Override
protected IFigure createFigure() {
NodeContainerUI nc = getNodeContainer();
LOGGER.debug("returning new sub metanode out port figure " + " with type " + getType() + " index " + getIndex() + " nr outports " + nc.getNrOutPorts() + " and tooltip " + nc.getOutPort(getIndex()).getPortName());
WorkflowOutPortUI model = (WorkflowOutPortUI) getModel();
LOGGER.debug("model: " + getModel() + " state: " + model.getNodeState());
NodeOutPortUI port = nc.getOutPort(getIndex());
String tooltip = getTooltipText(port.getPortName(), port);
MetaNodeOutPortFigure f = new MetaNodeOutPortFigure(getType(), getIndex(), nc.getNrOutPorts(), tooltip, model.getNodeState());
f.setInactive(model.isInactive());
f.setIsConnected(isConnected());
return f;
}
Aggregations