import static net.argius.stew.ui.window.AnyActionKey.refresh;
import static net.argius.stew.ui.window.DatabaseInfoTree.ActionKey.*;
import static net.argius.stew.ui.window.WindowOutputProcessor.showInformationMessageDialog;
-
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.List;
-
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
-
import net.argius.stew.*;
/**
private static final Logger log = Logger.getLogger(DatabaseInfoTree.class);
private static final ResourceManager res = ResourceManager.getInstance(DatabaseInfoTree.class);
+ private static final String TABLE_TYPE_TABLE = "TABLE";
+ private static final String TABLE_TYPE_VIEW = "VIEW";
+ private static final String TABLE_TYPE_INDEX = "INDEX";
+ private static final String TABLE_TYPE_SEQUENCE = "SEQUENCE";
+ private static final List<String> DEFAULT_TABLE_TYPES = //
+ Arrays.asList(TABLE_TYPE_TABLE, TABLE_TYPE_VIEW, TABLE_TYPE_INDEX, TABLE_TYPE_SEQUENCE);
+
static volatile boolean showColumnNumber;
private Connector currentConnector;
@Override
public void anyActionPerformed(AnyActionEvent ev) {
log.atEnter("anyActionPerformed", ev);
- if (ev.isAnyOf(copySimpleName)) {
+ if (ev.isAnyOf(copy)) {
+ final String cmd = ev.getActionCommand();
+ Action action = getActionMap().get(cmd);
+ if (action != null) {
+ action.actionPerformed(new ActionEvent(this, 1001, cmd));
+ }
+ } else if (ev.isAnyOf(copySimpleName)) {
copySimpleName();
} else if (ev.isAnyOf(copyFullName)) {
copyFullName();
++c;
}
}
- if (c >= 2) {
- return String.format("%s;%s", phrase, join(",", nCopies(c, "")));
+ if (c >= 1) {
+ return String.format("%s;%s", phrase, join("", nCopies(c - 1, ",")));
}
return phrase;
}
}
});
} catch (SQLException ex) {
+ try {
+ if (dbmeta.getConnection().isClosed())
+ return;
+ } catch (SQLException exx) {
+ ex.setNextException(exx);
+ }
throw new RuntimeException(ex);
}
}
static List<TableTypeNode> getTableTypeNodes(DatabaseMetaData dbmeta,
String catalog,
String schema) throws SQLException {
- List<TableTypeNode> a = new ArrayList<TableTypeNode>();
- ResultSet rs = dbmeta.getTableTypes();
+ List<String> tableTypes = new ArrayList<String>(DEFAULT_TABLE_TYPES);
try {
- while (rs.next()) {
- TableTypeNode typeNode = new TableTypeNode(catalog, schema, rs.getString(1));
- if (typeNode.hasItems(dbmeta)) {
- a.add(typeNode);
+ ResultSet rs = dbmeta.getTableTypes();
+ try {
+ while (rs.next()) {
+ final String tableType = rs.getString(1);
+ if (!DEFAULT_TABLE_TYPES.contains(tableType)) {
+ tableTypes.add(tableType);
+ }
}
+ } finally {
+ rs.close();
}
- } finally {
- rs.close();
+ } catch (SQLException ex) {
+ log.warn("getTableTypes at getTableTypeNodes", ex);
}
- if (a.isEmpty()) {
- a.add(new TableTypeNode(catalog, schema, "TABLE"));
+ List<TableTypeNode> a = new ArrayList<TableTypeNode>();
+ for (final String tableType : tableTypes) {
+ TableTypeNode typeNode = new TableTypeNode(catalog, schema, tableType);
+ if (typeNode.hasItems(dbmeta)) {
+ a.add(typeNode);
+ }
}
return a;
}
while (rs.next()) {
final String table = rs.getString(3);
final String type = rs.getString(4);
- final boolean kindOfTable = type.matches("TABLE|VIEW|SYNONYM");
- a.add(new TableNode(catalog, schema, table, kindOfTable));
+ a.add(new TableNode(catalog, schema, table, type));
}
} finally {
rs.close();
private final String catalog;
private final String schema;
private final String name;
- private final boolean kindOfTable;
+ private final String tableType;
- TableNode(String catalog, String schema, String name, boolean kindOfTable) {
+ TableNode(String catalog, String schema, String name, String tableType) {
super(name);
this.catalog = catalog;
this.schema = schema;
this.name = name;
- this.kindOfTable = kindOfTable;
+ this.tableType = tableType;
}
@Override
@Override
public boolean isLeaf() {
+ if (TABLE_TYPE_SEQUENCE.equals(tableType)) {
+ return true;
+ }
return false;
}
return name;
}
- boolean isKindOfTable() {
- return kindOfTable;
- }
-
}
static final class ColumnNode extends InfoNode {