use of org.apache.airavata.workflow.model.graph.Port in project airavata by apache.
the class GraphUtil method getNextNodes.
/**
* Returns next nodes connected to a specified node.
*
* @param node
* The specified node.
* @return The next nodes.
*/
public static List<Node> getNextNodes(Node node) {
List<Node> nextNodes = getOutputNodes(node);
for (Port port : node.getControlOutPorts()) {
Collection<Node> toNodes = port.getToNodes();
nextNodes.addAll(toNodes);
}
return nextNodes;
}
use of org.apache.airavata.workflow.model.graph.Port in project airavata by apache.
the class GraphCanvas method mouseReleased.
private void mouseReleased(MouseEvent event) {
Point point = event.getPoint();
if (this.draggedNode != null) {
NodeController.getGUI(this.draggedNode).setDraggedFlag(false);
this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
// Check if it s stream grouping
if (draggedNode instanceof InputNode) {
StreamSourceNode streamNode = NodeController.getGUI(this.graph).getStreamSourceAt(point);
if (streamNode != null) {
streamNode.addInputNode((InputNode) draggedNode);
}
}
this.draggedNode = null;
}
if (this.draggedPort != null) {
GraphPiece graphPiece = NodeController.getGUI(this.graph).getGraphPieceAt(point);
if (graphPiece instanceof DynamicNode) {
if (this.draggedPort.getKind() == Kind.DATA_OUT && draggedPort instanceof DataPort) {
this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
DynamicNode dynamicNode = (DynamicNode) graphPiece;
dynamicNode.getComponent();
DataPort freePort = dynamicNode.getFreeInPort();
try {
freePort.copyType((DataPort) draggedPort);
} catch (GraphException e) {
engine.getGUI().getErrorWindow().error(e);
return;
}
// selectInputPort(freePort);
connect(this.draggedPort, freePort);
this.dynamicNodeWithFreePort = null;
}
} else if (graphPiece instanceof Port) {
Port port = (Port) graphPiece;
if (this.draggedPort.getKind() == Kind.DATA_OUT && port.getKind() == Kind.DATA_IN) {
connect(this.draggedPort, port);
} else if (port.getKind() == Kind.DATA_OUT && this.draggedPort.getKind() == Kind.DATA_IN) {
connect(port, this.draggedPort);
} else if (this.draggedPort.getKind() == Kind.CONTROL_OUT && port.getKind() == Kind.CONTROL_IN) {
connect(this.draggedPort, port);
} else if (this.draggedPort.getKind() == Kind.CONTROL_IN && port.getKind() == Kind.CONTROL_OUT) {
connect(port, this.draggedPort);
} else if (this.draggedPort.getKind() == Kind.EPR && port.getKind() == Kind.DATA_IN) {
connect(this.draggedPort, port);
} else if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.EPR) {
connect(port, this.draggedPort);
}
}
this.draggedPort = null;
}
if (this.dynamicNodeWithFreePort != null) {
try {
this.dynamicNodeWithFreePort.removeLastDynamicallyAddedInPort();
} catch (GraphException e) {
this.engine.getGUI().getErrorWindow().error(e);
}
}
/*
* Multiple selected
*/
if (this.mousePointForSelection != null) {
double width = Math.abs(this.mousePoint.getX() - this.mousePointForSelection.getX());
double height = Math.abs(this.mousePoint.getY() - this.mousePointForSelection.getY());
int x = (int) (this.mousePoint.getX() > this.mousePointForSelection.getX() ? this.mousePointForSelection.getX() : this.mousePoint.getX());
int y = (int) (this.mousePoint.getY() > this.mousePointForSelection.getY() ? this.mousePointForSelection.getY() : this.mousePoint.getY());
this.multipleSelectedNodes = NodeController.getGUI(this.graph).getNodesIn(new Rectangle(x, y, (int) width, (int) height));
selectNodes(this.multipleSelectedNodes);
// clear mousepoint
this.mousePointForSelection = null;
}
if (this.multipleSelectedNodes != null) {
this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
}
maybeShowPopup(event);
updateSize();
this.panel.repaint();
event.consume();
}
use of org.apache.airavata.workflow.model.graph.Port in project airavata by apache.
the class GraphCanvas method mouseClicked.
private void mouseClicked(MouseEvent event) {
/*
* If there is multi-selected and a click on a node, switch to that node or deselect node if it is already
* selected
*/
Point point = event.getPoint();
GraphPiece clicked = NodeController.getGUI(this.graph).getGraphPieceAt(point);
if ((clicked instanceof Node) && this.multipleSelectedNodes != null) {
Node node = (Node) clicked;
if (!this.crtlPressed) {
selectNode(node);
}
return;
} else if ((clicked instanceof Port) && event.getClickCount() == 2) {
// double click to add Input/Output nodes and connect with them when a DataPort is double clicked
Port port = (Port) clicked;
Point pos = port.getNode().getPosition();
Node node = null;
int xgap = (int) (1.5 * NodeGUI.MINIMUM_WIDTH);
int ygap = (int) (NodeGUI.MINIMUM_HEIGHT / 2);
Point nodePos = null;
switch(port.getKind()) {
case DATA_IN:
if (port.getFromNode() == null) {
nodePos = new Point(Math.max(0, pos.x - xgap), Math.max(0, pos.y - ygap));
node = addNode(new InputComponent(), nodePos);
connect(node.getOutputPorts().get(0), port);
}
break;
case DATA_OUT:
nodePos = new Point(pos.x + NodeGUI.MINIMUM_WIDTH + xgap, pos.y + ygap);
node = addNode(new OutputComponent(), nodePos);
connect(port, node.getInputPorts().get(0));
break;
default:
}
}
// delegate the event.
NodeController.getGUI(this.graph).mouseClicked(event, this.engine);
}
use of org.apache.airavata.workflow.model.graph.Port in project airavata by apache.
the class GraphCanvas method mouseMoved.
private void mouseMoved(MouseEvent event) {
Point point = event.getPoint();
GraphPiece graphPiece = NodeController.getGUI(this.graph).getGraphPieceAt(point);
if (graphPiece instanceof Node) {
Node node = (Node) graphPiece;
if (NodeController.getGUI(node).isInConfig(point)) {
this.panel.setCursor(SwingUtil.HAND_CURSOR);
} else {
this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
}
} else if (graphPiece instanceof Port) {
this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
} else {
this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
}
}
use of org.apache.airavata.workflow.model.graph.Port in project airavata by apache.
the class JythonScript method writeInvocation.
/**
* @param node
* @param thread
* @param pw
*/
private void writeInvocation(WSNode node, boolean thread, PrintWriter pw) {
String id = node.getID();
String wsdlID = getWSDLID(node);
WSComponent component = node.getComponent();
QName portTypeQName = component.getPortTypeQName();
String operation = component.getOperationName();
pw.println(TAB + "# Invoke " + id + ".");
pw.println(TAB + id + QNAME_SUFFIX + " = QName('" + portTypeQName.getNamespaceURI() + "', '" + portTypeQName.getLocalPart() + "')");
pw.println(TAB + wsdlID + " = " + PROPERTIES_VARIABLE + "." + GET_PROPERTY_METHOD + "('" + wsdlID + "')");
pw.println(TAB + id + INVOKER_SUFFIX + " = " + "(" + id + QNAME_SUFFIX + ", " + wsdlID + ", '" + id + "',");
pw.println(TAB + TAB + MESSAGE_BOX_URL_VARIABLE + ", " + GFAC_VARIABLE + ", " + NOTIFICATION_VARIABLE + ")");
pw.println(TAB + "def " + INVOKE_METHOD + id + "():");
pw.println(TAB + TAB + id + INVOKER_SUFFIX + "." + SETUP_METHOD + "()");
pw.println(TAB + TAB + id + INVOKER_SUFFIX + "." + SET_OPERATION_METHOD + "('" + operation + "')");
// Ports
for (Port port : node.getInputPorts()) {
String portName = port.getName();
String value;
Node fromNode = port.getFromNode();
if (fromNode instanceof InputNode) {
value = PROPERTIES_VARIABLE + "." + GET_PROPERTY_METHOD + "('" + fromNode.getID() + "')";
} else {
Port fromPort = port.getFromPort();
value = "" + fromNode.getID() + INVOKER_SUFFIX + "." + GET_OUTPUT_METHOD + "('" + fromPort.getName() + "')";
// This might try to remove a node that has been removed
// already, but it's OK.
this.executingNodes.remove(fromNode);
}
pw.println(TAB + TAB + portName + VALUE_SUFFIX + " = " + value);
pw.println(TAB + TAB + id + INVOKER_SUFFIX + "." + SET_INPUT_METHOD + "('" + portName + "', " + portName + VALUE_SUFFIX + ")");
}
pw.println(TAB + TAB + "print 'Invoking " + id + ".'");
pw.println(TAB + TAB + id + INVOKER_SUFFIX + "." + INVOKE_METHOD + "()");
if (thread) {
pw.println(TAB + "thread.start_new_thread(" + INVOKE_METHOD + id + ", ())");
} else {
pw.println(TAB + INVOKE_METHOD + id + "()");
}
pw.println();
this.executingNodes.add(node);
}
Aggregations