Search in sources :

Example 6 with NodeAnnotationEditPart

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

the class NodeContainerEditPart method activate.

/**
 * {@inheritDoc}
 */
@Override
public void activate() {
    super.activate();
    initFigure();
    // If we already have extra info, init figure now
    NodeContainerUI cont = getNodeContainer();
    NodeUIInformation uiInfo = cont.getUIInformation();
    if (uiInfo != null) {
        // takes over all info except the coordinates
        updateFigureFromUIinfo(uiInfo);
    } else {
        // set a new empty UI info
        NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(0, 0, -1, -1).build();
        // not yet a listener -- no event received
        cont.setUIInformation(info);
    }
    // need to notify node annotation about our presence
    // the annotation is a child that's added first (placed in background)
    // to the viewer - so it doesn't know about the correct location yet
    NodeAnnotation nodeAnnotation = cont.getNodeAnnotation();
    NodeAnnotationEditPart nodeAnnotationEditPart = (NodeAnnotationEditPart) getViewer().getEditPartRegistry().get(nodeAnnotation);
    if (nodeAnnotationEditPart != null) {
        nodeAnnotationEditPart.nodeUIInformationChanged(null);
    }
    IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
    store.addPropertyChangeListener(this);
    // listen to node container (= model object)
    cont.addNodeStateChangeListener(this);
    cont.addNodeMessageListener(this);
    cont.addProgressListener(this);
    cont.addUIInformationListener(this);
    cont.addNodePropertyChangedListener(this);
    addEditPartListener(this);
    updateJobManagerIcon();
    checkMetaNodeTemplateIcon();
    checkMetaNodeLockIcon();
    checkNodeLockIcon();
    // set the active (or disabled) state
    ((NodeContainerFigure) getFigure()).setStateFromNC(cont);
    // set the node message
    updateNodeMessage();
    callHideNodeName();
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 7 with NodeAnnotationEditPart

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

the class WorkflowEditPartFactory method createEditPart.

/**
 * Creates the referring edit parts for the following parts of the model.
 * <ul>
 * <li>{@link WorkflowManager}: either {@link WorkflowRootEditPart} or {@link NodeContainerEditPart} (depending on
 * the currently displayed level)</li>
 * <li>{@link SingleNodeContainer}: {@link NodeContainerEditPart}</li>
 * <li>{@link NodeInPort}: {@link NodeInPortEditPart}</li>
 * <li>{@link NodeOutPort}: {@link NodeOutPortEditPart}</li>
 * <li>{@link ConnectionContainer}: {@link ConnectionContainerEditPart}</li>
 * <li>{@link WorkflowInPort}: {@link WorkflowInPortEditPart}</li>
 * <li>{@link WorkflowOutPort}: {@link WorkflowOutPortEditPart}</li>
 * </ul>
 *
 * The {@link WorkflowRootEditPart} has its {@link NodeContainer}s and its {@link WorkflowInPort}s and
 * {@link WorkflowOutPort}s as model children. The {@link NodeContainerEditPart} has its {@link NodePort}s as its
 * children.
 *
 * @see WorkflowRootEditPart#getModelChildren()
 * @see NodeContainerEditPart#getModelChildren()
 *
 * @throws IllegalArgumentException if any other object is passed
 *
 *             {@inheritDoc}
 */
@Override
public EditPart createEditPart(final EditPart context, final Object model) {
    // instantiated here
    // correct type in the if statement
    // model at the end of method
    EditPart part = null;
    if (model instanceof WorkflowManagerUI) {
        // this is out "root" workflow manager
        if (m_isTop) {
            // all following objects of type WorkflowManager are treated as
            // metanodes and displayed as NodeContainers
            m_isTop = false;
            part = new WorkflowRootEditPart();
        } else {
            // we already have a "root" workflow manager
            // must be a metanode
            part = new SubworkflowEditPart();
        }
    } else if (model instanceof NodeAnnotation) {
        /* IMPORTANT: first test NodeAnnotation then Annotation (as the
             * first derives from the latter! */
        part = new NodeAnnotationEditPart();
    } else if (model instanceof Annotation) {
        /* IMPORTANT: first test NodeAnnotation then Annotation (as the
             * first derives from the latter! */
        /* workflow annotations hang off the workflow manager */
        part = new AnnotationEditPart();
    } else if (model instanceof WorkflowPortBar) {
        WorkflowPortBar bar = (WorkflowPortBar) model;
        if (bar.isInPortBar()) {
            part = new WorkflowInPortBarEditPart();
        } else {
            part = new WorkflowOutPortBarEditPart();
        }
    } else if (model instanceof SingleNodeContainerUI) {
        // SingleNodeContainer -> NodeContainerEditPart
        part = new NodeContainerEditPart();
    // we have to test for WorkflowInPort first because it's a
    // subclass of NodeInPort (same holds for WorkflowOutPort and
    // NodeOutPort)
    } else if (model instanceof WorkflowInPortUI && context instanceof WorkflowInPortBarEditPart) {
        // WorkflowInPort and context WorkflowRootEditPart ->
        // WorkflowInPortEditPart
        /*
             * if the context is a WorkflowRootEditPart it indicates that the
             * WorkflowInPort is a model child of the WorkflowRootEditPart, i.e.
             * we look at it as a workflow in port. If the context is a
             * NodeContainerEditPart the WorkflowInPort is a model child of a
             * NodeContainerEditPart and we look at it as a node in port.
             */
        WorkflowInPortUI inport = (WorkflowInPortUI) model;
        part = new WorkflowInPortEditPart(inport.getPortType(), inport.getPortIndex());
    } else if (model instanceof WorkflowOutPortUI && context instanceof WorkflowOutPortBarEditPart) {
        // WorkflowOutPort and context WorkflowRootEditPart ->
        // WorkflowOutPortEditPart
        /*
             * if the context is a WorkflowRootEditPart it indicates that the
             * WorkflowOutPort is a model child of the WorkflowRootEditPart,
             * i.e. we look at it as a workflow out port. If the context is a
             * NodeContainerEditPart the WorkflowOutPort is a model child of a
             * NodeContainerEditPart and we look at it as a node out port.
             */
        // TODO: return SubWorkFlowOutPortEditPart
        WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
        part = new WorkflowOutPortEditPart(outport.getPortType(), outport.getPortIndex());
    } else if (model instanceof WorkflowOutPortUI) {
        // TODO: return SubWorkFlowOutPortEditPart
        WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
        part = new MetaNodeOutPortEditPart(outport.getPortType(), outport.getPortIndex());
    } else if (model instanceof NodeInPortUI) {
        // NodeInPort -> NodeInPortEditPart
        NodePortUI port = (NodeInPortUI) model;
        part = new NodeInPortEditPart(port.getPortType(), port.getPortIndex());
    } else if (model instanceof NodeOutPortUI) {
        // NodeOutPort -> NodeOutPortEditPart
        NodePortUI port = (NodeOutPortUI) model;
        part = new NodeOutPortEditPart(port.getPortType(), port.getPortIndex());
    } else if (model instanceof ConnectionContainerUI) {
        // ConnectionContainer -> ConnectionContainerEditPart
        part = new ConnectionContainerEditPart();
    } else {
        throw new IllegalArgumentException("unknown model obj: " + model);
    }
    // associate the model with the part (= the controller)
    part.setModel(model);
    return part;
}
Also used : SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) WorkflowOutPortUI(org.knime.core.ui.node.workflow.WorkflowOutPortUI) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation) NodeInPortUI(org.knime.core.ui.node.workflow.NodeInPortUI) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) NodeOutPortUI(org.knime.core.ui.node.workflow.NodeOutPortUI) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) WorkflowInPortUI(org.knime.core.ui.node.workflow.WorkflowInPortUI) NodePortUI(org.knime.core.ui.node.workflow.NodePortUI)

