use of org.knime.workbench.editor2.editparts.NodeAnnotationEditPart 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.NodeAnnotationEditPart 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.NodeAnnotationEditPart 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();
}
}
use of org.knime.workbench.editor2.editparts.NodeAnnotationEditPart in project knime-core by knime.
the class AnnotationEditPolicy method getDirectEditCommand.
/**
* {@inheritDoc}
*/
@Override
protected Command getDirectEditCommand(final DirectEditRequest edit) {
StyledTextEditor ste = (StyledTextEditor) edit.getCellEditor();
AnnotationData newAnnoData = (AnnotationData) ste.getValue();
AnnotationEditPart annoPart = (AnnotationEditPart) getHost();
Annotation oldAnno = annoPart.getModel();
Rectangle oldFigBounds = annoPart.getFigure().getBounds().getCopy();
// y-coordinate is the only dimension that doesn't change
newAnnoData.setY(oldFigBounds.y);
// trim was never really verified (was always 0 on my platform),
// see also StyledTextEditorLocator#relocate
Composite compositeEditor = (Composite) ste.getControl();
org.eclipse.swt.graphics.Rectangle trim = compositeEditor.computeTrim(0, 0, 0, 0);
if (annoPart instanceof NodeAnnotationEditPart) {
// the width and height grow with the text entered
newAnnoData.setX(compositeEditor.getBounds().x);
newAnnoData.setHeight(compositeEditor.getBounds().height - trim.height);
newAnnoData.setWidth(compositeEditor.getBounds().width - trim.width);
} else {
// with workflow annotations only the height grows with the text
newAnnoData.setX(oldFigBounds.x);
newAnnoData.setHeight(compositeEditor.getBounds().height - trim.height);
newAnnoData.setWidth(oldFigBounds.width - trim.width);
}
if (hasAnnotationDataChanged(oldAnno, newAnnoData)) {
return new AnnotationEditCommand(annoPart, oldAnno, newAnnoData);
}
return null;
}
use of org.knime.workbench.editor2.editparts.NodeAnnotationEditPart in project knime-core by knime.
the class StyledTextEditorLocator method relocate.
/**
* {@inheritDoc}
*/
@Override
public void relocate(final CellEditor celleditor) {
Composite edit = (Composite) celleditor.getControl();
final Rectangle figBounds = m_figure.getBounds().getCopy();
Rectangle absoluteWithZoomBounds = figBounds.getCopy();
// adapt to zoom level and viewport
// (shifts x,y to view port window and grows w,h with zoom level)
m_figure.translateToAbsolute(absoluteWithZoomBounds);
// add OS editor borders or insets -- never verified (result always 0)
org.eclipse.swt.graphics.Rectangle trim = edit.computeTrim(0, 0, 0, 0);
absoluteWithZoomBounds.translate(trim.x, trim.y);
figBounds.width += trim.width;
figBounds.height += trim.height;
StyledTextEditor stEditor = ((StyledTextEditor) celleditor);
org.eclipse.swt.graphics.Rectangle textBounds = stEditor.getTextBounds();
if (m_editPart instanceof NodeAnnotationEditPart) {
// grow the width and the height with the text entered
figBounds.height = Math.max(textBounds.height, NodeAnnotationEditPart.getNodeAnnotationMinHeight());
// add 5 pixel width to avoid flickering in auto-wrapping editors
int tw = textBounds.width + 5;
figBounds.width = Math.max(tw, NodeAnnotationEditPart.getNodeAnnotationMinWidth());
} else {
// grow only the height with the text entered
figBounds.height = Math.max(figBounds.height, textBounds.height + 5);
}
// center editor in case zoom != 1 (important for node annotations)
int x = absoluteWithZoomBounds.x + (absoluteWithZoomBounds.width - figBounds.width) / 2;
// use x,y from viewport coordinates,
// w,h are original figure coordinates as editor doesn't grow with zoom
edit.setBounds(new org.eclipse.swt.graphics.Rectangle(x, absoluteWithZoomBounds.y, figBounds.width, figBounds.height));
}
Aggregations