diff --git a/studio/src/main/java/acolyte/Studio.java b/studio/src/main/java/acolyte/Studio.java index 2f960184..2f6e4b51 100644 --- a/studio/src/main/java/acolyte/Studio.java +++ b/studio/src/main/java/acolyte/Studio.java @@ -501,12 +501,12 @@ public void actionPerformed(final ActionEvent e) { editCols.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_E); final JButton editColsBut = new JButton(editCols); - final DefaultTableColumnModel resCols = new DefaultTableColumnModel(); final Vector> resData = new Vector>(); - final NotEditableTableModel resModel = - new NotEditableTableModel(resData, new Vector()); - final JTable resTable = withColRenderers(new JTable(resModel, resCols)); - final TableCellRenderer headerRenderer = headerRenderer(resTable); + final Vector> resCols = + new Vector>(); + final NotEditableTableModel resModel = + new NotEditableTableModel(resData, resCols); + final JTable resTable = withColRenderers(new JTable(resModel)); final JLabel extractLabel1 = new JLabel("Fetch", SwingConstants.RIGHT); final JLabel extractLabel2 = new JLabel("result rows executing query and", SwingConstants.LEFT); @@ -545,32 +545,23 @@ public void actionPerformed(final ActionEvent e) { rs = stmt.executeQuery(sqlArea.getText()); final PropertyEditSession s = resModel.willChange(); - final Enumeration cols = - resCols.getColumns(); - - while (cols.hasMoreElements()) { - resCols.removeColumn(cols.nextElement()); - } // end of for + resCols.clear(); resData.clear(); if (rs.next()) { final TableData td = tableData(rs, f); for (final Map.Entry c : map.entrySet()) { - final TableColumn tc = new TableColumn(); - - tc.setHeaderValue(c); - tc.setHeaderRenderer(headerRenderer); - resCols.addColumn(tc); + resCols.add(new TableHeaderEntry(c)); } // end of for for (final ArrayList r : td.rows) { resData.add(new Vector(r)); } // end of for } // end of if - + resModel.fireTableStructureChanged(); resModel.fireTableDataChanged(); s.propertyDidChange(); @@ -1116,33 +1107,6 @@ public void keyReleased(KeyEvent e) { }; } // end of closeKeyStrokes - /** - * Header renderer for result table - */ - private static TableCellRenderer headerRenderer(final JTable t) { - final TableCellRenderer defaultRenderer = - t.getTableHeader().getDefaultRenderer(); - - return new TableCellRenderer() { - public Component getTableCellRendererComponent(final JTable table, - final Object value, - final boolean sel, - final boolean foc, - final int row, - final int column) { - - @SuppressWarnings("unchecked") - final Map.Entry headerVal = - (Map.Entry) value; - - return defaultRenderer. - getTableCellRendererComponent(table, headerVal.getKey(), - sel, foc, row, column); - - } - }; - } // end of headerRenderer - /** * Updates application configuration. */ @@ -1547,12 +1511,7 @@ public Void doInBackground() throws Exception { /** * Displays formatted rows. */ - private static void displayRows(final JFrame frm, - final TableColumnModel colModel, - final Vector> data, - final Charset charset, - final Formatting fmt, - final Callable end) { + private static void displayRows(final JFrame frm, final Vector> cols, final Vector> data, final Charset charset, final Formatting fmt, final Callable end) { final UnaryFunction> f = new UnaryFunction>() { @@ -1563,19 +1522,13 @@ public Callable apply(final Document doc) { final ArrayList cnames = new ArrayList(); final ArrayList ctypes = new ArrayList(); - final Enumeration n = colModel.getColumns(); - final int c = colModel.getColumnCount(); + final int c = cols.size(); ap.append(fmt.imports); ap.append("\r\n\r\nRowLists.rowList" + c + "("); int i = 0; - while (n.hasMoreElements()) { - @SuppressWarnings("unchecked") - final Map.Entry e = - (Map.Entry) n. - nextElement().getHeaderValue(); - + for (final Map.Entry e : cols) { final String name = e.getKey(); final ColumnType type = e.getValue(); @@ -1969,4 +1922,70 @@ public BigDecimal getBigDecimal(int p) { } public boolean isNull(int p) { return v.elementAt(p) == null; } } // end of class VectorRow + + /** + * Map entry as table column. + */ + private final class TableHeaderEntry + implements Map.Entry { + + private final Map.Entry wrappee; + + /** + * Value constructor + */ + TableHeaderEntry(final Map.Entry v) { + this.wrappee = v; + } // end of + + // --- + + /** + * {@inheritDoc} + */ + public boolean equals(final Object o) { + if (o == null || !(o instanceof TableHeaderEntry)) { + return false; + } // end of if + + final TableHeaderEntry other = (TableHeaderEntry) o; + + return this.wrappee.equals(other.wrappee); + } // end of equals + + /** + * {@inheritDoc} + */ + public int hashCode() { + return this.wrappee.hashCode(); + } // end of hashCode + + /** + * Returns name as string representation. + */ + public String toString() { + return this.wrappee.getKey(); + } // end of toString + + /** + * Throws exception. + */ + public ColumnType setValue(ColumnType v) { + throw new UnsupportedOperationException(); + } // end of setValue + + /** + * {@inheritDoc} + */ + public String getKey() { + return this.wrappee.getKey(); + } // end of getKey + + /** + * {@inheritDoc} + */ + public ColumnType getValue() { + return this.wrappee.getValue(); + } // end of getValue + } // end of class TableHeaderEntry } // end of class Studio