use of org.knime.workbench.editor2.figures.NodeContainerFigure in project knime-core by knime.
the class NodeContainerEditPart method checkMetaNodeLockIcon.
private void checkMetaNodeLockIcon() {
NodeContainerUI nc = getNodeContainer();
if (nc instanceof WorkflowManagerUI) {
WorkflowManagerUI wm = (WorkflowManagerUI) nc;
Image i;
if (wm.isEncrypted()) {
if (wm.isUnlocked()) {
i = META_NODE_UNLOCK_ICON;
} else {
i = META_NODE_LOCK_ICON;
}
} else {
i = null;
}
NodeContainerFigure fig = (NodeContainerFigure) getFigure();
fig.setMetaNodeLockIcon(i);
}
}
use of org.knime.workbench.editor2.figures.NodeContainerFigure in project knime-core by knime.
the class NodeContainerEditPart method refreshBounds.
/**
* Adjusts the height and width of the node's figure. It automatically sets them to the preferred height/width of
* the figure (which might change if the warning icons change). It doesn't change x/y position of the figure. It
* does change width and height.
*/
private void refreshBounds() {
NodeUIInformation uiInfo = getNodeContainer().getUIInformation();
int[] bounds = uiInfo.getBounds();
WorkflowRootEditPart parent = (WorkflowRootEditPart) getParent();
NodeContainerFigure fig = (NodeContainerFigure) getFigure();
Dimension pref = fig.getPreferredSize();
boolean set = false;
if (pref.width != bounds[2]) {
bounds[2] = pref.width;
set = true;
}
if (pref.height != bounds[3]) {
bounds[3] = pref.height;
set = true;
}
if (set) {
// notify uiInfo listeners (e.g. node annotations)
m_uiListenerActive = false;
getNodeContainer().setUIInformation(NodeUIInformation.builder().setNodeLocation(bounds[0], bounds[1], bounds[2], bounds[3]).build());
m_uiListenerActive = true;
}
// since ver2.3.0 all coordinates are relative to the icon
Point offset = fig.getOffsetToRefPoint(uiInfo);
bounds[0] -= offset.x;
bounds[1] -= offset.y;
Rectangle rect = new Rectangle(bounds[0], bounds[1], bounds[2], bounds[3]);
fig.setBounds(rect);
parent.setLayoutConstraint(this, fig, rect);
}
use of org.knime.workbench.editor2.figures.NodeContainerFigure in project knime-core by knime.
the class NewWorkflowXYLayoutPolicy method createChangeConstraintCommand.
/**
* Creates command to move / resize <code>NodeContainer</code> components on
* the project's client area.
*
* {@inheritDoc}
*/
@Override
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
// only rectangular constraints are supported
if (!(constraint instanceof Rectangle)) {
return null;
}
Command command = null;
Rectangle rect = ((Rectangle) constraint).getCopy();
if (child.getModel() instanceof NodeContainerUI) {
NodeContainerUI container = (NodeContainerUI) child.getModel();
if (!Wrapper.wraps(container, NodeContainer.class)) {
// not supported for others than ordinary NodeContainers
return null;
}
NodeContainerEditPart nodePart = (NodeContainerEditPart) child;
command = new ChangeNodeBoundsCommand(Wrapper.unwrapNC(container), (NodeContainerFigure) nodePart.getFigure(), rect);
} else if (child instanceof AbstractWorkflowPortBarEditPart) {
command = new ChangeWorkflowPortBarCommand((AbstractWorkflowPortBarEditPart) child, rect);
} else if (child instanceof AnnotationEditPart) {
AnnotationEditPart annoPart = (AnnotationEditPart) child;
// TODO the workflow annotation could know what its WFM is?
WorkflowRootEditPart root = (WorkflowRootEditPart) annoPart.getParent();
WorkflowManagerUI wm = root.getWorkflowManager();
if (!Wrapper.wraps(wm, WorkflowManager.class)) {
// not supported for others than an ordinary workflow manager
return null;
}
command = new ChangeAnnotationBoundsCommand(Wrapper.unwrapWFM(wm), annoPart, rect);
}
return command;
}
use of org.knime.workbench.editor2.figures.NodeContainerFigure 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);
}
use of org.knime.workbench.editor2.figures.NodeContainerFigure in project knime-core by knime.
the class NodeContainerEditPart method callHideNodeName.
/**
* Change hide/show node label status.
*/
public void callHideNodeName() {
WorkflowRootEditPart root = getRootEditPart();
if (root != null) {
NodeContainerFigure ncFigure = (NodeContainerFigure) getFigure();
ncFigure.hideNodeName(root.hideNodeNames());
}
}
Aggregations