📄 connectionstreepanel.java
字号:
defaultSchema.equalsIgnoreCase(object.getCatalogName()); int type = object.getType(); // populate the column nodes for table type nodes if ((type == BrowserConstants.TABLE_NODE || type == BrowserConstants.SYSTEM_TABLE_NODE) && !parent.isTypeParent()) { String[] columns = controller.getColumnNames( dc, object.getName(), object.getSchemaName()); for (int i = 0; i < columns.length; i++) { DatabaseObject column = new DatabaseObject( BrowserConstants.COLUMN_NODE, columns[i]); column.setCatalogName(object.getCatalogName()); column.setSchemaName(object.getSchemaName()); column.setParentName(object.getName()); column.setDefaultCatalog(isDefault); node = new BrowserTreeNode(column, false); parent.add(node); } } // populate the system functions types else if (type == BrowserConstants.SYSTEM_FUNCTION_NODE || type == BrowserConstants.SYSTEM_STRING_FUNCTIONS_NODE || type == BrowserConstants.SYSTEM_NUMERIC_FUNCTIONS_NODE || type == BrowserConstants.SYSTEM_DATE_TIME_FUNCTIONS_NODE) { String na = "Not Applicable"; // if its the parent node add the types if (parent.isTypeParent()) { String systemFunction = "System Function"; DatabaseObject table = new DatabaseObject( BrowserConstants.SYSTEM_STRING_FUNCTIONS_NODE, "String Functions"); table.setSchemaName(na); table.setMetaDataKey(systemFunction); table.setSystemObject(true); node = new BrowserTreeNode(table, true, false); parent.add(node); table = new DatabaseObject( BrowserConstants.SYSTEM_NUMERIC_FUNCTIONS_NODE, "Numeric Functions"); table.setSchemaName(na); table.setMetaDataKey(systemFunction); table.setSystemObject(true); node = new BrowserTreeNode(table, true, false); parent.add(node); table = new DatabaseObject( BrowserConstants.SYSTEM_DATE_TIME_FUNCTIONS_NODE, "Date/Time Functions"); table.setSchemaName(na); table.setMetaDataKey(systemFunction); table.setSystemObject(true); node = new BrowserTreeNode(table, true, false); parent.add(node); } else { // add the individual functions String[] functions = null; switch (type) { case BrowserConstants.SYSTEM_STRING_FUNCTIONS_NODE: functions = controller.getSystemFunctions(dc, MetaDataValues.STRING_FUNCTIONS); break; case BrowserConstants.SYSTEM_NUMERIC_FUNCTIONS_NODE: functions = controller.getSystemFunctions(dc, MetaDataValues.NUMERIC_FUNCTIONS); break; case BrowserConstants.SYSTEM_DATE_TIME_FUNCTIONS_NODE: functions = controller.getSystemFunctions(dc, MetaDataValues.TIME_DATE_FUNCTIONS); break; } if (functions != null && functions.length > 0) { for (int i = 0; i < functions.length; i++) { DatabaseObject table = new DatabaseObject(type, functions[i]); table.setSchemaName(na); table.setMetaDataKey(object.getMetaDataKey()); node = new BrowserTreeNode(table, false); parent.add(node); } } } } else { String[] tables = controller.getTables(dc, object.getCatalogName(), object.getSchemaName(), object.getName()); // if we have nothing check if its a proc or function node if (tables == null || tables.length == 0) { tables = controller.checkProcedureTerm(dc, object); } for (int i = 0; i < tables.length; i++) { DatabaseObject table = new DatabaseObject(type, tables[i]); table.setCatalogName(object.getCatalogName()); table.setSchemaName(object.getSchemaName()); table.setMetaDataKey(object.getMetaDataKey()); table.setDefaultCatalog(isDefault); if (type == BrowserConstants.TABLE_NODE || type == BrowserConstants.SYSTEM_TABLE_NODE) { node = new BrowserTreeNode(table, true, false); } else { node = new BrowserTreeNode(table, false); } parent.add(node); } } } private void populateSchemaObjectBranches(BrowserTreeNode parent) { ConnectionObject hostObject = getConnectionObject(parent); DatabaseConnection dc = hostObject.getDatabaseConnection(); boolean hasKeys = true; ArrayList keyNames = null; if (!hostObject.hasMetaKeys()) { hasKeys = false; keyNames = new ArrayList(BrowserConstants.META_TYPES.length); } BrowserTreeNode node = null; DatabaseObject schema = parent.getDatabaseUserObject(); for (int i = 0; i < BrowserConstants.META_TYPES.length; i++) { DatabaseObject object = new DatabaseObject(i, BrowserConstants.META_TYPES[i]); object.setCatalogName(schema.getCatalogName()); object.setSchemaName(schema.getName()); object.setMetaDataKey(BrowserConstants.META_TYPES[i]); node = new BrowserTreeNode(object, true); parent.add(node); if (!hasKeys) { keyNames.add(BrowserConstants.META_TYPES[i]); } } // add other non-default objects available boolean isDerivative = false; DatabaseObject object = null; String[] tableTypes = controller.getTableTypes(dc); for (int i = 0; i < tableTypes.length; i++) { if (!MiscUtils.containsValue( BrowserConstants.META_TYPES, tableTypes[i])) { if (!hasKeys) { keyNames.add(tableTypes[i]); } // check to see if the type is a derivative of a default // ie. SYSTEM INDEX is a derivative of INDEX so we use // the same icon and display format for (int j = 0; j < BrowserConstants.META_TYPES.length; j++) { if (MiscUtils.containsWholeWord(tableTypes[i], BrowserConstants.META_TYPES[j])) { isDerivative = true; object = new DatabaseObject(j, tableTypes[i]); break; } } if (!isDerivative) { object = new DatabaseObject( BrowserConstants.OTHER_NODE, tableTypes[i]); } isDerivative = false; object.setCatalogName(schema.getCatalogName()); object.setSchemaName(schema.getName()); object.setMetaDataKey(tableTypes[i]); node = new BrowserTreeNode(object, true); parent.add(node); } } if (!hasKeys) { hostObject.setMetaKeyNames( (String[])keyNames.toArray(new String[keyNames.size()])); } } private void populateSchemaBranches(BrowserTreeNode parent) { DatabaseConnection dc = getDatabaseConnection(parent); List schemas = controller.getCatalogSchemas(dc); String defaultSchema = controller.getSchemaName(dc); // no schemas = try by catalogue if (schemas == null || schemas.isEmpty()) { populateSchemaObjectBranches(parent); } // no schemas or catalogues available - bail if (schemas == null || schemas.isEmpty()) { return; } BrowserTreeNode node = null; DatabaseObject catalog = parent.getDatabaseUserObject(); for (int i = 0, k = schemas.size(); i < k; i++) { String value = (String)schemas.get(i); DatabaseObject schema = new DatabaseObject(BrowserConstants.SCHEMA_NODE, value); schema.setCatalogName(catalog.getName()); schema.setDefaultCatalog(defaultSchema.equalsIgnoreCase(value)); node = new BrowserTreeNode(schema, true); parent.add(node); populateSchemaObjectBranches(node); node.setExpanded(true); } } /** * Removes the selected node.<br> * * This will attempt to propagate the call to the connected * database using a DROP statement. */ public void removeTreeNode() { tree.removeTreeSelectionListener(this); int row = tree.getSelectionRows()[0]; try { TreePath selection = tree.getSelectionPath(); if (selection != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)selection.getLastPathComponent(); DatabaseObject object = (DatabaseObject)node.getUserObject(); String name = object.getName(); int yesNo = GUIUtilities.displayConfirmDialog( "Are you sure you want to drop " + object.getName() + "?"); if (yesNo == JOptionPane.NO_OPTION) { return; } else { try { DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent(); int result = controller.dropObject( getSelectedMetaObject().getDatabaseConnection(), object); if (result >= 0 && parent != null) { tree.removeNode(node); row = (row == 0 ? 1 : row - 1); return; } } catch (SQLException e) { StringBuffer sb = new StringBuffer(); sb.append("An error occurred removing the selected object."). append("\n\nThe system returned:\n"). append(MiscUtils.formatSQLError(e)); GUIUtilities.displayExceptionErrorDialog(sb.toString(), e); } } } } finally { tree.addTreeSelectionListener(this); tree.setSelectionRow(row); } } /** * Returns the name of a new connection to be added where * the name of the connection may already exist. * * @param name - the name of the connection */ private String buildConnectionName(String name) { int count = 0; for (int i = 0, n = connections.size(); i < n; i++) { DatabaseConnection _dc = connections.get(i); if (_dc.getName().startsWith(name)) { count++; } } if (count > 0) { count++; name += " " + count; } return name; } public boolean isRootSelectOnDisconnect() { return rootSelectOnDisconnect; } public void setRootSelectOnDisconnect(boolean rootSelectOnDisconnect) { this.rootSelectOnDisconnect = rootSelectOnDisconnect; } public String toString() { return TITLE; } public static final String MENU_ITEM_KEY = "viewConnections"; public static final String PROPERTY_KEY = "system.display.connections"; // ---------------------------------------- // DockedTabView Implementation // ---------------------------------------- /** * Returns the display title for this view. * * @return the title displayed for this view */ public String getTitle() { return TITLE; } /** * Returns the name defining the property name for this docked tab view. * * @return the key */ public String getPropertyKey() { return PROPERTY_KEY; } /** * Returns the name defining the menu cache property * for this docked tab view. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -