Search in sources :

Example 41 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class GraphCanvas method mousePressed.

private void mousePressed(MouseEvent event) {
    Point point = event.getPoint();
    // Get focus to handle key board events
    this.panel.requestFocusInWindow();
    // Get select item
    GraphPiece selected = NodeController.getGUI(this.graph).getGraphPieceAt(point);
    /*
         * Doing Nothing if pressed is on the selected node
         */
    if (this.multipleSelectedNodes != null) {
        maybeShowPopup(event);
        if (this.crtlPressed && this.multipleSelectedNodes.contains(selected)) {
            deselectNode((Node) selected);
            return;
        } else if (this.multipleSelectedNodes.contains(selected)) {
            this.mousePoint = point;
            this.panel.setCursor(SwingUtil.MOVE_CURSOR);
            return;
        } else if ((selected instanceof Node) && this.crtlPressed) {
            this.mousePoint = point;
            this.multipleSelectedNodes.add((Node) selected);
            this.panel.setCursor(SwingUtil.MOVE_CURSOR);
            selectNodes(this.multipleSelectedNodes);
            return;
        }
    }
    // control selection
    if ((selected instanceof Node) && this.crtlPressed) {
        this.multipleSelectedNodes = new ArrayList<Node>();
        if (this.selectedNode != null) {
            this.multipleSelectedNodes.add(this.selectedNode);
        }
        this.multipleSelectedNodes.add((Node) selected);
        this.panel.setCursor(SwingUtil.MOVE_CURSOR);
        selectNodes(this.multipleSelectedNodes);
        return;
    }
    deselectNode();
    deselectEdge();
    if (selected instanceof Node) {
        Node node = (Node) selected;
        selectNode(node);
        if (!NodeController.getGUI(node).isInConfig(point)) {
            this.draggedNode = node;
            NodeController.getGUI(node).setDraggedFlag(true);
            this.panel.setCursor(SwingUtil.MOVE_CURSOR);
        }
    } else if (selected instanceof Port) {
        Port port = (Port) selected;
        NodeController.getGUI(port).setSelectedFlag(true);
        switch(port.getKind()) {
            case DATA_IN:
            case CONTROL_IN:
                selectInputPort(port);
                break;
            case CONTROL_OUT:
            case DATA_OUT:
            case EPR:
                selectOutputPort(port);
                break;
        }
        this.draggedPort = port;
    } else if (selected instanceof Edge) {
        Edge edge = (Edge) selected;
        selectEdge(edge);
    } else {
        /*
             * If nothing is selected
             */
        this.mousePointForSelection = event.getPoint();
    }
    maybeShowPopup(event);
    this.mousePoint = point;
    this.panel.repaint();
    event.consume();
}
Also used : GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) Point(java.awt.Point) Edge(org.apache.airavata.workflow.model.graph.Edge)

Example 42 with Node

use of org.apache.airavata.workflow.model.graph.Node 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();
        }
    }
}
Also used : PortAddable(org.apache.airavata.workflow.model.graph.dynamic.PortAddable) GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) Point(java.awt.Point) Point(java.awt.Point)

Example 43 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class GraphGUI method getGraphPieceAt.

/**
 * Returns the visible object at the specified location. The object is either a Node, a Port, or an Edge.
 *
 * @param point
 *            The location
 * @return The visible object a the specified location
 */
protected GraphPiece getGraphPieceAt(Point point) {
    GraphPiece piece = null;
    // Starts from edge because it is drawn first, which means it's at the
    // bottom.
    double minEdgeDist = Double.MAX_VALUE;
    Edge closestEdge = null;
    for (Edge edge : this.graph.getEdges()) {
        double dist = NodeController.getGUI(edge).getMiddlePosition().distance(point);
        if (dist < minEdgeDist) {
            closestEdge = edge;
            minEdgeDist = dist;
        }
    }
    if (minEdgeDist < 20) {
        piece = closestEdge;
    }
    // Then, each node and ports of it.
    for (Node node : this.graph.getNodes()) {
        // Check the node first
        if (NodeController.getGUI(node).isIn(point)) {
            piece = node;
        }
        // Find the closest port of this node.
        double minPortDist = Double.MAX_VALUE;
        Port closestPort = null;
        for (Port port : node.getAllPorts()) {
            double dist = NodeController.getGUI(port).getPosition().distance(point);
            if (dist < minPortDist) {
                closestPort = port;
                minPortDist = dist;
            }
        }
        if (minPortDist <= PortGUI.DATA_PORT_SIZE) {
            piece = closestPort;
        }
    // Don't break from this loop because the later ones are drawn at
    // the top of other nodes.
    }
    return piece;
}
Also used : GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) Node(org.apache.airavata.workflow.model.graph.Node) Port(org.apache.airavata.workflow.model.graph.Port) Edge(org.apache.airavata.workflow.model.graph.Edge)

