From 9dcb81b4a8317cd69139b5ec234411ab741a04da Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 14 Apr 2021 17:10:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-50096=20=E5=A4=84=E7=90=86=E4=B8=8B?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E5=9C=BA?= =?UTF-8?q?=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/data/datapane/connect/JDBCDefPane.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java index 94a612b661..c47a0d75c2 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java @@ -100,6 +100,7 @@ public class JDBCDefPane extends JPanel { private IntegerEditor DBCP_MINEVICTABLEIDLETIMEMILLIS = new IntegerEditor(); private JDBCDatabaseConnection jdbcDatabase; + private boolean needRefresh = true; public JDBCDefPane() { this.setBorder(UITitledBorder.createBorderWithTitle("JDBC" + ":")); @@ -201,11 +202,11 @@ public class JDBCDefPane extends JPanel { } public void populate(JDBCDatabaseConnection jdbcDatabase) { + needRefresh = false; if (jdbcDatabase == null) { jdbcDatabase = new JDBCDatabaseConnection(); } this.jdbcDatabase = jdbcDatabase; - this.dbtypeComboBox.removeActionListener(dbtypeActionListener); if (ComparatorUtils.equals(jdbcDatabase.getDriver(), "sun.jdbc.odbc.JdbcOdbcDriver") && jdbcDatabase.getURL().startsWith("jdbc:odbc:Driver={Microsoft")) { this.dbtypeComboBox.setSelectedItem("Access"); @@ -230,7 +231,6 @@ public class JDBCDefPane extends JPanel { this.dbtypeComboBox.setSelectedItem(OTHER_DB); } } - this.dbtypeComboBox.addActionListener(dbtypeActionListener); this.driverComboBox.setSelectedItem(jdbcDatabase.getDriver()); this.urlTextField.setText(jdbcDatabase.getURL()); this.userNameTextField.setText(jdbcDatabase.getUser()); @@ -254,6 +254,7 @@ public class JDBCDefPane extends JPanel { this.DBCP_MINEVICTABLEIDLETIMEMILLIS.setValue(dbcpAttr.getMinEvictableIdleTimeMillis() / TIME_MULTIPLE); this.DBCP_NUMTESTSPEREVICTIONRUN.setValue(dbcpAttr.getNumTestsPerEvictionRun()); this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.setValue(dbcpAttr.getTimeBetweenEvictionRunsMillis()); + needRefresh = true; } public JDBCDatabaseConnection update() { @@ -306,7 +307,9 @@ public class JDBCDefPane extends JPanel { } } // 更改数据库类型后 数据库名称置空和之前逻辑保持一致 - jdbcDatabase.setDatabase(StringUtils.EMPTY); + if (needRefresh) { + jdbcDatabase.setDatabase(StringUtils.EMPTY); + } } }; From 887bd33a2f16e79ab432786d65a851b3a75e7114 Mon Sep 17 00:00:00 2001 From: lucian Date: Thu, 15 Apr 2021 09:58:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?REPORT-50908=20=E5=A1=AB=E6=8A=A5-=E5=A1=AB?= =?UTF-8?q?=E6=8A=A5=E5=B1=9E=E6=80=A7=E8=AE=BE=E7=BD=AE-=E5=A1=AB?= =?UTF-8?q?=E6=8A=A5=E5=B1=9E=E6=80=A7=E4=B8=AD=E5=AF=B9=E8=A1=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=AE=9A=E4=BD=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/data/datapane/ChoosePane.java | 21 ++++-- .../design/gui/icombobox/FRTreeComboBox.java | 13 +++- .../icombobox/SearchPreTaskTreeComboBox.java | 73 +++++++++++++++++++ 3 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/gui/icombobox/SearchPreTaskTreeComboBox.java diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java index fce7832ac0..38801ec905 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java @@ -1,6 +1,7 @@ package com.fr.design.data.datapane; import com.fr.base.TableData; +import com.fr.concurrent.NamedThreadFactory; import com.fr.data.core.DataCoreUtils; import com.fr.data.core.db.DBUtils; import com.fr.data.core.db.TableProcedure; @@ -17,7 +18,7 @@ import com.fr.design.data.datapane.preview.PreviewLabel.Previewable; import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.data.tabledata.Prepare4DataSourceChange; import com.fr.design.dialog.FineJOptionPane; -import com.fr.design.gui.icombobox.FRTreeComboBox; +import com.fr.design.gui.icombobox.SearchPreTaskTreeComboBox; import com.fr.design.gui.icombobox.FilterableComboBoxModel; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBoxEditor; @@ -59,6 +60,10 @@ import java.util.Collection; import java.util.Enumeration; import java.util.List; import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.FutureTask; /** * @author zhou @@ -80,21 +85,25 @@ public class ChoosePane extends BasicBeanPane implements Refresha /** * 表名 */ - protected FRTreeComboBox tableNameComboBox; + protected SearchPreTaskTreeComboBox tableNameComboBox; private SwingWorker populateWorker; + private ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("ChoosePaneThread")); private PopupMenuListener popupMenuListener = new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - new Thread() { + FutureTask task = new FutureTask(new Callable() { @Override - public void run() { + public Object call() { calculateTableDataNames(); + return null; } - }.start(); + }); + service.submit(task); + tableNameComboBox.setPreSearchTask(task); } @Override @@ -158,7 +167,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha schemaBox = new StringUIComboBox(); schemaBox.setEditor(new ComboBoxEditor()); - tableNameComboBox = new FRTreeComboBox(new JTree(new DefaultMutableTreeNode()), tableNameTreeRenderer, false); + tableNameComboBox = new SearchPreTaskTreeComboBox(new JTree(new DefaultMutableTreeNode()), tableNameTreeRenderer, false); tableNameComboBox.setEditable(true); tableNameComboBox.setRenderer(listCellRenderer); registerDSChangeListener(); diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java index a7a9133351..f0c60d2e8a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java @@ -597,6 +597,10 @@ public class FRTreeComboBox extends UIComboBox { return this.item; } + public boolean isSetting() { + return setting; + } + public void insertUpdate(DocumentEvent e) { changeHandler(); } @@ -614,11 +618,18 @@ public class FRTreeComboBox extends UIComboBox { return; } setPopupVisible(true); + search(); + } + + /** + * 模糊搜索,选中首个匹配项 + */ + protected void search() { this.item = textField.getText(); TreeNode root = (TreeNode) tree.getModel().getRoot(); TreePath parent = new TreePath(root); TreeNode node = (TreeNode) parent.getLastPathComponent(); - dealSamePath(parent,node,textField); + dealSamePath(parent, node, textField); this.getEditorComponent().requestFocus(); } diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/SearchPreTaskTreeComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/SearchPreTaskTreeComboBox.java new file mode 100644 index 0000000000..9e453471ef --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/SearchPreTaskTreeComboBox.java @@ -0,0 +1,73 @@ +package com.fr.design.gui.icombobox; + +import com.fr.log.FineLoggerFactory; + +import javax.swing.JTree; +import javax.swing.SwingWorker; +import javax.swing.tree.TreeCellRenderer; +import java.util.concurrent.FutureTask; + +/** + * 模糊搜索前需执行完前置任务的TreeComboBox + * @author Lucian.Chen + * @version 10.0 + * Created by Lucian.Chen on 2021/4/14 + */ +public class SearchPreTaskTreeComboBox extends FRTreeComboBox { + + /** + * 模糊搜索前任务 + */ + private FutureTask preSearchTask; + + public SearchPreTaskTreeComboBox(JTree tree, TreeCellRenderer renderer, boolean editable) { + super(tree, renderer, editable); + } + + public FutureTask getPreSearchTask() { + return preSearchTask; + } + + public void setPreSearchTask(FutureTask preSearchTask) { + this.preSearchTask = preSearchTask; + } + + protected UIComboBoxEditor createEditor() { + return new SearchPreTaskComboBoxEditor(this); + } + + private class SearchPreTaskComboBoxEditor extends FrTreeSearchComboBoxEditor { + + public SearchPreTaskComboBoxEditor(FRTreeComboBox comboBox) { + super(comboBox); + } + + protected void changeHandler() { + if (isSetting()) { + return; + } + setPopupVisible(true); + // 模糊搜索异步 + new SwingWorker() { + @Override + protected Void doInBackground() { + FutureTask task = getPreSearchTask(); + try { + // 确保模糊搜索前任务执行完成后,再进行模糊搜索 + if (task != null) { + task.get(); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + if (task != null) { + // 任务执行后置空,否则会被别的操作重复触发 + setPreSearchTask(null); + } + search(); + return null; + } + }.execute(); + } + } +} From 85cfe2f9a1895f26a5ad9faf890beea726c4d399 Mon Sep 17 00:00:00 2001 From: lucian Date: Fri, 16 Apr 2021 09:52:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-50908=20=E5=A1=AB=E6=8A=A5-=E5=A1=AB?= =?UTF-8?q?=E6=8A=A5=E5=B1=9E=E6=80=A7=E8=AE=BE=E7=BD=AE-=E5=A1=AB?= =?UTF-8?q?=E6=8A=A5=E5=B1=9E=E6=80=A7=E4=B8=AD=E5=AF=B9=E8=A1=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=AE=9A=E4=BD=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/data/datapane/ChoosePane.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java index 38801ec905..6460cadb9e 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java @@ -89,7 +89,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha private SwingWorker populateWorker; - private ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("ChoosePaneThread")); + private static final ExecutorService SERVICE = Executors.newSingleThreadExecutor(new NamedThreadFactory("ChoosePaneThread")); private PopupMenuListener popupMenuListener = new PopupMenuListener() { @@ -102,7 +102,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha return null; } }); - service.submit(task); + SERVICE.submit(task); tableNameComboBox.setPreSearchTask(task); }