use of org.knime.core.ui.node.workflow.WorkflowManagerUI 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.WorkflowManagerUI in project knime-core by knime.
the class WorkflowInPortBarEditPart method getModelChildren.
/**
* {@inheritDoc}
*/
@Override
protected List<NodePortUI> getModelChildren() {
WorkflowManagerUI manager = ((WorkflowPortBar) getModel()).getWorkflowManager();
List<NodePortUI> ports = new ArrayList<NodePortUI>();
for (int i = 0; i < manager.getNrWorkflowIncomingPorts(); i++) {
ports.add(manager.getInPort(i));
}
return ports;
}
use of org.knime.core.ui.node.workflow.WorkflowManagerUI in project knime-core by knime.
the class PortGraphicalRoleEditPolicy method getConnectionCreateCommand.
/**
* This tries to initialize the command to create a connection as far as
* possible. However, it is completed by
* <code>getConnectionCompleteCommand</code>
*
* {@inheritDoc}
*/
@Override
protected Command getConnectionCreateCommand(final CreateConnectionRequest req) {
if (!(getHost() instanceof AbstractPortEditPart)) {
return null;
}
ConnectableEditPart nodePart = (ConnectableEditPart) getHost().getParent();
WorkflowManagerUI wm;
// TODO: if NodeContainerEditPart -> getParent
if (nodePart instanceof NodeContainerEditPart) {
NodeContainerEditPart p = (NodeContainerEditPart) nodePart;
wm = p.getWorkflowManager();
} else if (nodePart instanceof WorkflowInPortBarEditPart) {
WorkflowInPortBarEditPart barEditPart = (WorkflowInPortBarEditPart) nodePart;
WorkflowPortBar model = (WorkflowPortBar) barEditPart.getModel();
wm = model.getWorkflowManager();
} else {
return null;
}
CreateConnectionCommand cmd = new CreateConnectionCommand(Wrapper.unwrapWFM(wm));
if (getHost() instanceof NodeOutPortEditPart || getHost() instanceof WorkflowInPortEditPart || getHost() instanceof MetaNodeOutPortEditPart) {
// request started on out port?
cmd.setSourceNode(nodePart);
cmd.setSourcePortID(((AbstractPortEditPart) getHost()).getIndex());
cmd.setStartedOnOutPort(true);
} else if (getHost() instanceof NodeInPortEditPart || getHost() instanceof WorkflowOutPortEditPart) {
return null;
}
// we need the manager to execute the command
// we must remember this partially initialized command in the request.
req.setStartCommand(cmd);
return cmd;
}
use of org.knime.core.ui.node.workflow.WorkflowManagerUI 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.WorkflowManagerUI in project knime-core by knime.
the class KnimeResourceContentProvider method hasChildren.
/**
* {@inheritDoc}
*/
@Override
public boolean hasChildren(final Object element) {
if (element instanceof IFile) {
return false;
}
if (isKNIMEWorkflow(element)) {
IContainer project = (IContainer) element;
NodeContainerUI workflow = ProjectWorkflowMap.getWorkflowUI(project.getLocationURI());
if (workflow != null) {
// the number of contained nodes is returned
return ((WorkflowManagerUI) workflow).getNodeContainers().size() > 0;
}
} else if (element instanceof WorkflowManagerUI) {
return ((WorkflowManagerUI) element).getNodeContainers().size() > 0;
}
// then it is a node and has no children
if (element instanceof IContainer) {
IContainer container = (IContainer) element;
if (isKNIMEWorkflow(container.getParent())) {
return false;
}
}
return getFolders(element).length > 0;
}
Aggregations