Search in sources :

Example 1 with NodeAnnotation

use of org.knime.core.node.workflow.NodeAnnotation 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 2 with NodeAnnotation

use of org.knime.core.node.workflow.NodeAnnotation in project knime-core by knime.

the class StyledTextEditor method doSetValue.

/**
 * {@inheritDoc}
 */
@Override
protected void doSetValue(final Object value) {
    assert value instanceof Annotation : "Wrong value object!";
    Annotation wa = (Annotation) value;
    int alignment;
    switch(wa.getAlignment()) {
        case CENTER:
            alignment = SWT.CENTER;
            break;
        case RIGHT:
            alignment = SWT.RIGHT;
            break;
        default:
            alignment = SWT.LEFT;
    }
    checkSelectionOfAlignmentMenuItems(alignment);
    m_selectAllUponFocusGain = false;
    String text;
    if (wa instanceof NodeAnnotation) {
        if (AnnotationEditPart.isDefaultNodeAnnotation(wa)) {
            text = AnnotationEditPart.getAnnotationText(wa);
            m_selectAllUponFocusGain = true;
        } else {
            text = wa.getText();
        }
    } else {
        text = wa.getText();
        m_selectAllUponFocusGain = AddAnnotationCommand.INITIAL_FLOWANNO_TEXT.equals(text);
        int annotationBorderSize = wa.getBorderSize();
        // set margins as borders
        m_styledText.setMarginColor(AnnotationEditPart.RGBintToColor(wa.getBorderColor()));
        if (annotationBorderSize > 0) {
            m_styledText.setMargins(annotationBorderSize, annotationBorderSize, annotationBorderSize, annotationBorderSize);
        }
        // for workflow annotations set the default font to the size stored in the annotation
        Font defFont;
        int defFontSize = wa.getDefaultFontSize();
        if (defFontSize < 0) {
            // uses the size from the pref page
            defFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont();
        } else {
            defFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont(defFontSize);
        }
        setDefaultFont(defFont);
    }
    m_styledText.setAlignment(alignment);
    m_styledText.setText(text);
    m_styledText.setStyleRanges(AnnotationEditPart.toSWTStyleRanges(wa.getData(), m_styledText.getFont()));
    setBackgroundColor(AnnotationEditPart.RGBintToColor(wa.getBgColor()));
    syncShadowWithEditor();
}
Also used : NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation) Font(org.eclipse.swt.graphics.Font)

Example 3 with NodeAnnotation

use of org.knime.core.node.workflow.NodeAnnotation in project knime-core by knime.

the class WorkflowRootEditPart method getModelChildren.

/**
 * Returns the model chidlren, that is, the <code>NodeConatiner</code>s that
 * are stored in the workflow manager.
 *
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
protected List getModelChildren() {
    List modelChildren = new ArrayList();
    WorkflowManagerUI wfm = getWorkflowManager();
    // Add them first so they appear behind everything else
    for (Annotation anno : wfm.getWorkflowAnnotations()) {
        modelChildren.add(anno);
    }
    // workflow annotations so they appear above them)
    for (NodeAnnotation nodeAnno : wfm.getNodeAnnotations()) {
        modelChildren.add(nodeAnno);
    }
    modelChildren.addAll(wfm.getNodeContainers());
    if (wfm.getNrWorkflowIncomingPorts() > 0) {
        if (m_inBar == null) {
            m_inBar = new WorkflowPortBar(wfm, true);
            NodeUIInformation uiInfo = wfm.getInPortsBarUIInfo();
            if (uiInfo != null) {
                m_inBar.setUIInfo(wfm.getInPortsBarUIInfo());
            }
        }
        modelChildren.add(m_inBar);
    }
    if (wfm.getNrWorkflowOutgoingPorts() > 0) {
        if (m_outBar == null) {
            m_outBar = new WorkflowPortBar(wfm, false);
            NodeUIInformation uiInfo = wfm.getOutPortsBarUIInfo();
            if (uiInfo != null) {
                m_outBar.setUIInfo(wfm.getOutPortsBarUIInfo());
            }
        }
        modelChildren.add(m_outBar);
    }
    return modelChildren;
}
Also used : WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) ArrayList(java.util.ArrayList) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation)

Example 4 with NodeAnnotation

use of org.knime.core.node.workflow.NodeAnnotation 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 5 with NodeAnnotation

use of org.knime.core.node.workflow.NodeAnnotation 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)

Aggregations

NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)8 Annotation (org.knime.core.node.workflow.Annotation)3 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)3 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)3 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)3 ArrayList (java.util.ArrayList)2 EditPart (org.eclipse.gef.EditPart)2 Font (org.eclipse.swt.graphics.Font)2 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)2 ConnectionContainerUI (org.knime.core.ui.node.workflow.ConnectionContainerUI)2 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)2 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)2 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)2 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)2 NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)2 List (java.util.List)1 IFigure (org.eclipse.draw2d.IFigure)1 Point (org.eclipse.draw2d.geometry.Point)1 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)1 BlockFlow (org.eclipse.draw2d.text.BlockFlow)1