From 54aee8313f6e19410ac41d96c0e87fe76d0c3103 Mon Sep 17 00:00:00 2001 From: lucian Date: Thu, 28 Apr 2022 17:39:00 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-70504=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-=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A1=A8=E6=90=9C=E7=B4=A2=E6=97=B6=E6=9C=89=E8=BE=83?= =?UTF-8?q?=E5=A4=A7=E6=A6=82=E7=8E=87=E5=A4=9A=E4=B8=AA=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E7=9A=84=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/icombobox/TableSearchTreeComboBox.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/TableSearchTreeComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/TableSearchTreeComboBox.java index 7198eeef09..63a0d71862 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/TableSearchTreeComboBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/TableSearchTreeComboBox.java @@ -1,5 +1,6 @@ package com.fr.design.gui.icombobox; +import com.fr.concurrent.NamedThreadFactory; import com.fr.data.core.DataCoreUtils; import com.fr.data.core.db.TableProcedure; import com.fr.data.impl.Connection; @@ -24,6 +25,8 @@ import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.util.Enumeration; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * 实现模糊搜索表名的FRTreeComboBox @@ -37,6 +40,10 @@ import java.util.Enumeration; public class TableSearchTreeComboBox extends FRTreeComboBox { // 持有父容器,需要实时获取其他组件值 private final ChoosePane parent; + /** + * 保证模糊搜索的原子性操作 + */ + private final ExecutorService singleExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("TableSearchTreeComboBox")); public TableSearchTreeComboBox(ChoosePane parent, JTree tree, TreeCellRenderer renderer) { super(tree, renderer); @@ -69,14 +76,16 @@ public class TableSearchTreeComboBox extends FRTreeComboBox { */ private void searchExecute() { UIComboBoxEditor searchEditor = (UIComboBoxEditor) this.getEditor(); - new SwingWorker() { + String searchText = (String) searchEditor.getItem(); + singleExecutor.execute( + new SwingWorker() { @Override protected Void doInBackground() { processTableDataNames( parent.getDSName(), parent.getConnection(), parent.getSchema(), - createFilter((String) searchEditor.getItem())); + createFilter(searchText)); return null; } @@ -86,7 +95,7 @@ public class TableSearchTreeComboBox extends FRTreeComboBox { // 输入框获取焦点 searchEditor.getEditorComponent().requestFocus(); } - }.execute(); + }); } private TableNameFilter createFilter(String text) {