use of org.apache.airavata.workflow.model.graph.GraphException in project airavata by apache.
the class GraphCanvas method connect.
/**
* Connects two ports specified.
*
* @param fromPort
* @param toPort
*/
private void connect(Port fromPort, Port toPort) {
try {
// check the validity of the connection.
Edge edge = this.graph.addEdge(fromPort, toPort);
selectEdge(edge);
} catch (GraphException e) {
logger.error(e.getMessage(), e);
this.engine.getGUI().getErrorWindow().warning(e.getMessage());
} catch (RuntimeException e) {
logger.error(e.getMessage(), e);
this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR);
}
}
use of org.apache.airavata.workflow.model.graph.GraphException 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.GraphException in project airavata by apache.
the class GraphCanvas method createNodePopupMenu.
private void createNodePopupMenu() {
this.nodePopup = new JPopupMenu();
if (editable) {
JMenuItem deleteItem = new JMenuItem("Delete");
deleteItem.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent event) {
try {
removeSelectedNode();
} catch (GraphException e) {
// Should not happen
logger.error(e.getMessage(), e);
GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
} catch (RuntimeException e) {
logger.error(e.getMessage(), e);
GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
} catch (Error e) {
logger.error(e.getMessage(), e);
GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
}
}
});
this.nodePopup.add(deleteItem);
}
rerunItem = new JMenuItem("ReRun");
rerunItem.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent event) {
try {
rerunSelectedNode();
} catch (RuntimeException e) {
logger.error(e.getMessage(), e);
GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
} catch (Error e) {
logger.error(e.getMessage(), e);
GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
}
}
});
breakPointItem = new JMenuItem("Add break Point");
breakPointItem.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent event) {
try {
toggleBreakPointToNode();
} catch (RuntimeException e) {
logger.error(e.getMessage(), e);
GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
} catch (Error e) {
logger.error(e.getMessage(), e);
GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
}
}
});
}
use of org.apache.airavata.workflow.model.graph.GraphException in project airavata by apache.
the class EndBlockNode method portTypeChanged.
/**
* @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
*/
@Override
protected void portTypeChanged(SystemDataPort port) throws GraphException {
super.portTypeChanged(port);
List<DataPort> inputPorts = getInputPorts();
List<DataPort> outputPorts = getOutputPorts();
int size = outputPorts.size();
Kind kind = port.getKind();
int index;
if (kind == Kind.DATA_IN) {
index = inputPorts.indexOf(port) % size;
} else if (kind == Kind.DATA_OUT) {
index = outputPorts.indexOf(port);
} else {
throw new WorkflowRuntimeException();
}
DataPort inputPort1 = inputPorts.get(index);
DataPort inputPort2 = inputPorts.get(size + index);
DataPort outputPort = outputPorts.get(index);
DataType inputType1 = inputPort1.getType();
DataType inputType2 = inputPort2.getType();
DataType outputType = outputPort.getType();
DataType portType = port.getType();
if (portType == null || portType.equals(WSConstants.XSD_ANY_TYPE)) {
// Do nothing
return;
}
if (port == inputPort1) {
// input1 -> input2
if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort2.copyType(port);
} else if (inputType2.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
throw new GraphException(message);
}
// input1 -> output
if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
outputPort.copyType(port);
} else if (outputType.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else if (port == inputPort2) {
// input2 -> input1
if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort1.copyType(port);
} else if (inputType1.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
throw new GraphException(message);
}
// input2 -> output
if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
outputPort.copyType(port);
} else if (outputType.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else if (port == outputPort) {
// output -> input1
if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort1.copyType(port);
} else if (inputType1.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
// output -> input2
if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort2.copyType(port);
} else if (inputType2.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID() + " must be same as the type of input " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else {
throw new WorkflowRuntimeException();
}
}
use of org.apache.airavata.workflow.model.graph.GraphException in project airavata by apache.
the class BPELScript method getSpecialBlock.
/**
* @param node
* @param depth
* @param block
* It's a set so that duplicated nodes won't be added.
* @param startClass
* @param endClass
* @throws GraphException
*/
private void getSpecialBlock(Node node, int depth, Set<Node> block, Class startClass, Class endClass) throws GraphException {
List<Node> nextNodes = GraphUtil.getNextNodes(node);
for (Node nextNode : nextNodes) {
if (nextNode instanceof OutputNode) {
throw new GraphException("Nodes after " + startClass.getName() + " cannot be connected to the output without going through " + endClass.getName() + ".");
} else if (endClass.isInstance(nextNode)) {
block.add(nextNode);
if (depth == 0) {
// Stop the recursion here.
} else {
getSpecialBlock(nextNode, depth - 1, block, startClass, endClass);
}
} else if (startClass.isInstance(nextNode)) {
// handle embedded forEach
block.add(nextNode);
getSpecialBlock(nextNode, depth + 1, block, startClass, endClass);
} else {
block.add(nextNode);
getSpecialBlock(nextNode, depth, block, startClass, endClass);
}
}
}
Aggregations