use of org.apache.airavata.workflow.model.graph.dynamic.DynamicNode in project airavata by apache.
the class WorkflowInterpreter method handleDynamicComponent.
private void handleDynamicComponent(Node node) throws WorkflowException {
DynamicComponent dynamicComponent = (DynamicComponent) node.getComponent();
String className = dynamicComponent.getClassName();
String operationName = dynamicComponent.getOperationName();
URL implJarLocation = dynamicComponent.getImplJarLocation();
DynamicNode dynamicNode = (DynamicNode) node;
LinkedList<Object> inputs = new LinkedList<Object>();
List<DataPort> inputPorts = dynamicNode.getInputPorts();
for (DataPort dataPort : inputPorts) {
Object inputVal = InterpreterUtil.findInputFromPort(dataPort, this.invokerMap);
/*
* Set type after get input value, and override inputValue if output
* type is array
*/
Node fromNode = dataPort.getFromNode();
DataType type = null;
if (fromNode instanceof InputNode) {
type = DataType.STRING;
} else if (fromNode instanceof ConstantNode) {
type = ((ConstantNode) fromNode).getType();
} else if ((dataPort.getFromPort() instanceof WSPort) && BasicTypeMapping.isArrayType(((WSPort) dataPort.getFromPort()).getComponentPort().getElement())) {
Invoker fromInvoker = this.invokerMap.get(fromNode);
// inputVal = BasicTypeMapping.getOutputArray(XmlConstants.BUILDER.parseFragmentFromString(fromInvoker.getOutputs().toString()), dataPort
// .getFromPort().getName(), BasicTypeMapping.getSimpleTypeIndex(((DataPort) dataPort.getFromPort()).getType()));
type = ((DataPort) dataPort.getFromPort()).getType();
} else {
type = ((DataPort) dataPort.getFromPort()).getType();
}
if (null == inputVal) {
throw new WorkFlowInterpreterException("Unable to find inputs for the node:" + node.getID());
}
// inputs.add(BasicTypeMapping.getObjectOfType(type, inputVal));
}
DynamicInvoker dynamicInvoker = new DynamicInvoker(className, implJarLocation, operationName, inputs.toArray());
this.invokerMap.put(node, dynamicInvoker);
dynamicInvoker.setup();
dynamicInvoker.invoke();
node.setState(NodeExecutionState.FINISHED);
}
use of org.apache.airavata.workflow.model.graph.dynamic.DynamicNode 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.dynamic.DynamicNode in project airavata by apache.
the class GraphCanvas method mouseDragged.
private void mouseDragged(MouseEvent event) {
Point point = event.getPoint();
if (editable) {
/*
* Move nodes
*/
if (this.multipleSelectedNodes != null) {
if (point.x < 0) {
point.x = 0;
}
if (point.y < 0) {
point.y = 0;
}
int diffX = point.x - this.mousePoint.x;
int diffY = point.y - this.mousePoint.y;
for (Node node : this.multipleSelectedNodes) {
Point newPoint = new Point();
Point currentPoint = node.getPosition();
newPoint.x = currentPoint.x + diffX;
if (newPoint.x < 0) {
newPoint.x = 0;
}
newPoint.y = currentPoint.y + diffY;
if (newPoint.y < 0) {
newPoint.y = 0;
}
node.setPosition(newPoint);
}
this.panel.repaint();
event.consume();
}
if (this.draggedNode != null) {
if (point.x < 0) {
point.x = 0;
}
if (point.y < 0) {
point.y = 0;
}
int diffX = point.x - this.mousePoint.x;
int diffY = point.y - this.mousePoint.y;
Point newPoint = new Point();
Point currentPoint = this.draggedNode.getPosition();
newPoint.x = currentPoint.x + diffX;
if (newPoint.x < 0) {
newPoint.x = 0;
}
newPoint.y = currentPoint.y + diffY;
if (newPoint.y < 0) {
newPoint.y = 0;
}
this.draggedNode.setPosition(newPoint);
this.panel.repaint();
event.consume();
}
if (this.draggedPort != null) {
GraphPiece piece = NodeController.getGUI(this.graph).getGraphPieceAt(point);
if (piece instanceof Port) {
Port port = (Port) piece;
// pointer.
if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.DATA_OUT) {
this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
selectOutputPort(port);
} else if (this.draggedPort.getKind() == Kind.DATA_OUT && port.getKind() == Kind.DATA_IN) {
this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
selectInputPort(port);
} else if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.EPR) {
this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
selectOutputPort(port);
} else if (this.draggedPort.getKind() == Kind.EPR && port.getKind() == Kind.DATA_IN) {
this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
selectInputPort(port);
} else {
this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
}
} else if (piece instanceof PortAddable) {
PortAddable dynamicNode = (PortAddable) piece;
dynamicNode.getFreeInPort();
this.dynamicNodeWithFreePort = dynamicNode;
} else {
this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
}
this.panel.repaint();
event.consume();
}
this.mousePoint = point;
// draw rectangle
if (this.mousePointForSelection != null) {
this.panel.repaint();
}
}
}
use of org.apache.airavata.workflow.model.graph.dynamic.DynamicNode in project airavata by apache.
the class DynamicComponent method createNode.
public Node createNode(Graph graph) {
DynamicNode node = new DynamicNode(graph);
// Copy some infomation from the component
node.setName(getName());
node.setComponent(new DynamicComponent());
// Creates a unique ID for the node. This has to be after setName().
node.createID();
// Creat ports
createPorts(node);
return node;
}
Aggregations