use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class ShiftConnectionCommand method getLastConnectedPort.
/**
* @return the lowest index of a port that is not connected.
*/
private int getLastConnectedPort() {
NodeContainerUI nc = m_node.getNodeContainer();
int startIdx = 1;
if (nc instanceof WorkflowManagerUI) {
startIdx = 0;
}
int lastConnPort = -1;
for (int p = startIdx; p < nc.getNrInPorts(); p++) {
if (getHostWFM().getIncomingConnectionFor(m_nodeID, p) != null) {
lastConnPort = p;
}
}
if ((lastConnPort < 0) && (startIdx > 0) && (getHostWFM().getIncomingConnectionFor(m_nodeID, 0) != null)) {
// test the implicit flow var port, if it is the only connected port
lastConnPort = 0;
}
return lastConnPort;
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class AbstractWorkflowPortBarEditPart method getMinMaxXcoordInWorkflow.
/**
* returns the minX coordinate and the maxX coordinate of all nodes, annotations and bendpoints in the flow (taking
* the size of the elements into account). Or Integer.MIN/MAX_value if no elements exist.
* @return new int[] {minX, maxX};
*/
protected int[] getMinMaxXcoordInWorkflow() {
int maxX = Integer.MIN_VALUE;
int minX = Integer.MAX_VALUE;
// find the smallest and the biggest X coordinate in all the UI infos in the flow
WorkflowManagerUI manager = ((WorkflowPortBar) getModel()).getWorkflowManager();
for (NodeContainerUI nc : manager.getNodeContainers()) {
int nodeWidth = NodeContainerFigure.WIDTH;
NodeAnnotation nodeAnno = nc.getNodeAnnotation();
if ((nodeAnno != null) && (nodeAnno.getWidth() > nodeWidth)) {
nodeWidth = nodeAnno.getWidth();
}
NodeUIInformation uiInfo = nc.getUIInformation();
if (uiInfo != null) {
int x = uiInfo.getBounds()[0];
// right border of node
x = x + (nodeWidth / 2);
if (maxX < x) {
maxX = x;
}
// left border of node
x = x - nodeWidth;
if (minX > x) {
minX = x;
}
}
}
for (WorkflowAnnotation anno : manager.getWorkflowAnnotations()) {
int x = anno.getX();
if (minX > x) {
minX = x;
}
x = x + anno.getWidth();
if (maxX < x) {
maxX = x;
}
}
for (ConnectionContainerUI conn : manager.getConnectionContainers()) {
ConnectionUIInformation uiInfo = conn.getUIInfo();
if (uiInfo != null) {
int[][] bendpoints = uiInfo.getAllBendpoints();
if (bendpoints != null) {
for (int[] b : bendpoints) {
if (maxX < b[0]) {
maxX = b[0];
}
if (minX > b[0]) {
minX = b[0];
}
}
}
}
}
return new int[] { minX, maxX };
}
use of org.knime.core.ui.node.workflow.NodeContainerUI 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();
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class NodeContainerEditPart method getFreeInPort.
/**
* @param sourceNode
* @param srcPortIdx
* @return the first free port the specified port could be connected to. Or -1 if there is none.
*/
public int getFreeInPort(final ConnectableEditPart sourceNode, final int srcPortIdx) {
WorkflowManagerUI wm = getWorkflowManager();
if (wm == null || sourceNode == null || srcPortIdx < 0) {
return -1;
}
// skip variable ports
int startPortIdx = 1;
int connPortIdx = -1;
NodeContainerUI nc = getNodeContainer();
if (nc instanceof WorkflowManagerUI) {
startPortIdx = 0;
}
for (int i = startPortIdx; i < nc.getNrInPorts(); i++) {
if (wm.canAddNewConnection(sourceNode.getNodeContainer().getID(), srcPortIdx, nc.getID(), i)) {
connPortIdx = i;
break;
}
}
if ((connPortIdx < 0) && (startPortIdx == 1) && wm.canAddConnection(sourceNode.getNodeContainer().getID(), srcPortIdx, nc.getID(), 0)) {
// if the src is a flow var port, connect it to impl flow var port
connPortIdx = 0;
}
return connPortIdx;
}
use of org.knime.core.ui.node.workflow.NodeContainerUI 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