Search in sources :

Example 1 with AnnotationEditPart

use of org.knime.workbench.editor2.editparts.AnnotationEditPart in project knime-core by knime.

the class WorkflowMarqueeSelectionTool method calculateNewSelection.

private void calculateNewSelection(final Collection<GraphicalEditPart> newSelections, final Collection<GraphicalEditPart> deselections) {
    Rectangle marqueeRect = getMarqueeSelectionRectangle();
    for (Iterator<GraphicalEditPart> itr = getAllChildren().iterator(); itr.hasNext(); ) {
        GraphicalEditPart child = itr.next();
        IFigure figure = child.getFigure();
        if (!child.isSelectable() || child.getTargetEditPart(MARQUEE_REQUEST) != child || !isFigureVisible(figure) || !figure.isShowing()) {
            continue;
        }
        if (!(child instanceof NodeContainerEditPart || child instanceof ConnectionContainerEditPart || child instanceof AbstractWorkflowPortBarEditPart || child instanceof AnnotationEditPart)) {
            continue;
        }
        Rectangle r = figure.getBounds().getCopy();
        figure.translateToAbsolute(r);
        boolean included = false;
        if (child instanceof ConnectionEditPart && marqueeRect.intersects(r)) {
            Rectangle relMarqueeRect = Rectangle.SINGLETON;
            figure.translateToRelative(relMarqueeRect.setBounds(marqueeRect));
            included = ((PolylineConnection) figure).getPoints().intersects(relMarqueeRect);
        } else if (child instanceof AnnotationEditPart) {
            // select WorkflowAnnotations only if they are fully included in the selection
            if (figure instanceof WorkflowAnnotationFigure) {
                included = marqueeRect.contains(r);
            }
        } else if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
            included = marqueeRect.intersects(r);
        } else {
            included = marqueeRect.contains(r);
        }
        if (included) {
            if (isToggle()) {
                if (wasSelected(child)) {
                    deselections.add(child);
                } else {
                    newSelections.add(child);
                }
            } else {
                newSelections.add(child);
            }
        } else if (isToggle()) {
            // readded if it was in the selection before
            if (wasSelected(child)) {
                newSelections.add(child);
            } else {
                deselections.add(child);
            }
        }
    }
    if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
        calculateConnections(newSelections, deselections);
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) WorkflowAnnotationFigure(org.knime.workbench.editor2.figures.WorkflowAnnotationFigure) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) ConnectionEditPart(org.eclipse.gef.ConnectionEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IFigure(org.eclipse.draw2d.IFigure) PolylineConnection(org.eclipse.draw2d.PolylineConnection)

Example 2 with AnnotationEditPart

use of org.knime.workbench.editor2.editparts.AnnotationEditPart in project knime-core by knime.

the class CutAction method runInSWT.

/**
 * Invokes the copy action followed by the delete command.
 * {@inheritDoc}
 */
@Override
public void runInSWT() {
    LOGGER.debug("Clipboard cut action invoked...");
    // invoke copy action
    CopyAction copy = new CopyAction(getEditor());
    copy.runInSWT();
    NodeContainerEditPart[] nodeParts = copy.getNodeParts();
    AnnotationEditPart[] annotationParts = copy.getAnnotationParts();
    Collection<EditPart> coll = new ArrayList<EditPart>();
    coll.addAll(Arrays.asList(nodeParts));
    coll.addAll(Arrays.asList(annotationParts));
    DeleteCommand delete = new DeleteCommand(coll, getEditor().getWorkflowManager().get());
    // enable undo
    getCommandStack().execute(delete);
    getEditor().updateActions();
    // Give focus to the editor again. Otherwise the actions (selection)
    // is not updated correctly.
    getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
}
Also used : DeleteCommand(org.knime.workbench.editor2.commands.DeleteCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList)

Example 3 with AnnotationEditPart

use of org.knime.workbench.editor2.editparts.AnnotationEditPart in project knime-core by knime.

the class NewWorkflowXYLayoutPolicy method createChangeConstraintCommand.

/**
 * Creates command to move / resize <code>NodeContainer</code> components on
 * the project's client area.
 *
 * {@inheritDoc}
 */
@Override
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
    // only rectangular constraints are supported
    if (!(constraint instanceof Rectangle)) {
        return null;
    }
    Command command = null;
    Rectangle rect = ((Rectangle) constraint).getCopy();
    if (child.getModel() instanceof NodeContainerUI) {
        NodeContainerUI container = (NodeContainerUI) child.getModel();
        if (!Wrapper.wraps(container, NodeContainer.class)) {
            // not supported for others than ordinary NodeContainers
            return null;
        }
        NodeContainerEditPart nodePart = (NodeContainerEditPart) child;
        command = new ChangeNodeBoundsCommand(Wrapper.unwrapNC(container), (NodeContainerFigure) nodePart.getFigure(), rect);
    } else if (child instanceof AbstractWorkflowPortBarEditPart) {
        command = new ChangeWorkflowPortBarCommand((AbstractWorkflowPortBarEditPart) child, rect);
    } else if (child instanceof AnnotationEditPart) {
        AnnotationEditPart annoPart = (AnnotationEditPart) child;
        // TODO the workflow annotation could know what its WFM is?
        WorkflowRootEditPart root = (WorkflowRootEditPart) annoPart.getParent();
        WorkflowManagerUI wm = root.getWorkflowManager();
        if (!Wrapper.wraps(wm, WorkflowManager.class)) {
            // not supported for others than an ordinary workflow manager
            return null;
        }
        command = new ChangeAnnotationBoundsCommand(Wrapper.unwrapWFM(wm), annoPart, rect);
    }
    return command;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) ChangeNodeBoundsCommand(org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ChangeWorkflowPortBarCommand(org.knime.workbench.editor2.commands.ChangeWorkflowPortBarCommand) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NodeContainer(org.knime.core.node.workflow.NodeContainer) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure) ChangeAnnotationBoundsCommand(org.knime.workbench.editor2.commands.ChangeAnnotationBoundsCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) ChangeWorkflowPortBarCommand(org.knime.workbench.editor2.commands.ChangeWorkflowPortBarCommand) ChangeNodeBoundsCommand(org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand) ChangeAnnotationBoundsCommand(org.knime.workbench.editor2.commands.ChangeAnnotationBoundsCommand) Command(org.eclipse.gef.commands.Command)

Example 4 with AnnotationEditPart

use of org.knime.workbench.editor2.editparts.AnnotationEditPart 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 5 with AnnotationEditPart

use of org.knime.workbench.editor2.editparts.AnnotationEditPart 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)

Aggregations

AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)9 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)7 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)7 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 EditPart (org.eclipse.gef.EditPart)4 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)4 Annotation (org.knime.core.node.workflow.Annotation)3 IFigure (org.eclipse.draw2d.IFigure)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)2 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)2 ChangeAnnotationBoundsCommand (org.knime.workbench.editor2.commands.ChangeAnnotationBoundsCommand)2 ChangeNodeBoundsCommand (org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand)2 AbstractWorkflowEditPart (org.knime.workbench.editor2.editparts.AbstractWorkflowEditPart)2 AbstractWorkflowPortBarEditPart (org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart)2 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)2 NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)2 ArrayList (java.util.ArrayList)1 EventObject (java.util.EventObject)1 HashSet (java.util.HashSet)1