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);
}
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();
}
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;
}
}
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);
}
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();
}
}
});
}
}
Aggregations