Example 8 with NodeAnnotationEditPart

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

the class MoveNodeAbstractAction method getMoveableSelectedEditParts.

private List<EditPart> getMoveableSelectedEditParts() {
    @SuppressWarnings("rawtypes") List selectedObjects = getSelectedObjects();
    LinkedList<EditPart> result = new LinkedList<EditPart>();
    for (Object o : selectedObjects) {
        if ((o instanceof AnnotationEditPart) && !(o instanceof NodeAnnotationEditPart)) {
            result.add((AnnotationEditPart) o);
            continue;
        }
        if (o instanceof NodeContainerEditPart) {
            result.add((NodeContainerEditPart) o);
            continue;
        }
    }
    return result;
}
Also used : AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) AbstractWorkflowEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowEditPart) EditPart(org.eclipse.gef.EditPart) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Example 9 with NodeAnnotationEditPart

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

the class MoveNodeAbstractAction method createCompoundCommand.

/**
 * @param nodeParts selected nodes and connections
 * @return compound command of all move commands or null if no edit part is selected
 */
public CompoundCommand createCompoundCommand(final NodeContainerEditPart[] nodeParts) {
    List<EditPart> selParts = getMoveableSelectedEditParts();
    if (selParts.size() < 1) {
        return null;
    }
    // should be initialized from the pref page
    // (0, 1) moves down, (-1, 0) moves left
    Point offset = getMoveDirection();
    int signX = (int) Math.signum(offset.x);
    int signY = (int) Math.signum(offset.y);
    CompoundCommand compoundCommand = new CompoundCommand();
    if (getEditor().getEditorSnapToGrid()) {
        // adjust offset to grid size (note: arguments must be not-negative numbers)
        offset = new Point(signX * getEditor().getEditorGridXOffset(signX * offset.x), signY * getEditor().getEditorGridYOffset(signY * offset.y));
        if (selParts.size() == 1) {
            // with one element we move the element onto the grid if it is off
            Point refLoc = null;
            if (selParts.get(0) instanceof NodeContainerEditPart) {
                NodeContainerEditPart node = (NodeContainerEditPart) selParts.get(0);
                NodeContainerFigure figure = (NodeContainerFigure) node.getFigure();
                Point iconOffset = SnapIconToGrid.getGridRefPointOffset(figure);
                refLoc = new Point(figure.getBounds().x, figure.getBounds().y);
                refLoc.translate(iconOffset);
            } else {
                IFigure fig = ((AbstractWorkflowEditPart) selParts.get(0)).getFigure();
                refLoc = new Point(fig.getBounds().x, fig.getBounds().y);
            }
            Point gridLoc = new Point(0, 0);
            Point prevGridLoc = getEditor().getPrevGridLocation(refLoc);
            Point nextGridLoc = getEditor().getNextGridLocation(refLoc);
            boolean toGrid = false;
            if (signX < 0) {
                gridLoc.x = prevGridLoc.x;
                toGrid = (gridLoc.x != refLoc.x);
            }
            if (signX > 0) {
                gridLoc.x = nextGridLoc.x;
                toGrid = (gridLoc.x != refLoc.x);
            }
            if (signY < 0) {
                gridLoc.y = prevGridLoc.y;
                toGrid = (gridLoc.y != refLoc.y);
            }
            if (signY > 0) {
                gridLoc.y = nextGridLoc.y;
                toGrid = (gridLoc.y != refLoc.y);
            }
            if (toGrid) {
                offset = new Point(Math.abs(gridLoc.x - refLoc.x) * signX, Math.abs(gridLoc.y - refLoc.y) * signY);
            }
        }
    }
    int noNodes = 0;
    // apply the offset to all selected elements
    for (EditPart epart : selParts) {
        // apply to selected nodes
        if (epart instanceof NodeContainerEditPart) {
            NodeContainerEditPart node = (NodeContainerEditPart) epart;
            noNodes++;
            NodeContainerUI nc = node.getNodeContainer();
            NodeContainerFigure figure = (NodeContainerFigure) node.getFigure();
            Rectangle bounds = figure.getBounds().getCopy();
            bounds.translate(offset);
            ChangeNodeBoundsCommand cmd = new ChangeNodeBoundsCommand(Wrapper.unwrapNC(nc), figure, bounds);
            compoundCommand.add(cmd);
        }
        // apply to all selected workflow annotations
        if ((epart instanceof AnnotationEditPart) && !(epart instanceof NodeAnnotationEditPart)) {
            AnnotationEditPart anno = (AnnotationEditPart) epart;
            Rectangle bounds = anno.getFigure().getBounds().getCopy();
            bounds.translate(offset);
            ChangeAnnotationBoundsCommand cmd = new ChangeAnnotationBoundsCommand(getManager(), anno, bounds);
            compoundCommand.add(cmd);
        }
    }
    if (noNodes > 1) {
        // if multiple nodes are selected/moved we need to move fully contained connections as well
        ConnectionContainerEditPart[] conns = WorkflowSelectionDragEditPartsTracker.getEmbracedConnections(selParts);
        for (ConnectionContainerEditPart conn : conns) {
            ChangeBendPointLocationCommand connCmd = new ChangeBendPointLocationCommand(conn, offset.getCopy(), null);
            compoundCommand.add(connCmd);
        }
    }
    return compoundCommand;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) ChangeNodeBoundsCommand(org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) AbstractWorkflowEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowEditPart) EditPart(org.eclipse.gef.EditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) 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) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) AbstractWorkflowEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowEditPart) IFigure(org.eclipse.draw2d.IFigure) ChangeBendPointLocationCommand(org.knime.workbench.editor2.commands.ChangeBendPointLocationCommand)

