Search in sources :

Example 11 with NodeContainerFigure

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

the class NodeContainerEditPart method updateLabelText.

/**
 * Updates the label text either with or without the node id, depending on the settings in the root.
 */
private void updateLabelText() {
    WorkflowRootEditPart root = getRootEditPart();
    NodeContainerFigure ncFigure = (NodeContainerFigure) getFigure();
    String nodeName = getNodeContainer().getName();
    if (root != null && root.showNodeId()) {
        nodeName += " (#" + getNodeContainer().getID().getIndex() + ")";
    }
    ncFigure.setLabelText(nodeName);
}
Also used : NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 12 with NodeContainerFigure

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

the class NodeContainerEditPart method setBoundsFromUIinfo.

private void setBoundsFromUIinfo(final NodeUIInformation uiInfo) {
    NodeContainerFigure fig = (NodeContainerFigure) getFigure();
    int[] bounds = uiInfo.getBounds();
    Point iconOffset = fig.getOffsetToRefPoint(uiInfo);
    Point iconCenterOffset = SnapIconToGrid.getGridRefPointOffset(fig);
    Point diff = new Point(iconCenterOffset.x - iconOffset.x, iconCenterOffset.y - iconOffset.y);
    boolean newBounds = false;
    if (uiInfo.isDropLocation()) {
        bounds[0] -= diff.x;
        bounds[1] -= diff.y;
        // apply these new values at the end of the method
        newBounds = true;
    }
    if (!uiInfo.hasAbsoluteCoordinates()) {
        // make it absolute coordinates taking scrolling into account
        Point p = new Point(bounds[0], bounds[1]);
        fig.translateToRelative(p);
        bounds[0] = p.x;
        bounds[1] = p.y;
        // apply these new values at the end of the method
        newBounds = true;
    }
    if (uiInfo.getSnapToGrid()) {
        // snap icon center to grid
        Point iconCenterLoc = new Point(bounds[0] + diff.x, bounds[1] + diff.y);
        iconCenterLoc = WorkflowEditor.getActiveEditorClosestGridLocation(iconCenterLoc);
        // ui coordinates use the icon top left corner as reference
        bounds[0] = iconCenterLoc.x - diff.x;
        bounds[1] = iconCenterLoc.y - diff.y;
        newBounds = true;
    }
    if (!uiInfo.isSymbolRelative()) {
        // ui info from an earlier version - x/y is top top left coordinates
        // store symbol relative coordinates
        int xCorr = 29;
        int yCorr = Platform.OS_LINUX.equals(Platform.getOS()) ? 18 : 15;
        // don't trigger another entry into this method
        bounds[0] += xCorr;
        bounds[1] += yCorr;
        newBounds = true;
    }
    if (newBounds) {
        // don't trigger another event here, when updating ui info
        m_uiListenerActive = false;
        getNodeContainer().setUIInformation(NodeUIInformation.builder().setNodeLocation(bounds[0], bounds[1], bounds[2], bounds[3]).build());
        m_uiListenerActive = true;
    }
    // since v2.5 we ignore any width and height and keep bounds minimal
    refreshBounds();
}
Also used : Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 13 with NodeContainerFigure

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

the class NodeContainerEditPart method propertyChange.

/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(final PropertyChangeEvent pce) {
    if (pce.getProperty().equals(PreferenceConstants.P_NODE_LABEL_FONT_SIZE)) {
        NodeContainerFigure fig = (NodeContainerFigure) getFigure();
        Object value = pce.getNewValue();
        Integer fontSize = null;
        if (value == null) {
            return;
        } else if (value instanceof Integer) {
            fontSize = (Integer) value;
        } else if (value instanceof String && !value.toString().isEmpty()) {
            try {
                fontSize = Integer.parseInt((String) value);
            } catch (NumberFormatException e) {
                LOGGER.warn("Setting " + PreferenceConstants.P_NODE_LABEL_FONT_SIZE + " could not be updated. Unable to parse the value.");
            }
        }
        if (fontSize != null) {
            fig.setFontSize(fontSize);
            Display.getCurrent().syncExec(new Runnable() {

                @Override
                public void run() {
                    updateFigureFromUIinfo(getNodeContainer().getUIInformation());
                    getRootEditPart().getFigure().invalidate();
                    getRootEditPart().refreshVisuals();
                }
            });
        }
        return;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 14 with NodeContainerFigure

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

the class NodeContainerEditPart method initFigure.

private void initFigure() {
    NodeContainerFigure f = (NodeContainerFigure) getFigure();
    NodeType type = getNodeContainer().getType();
    String name = getNodeContainer().getName();
    String description = getNodeContainer().getCustomDescription();
    // get the icon
    Image icon = org.knime.workbench.core.util.ImageRepository.getUnscaledIconImage(getNodeContainer().getIcon());
    // get default image if null
    if (icon == null) {
        icon = org.knime.workbench.core.util.ImageRepository.getUnscaledIconImage(NodeFactory.getDefaultIcon());
    }
    if (icon != null) {
        f.setIcon(icon);
    }
    f.setType(type);
    updateLabelText();
    f.setCustomDescription(description);
}
Also used : NodeType(org.knime.core.node.NodeFactory.NodeType) Image(org.eclipse.swt.graphics.Image) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 15 with NodeContainerFigure

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

the class NodeContainerEditPart method stateChanged.

/**
 * {@inheritDoc}
 */
@Override
public void stateChanged(final NodeStateEvent state) {
    // works because we are retrieving the current state information!
    if (m_updateInProgress.compareAndSet(false, true)) {
        Display display = Display.getDefault();
        if (display.isDisposed()) {
            return;
        }
        display.asyncExec(new Runnable() {

            @Override
            public void run() {
                // let others know we are in the middle of processing
                // this update - they will now need to start their own job.
                NodeContainerFigure fig = (NodeContainerFigure) getFigure();
                m_updateInProgress.set(false);
                if (isActive()) {
                    NodeContainerUI nc = getNodeContainer();
                    fig.setStateFromNC(nc);
                    updateNodeMessage();
                    // reset the tooltip text of the outports
                    for (Object part : getChildren()) {
                        if (part instanceof NodeOutPortEditPart || part instanceof WorkflowInPortEditPart || part instanceof MetaNodeOutPortEditPart) {
                            AbstractPortEditPart outPortPart = (AbstractPortEditPart) part;
                            outPortPart.rebuildTooltip();
                        }
                    }
                    // always refresh visuals (does not seem to do anything
                    // by default though: call repaints on updated figures).
                    refreshVisuals();
                }
            }
        });
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) Display(org.eclipse.swt.widgets.Display) 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