From 501ea1fb40ac0d645cc1074cefeda0ba5940f044 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Tue, 29 May 2018 19:48:25 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-8114=20=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E5=AD=97=E5=85=B8=20=E8=AE=BE=E8=AE=A1=E5=99=A8=E6=97=A0?= =?UTF-8?q?=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/data/datapane/ChoosePane.java | 110 +++++++++++------- 1 file changed, 71 insertions(+), 39 deletions(-) diff --git a/designer-base/src/com/fr/design/data/datapane/ChoosePane.java b/designer-base/src/com/fr/design/data/datapane/ChoosePane.java index 5e9c16bdea..281a61de51 100644 --- a/designer-base/src/com/fr/design/data/datapane/ChoosePane.java +++ b/designer-base/src/com/fr/design/data/datapane/ChoosePane.java @@ -37,7 +37,11 @@ import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.stable.StringUtils; -import javax.swing.*; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTree; +import javax.swing.SwingWorker; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.PopupMenuEvent; @@ -48,7 +52,9 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.ItemEvent; @@ -85,6 +91,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha private PopupMenuListener popupMenuListener = new PopupMenuListener() { + @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { new Thread() { @Override @@ -94,26 +101,41 @@ public class ChoosePane extends BasicBeanPane implements Refresha }.start(); } + @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } + @Override public void popupMenuCanceled(PopupMenuEvent e) { } }; private PopupMenuListener listener = new PopupMenuListener() { + @Override public void popupMenuCanceled(PopupMenuEvent e) { } + @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } + @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { executePopulateWorker(); } }; + private FocusAdapter focusAdapter = new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + if (schemaBox.getSelectedIndex() == -1) { + schemaBox.updateUI(); + schemaBox.showPopup(); + } + } + }; + public ChoosePane() { this(null); } @@ -146,6 +168,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha private void initBoxListener() { addDSBoxListener(); schemaBox.addItemListener(new ItemListener() { + @Override public void itemStateChanged(ItemEvent evt) { tableNameComboBox.setSelectedItem(""); } @@ -176,16 +199,9 @@ public class ChoosePane extends BasicBeanPane implements Refresha } protected void addFocusListener() { - schemaBox.addFocusListener(new FocusAdapter() { - public void focusGained(FocusEvent e) { - if (schemaBox.getSelectedIndex() == -1) { - schemaBox.updateUI(); - schemaBox.showPopup(); - } - } - }); } + @SuppressWarnings("unchecked") protected void initDsNameComboBox() { dsNameComboBox.setRefreshingModel(true); ConnectionConfig connectionConfig = ConnectionConfig.getInstance(); @@ -233,12 +249,18 @@ public class ChoosePane extends BasicBeanPane implements Refresha } populateWorker = new SwingWorker() { - protected com.fr.data.impl.Connection doInBackground() throws Exception { + @SuppressWarnings("unchecked") + @Override + protected com.fr.data.impl.Connection doInBackground() { + schemaBox.setRefreshingModel(true); schemaBox.addItem(Inter.getLocText("FR-Designer_Loading") + "..."); schemaBox.setSelectedItem(null); + schemaBox.setRefreshingModel(false); return getConnection(); } + @SuppressWarnings("unchecked") + @Override public void done() { try { com.fr.data.impl.Connection selectedDatabase = get(); @@ -267,6 +289,8 @@ public class ChoosePane extends BasicBeanPane implements Refresha schemaBox.removePopupMenuListener(listener); schemaBox.setPopupVisible(true); schemaBox.addPopupMenuListener(listener); + schemaBox.removeFocusListener(focusAdapter); + schemaBox.addFocusListener(focusAdapter); } }; populateWorker.execute(); @@ -292,7 +316,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha return null; // peter:选中了当前的零长度的节点,直接返回. } ConnectionConfig connectionConfig = ConnectionConfig.getInstance(); - for (Map.Entry entry: connectionConfig.getConnections().entrySet()) { + for (Map.Entry entry : connectionConfig.getConnections().entrySet()) { if (ComparatorUtils.equals(selectedDSName, entry.getKey())) { return entry.getValue(); } @@ -303,6 +327,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha /** * 刷新没多大用。而且要刷新也不是这儿刷新。 */ + @Override public void refresh() { DBUtils.refreshDatabase(); String schema = StringUtils.isEmpty(schemaBox.getSelectedItem()) ? null : schemaBox.getSelectedItem(); @@ -312,6 +337,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha } TreeCellRenderer tableNameTreeRenderer = new DefaultTreeCellRenderer() { + @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { @@ -328,6 +354,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha }; public static UIComboBoxRenderer listCellRenderer = new UIComboBoxRenderer() { + @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof TreePath) { @@ -344,16 +371,18 @@ public class ChoosePane extends BasicBeanPane implements Refresha /** - * 添加项目监听事件 - * @param aListener 事件监听器 + * 添加项目监听事件 + * + * @param aListener 事件监听器 */ public void addItemListener(ItemListener aListener) { this.tableNameComboBox.addItemListener(aListener); } /** - * 删除项目监听事件 - * @param aListener 事件监听器 + * 删除项目监听事件 + * + * @param aListener 事件监听器 */ public void removeItemListener(ItemListener aListener) { this.tableNameComboBox.removeItemListener(aListener); @@ -398,9 +427,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha } } ((DefaultTreeModel) tree.getModel()).reload(); - /** - * daniel 展开所有tree - */ + // daniel 展开所有tree TreeNode root = (TreeNode) tree.getModel().getRoot(); TreePath parent = new TreePath(root); TreeNode node = (TreeNode) parent.getLastPathComponent(); @@ -416,42 +443,41 @@ public class ChoosePane extends BasicBeanPane implements Refresha /** * 创建选中的数据集数据 - * @return 数据集数据 + * + * @return 数据集数据 */ public TableData createSelectTableData() { DataBaseItems paras = this.updateBean(); boolean connect = false; com.fr.data.impl.Connection database = DBUtils.checkDBConnection(paras.getDatabaseName()); if (database == null) { - failedToFindTable(); + failedToFindTable(); return TableData.EMPTY_TABLEDATA; } try { connect = FRContext.getCurrentEnv().testConnection(database); - } catch (Exception e1) { - connect = false; + } catch (Exception ignored) { } if (!connect) { DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); JOptionPane.showMessageDialog(designerFrame, Inter.getLocText("Datasource-Connection_failed"), - Inter.getLocText("FR-Designer_Failed"), JOptionPane.INFORMATION_MESSAGE); - failedToFindTable(); + Inter.getLocText("FR-Designer_Failed"), JOptionPane.INFORMATION_MESSAGE); + failedToFindTable(); return null; } // 显示Table数据. TableData tableData = null; if (FRContext.getCurrentEnv() instanceof LocalEnv) { - TableData tableDataLocal = new DBTableData(database, DataCoreUtils.createSelectSQL(paras.getSchemaName(), paras.getTableName(), + tableData = new DBTableData(database, DataCoreUtils.createSelectSQL(paras.getSchemaName(), paras.getTableName(), DialectFactory.getDialectByName(paras.getDatabaseName()))); - tableData = tableDataLocal; } else { try { TableData tableDataLocal = new DBTableData(database, DataCoreUtils.createSelectSQL(paras.getSchemaName(), paras.getTableName(), DialectFactory.getDialectByName(paras.getDatabaseName()))); tableData = FRContext.getCurrentEnv().previewTableData(tableDataLocal, java.util.Collections.EMPTY_MAP, DesignerEnvManager.getEnvManager().getMaxNumberOrPreviewRow()); } catch (Exception e) { - failedToFindTable(); + failedToFindTable(); FRContext.getLogger().error(e.getMessage(), e); } } @@ -463,8 +489,8 @@ public class ChoosePane extends BasicBeanPane implements Refresha return this.dsNameComboBox.getSelectedItem(); } - protected void failedToFindTable() { - } + protected void failedToFindTable() { + } protected String getTableName() { String tableName = ""; @@ -485,7 +511,8 @@ public class ChoosePane extends BasicBeanPane implements Refresha /** * 得到当前的ColumnName[] - * @return 返回当前的ColumnName[] + * + * @return 返回当前的ColumnName[] */ public String[] currentColumnNames() { String[] colNames = null; @@ -493,21 +520,19 @@ public class ChoosePane extends BasicBeanPane implements Refresha DataBaseItems paras = this.updateBean(); String selectedDSName = paras.getDatabaseName(); if (StringUtils.isBlank(selectedDSName)) { - return colNames = new String[0]; // peter:选中了当前的零长度的节点,直接返回. + // peter:选中了当前的零长度的节点,直接返回. + return new String[0]; } String selectedTableObject = paras.getTableName(); if (StringUtils.isEmpty(selectedTableObject)) { - return colNames = new String[0]; + return new String[0]; } - java.sql.Connection conn = null; try { // daniel:增加参数 colNames = FRContext.getCurrentEnv().getColumns(selectedDSName, paras.getSchemaName(), selectedTableObject); } catch (Exception e2) { FRContext.getLogger().error(e2.getMessage(), e2); - } finally { - DBUtils.closeConnection(conn); } if (colNames == null) { @@ -517,9 +542,10 @@ public class ChoosePane extends BasicBeanPane implements Refresha } /** - * 预览key value对应的数据 + * 预览key value对应的数据 + * * @param key 键 - * @param value 值 + * @param value 值 */ public void preview(int key, int value) { PreviewTablePane.previewTableData(createSelectTableData(), key, value); @@ -528,6 +554,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha /** * 默认预览 */ + @Override public void preview() { preview(-1, -1); } @@ -540,10 +567,12 @@ public class ChoosePane extends BasicBeanPane implements Refresha } /** - *注册listener,相应数据集改变 + * 注册listener,相应数据集改变 */ + @Override public void registerDSChangeListener() { DesignTableDataManager.addDsChangeListener(new ChangeListener() { + @Override public void stateChanged(ChangeEvent e) { initDsNameComboBox(); } @@ -578,6 +607,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha this.refreshingModel = refreshingModel; } + @Override public void setSelectedItem(Object ob) { this.getModel().setSelectedItem(ob); if (ob != null && StringUtils.isEmpty(ob.toString())) { @@ -591,11 +621,13 @@ public class ChoosePane extends BasicBeanPane implements Refresha private class ComboBoxEditor extends UIComboBoxEditor { private Object item; + @Override public void setItem(Object item) { this.item = item; textField.setText((item == null) ? "" : item.toString()); } + @Override public Object getItem() { return this.item; }