Search in sources :

Example 1 with NodeAnnotationEditPart

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);
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NonResizableEditPolicy(org.eclipse.gef.editpolicies.NonResizableEditPolicy) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Example 2 with NodeAnnotationEditPart

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);
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 3 with NodeAnnotationEditPart

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();
    }
}
Also used : NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) EventObject(java.util.EventObject) ContentObject(org.knime.workbench.explorer.view.ContentObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) HashSet(java.util.HashSet)

Example 4 with NodeAnnotationEditPart

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;
}
Also used : AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) Composite(org.eclipse.swt.widgets.Composite) AnnotationData(org.knime.core.node.workflow.AnnotationData) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Annotation(org.knime.core.node.workflow.Annotation) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Example 5 with NodeAnnotationEditPart

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));
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Rectangle(org.eclipse.draw2d.geometry.Rectangle) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Aggregations

NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)10 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)7 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)6 EditPart (org.eclipse.gef.EditPart)4 Point (org.eclipse.draw2d.geometry.Point)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)3 Annotation (org.knime.core.node.workflow.Annotation)3 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)3 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)3 NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)3 IFigure (org.eclipse.draw2d.IFigure)2 Composite (org.eclipse.swt.widgets.Composite)2 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)2 AbstractWorkflowEditPart (org.knime.workbench.editor2.editparts.AbstractWorkflowEditPart)2 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)2 EventObject (java.util.EventObject)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1