/** * Converts an Obvious tree to an infovis tree. * @param tree tree to convert * @return the converted infovis tree */ private infovis.Tree convertToIvtkTree(Tree<Node, Edge> tree) { if (tree.getEdges().size() != 0 && tree.getNodes().size() != 0) { Schema nodeSchema = tree.getNodes().iterator().next().getSchema() .getDataSchema(); Schema edgeSchema = tree.getEdges().iterator().next().getSchema() .getDataSchema(); Tree<Node, Edge> ivtkTree = new IvtkObviousTree(nodeSchema, edgeSchema); ObviousLib.fillTree(tree, ivtkTree); return (infovis.Tree) ivtkTree.getUnderlyingImpl(infovis.Tree.class); } else { throw new ObviousRuntimeException("Empty tree!"); } }
/** * Constructor. * @param inNetwork obvious network to wrap */ public WrapToPrefGraph(Network inNetwork) { super(new WrapToPrefTable(inNetwork.getNodeTable()), new WrapToPrefTable(inNetwork.getEdgeTable()), true); this.network = inNetwork; if (network.getNodes().size() != 0) { this.nodeSchema = network.getNodes().iterator().next().getSchema(); } if (network.getEdges().size() != 0) { this.edgeSchema = network.getEdges().iterator().next().getSchema(); } m_nodeTuples = new TupleManager(getNodeTable(), this, Table.class); m_edgeTuples = new TupleManager(getEdgeTable(), this, Table.class); }
/** * Adds an edge to the graph. * @param edge edge to add * @param source source node * @param target target node * @param edgeType unused parameter * @return true if added */ public boolean addEdge(Edge edge, Node source, Node target, obvious.data.Graph.EdgeType edgeType) { try { int edgeId = graph.addEdge(getNodeId(source), getNodeId(target)); for (int i = 0; i < edge.getSchema().getColumnCount(); i++) { if (edgeSchema.hasColumn(edge.getSchema().getColumnName(i))) { TypedFormat format = formatFactory.getFormat( edge.getSchema().getColumnType(i).getSimpleName()); StringBuffer v = format.format(edge.get(i), new StringBuffer(), new FieldPosition(0)); graph.getEdgeTable().setValueAt(v.toString(), edgeId, graph.getEdgeTable().indexOf(edge.getSchema().getColumnName(i))); } } edgeToId.put(edge, edgeId); fireNetworkEvent(edge.getRow(), edge.getRow(), 0, NetworkListener.INSERT_EDGE); return true; } catch (Exception e) { throw new ObviousRuntimeException(e); } }
edgeToId.put(edge, edgeId); for (int i = 0; i < edgeTable.getSchema().getColumnCount(); i++) { edgeTable.set(edgeId - 1, edge.getSchema().getColumnName(i), edge.get(i));