private GraphNode[] replaceAllSubGraphs() throws GraphException { final SubGraphData[] dataList = findSubGraphs("SubGraph"); final List<GraphNode> savedList = new ArrayList<>(); for (SubGraphData data : dataList) { final GraphNode sourceNode = graphNodeList.findGraphNode(data.nodeID); if (data.subGraph != null) { replaceSubGraph(sourceNode, data.subGraph); removeNode(sourceNode); savedList.add(sourceNode); } } return savedList.toArray(new GraphNode[savedList.size()]); }
public SubGraphHandler(final Graph graph, final GraphNodeList graphNodeList) throws GraphException { this.graph = graph; this.graphNodeList = graphNodeList; this.savedSubGraphList = replaceAllSubGraphs(); }
public boolean InitGraph() throws GraphException { if (graphNodeList.isGraphComplete()) { AssignAllParameters(); ProductSetUIHandler productSetHandler = new ProductSetUIHandler(graph, graphNodeList); SubGraphHandler subGraphHandler = new SubGraphHandler(graph, graphNodeList); try { recreateGraphContext(); graphNodeList.updateGraphNodes(graphContext); //todo recreateGraphContext(); } catch (Exception e) { e.printStackTrace(); throw new GraphException(e.getMessage()); } finally { subGraphHandler.restore(); productSetHandler.restore(); } return true; } return false; }
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()); } }