Skip to content

Commit

Permalink
Added comment support.
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurrier committed Apr 28, 2006
1 parent 915b96b commit c9cce71
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
16 changes: 5 additions & 11 deletions src/net/sourceforge/schemaspy/view/HtmlColumnsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,20 @@ public int compare(Object object1, Object object2) {
}
}

boolean hasComments = false;
iter = columns.iterator();
while (!hasComments && iter.hasNext()) {
TableColumn column = (TableColumn)iter.next();
hasComments |= column.getComments() != null;
}

writeHeader(database, columns.size(), showRelationshipsGraph, showOrphansGraph, hasComments, html);
writeHeader(database, columns.size(), showRelationshipsGraph, showOrphansGraph, html);

HtmlTablePage formatter = HtmlTablePage.getInstance();

iter = columns.iterator();
while (iter.hasNext()) {
TableColumn column = (TableColumn)iter.next();
formatter.writeColumn(column, column.getTable().getName(), primaryColumns, indexedColumns, false, hasComments, html);
formatter.writeColumn(column, column.getTable().getName(), primaryColumns, indexedColumns, false, false, html);
}

writeFooter(html);
}

private void writeHeader(Database db, int numberOfColumns, boolean hasRelationships, boolean hasOrphans, boolean hasComments, LineWriter html) throws IOException {
private void writeHeader(Database db, int numberOfColumns, boolean hasRelationships, boolean hasOrphans, LineWriter html) throws IOException {
writeHeader(db, null, "Columns", hasRelationships, hasOrphans, html);

html.writeln("<table width='100%' border='0'>");
Expand All @@ -79,6 +72,7 @@ private void writeHeader(Database db, int numberOfColumns, boolean hasRelationsh
html.writeln("<p/>");
StyleSheet css = StyleSheet.getInstance();
html.writeln("<form name='options' action=''>");
html.writeln(" <input type=checkbox onclick=\"toggle(" + css.getOffsetOf(".comment") + ");\" id=showComments>Comments");
html.writeln(" <input type=checkbox onclick=\"toggle(" + css.getOffsetOf(".tableKey") + ");\" id=showRelatedCols>Related columns");
html.writeln(" <input type=checkbox onclick=\"toggle(" + css.getOffsetOf(".constraint") + ");\" id=showConstNames>Constraint names");
html.writeln(" <input type=checkbox checked onclick=\"toggle(" + css.getOffsetOf(".legend") + ");\" id=showLegend>Legend");
Expand All @@ -97,7 +91,7 @@ private void writeHeader(Database db, int numberOfColumns, boolean hasRelationsh
html.write(" columns:</b>");
Collection tables = db.getTables();
boolean hasTableIds = tables.size() > 0 && ((Table)tables.iterator().next()).getId() != null;
HtmlTablePage.getInstance().writeMainTableHeader(hasTableIds, true, hasComments, html);
HtmlTablePage.getInstance().writeMainTableHeader(hasTableIds, true, html);
html.writeln("<tbody valign='top'>");
}

Expand Down
14 changes: 8 additions & 6 deletions src/net/sourceforge/schemaspy/view/HtmlMainIndexPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ public int compare(Object object1, Object object2) {
});
byName.addAll(tables);

Table tempTable = tables.isEmpty() ? null : (Table)tables.iterator().next();
boolean showIds = tempTable != null && tempTable.getId() != null;

boolean showIds = false;
int numViews = 0;

for (Iterator iter = byName.iterator(); iter.hasNext(); ) {
Table table = (Table)iter.next();
if (table.isView())
++numViews;
showIds |= table.getId() != null;
}

writeHeader(database, byName.size() - numViews, numViews, showIds, showRelationshipsGraph, showOrphansGraph, html);

int numRows = 0;
for (Iterator iter = byName.iterator(); iter.hasNext(); ) {
Table table = (Table)iter.next();
numRows += writeLineItem(table, html);
numRows += writeLineItem(table, showIds, html);
}

writeFooter(numRows, html);
Expand Down Expand Up @@ -96,6 +96,7 @@ private void writeHeader(Database db, int numberOfTables, int numberOfViews, boo
html.writeln("<colgroup>");
html.writeln("<colgroup>");
html.writeln("<colgroup>");
html.writeln("<colgroup>");
if (showIds)
html.writeln("<colgroup>");
html.writeln("<thead align='left'>");
Expand All @@ -106,20 +107,21 @@ private void writeHeader(Database db, int numberOfTables, int numberOfViews, boo
html.writeln(" <th align='right' valign='bottom'>Children</th>");
html.writeln(" <th align='right' valign='bottom'>Parents</th>");
html.writeln(" <th align='right' valign='bottom'>Rows</th>");
html.writeln(" <th align='left' valign='bottom'>Comments</th>");
html.writeln("</tr>");
html.writeln("</thead>");
html.writeln("<tbody>");
}

private int writeLineItem(Table table, LineWriter html) throws IOException {
private int writeLineItem(Table table, boolean showIds, LineWriter html) throws IOException {
html.writeln(" <tr>");
html.write(" <td class='detail'><a href='tables/");
html.write(table.getName());
html.write(".html'>");
html.write(table.getName());
html.writeln("</a></td>");

if (table.getId() != null) {
if (showIds) {
html.write(" <td class='detail' align='right'>");
html.write(String.valueOf(table.getId()));
html.writeln("</td>");
Expand Down
36 changes: 15 additions & 21 deletions src/net/sourceforge/schemaspy/view/HtmlTablePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private void writeHeader(Table table, WriteStats stats, File graphDir, LineWrite
html.write("syncDegrees();\">");
html.writeln("Implied relationships");
}
html.writeln(" <input type=checkbox onclick=\"toggle(" + css.getOffsetOf(".comment") + ");\" id=showComments>Comments");
html.writeln(" <input type=checkbox onclick=\"toggle(" + css.getOffsetOf(".tableKey") + ");\" id=showRelatedCols>Related columns");
html.writeln(" <input type=checkbox onclick=\"toggle(" + css.getOffsetOf(".constraint") + ");\" id=showConstNames>Constraint names");
html.writeln(" <input type=checkbox checked onclick=\"toggle(" + css.getOffsetOf(".legend") + ");\" id=showLegend>Legend");
Expand All @@ -88,13 +89,8 @@ private void writeHeader(Table table, WriteStats stats, File graphDir, LineWrite

public boolean writeMainTable(Table table, LineWriter out) throws IOException {
boolean onCascadeDelete = false;
boolean hasComments = false;
for (Iterator iter = table.getColumns().iterator(); !hasComments && iter.hasNext(); ) {
TableColumn column = (TableColumn)iter.next();
hasComments |= column.getComments() != null;
}

writeMainTableHeader(table.getId() != null, false, hasComments, out);
writeMainTableHeader(table.getId() != null, false, out);

out.writeln("<tbody valign='top'>");
Set primaries = new HashSet(table.getPrimaryColumns());
Expand All @@ -105,16 +101,17 @@ public boolean writeMainTable(Table table, LineWriter out) throws IOException {
indexedColumns.addAll(index.getColumns());
}

boolean showIds = table.getId() != null;
for (Iterator iter = table.getColumns().iterator(); iter.hasNext(); ) {
TableColumn column = (TableColumn)iter.next();
onCascadeDelete = writeColumn(column, null, primaries, indexedColumns, onCascadeDelete, hasComments, out);
onCascadeDelete = writeColumn(column, null, primaries, indexedColumns, onCascadeDelete, showIds, out);
}
out.writeln("</table>");

return onCascadeDelete;
}

public void writeMainTableHeader(boolean hasTableIds, boolean hasTableName, boolean hasComments, LineWriter out) throws IOException {
public void writeMainTableHeader(boolean hasTableIds, boolean hasTableName, LineWriter out) throws IOException {
out.writeln("<table class='dataTable' border='1' rules='groups'>");
int span = 6;
if (hasTableIds)
Expand All @@ -124,6 +121,7 @@ public void writeMainTableHeader(boolean hasTableIds, boolean hasTableName, bool
out.writeln("<colgroup span='" + span + "'>");
out.writeln("<colgroup>");
out.writeln("<colgroup>");
out.writeln("<colgroup class='comment'>");

out.writeln("<thead align='left'>");
out.writeln("<tr>");
Expand All @@ -139,16 +137,14 @@ public void writeMainTableHeader(boolean hasTableIds, boolean hasTableName, bool
out.writeln(" <th title='Default value'>Default</th>");
out.writeln(" <th title='Columns in tables that reference this column'>Children</th>");
out.writeln(" <th title='Columns in tables that are referenced by this column'>Parents</th>");
if (hasComments)
out.writeln(" <th title='Comments'>Comments</th>");
out.writeln(" <th title='Comments' class='comment'>Comments</th>");
out.writeln("</tr>");
out.writeln("</thead>");
}

public boolean writeColumn(TableColumn column, String tableName, Set primaries, Set indexedColumns, boolean onCascadeDelete, boolean includeComments, LineWriter out) throws IOException {
public boolean writeColumn(TableColumn column, String tableName, Set primaries, Set indexedColumns, boolean onCascadeDelete, boolean showIds, LineWriter out) throws IOException {
out.writeln("<tr>");
Table table = column.getTable();
if (table.getId() != null) {
if (showIds) {
out.write(" <td class='detail' align='right'>");
out.write(String.valueOf(column.getId()));
out.writeln("</td>");
Expand Down Expand Up @@ -212,15 +208,13 @@ else if (indexedColumns.contains(column))
out.write(" <td>");
onCascadeDelete |= writeRelatives(column, true, path, out);
out.writeln(" </td>");
if (includeComments) {
out.write(" <td class='detail'>");
String comments = column.getComments();
if (comments != null) {
for (int i = 0; i < comments.length(); ++i)
out.write(HtmlEncoder.encode(comments.charAt(i)));
}
out.writeln(" </td>");
out.write(" <td class='comment'>");
String comments = column.getComments();
if (comments != null) {
for (int i = 0; i < comments.length(); ++i)
out.write(HtmlEncoder.encode(comments.charAt(i)));
}
out.writeln(" </td>");
out.writeln("</tr>");
return onCascadeDelete;
}
Expand Down
5 changes: 5 additions & 0 deletions src/schemaSpy.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ table {
text-align: right;
}

.comment {
display: none;
padding: 0px 4px;
}

.impliedNotOrphan {
}

Expand Down

0 comments on commit c9cce71

Please sign in to comment.