📄 comparedatatypespanel.java
字号:
} private void handleError(Throwable e) { GUIUtilities.displayExceptionErrorDialog( "Error retrieving data types.\nThe system returned:\n\n" + e.getMessage(), e); } public void firstConnectionChanged() { GUIUtils.startWorker(new Runnable() { public void run() { try { setInProcess(true); buildFirstConnectionValues(); } finally { setInProcess(false); } } }); } public void buildFirstConnectionValues() { // retrieve connection selection DatabaseConnection connection = (DatabaseConnection)connectionsCombo.getSelectedItem(); // reset meta data metaData.setDatabaseConnection(connection); // set the database name try { setDatabaseFieldText(1, metaData.getDatabaseProductName()); } catch (DataSourceException e) { setDatabaseFieldText(1, "Not Available"); } ResultSet rs = null; try { rs = metaData.getDataTypesResultSet(); } catch (DataSourceException e) { GUIUtilities.displayExceptionErrorDialog( "Error retrieving data types for selected " + "connection:.\n\nThe system returned:\n" + e.getExtendedMessage(), e); return; } masterTypes = buildDataTypeList(masterTypes, rs, true); // sort the rows in alpha Collections.sort(masterTypes, sorter); GUIUtils.invokeAndWait(new Runnable() { public void run() { masterListModel.fireContentsChanged(); if (masterTypes.size() > 0) { masterList.setSelectedIndex(0); masterList.ensureIndexIsVisible(0); } if (mappedToTypes != null && mappedToTypes.size() > 0) { generateMappedList(); } } }); } private void setDatabaseFieldText(final int connection, final String name) { GUIUtils.invokeAndWait(new Runnable() { public void run() { if (connection == 1) { databaseField_1.setText(name); } else if (connection == 2) { databaseField_2.setText(name); } } }); } public void secondConnectionChanged() { GUIUtils.startWorker(new Runnable() { public void run() { try { setInProcess(true); buildSecondConnectionValues(); } finally { setInProcess(false); } } }); } public void buildSecondConnectionValues() { // retrieve connection selection DatabaseConnection connection = (DatabaseConnection)connectionsCombo2.getSelectedItem(); // reset meta data metaData.setDatabaseConnection(connection); try { setDatabaseFieldText(2, metaData.getDatabaseProductName()); } catch (DataSourceException e) { setDatabaseFieldText(2, "Not Available"); } ResultSet rs = null; try { rs = metaData.getDataTypesResultSet(); } catch (DataSourceException e) { GUIUtilities.displayExceptionErrorDialog( "Error retrieving data types for the selected " + "connection.\n\nThe system returned:\n" + e.getExtendedMessage(), e); return; } mappedToTypes = buildDataTypeList(mappedToTypes, rs, false); GUIUtils.invokeAndWait(new Runnable() { public void run() { if (mappedToTypes != null && mappedToTypes.size() > 0) { generateMappedList(); } } }); } /** dummy reset value */ private Object[] dummyListData = new Object[0]; private void generateMappedList() { int index = masterList.getSelectedIndex(); if (index == -1) { return; } if (tableData == null) { tableData = new ArrayList<List>(); } else { tableData.clear(); } if (masterTypes.size() == 0) { return; } // retrieve the selected data type List row = masterTypes.get(index); String typeString = row.get(TYPE_COLUMN - 1).toString(); int typeValue = Integer.parseInt(typeString); // add as the first row to the table display tableData.add(row); selectedDataType = row; // clear the current list mappedList.setListData(dummyListData); if (mappedToTypes == null) { return; } // loop through the second conns types and pick out the mapped ones Vector<String> mappedListV = new Vector<String>(); for (int i = 0, n = mappedToTypes.size(); i < n; i++) { row = mappedToTypes.get(i); typeString = row.get(TYPE_COLUMN - 1).toString(); int _typeValue = Integer.parseInt(typeString); if (_typeValue == typeValue) { mappedListV.add(row.get(NAME_COLUMN - 1).toString()); // add the row to the table display tableData.add(row); } } mappedList.setListData(mappedListV); // apply the cell renderer if it hasn't been if (rendererApplied) { tableModel.fireTableDataChanged(); } else { tableModel.fireTableStructureChanged(); applyCellRenderer(); } } private void releaseResources(ResultSet rs) { try { if (rs != null) { rs.close(); } } catch (SQLException sqlExc) {} } /** * Called whenever the value of the selection changes. * * @param e the event that characterizes the change. */ public void valueChanged(ListSelectionEvent e) { generateMappedList(); } public void cleanup() { EventMediator.deregisterListener(EventMediator.CONNECTION_EVENT, this); if (metaData != null) { closeConnection(); } } public void closeConnection() { metaData.closeConnection(); } private void enableCombos(boolean enable) { connectionsCombo.setEnabled(enable); connectionsCombo2.setEnabled(enable); } // --------------------------------------------- // ConnectionListener implementation // --------------------------------------------- /** * Indicates a connection has been established. * * @param the encapsulating event */ public void connected(ConnectionEvent connectionEvent) { enableCombos(true); connectionsModel_1.addElement(connectionEvent.getSource()); connectionsModel_2.contentsChanged(); //connectionsModel_2.addElement(connectionEvent.getSource()); } /** * Indicates a connection has been closed. * * @param the encapsulating event */ public void disconnected(ConnectionEvent connectionEvent) { connectionsModel_1.removeElement(connectionEvent.getSource()); connectionsModel_2.contentsChanged(); //connectionsModel_2.removeElement(connectionEvent.getSource()); if (connectionsModel_1.getSize() == 0) { enableCombos(false); } // TODO: NEED TO CHECK OPEN CONN } /** * Returns the display name for this view. * * @return the display name */ public String getDisplayName() { return TITLE + (count++); } // -------------------------------------------- // TabView implementation // -------------------------------------------- /** * Indicates the panel is being removed from the pane */ public boolean tabViewClosing() { cleanup(); return true; } /** * Indicates the panel is being selected in the pane */ public boolean tabViewSelected() { return true; } /** * Indicates the panel is being de-selected in the pane */ public boolean tabViewDeselected() { return true; } // -------------------------------------------- class DataTypeListModel extends DefaultListModel { public DataTypeListModel() {} public void fireContentsChanged() { fireContentsChanged(this, -1, -1); } public Object getElementAt(int index) { if (masterTypes == null) { return null; } return masterTypes.get(index).get(NAME_COLUMN - 1); } public int getSize() { if (masterTypes == null) { return 0; } return masterTypes.size(); } public boolean isEmpty() { return getSize() == 0; } } class DataTypesTableModel extends AbstractTableModel { public DataTypesTableModel() {} public String getColumnName(int column) { if (columns == null) { return ""; } return columns[column]; } public int getColumnCount() { if (columns == null) { return 0; } return columns.length; } public int getRowCount() { if (tableData == null) { return 0; } return tableData.size(); } public Object getValueAt(int rowIndex, int columnIndex) { if (rowIndex >= tableData.size()) { return null; } List row = tableData.get(rowIndex); return row.get(columnIndex); } public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } } // diff cell backgrounds private Color masterTypeBg = new Color(153,204,153); private Color diffTypeBg = new Color(255,255,102); class DataTypeCellRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (isSelected) { setBackground(table.getSelectionBackground()); setForeground(table.getSelectionForeground()); } else { if (row == 0) { setBackground(masterTypeBg); } else { setBackground(table.getBackground()); if (column > 0) { Object masterValue = selectedDataType.get(column); if (masterValue != null) { if (!masterValue.equals(value)) { setBackground(diffTypeBg); } } } } setForeground(table.getForeground()); } setValue(value); return this; } } class DataTypeRowSorter implements Comparator { public int compare(Object obj1, Object obj2) { List<String> row1 = (List<String>)obj1; List<String> row2 = (List<String>)obj2; String value1 = row1.get(NAME_COLUMN - 1); String value2 = row2.get(NAME_COLUMN - 1); int result = value1.compareTo(value2); if (result < 0) { return -1; } else if (result > 0) { return 1; } else { return 0; } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -