DBVIEW
|
00001 /* 00002 DbView - Graph Visualization 00003 Copyright (C) 2012 Denis BEURIVE 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 /** 00020 * @author Denis Beurive 00021 */ 00022 00023 package org.dbview.databaseExporters.dot; 00024 00025 import java.util.ArrayList; 00026 import java.util.Hashtable; 00027 import org.dbview.db.structure.Database; 00028 import org.dbview.db.structure.Table; 00029 import org.dbview.utils.dot.*; 00030 00031 00032 /** 00033 * This class implements the export to DOT, with a low level of details. 00034 * @see AbstractDatabaseExporter 00035 * @author Denis Beurive 00036 */ 00037 public class DotLight extends AbstractDatabaseExporter 00038 { 00039 /** 00040 * Create the exporter. 00041 * @param in_tables List of tables to export. 00042 * @param in_db Handle to the database. 00043 */ 00044 public DotLight(ArrayList<Table> in_tables, Database in_db) 00045 { 00046 super(in_tables, in_db); 00047 } 00048 00049 /** 00050 * This method exports the given tables, from the given database. 00051 * @param in_options Options. 00052 * Options may be: 00053 * <ul> 00054 * <li>"layout"</li> 00055 * </ul> 00056 * @return The method returns a string that represents the DOT representation. 00057 * @throws Exception 00058 */ 00059 public String export(Hashtable<String, Object> in_options) throws Exception 00060 { 00061 DiGraph digraph = new DiGraph(); 00062 if (null != in_options) 00063 { 00064 if (in_options.containsKey("layout")) 00065 digraph.setRankdir((String)in_options.get("layout")); 00066 } 00067 00068 // ------------------------------------------------------------------ 00069 // Configure the directed graph. 00070 // ------------------------------------------------------------------ 00071 00072 digraph.setNodesep(new Float(0.5)); 00073 digraph.setRankset(new Float(0.7)); 00074 digraph.setCompound(Boolean.TRUE); 00075 00076 // ------------------------------------------------------------------ 00077 // Add the table. 00078 // ------------------------------------------------------------------ 00079 00080 for (Table table : this._tables) 00081 { 00082 Node table_node = new Node(table.getName()); 00083 table_node.setShape("record"); 00084 table_node.setStyle("bold"); 00085 table_node.setLabel(table.getName()); 00086 digraph.addNode(table_node); 00087 } 00088 00089 // ------------------------------------------------------------------ 00090 // Add the joins between tables. 00091 // ------------------------------------------------------------------ 00092 00093 for (Table reference_table : this._tables) 00094 { 00095 for (Table target_table : this._db.getReferenceTables(reference_table)) 00096 { 00097 // WARNING: If we work on a sub list of the total list of tables (zoom level is activated), then some target's tables may not be printed! 00098 if (! this._tables.contains(target_table)) { continue; } 00099 00100 String edge_color = this._relationColor(this._db.getTableToTableRelationType(reference_table, target_table)); 00101 Edge join = new Edge(); 00102 00103 // Create the edge from the source table to the relation's node. 00104 join.setFrom(reference_table.getName()); 00105 join.setTo(target_table.getName()); 00106 join.setPenwidth("2"); 00107 join.setColor(edge_color); 00108 00109 digraph.addEdge(join); 00110 } 00111 } 00112 00113 return digraph.toString(); 00114 } 00115 }