use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class NewWorkflowXYLayoutPolicy method createChildEditPolicy.
/**
* {@inheritDoc}
*/
@Override
protected EditPolicy createChildEditPolicy(final EditPart child) {
if (child instanceof NodeContainerEditPart) {
return new NonResizeNoHandlesEditPolicy((GraphicalEditPart) child);
}
if (child instanceof NodeAnnotationEditPart) {
NonResizableEditPolicy pol = new NonResizeNoHandlesEditPolicy((GraphicalEditPart) child);
pol.setDragAllowed(false);
return pol;
}
return super.createChildEditPolicy(child);
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class NodeMonitorView method selectionChanged.
/**
* The method updating the content of the monitor.
*
* {@inheritDoc}
*/
@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (!(selection instanceof IStructuredSelection)) {
return;
}
IStructuredSelection structSel = (IStructuredSelection) selection;
if (m_pinned) {
m_lastSelectionWhilePinned = structSel;
return;
}
if (structSel.equals(m_lastSelection)) {
// selection hasn't changed - return.
return;
}
m_lastSelection = structSel;
if (structSel.size() < 1) {
// Nothing selected
m_title.setText("");
m_state.setText("no node selected");
m_table.removeAll();
return;
}
if (structSel.size() > 1) {
// too many selected items
m_title.setText("");
m_state.setText("more than one element selected.");
m_table.removeAll();
return;
}
// retrieve first (and only!) selection:
Iterator<?> selIt = structSel.iterator();
Object sel = selIt.next();
//
if (sel instanceof NodeContainerEditPart) {
// a NodeContainer was selected, display it's name and status
NodeContainerUI nc = ((NodeContainerEditPart) sel).getNodeContainer();
updateNodeContainerInfo(nc);
} else {
// unsupported selection
unsupportedSelection(sel);
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class SnapIconToGrid method snapRectangle.
/**
* {@inheritDoc}
*/
@Override
public int snapRectangle(final Request request, final int snapLocations, final PrecisionRectangle rect, final PrecisionRectangle result) {
PrecisionRectangle r = rect;
if (request instanceof ChangeBoundsRequest) {
EditPart refPart = getReferencePart(((ChangeBoundsRequest) request).getEditParts(), ((ChangeBoundsRequest) request).getLocation(), ((ChangeBoundsRequest) request).getMoveDelta());
if (refPart instanceof NodeContainerEditPart) {
// adjust the rectangle to snap the center of the icon of the node
NodeContainerEditPart contPart = (NodeContainerEditPart) refPart;
NodeContainerFigure fig = (NodeContainerFigure) contPart.getFigure();
Point iconOffset = getIconOffset(fig);
r = rect.getPreciseCopy();
r.translate(iconOffset);
} else if (refPart instanceof NodeAnnotationEditPart) {
// the rect is the annotation outline - adjust it to snap the center of the corresponding node icon
NodeAnnotationEditPart annoPart = (NodeAnnotationEditPart) refPart;
WorkflowRootEditPart parent = (WorkflowRootEditPart) annoPart.getParent();
IFigure annoFig = annoPart.getFigure();
NodeAnnotation anno = (NodeAnnotation) annoPart.getModel();
NodeContainerEditPart nodePart = (NodeContainerEditPart) m_container.getViewer().getEditPartRegistry().get(parent.getWorkflowManager().getNodeContainer(anno.getNodeID()));
NodeContainerFigure nodeFig = (NodeContainerFigure) nodePart.getFigure();
Point iconOffset = getIconOffset(nodeFig);
int xOff = nodeFig.getBounds().x - annoFig.getBounds().x;
xOff += iconOffset.x;
int yOff = iconOffset.y - nodeFig.getBounds().height;
r = rect.getPreciseCopy();
r.translate(new Point(xOff, yOff));
}
}
return super.snapRectangle(request, snapLocations, r, result);
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class WorkflowEditor method onF2Pressed.
/**
* Opens editor for (node) annotation (given that a single node or
* annotation is selected).
*/
private void onF2Pressed() {
ISelectionProvider provider = getEditorSite().getSelectionProvider();
if (provider == null) {
return;
}
ISelection sel = provider.getSelection();
if (!(sel instanceof IStructuredSelection)) {
return;
}
Set<AnnotationEditPart> selectedAnnoParts = new HashSet<AnnotationEditPart>();
@SuppressWarnings("rawtypes") Iterator selIter = ((IStructuredSelection) sel).iterator();
while (selIter.hasNext()) {
Object next = selIter.next();
if (next instanceof AnnotationEditPart) {
selectedAnnoParts.add((AnnotationEditPart) next);
} else if (next instanceof NodeContainerEditPart) {
NodeAnnotationEditPart nodeAnnoPart = ((NodeContainerEditPart) next).getNodeAnnotationEditPart();
if (nodeAnnoPart != null) {
selectedAnnoParts.add(nodeAnnoPart);
}
} else {
// unknown type selected
return;
}
}
if (selectedAnnoParts.size() == 1) {
AnnotationEditPart next = selectedAnnoParts.iterator().next();
next.performEdit();
}
}
Aggregations