Example 10 with NodeAnnotationEditPart

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

the class AnnotationEditManager method initCellEditor.

/**
 * Initializes the cell editor.
 *
 * @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
 */
@Override
protected void initCellEditor() {
    // de-select the underlying annotation to remove the selection handles
    final GraphicalEditPart editPart = getEditPart();
    editPart.getRoot().getViewer().deselectAll();
    editPart.getFigure().setVisible(false);
    StyledTextEditor stw = (StyledTextEditor) getCellEditor();
    Annotation anno = ((AnnotationEditPart) editPart).getModel();
    Font defaultFont;
    if (editPart instanceof NodeAnnotationEditPart) {
        defaultFont = AnnotationEditPart.getNodeAnnotationDefaultFont();
    } else if (anno.getVersion() < AnnotationData.VERSION_20151012) {
        defaultFont = FontStore.INSTANCE.getSystemDefaultFont();
    } else {
        defaultFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont();
    }
    stw.setDefaultFont(defaultFont);
    stw.setValue(anno);
    // Hook the cell editor's copy/paste actions to the actionBars so that
    // they can
    // be invoked via keyboard shortcuts.
    m_actionBars = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorSite().getActionBars();
    saveCurrentActions(m_actionBars);
    m_actionHandler = new CellEditorActionHandler(m_actionBars);
    m_actionHandler.addCellEditor(getCellEditor());
    m_actionBars.updateActionBars();
}
Also used : AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) CellEditorActionHandler(org.eclipse.ui.part.CellEditorActionHandler) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) Annotation(org.knime.core.node.workflow.Annotation) Font(org.eclipse.swt.graphics.Font) 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