Search in sources :

Example 6 with NodeContainerFigure

use of org.knime.workbench.editor2.figures.NodeContainerFigure in project knime-core by knime.

the class NodeContainerEditPart method checkMetaNodeTemplateIcon.

private void checkMetaNodeTemplateIcon() {
    NodeContainerUI nc = getNodeContainer();
    MetaNodeTemplateInformation templInfo = null;
    if (Wrapper.wraps(nc, NodeContainerTemplate.class)) {
        NodeContainerTemplate t = Wrapper.unwrap(nc, NodeContainerTemplate.class);
        templInfo = t.getTemplateInformation();
    }
    if (templInfo != null) {
        NodeContainerFigure fig = (NodeContainerFigure) getFigure();
        switch(templInfo.getRole()) {
            case Link:
                Image i;
                switch(templInfo.getUpdateStatus()) {
                    case HasUpdate:
                        i = META_NODE_LINK_RED_ICON;
                        break;
                    case UpToDate:
                        i = META_NODE_LINK_GREEN_ICON;
                        break;
                    default:
                        i = META_NODE_LINK_PROBLEM_ICON;
                }
                fig.setMetaNodeLinkIcon(i);
                break;
            default:
                fig.setMetaNodeLinkIcon(null);
        }
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) Image(org.eclipse.swt.graphics.Image) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 7 with NodeContainerFigure

use of org.knime.workbench.editor2.figures.NodeContainerFigure 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 8 with NodeContainerFigure

use of org.knime.workbench.editor2.figures.NodeContainerFigure 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 9 with NodeContainerFigure

use of org.knime.workbench.editor2.figures.NodeContainerFigure in project knime-core by knime.

the class NodeContainerEditPart method updateFigureFromUIinfo.

private void updateFigureFromUIinfo(final NodeUIInformation uiInfo) {
    NodeContainerFigure fig = (NodeContainerFigure) getFigure();
    setBoundsFromUIinfo(uiInfo);
    // update tooltip
    fig.setCustomDescription(getNodeContainer().getCustomDescription());
    // check status of node
    updateNodeMessage();
    // reset the tooltip text of the outports
    for (Object part : getChildren()) {
        if (part instanceof NodeOutPortEditPart) {
            NodeOutPortEditPart outPortPart = (NodeOutPortEditPart) part;
            outPortPart.rebuildTooltip();
        }
    }
    // for sub node refresh all tooltips
    if (getNodeContainer() instanceof SubNodeContainerUI) {
        for (Object part : getChildren()) {
            if (part instanceof NodeInPortEditPart) {
                NodeInPortEditPart inPortPart = (NodeInPortEditPart) part;
                inPortPart.rebuildTooltip();
            }
            if (part instanceof NodeOutPortEditPart) {
                NodeOutPortEditPart outPortPart = (NodeOutPortEditPart) part;
                outPortPart.rebuildTooltip();
            }
        }
    }
    // always refresh visuals
    refreshVisuals();
}
Also used : SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 10 with NodeContainerFigure

use of org.knime.workbench.editor2.figures.NodeContainerFigure in project knime-core by knime.

the class NodeContainerEditPart method updateNodeMessage.

/**
 * Checks the message of the this node and if there is a message in the <code>NodeStatus</code> object the message
 * is set. Otherwise the currently displayed message is removed.
 */
private void updateNodeMessage() {
    NodeContainerUI nc = getNodeContainer();
    NodeContainerFigure containerFigure = (NodeContainerFigure) getFigure();
    NodeMessage nodeMessage = nc.getNodeMessage();
    containerFigure.setMessage(nodeMessage);
    refreshBounds();
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) NodeMessage(org.knime.core.node.workflow.NodeMessage) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Aggregations

NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)17 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 SubNodeContainerUI (org.knime.core.ui.node.workflow.SubNodeContainerUI)8 Image (org.eclipse.swt.graphics.Image)5 Point (org.eclipse.draw2d.geometry.Point)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)3 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)3 IFigure (org.eclipse.draw2d.IFigure)2 EditPart (org.eclipse.gef.EditPart)2 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)2 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)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 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)2 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)2 URL (java.net.URL)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1