Example 44 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class MonitorEventHandler method finishPredecessorNodes.

/**
 * Make preceding nodes done. This helps the monitoring GUI when a user subscribes from the middle of the workflow
 * execution.
 *
 * @param node
 */
private void finishPredecessorNodes(Node node) {
    for (Port inputPort : node.getInputPorts()) {
        for (Edge edge : inputPort.getEdges()) {
            Port fromPort = edge.getFromPort();
            if (!(fromPort instanceof EPRPort)) {
                Node fromNode = fromPort.getNode();
                finishNode(fromNode);
                finishPredecessorNodes(fromNode);
            }
        }
    }
    Port controlInPort = node.getControlInPort();
    if (controlInPort != null) {
        for (Node fromNode : controlInPort.getFromNodes()) {
            finishNode(fromNode);
            finishPredecessorNodes(fromNode);
        }
    }
}
Also used : EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) Port(org.apache.airavata.workflow.model.graph.Port) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) Node(org.apache.airavata.workflow.model.graph.Node) OutputNode(org.apache.airavata.workflow.model.graph.system.OutputNode) Edge(org.apache.airavata.workflow.model.graph.Edge)

Example 45 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class DifferedInputHandler method handleDifferredInputsofDependentNodes.

public static void handleDifferredInputsofDependentNodes(Node node, final XBayaGUI xbayaGUI) {
    List<DataPort> inputPorts = node.getInputPorts();
    for (DataPort dataPort : inputPorts) {
        Node fromNode = dataPort.getFromNode();
        if (isDifferedInputNode(fromNode)) {
            final DifferedInputNode differedInputNode = (DifferedInputNode) fromNode;
            if (!differedInputNode.isConfigured()) {
                // not configured differed node this is what we are looking for
                // set the flag and ensure all the rest is finished
                Runnable task = new Runnable() {

                    @Override
                    public void run() {
                        ((DifferedInputNodeGUI) NodeController.getGUI(differedInputNode)).showConfigurationDialog(xbayaGUI);
                    }
                };
                new Thread(task).start();
            }
        }
    }
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) DifferedInputNode(org.apache.airavata.workflow.model.graph.system.DifferedInputNode) Node(org.apache.airavata.workflow.model.graph.Node) DifferedInputNode(org.apache.airavata.workflow.model.graph.system.DifferedInputNode)

Aggregations

Node (org.apache.airavata.workflow.model.graph.Node)74 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)46 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)40 DataPort (org.apache.airavata.workflow.model.graph.DataPort)31 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)24 Port (org.apache.airavata.workflow.model.graph.Port)20 OutputNode (org.apache.airavata.workflow.model.graph.system.OutputNode)20 StreamSourceNode (org.apache.airavata.workflow.model.graph.system.StreamSourceNode)18 EndForEachNode (org.apache.airavata.workflow.model.graph.system.EndForEachNode)16 ForEachNode (org.apache.airavata.workflow.model.graph.system.ForEachNode)16 MemoNode (org.apache.airavata.workflow.model.graph.system.MemoNode)15 NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)14 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)14 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)13 ConstantNode (org.apache.airavata.workflow.model.graph.system.ConstantNode)12 EndifNode (org.apache.airavata.workflow.model.graph.system.EndifNode)12 IfNode (org.apache.airavata.workflow.model.graph.system.IfNode)12 GraphException (org.apache.airavata.workflow.model.graph.GraphException)11 LinkedList (java.util.LinkedList)9 ArrayList (java.util.ArrayList)8