From 40663f225c826dd4504ba4ab765f8eb37fc428b0 Mon Sep 17 00:00:00 2001 From: Yvan Date: Tue, 24 Nov 2020 09:50:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?KERNEL-6188=20DatabaseConnectionPane?= =?UTF-8?q?=E4=B8=AD=E7=9A=84SwingWorker=E9=97=AE=E9=A2=98=20=E3=80=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=8E=9F=E5=9B=A0=E3=80=91=E5=9C=A8Swingwork?= =?UTF-8?q?er=E7=9A=84doInBackground=E4=B8=AD=E6=9B=B4=E6=96=B0UI=E4=BC=9A?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=87=BA=E7=8E=B0=E5=8D=A1=E6=AD=BB=E7=AD=89?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E3=80=90=E6=94=B9=E5=8A=A8=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E3=80=91=E5=B0=86doInBackground=E4=B8=AD=E4=B8=8EUI?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E7=9A=84=E9=83=A8=E5=88=86=E7=A7=BB=E5=88=B0?= =?UTF-8?q?done=E6=96=B9=E6=B3=95=E4=B8=AD=EF=BC=8C=E5=9C=A8EDT=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=A4=84=E7=90=86UI=EF=BC=8C=E6=AF=94=E8=BE=83?= =?UTF-8?q?=E5=AE=89=E5=85=A8=EF=BC=9B=E5=8F=A6=E5=A4=96=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86dialog.show()=E8=BF=87=E6=97=B6=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=92=8C=E4=B8=80=E4=BA=9B=E5=AF=BC=E5=8C=85=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../connect/DatabaseConnectionPane.java | 68 +++++++++++++------ 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java index fc666f15fd..3ef5aa8f85 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java @@ -3,6 +3,7 @@ */ package com.fr.design.data.datapane.connect; +import com.fr.data.impl.Connection; import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JNDIDatabaseConnection; import com.fr.data.operator.DataOperator; @@ -10,6 +11,7 @@ import com.fr.design.beans.BasicBeanPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.scrollruler.ModLineBorder; import com.fr.design.utils.gui.GUICoreUtils; @@ -19,12 +21,24 @@ import com.fr.stable.ArrayUtils; import com.fr.stable.EncodeConstants; import com.fr.stable.StringUtils; -import javax.swing.*; -import java.awt.*; +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; +import javax.swing.UIManager; +import java.awt.BorderLayout; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; /** * Database Connection pane. @@ -48,9 +62,9 @@ public abstract class DatabaseConnectionPane map = new HashMap<>(); + map.put("database", database); + map.put("connect", connect); + return map; + } catch (Exception exp) { + FineLoggerFactory.getLogger().error(exp.getMessage(), exp); + } + return null; + } + + @Override + protected void done() { + try { + Map map = (Map) get(); + Connection database = (Connection) map.get("database"); + boolean connect = (boolean) map.get("connect"); okButton.setEnabled(true); message.setText(database.connectMessage(connect)); if (connect) { uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon")); - message.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully")); + message.setText(Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully")); }else{ uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon")); - message.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Failed")); + message.setText(Toolkit.i18nText("Fine-Design_Basic_Connection_Failed")); } - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); + } catch (InterruptedException | ExecutionException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } - return null; } }; @@ -158,18 +188,18 @@ public abstract class DatabaseConnectionPane Date: Tue, 24 Nov 2020 10:18:04 +0800 Subject: [PATCH 2/4] =?UTF-8?q?KERNEL-6188=20=E4=BF=AE=E6=94=B9=E4=B8=80?= =?UTF-8?q?=E4=B8=8BdoInBackground()=E6=96=B9=E6=B3=95=E4=B8=8Edone()?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=B9=8B=E9=97=B4=E4=BC=A0=E9=80=92=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E7=B1=BB=E5=9E=8B=EF=BC=8C=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datapane/connect/DatabaseConnectionPane.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java index 3ef5aa8f85..b90fc7f372 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java @@ -131,16 +131,13 @@ public abstract class DatabaseConnectionPane connectionThread = new SwingWorker<>() { @Override - protected Object doInBackground() throws Exception { + protected Boolean doInBackground() throws Exception { try { Connection database = DatabaseConnectionPane.this.updateBean(); - boolean connect = DataOperator.getInstance().testConnection(database); - Map map = new HashMap<>(); - map.put("database", database); - map.put("connect", connect); - return map; + // 返回连接结果 + return DataOperator.getInstance().testConnection(database); } catch (Exception exp) { FineLoggerFactory.getLogger().error(exp.getMessage(), exp); } @@ -150,11 +147,8 @@ public abstract class DatabaseConnectionPane map = (Map) get(); - Connection database = (Connection) map.get("database"); - boolean connect = (boolean) map.get("connect"); + boolean connect = get(); okButton.setEnabled(true); - message.setText(database.connectMessage(connect)); if (connect) { uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon")); message.setText(Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully")); From f549b55ca174954c8e4965fce74e531ed51ddb98 Mon Sep 17 00:00:00 2001 From: Yvan Date: Tue, 24 Nov 2020 10:22:36 +0800 Subject: [PATCH 3/4] =?UTF-8?q?KERNEL-6188=20=E5=8E=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E7=9A=84try-catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datapane/connect/DatabaseConnectionPane.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java index b90fc7f372..e3ee4cdb9c 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java @@ -134,14 +134,9 @@ public abstract class DatabaseConnectionPane connectionThread = new SwingWorker<>() { @Override protected Boolean doInBackground() throws Exception { - try { - Connection database = DatabaseConnectionPane.this.updateBean(); - // 返回连接结果 - return DataOperator.getInstance().testConnection(database); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } - return null; + Connection database = DatabaseConnectionPane.this.updateBean(); + // 返回连接结果 + return DataOperator.getInstance().testConnection(database); } @Override From fbee3b92776c2d04579bc719229d1ad827d33818 Mon Sep 17 00:00:00 2001 From: Yvan Date: Tue, 24 Nov 2020 10:35:44 +0800 Subject: [PATCH 4/4] =?UTF-8?q?KERNEL-6188=20=E8=A1=A5=E5=85=85=E6=B3=9B?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/data/datapane/connect/DatabaseConnectionPane.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java index e3ee4cdb9c..f6bfdd29a7 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java @@ -131,7 +131,7 @@ public abstract class DatabaseConnectionPane connectionThread = new SwingWorker<>() { + final SwingWorker connectionThread = new SwingWorker() { @Override protected Boolean doInBackground() throws Exception { Connection database = DatabaseConnectionPane.this.updateBean();