public void restore() { for (GraphNode savedNode : savedSubGraphList) { final GraphNode[] nodesToRemove = subGraphNodesToRemoveMap.get(savedNode); for (GraphNode n : nodesToRemove) { final GraphNode[] connectedNodes = graphNodeList.findConnectedNodes(n); for (GraphNode node : connectedNodes) { node.connectOperatorSource(savedNode.getID()); final String name = node.getSourceName(n.getID()); node.setSourceName(name, savedNode.getNode().getId()); } removeNode(n); } graphNodeList.add(savedNode); graph.addNode(savedNode.getNode()); } }
public void remove(final GraphNode node) { // remove as a source from all nodes for (GraphNode n : nodeList) { n.disconnectOperatorSources(node.getID()); } nodeList.remove(node); }
private void addGraphTabs(final String title, final boolean addUI) { if (graphExecutorList.isEmpty()) { return; } tabbedPane.setSelectedIndex(0); while (tabbedPane.getTabCount() > 1) { tabbedPane.remove(tabbedPane.getTabCount() - 1); } final GraphExecuter graphEx = graphExecutorList.get(0); for (GraphNode n : graphEx.GetGraphNodes()) { if (n.GetOperatorUI() == null) continue; if (n.getNode().getOperatorName().equals("Read") || (replaceWritersWithUniqueTargetProduct && n.getNode().getOperatorName().equals("Write")) || n.getNode().getOperatorName().equals("ProductSet-Reader")) { n.setOperatorUI(null); continue; } if (addUI) { String tabTitle = title; if (tabTitle.isEmpty()) tabTitle = n.getOperatorName(); tabbedPane.addTab(tabTitle, null, n.GetOperatorUI().CreateOpTab(n.getOperatorName(), n.getParameterMap(), appContext), n.getID() + " Operator"); } } }
public void assignParameters(final XppDom presentationXML) throws GraphException { for (GraphNode n : nodeList) { if (n.GetOperatorUI() != null) { n.AssignParameters(presentationXML); } } }
void AssignParameters(final XppDom presentationXML) throws GraphException { updateParameters(); AssignDisplayParameters(presentationXML); }
n.drawNode(g, selColor); else n.drawNode(g, opColor); final NodeSource[] nSources = n.getNode().getSources(); for (NodeSource nSource : nSources) { final GraphNode srcNode = graphEx.getGraphNodeList().findGraphNode(nSource.getSourceNodeId()); if (srcNode != null) n.drawConnectionLine(g, srcNode); selectedNode.drawHeadHotspot(g, Color.red); selectedNode.drawTailHotspot(g, Color.red); final Point p1 = connectSourceTargetNode.getPos(); final Point p2 = connectingSourcePos; if (p1 != null && p2 != null) { g.setColor(Color.red); g.drawLine(p1.x, p1.y + connectSourceTargetNode.getHalfNodeHeight(), p2.x, p2.y); final Point p1 = connectSourceTargetNode.getPos(); final Point p2 = connectingSourcePos; if (p1 != null && p2 != null) { g.setColor(Color.red); g.drawLine(p1.x + connectSourceTargetNode.getWidth(), p1.y + connectSourceTargetNode.getHalfNodeHeight(), p2.x, p2.y);
@Test public void testSourceConnection() { final Node sourceNode = new Node("sourceID", "testSourceNodeOp"); final XppDomElement parameters = new XppDomElement("parameters"); sourceNode.setConfiguration(parameters); GraphNode sourceGraphNode = new GraphNode(sourceNode); // test connect graphNode.connectOperatorSource(sourceGraphNode.getID()); NodeSource ns = node.getSource(0); assertNotNull(ns); assertEquals(ns.getSourceNodeId(), sourceNode.getId()); // test disconnect graphNode.disconnectOperatorSources(sourceGraphNode.getID()); NodeSource[] nsList = node.getSources(); assertEquals(nsList.length, 0); } }
static GraphNode createNewGraphNode(final Graph graph, final GraphNodeList graphNodeList, final String opName, final String id) { final Node newNode = new Node(id, opName); final XppDomElement parameters = new XppDomElement("parameters"); newNode.setConfiguration(parameters); graph.addNode(newNode); final GraphNode newGraphNode = new GraphNode(newNode); graphNodeList.add(newGraphNode); newGraphNode.setOperatorUI(OperatorUIRegistry.CreateOperatorUI(newGraphNode.getOperatorName())); return newGraphNode; }
public GraphNode findGraphNode(String id) { for (GraphNode n : nodeList) { if (n.getID().equals(id)) { return n; } } return null; }
public void setGraph(final Graph graphFromFile, final boolean addUI) throws GraphException { if (graphFromFile != null) { graph = graphFromFile; graphNodeList.clear(); final XppDom presentationXML = graph.getApplicationData("Presentation"); if (presentationXML != null) { // get graph description final XppDom descXML = presentationXML.getChild("Description"); if (descXML != null && descXML.getValue() != null) { graphDescription = descXML.getValue(); } } final Node[] nodes = graph.getNodes(); for (Node n : nodes) { final GraphNode newGraphNode = new GraphNode(n); if (presentationXML != null) newGraphNode.setDisplayParameters(presentationXML); graphNodeList.add(newGraphNode); if (addUI) { OperatorUI ui = OperatorUIRegistry.CreateOperatorUI(newGraphNode.getOperatorName()); if (ui == null) { throw new GraphException("Unable to load " + newGraphNode.getOperatorName()); } newGraphNode.setOperatorUI(ui); } notifyGraphEvent(new GraphEvent(events.ADD_EVENT, newGraphNode)); } } }
@Test public void testNode() { assertEquals(node, graphNode.getNode()); assertEquals(node.getId(), graphNode.getID()); assertEquals(node.getOperatorName(), graphNode.getOperatorName()); }
public void autoConnectGraph() { final List<GraphNode> nodeList = Arrays.asList(GetGraphNodes()); Collections.sort(nodeList, new GraphNodePosComparator()); final GraphNode[] nodes = nodeList.toArray(new GraphNode[nodeList.size()]); for (int i = 0; i < nodes.length - 1; ++i) { if (!nodes[i].HasSources()) { nodes[i].connectOperatorSource(nodes[i + 1].getID()); } } notifyConnection(); }
final int hotspotSize = GraphNode.getHotSpotSize(); final Point headPoint = new Point(n.getPos().x, n.getPos().y + selectedNode.getHotSpotOffset()); final Point tailPoint = new Point(n.getPos().x + n.getWidth() - hotspotSize, n.getPos().y + selectedNode.getHotSpotOffset());
/** * Handle mouse dragged event * * @param e the mouse event */ public void mouseDragged(MouseEvent e) { if (selectedNode != null && !connectingSourceFromHead && !connectingSourceFromTail) { final Point p = new Point(e.getX() - (lastMousePos.x - selectedNode.getPos().x), e.getY() - (lastMousePos.y - selectedNode.getPos().y)); selectedNode.setPos(p); lastMousePos = e.getPoint(); repaint(); } if (connectingSourceFromHead || connectingSourceFromTail) { connectingSourcePos = e.getPoint(); repaint(); } }
/** * Handle mouse released event * * @param e the mouse event */ public void mouseReleased(MouseEvent e) { checkPopup(e); if (connectingSourceFromHead) { final GraphNode n = findNode(e.getPoint()); if (n != null && selectedNode != n) { connectSourceTargetNode.connectOperatorSource(n.getID()); } } else if (connectingSourceFromTail) { final GraphNode n = findNode(e.getPoint()); if (n != null && selectedNode != n) { n.connectOperatorSource(connectSourceTargetNode.getID()); } } connectingSourceFromHead = false; connectingSourceFromTail = false; connectSourceTargetNode = null; if (graphEx.getGraphNodeList().isGraphComplete()) { graphEx.notifyConnection(); } repaint(); }
private void replaceProductSetWithReaders(final GraphNode sourceNode, final String id, final String value) { final GraphNode newReaderNode = GraphExecuter.createNewGraphNode(graph, graphNodeList, OperatorSpi.getOperatorAlias(ReadOp.class), id); newReaderNode.setOperatorUI(null); final DomElement config = newReaderNode.getNode().getConfiguration(); final DomElement fileParam = new XppDomElement("file"); fileParam.setValue(value); config.addChild(fileParam); final String format = CommonReaders.findCommonProductFormat(new File(value)); if(format != null) { final DomElement formatParam = new XppDomElement("formatName"); formatParam.setValue(format); config.addChild(formatParam); } graphNodeList.switchConnections(sourceNode, newReaderNode.getID()); }
private JComponent CreateOperatorTab(final GraphNode node) { return node.GetOperatorUI().CreateOpTab(node.getOperatorName(), node.getParameterMap(), appContext); }
void updateGraphNodes(final GraphContext graphContext) throws GraphException { if (graphContext != null) { for (GraphNode n : nodeList) { final NodeContext context = graphContext.getNodeContext(n.getNode()); if(context.getOperator() != null) { n.setSourceProducts(context.getSourceProducts()); } n.updateParameters(); } } }
public void restore() { for (GraphNode multiSrcNode : savedProductSetList) { final List<GraphNode> nodesToRemove = new ArrayList<>(); for (GraphNode n : graphNodeList.getGraphNodes()) { final String id = n.getID(); if (id.startsWith("inserted--" + multiSrcNode.getID()) && id.contains(multiSrcNode.getID())) { graphNodeList.switchConnections(n, multiSrcNode.getID()); nodesToRemove.add(n); } } for (GraphNode r : nodesToRemove) { removeNode(r); } graphNodeList.add(multiSrcNode); graph.addNode(multiSrcNode.getNode()); } }