From 7247a789a97ccbb34d0bcad0a5f3ea2701531ee2 Mon Sep 17 00:00:00 2001 From: pengda Date: Wed, 14 Apr 2021 14:13:35 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-49055=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E9=85=8D=E7=BD=AE=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datapane/connect/DBCPAttrPane.java | 118 ++++++ .../connect/DatabaseConnectionPane.java | 60 ++- .../data/datapane/connect/JDBCDefPane.java | 392 ++++++++++++------ .../fr/design/layout/TableLayoutHelper.java | 2 +- 4 files changed, 426 insertions(+), 146 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java new file mode 100644 index 0000000000..01af972931 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java @@ -0,0 +1,118 @@ +package com.fr.design.data.datapane.connect; + +import com.fr.data.impl.JDBCDatabaseConnection; +import com.fr.data.pool.DBCPConnectionPoolAttr; +import com.fr.design.constants.UIConstants; +import com.fr.design.dialog.BasicPane; +import com.fr.design.editor.editor.IntegerEditor; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import java.awt.BorderLayout; +import java.awt.Component; +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.SwingConstants; + +public class DBCPAttrPane extends BasicPane { + public static final int TIME_MULTIPLE = 1000; + // carl:DBCP的一些属性 + private IntegerEditor DBCP_INITIAL_SIZE = new IntegerEditor(); + private IntegerEditor DBCP_MAX_ACTIVE = new IntegerEditor(); + private IntegerEditor DBCP_MAX_IDLE = new IntegerEditor(); + private IntegerEditor DBCP_MIN_IDLE = new IntegerEditor(); + private IntegerEditor DBCP_MAX_WAIT = new IntegerEditor(); + private UITextField DBCP_VALIDATION_QUERY = new UITextField(); + + private UIComboBox DBCP_TESTONBORROW = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); + private UIComboBox DBCP_TESTONRETURN = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); + private UIComboBox DBCP_TESTWHILEIDLE = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); + + private IntegerEditor DBCP_TIMEBETWEENEVICTIONRUNSMILLS = new IntegerEditor(); + private IntegerEditor DBCP_NUMTESTSPEREVICTIONRUN = new IntegerEditor(); + private IntegerEditor DBCP_MINEVICTABLEIDLETIMEMILLIS = new IntegerEditor(); + + public DBCPAttrPane() { + JPanel defaultPane = this; + + // JPanel northFlowPane + JPanel northFlowPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); + defaultPane.add(northFlowPane, BorderLayout.NORTH); + + DBCP_VALIDATION_QUERY.setColumns(15); + // ContextPane + + double f = TableLayout.FILL; + // double p = TableLayout.PREFERRED; + double[] rowSize = {f, f, f, f, f, f, f, f, f, f, f, f}; + double[] columnSize = {f, f}; + Component[][] comps = { + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Initial_Size") + ":", SwingConstants.RIGHT), DBCP_INITIAL_SIZE}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Idle") + ":", SwingConstants.RIGHT), DBCP_MAX_IDLE}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Min_Idle") + ":", SwingConstants.RIGHT), DBCP_MIN_IDLE}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Max_Wait_Time") + ":", SwingConstants.RIGHT), DBCP_MAX_WAIT}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Borrow") + ":", SwingConstants.RIGHT), DBCP_TESTONBORROW}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Return") + ":", SwingConstants.RIGHT), DBCP_TESTONRETURN}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_While_Idle") + ":", SwingConstants.RIGHT), DBCP_TESTWHILEIDLE}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Evictionruns_millis") + ":", SwingConstants.RIGHT), + DBCP_TIMEBETWEENEVICTIONRUNSMILLS}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Num_Test_Per_Evction_Run") + ":", SwingConstants.RIGHT), DBCP_NUMTESTSPEREVICTIONRUN}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Mix_Evictable_Idle_Time_Millis") + ":", SwingConstants.RIGHT), + DBCP_MINEVICTABLEIDLETIMEMILLIS}}; + + JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSize, columnSize, 10, 4); + contextPane.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, UIConstants.LINE_COLOR)); + northFlowPane.add(contextPane); + } + + public void populate(JDBCDatabaseConnection jdbcDatabase) { + DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); + if (dbcpAttr == null) { + dbcpAttr = new DBCPConnectionPoolAttr(); + jdbcDatabase.setDbcpAttr(dbcpAttr); + } + this.DBCP_INITIAL_SIZE.setValue(dbcpAttr.getInitialSize()); + this.DBCP_MAX_ACTIVE.setValue(dbcpAttr.getMaxActive()); + this.DBCP_MAX_IDLE.setValue(dbcpAttr.getMaxIdle()); + this.DBCP_MAX_WAIT.setValue(dbcpAttr.getMaxWait()); + this.DBCP_MIN_IDLE.setValue(dbcpAttr.getMinIdle()); + this.DBCP_VALIDATION_QUERY.setText(dbcpAttr.getValidationQuery()); + this.DBCP_TESTONBORROW.setSelectedIndex(dbcpAttr.isTestOnBorrow() ? 1 : 0); + this.DBCP_TESTONRETURN.setSelectedIndex(dbcpAttr.isTestOnReturn() ? 1 : 0); + this.DBCP_TESTWHILEIDLE.setSelectedIndex(dbcpAttr.isTestWhileIdle() ? 1 : 0); + this.DBCP_MINEVICTABLEIDLETIMEMILLIS.setValue(dbcpAttr.getMinEvictableIdleTimeMillis() / TIME_MULTIPLE); + this.DBCP_NUMTESTSPEREVICTIONRUN.setValue(dbcpAttr.getNumTestsPerEvictionRun()); + this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.setValue(dbcpAttr.getTimeBetweenEvictionRunsMillis()); + } + + public void update(JDBCDatabaseConnection jdbcDatabase) { + DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); + if (dbcpAttr == null) { + dbcpAttr = new DBCPConnectionPoolAttr(); + jdbcDatabase.setDbcpAttr(dbcpAttr); + } + dbcpAttr.setInitialSize(this.DBCP_INITIAL_SIZE.getValue().intValue()); + dbcpAttr.setMaxActive(this.DBCP_MAX_ACTIVE.getValue().intValue()); + dbcpAttr.setMaxIdle(this.DBCP_MAX_IDLE.getValue().intValue()); + dbcpAttr.setMaxWait(this.DBCP_MAX_WAIT.getValue().intValue()); + dbcpAttr.setMinIdle(this.DBCP_MIN_IDLE.getValue().intValue()); + dbcpAttr.setValidationQuery(this.DBCP_VALIDATION_QUERY.getText()); + dbcpAttr.setTestOnBorrow(this.DBCP_TESTONBORROW.getSelectedIndex() == 0 ? false : true); + dbcpAttr.setTestOnReturn(this.DBCP_TESTONRETURN.getSelectedIndex() == 0 ? false : true); + dbcpAttr.setTestWhileIdle(this.DBCP_TESTWHILEIDLE.getSelectedIndex() == 0 ? false : true); + dbcpAttr.setMinEvictableIdleTimeMillis(((Number) this.DBCP_MINEVICTABLEIDLETIMEMILLIS.getValue()).intValue() * TIME_MULTIPLE); + dbcpAttr.setNumTestsPerEvictionRun(((Number) this.DBCP_NUMTESTSPEREVICTIONRUN.getValue()).intValue()); + dbcpAttr.setTimeBetweenEvictionRunsMillis(((Number) this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.getValue()).intValue()); + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr"); + } +} 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 16c992b0f3..d58b4d727e 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 @@ -12,8 +12,10 @@ import com.fr.data.solution.entity.DriverPage; import com.fr.data.solution.processor.ClassNotFoundExceptionSolutionProcessor; import com.fr.data.solution.processor.SolutionProcessor; import com.fr.design.beans.BasicBeanPane; +import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; @@ -245,14 +247,16 @@ public abstract class DatabaseConnectionPane { private static JDBCDefPane jdbcDefPane = new JDBCDefPane(); + private static DBCPAttrPane dbcpAttrPane = new DBCPAttrPane(); @Override protected JPanel mainPanel() { @@ -362,14 +393,21 @@ public abstract class DatabaseConnectionPane jdbcMap = new HashMap(); static { @@ -59,45 +64,38 @@ public class JDBCDefPane extends JPanel { new DriverURLName("COM.cloudscape.JDBCDriver", "jdbc:cloudscape:/cloudscape/"), new DriverURLName("com.internetcds.jdbc.tds.Driver", "jdbc:freetds:sqlserver://localhost/"), new DriverURLName("com.fr.swift.jdbc.Driver", "jdbc:swift:emb://default")}); - jdbcMap.put("Inceptor", new DriverURLName[]{new DriverURLName("org.apache.hive.jdbc.HiveDriver", "jdbc:inceptor2://localhost:10000/default"), - new DriverURLName("org.apache.hadoop.hive.jdbc.HiveDriver", "jdbc:inceptor://localhost:10000/default")}); - jdbcMap.put("Oracle", new DriverURLName[]{new DriverURLName("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@localhost:1521:databaseName")}); - jdbcMap.put("DB2", new DriverURLName[]{new DriverURLName("com.ibm.db2.jcc.DB2Driver", "jdbc:db2://localhost:50000/")}); - jdbcMap.put("SQL Server", new DriverURLName[]{new DriverURLName("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://localhost:1433;" + "databaseName=")}); - jdbcMap.put("MySQL", new DriverURLName[]{new DriverURLName("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/"), - new DriverURLName("org.gjt.mm.mysql.Driver", "jdbc:mysql://localhost/")}); - jdbcMap.put("Sybase", new DriverURLName[]{new DriverURLName("com.sybase.jdbc2.jdbc.SybDriver", "jdbc:sybase:Tds:localhost:5000/")}); + jdbcMap.put("Inceptor", new DriverURLName[]{new DriverURLName("org.apache.hive.jdbc.HiveDriver", "jdbc:inceptor2://localhost:port/databaseName"), + new DriverURLName("org.apache.hadoop.hive.jdbc.HiveDriver", "jdbc:inceptor://localhost:port/databaseName")}); + jdbcMap.put("Oracle", new DriverURLName[]{new DriverURLName("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@localhost:port:databaseName")}); + jdbcMap.put("DB2", new DriverURLName[]{new DriverURLName("com.ibm.db2.jcc.DB2Driver", "jdbc:db2://localhost:port/databaseName")}); + jdbcMap.put("SQL Server", new DriverURLName[]{new DriverURLName("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://localhost:port;databaseName=databaseName")}); + jdbcMap.put("MySQL", new DriverURLName[]{new DriverURLName("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:port/databaseName"), + new DriverURLName("org.gjt.mm.mysql.Driver", "jdbc:mysql://localhost:port/databaseName")}); + jdbcMap.put("Sybase", new DriverURLName[]{new DriverURLName("com.sybase.jdbc2.jdbc.SybDriver", "jdbc:sybase:Tds:localhost:port/databaseName")}); + jdbcMap.put("Derby", new DriverURLName[]{new DriverURLName("org.apache.derby.jdbc.ClientDriver", "jdbc:derby://localhost:port/databaseName")}); + jdbcMap.put("Postgre", new DriverURLName[]{new DriverURLName("org.postgresql.Driver", "jdbc:postgresql://localhost:port/databaseName")}); + jdbcMap.put("Access", new DriverURLName[]{new DriverURLName("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=")}); - jdbcMap.put("Derby", new DriverURLName[]{new DriverURLName("org.apache.derby.jdbc.ClientDriver", "jdbc:derby://localhost:1527/")}); - jdbcMap.put("Postgre", new DriverURLName[]{new DriverURLName("org.postgresql.Driver", "jdbc:postgresql://localhost:5432/")}); jdbcMap.put("SQLite", new DriverURLName[]{new DriverURLName("org.sqlite.JDBC", "jdbc:sqlite://${ENV_HOME}/../help/FRDemo.db")}); } private UIButton dbtypeButton; private UIComboBox dbtypeComboBox; private UIComboBox driverComboBox; + private UITextField dbNameTextField; + private UITextField hostTextField; + private UITextField portTextField; private UITextField urlTextField; private UITextField userNameTextField; private JPasswordField passwordTextField; + private UIComboBox charSetComboBox; private ActionLabel odbcTipsLink; + private JPanel centerPanel; + private Component[][] allComponents; + private Component[][] partComponents; // 请不要改动dbtype,只应该最后添加 private final String[] dbtype = {"Oracle", "DB2", "SQL Server", "MySQL", "Sybase", "Access", "Derby", "Postgre", "SQLite", "Inceptor", OTHER_DB}; - // carl:DBCP的一些属性 - private IntegerEditor DBCP_INITIAL_SIZE = new IntegerEditor(); - private IntegerEditor DBCP_MAX_ACTIVE = new IntegerEditor(); - private IntegerEditor DBCP_MAX_IDLE = new IntegerEditor(); - private IntegerEditor DBCP_MIN_IDLE = new IntegerEditor(); - private IntegerEditor DBCP_MAX_WAIT = new IntegerEditor(); - private UITextField DBCP_VALIDATION_QUERY = new UITextField(); - - private UIComboBox DBCP_TESTONBORROW = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); - private UIComboBox DBCP_TESTONRETURN = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); - private UIComboBox DBCP_TESTWHILEIDLE = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); - - private IntegerEditor DBCP_TIMEBETWEENEVICTIONRUNSMILLS = new IntegerEditor(); - private IntegerEditor DBCP_NUMTESTSPEREVICTIONRUN = new IntegerEditor(); - private IntegerEditor DBCP_MINEVICTABLEIDLETIMEMILLIS = new IntegerEditor(); private JDBCDatabaseConnection jdbcDatabase; @@ -118,7 +116,14 @@ public class JDBCDefPane extends JPanel { driverComboBox = new UIComboBox(); driverComboBox.setEditable(true); driverComboBox.addActionListener(driverListener); + dbNameTextField = new UITextField(15); + hostTextField = new UITextField(15); + portTextField = new UITextField(15); + portTextField.addInputMethodListener(portInputMethodListener); + portTextField.addKeyListener(portKeyListener); urlTextField = new UITextField(15); + urlTextField.getDocument().addDocumentListener(updateParaListener); + enableSubDocListener(); userNameTextField = new UITextField(15); userNameTextField.setName(USER_NAME); passwordTextField = new UIPasswordFieldWithFixedLength(15); @@ -130,11 +135,10 @@ public class JDBCDefPane extends JPanel { double f = TableLayout.FILL; JPanel dbtypePane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); dbtypePane.add(new UILabel((Toolkit.i18nText("Fine-Design_Basic_Database") + ":"))); - JPanel dbtypeComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); Component[][] dbtypeComComponents = {{dbtypeComboBox}}; double[] dbtypeRowSize = {p}; double[] dbtypeColumnSize = {p}; - dbtypeComPane = TableLayoutHelper.createTableLayoutPane(dbtypeComComponents, dbtypeRowSize, dbtypeColumnSize); + JPanel dbtypeComPane = TableLayoutHelper.createTableLayoutPane(dbtypeComComponents, dbtypeRowSize, dbtypeColumnSize); JPanel driverPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); driverPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Driver") + ":")); @@ -161,43 +165,61 @@ public class JDBCDefPane extends JPanel { driverComboBoxAndTips.add(driverComboBox, BorderLayout.WEST); driverComboBoxAndTips.add(odbcTipsPane, BorderLayout.CENTER); + JPanel hostPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); + hostPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Host") + ":")); + Component[][] hostComComponents = {{hostTextField}}; + double[] hostRowSize = {p}; + double[] hostColumnSize = {p}; + JPanel hostComPane = TableLayoutHelper.createTableLayoutPane(hostComComponents, hostRowSize, hostColumnSize); + + JPanel portPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); + portPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Port") + ":")); + Component[][] portComComponents = {{portTextField}}; + double[] portRowSize = {p}; + double[] portColumnSize = {p}; + JPanel portComPane = TableLayoutHelper.createTableLayoutPane(portComComponents, portRowSize, portColumnSize); + + JPanel dbNamePane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); + dbNamePane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_DatabaseName") + ":")); + Component[][] dbNameComComponents = {{dbNameTextField}}; + double[] dbNameRowSize = {p}; + double[] dbNameColumnSize = {p}; + JPanel dbNameComPane = TableLayoutHelper.createTableLayoutPane(dbNameComComponents, dbNameRowSize, dbNameColumnSize); + JPanel urlPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); urlPane.add(new UILabel("URL:")); - JPanel urlComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); Component[][] urlComComponents = {{urlTextField, dbtypeButton}}; double[] urlRowSize = {p}; double[] urlColumnSize = {f, 21}; - urlComPane = TableLayoutHelper.createCommonTableLayoutPane(urlComComponents, urlRowSize, urlColumnSize, 4); + JPanel urlComPane = TableLayoutHelper.createCommonTableLayoutPane(urlComComponents, urlRowSize, urlColumnSize, 4); JPanel userPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); userPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_UserName") + ":")); - JPanel userComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); Component[][] userComComponents = {{userNameTextField, new UILabel(Toolkit.i18nText("Fine-Design_Basic_Password") + ":"), passwordTextField}}; double[] userRowSize = {p}; double[] userColumnSize = {f, p, f}; - userComPane = TableLayoutHelper.createCommonTableLayoutPane(userComComponents, userRowSize, userColumnSize, 4); - - JPanel passwordPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); - passwordPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Password") + ":")); - - Component[][] components = {{dbtypePane, dbtypeComPane}, {driverPane, driverComboBoxAndTips}, {urlPane, urlComPane}, {userPane, userComPane},}; - - double[] rowSize = {p, p, p, p}; + JPanel userComPane = TableLayoutHelper.createCommonTableLayoutPane(userComComponents, userRowSize, userColumnSize, 4); + + String[] defaultEncode = new String[]{Toolkit.i18nText("Fine-Design_Encode_Auto")}; + charSetComboBox = new UIComboBox(ArrayUtils.addAll(defaultEncode, EncodeConstants.ENCODING_ARRAY)); + JPanel chartSetPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); + chartSetPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Datasource_Charset") + ":")); + Component[][] charSetComComponents = {{charSetComboBox}}; + double[] charSetRowSize = {p}; + double[] charSetColumnSize = {f}; + JPanel charSetComPane = TableLayoutHelper.createTableLayoutPane(charSetComComponents, charSetRowSize, charSetColumnSize); + + //这边调整的话注意下面的changePane + allComponents = new Component[][]{{dbtypePane, dbtypeComPane}, {driverPane, driverComboBoxAndTips}, {hostPane, hostComPane}, + {portPane, portComPane}, {dbNamePane, dbNameComPane}, {userPane, userComPane}, + {chartSetPane, charSetComPane}, {urlPane, urlComPane}}; + partComponents = new Component[][]{{dbtypePane, dbtypeComPane}, {driverPane, driverComboBoxAndTips}, {urlPane, urlComPane}, + {userPane, userComPane}, {chartSetPane, charSetComPane}}; + double[] rowSize = {p, p, p, p, p, p, p, p}; double[] columnSize = {p, f, 22}; // REPORT-41450 Windows环境的jdk11下dpi为125%时会因为缩放导致显示问题,因此加个水平gap值 - JPanel centerPanel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 6, 6); + centerPanel = TableLayoutHelper.createGapTableLayoutPane(allComponents, rowSize, columnSize, 6, 6); innerthis.add(centerPanel); - JPanel southPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - innerthis.add(southPanel); - southPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 4, 20)); - ActionLabel actionLabel = new ActionLabel(Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr")); - southPanel.add(actionLabel, BorderLayout.EAST); - actionLabel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - JDialog wDialog = createJDialog(); - wDialog.setVisible(true); - } - }); } public void populate(JDBCDatabaseConnection jdbcDatabase) { @@ -231,29 +253,36 @@ public class JDBCDefPane extends JPanel { } } this.dbtypeComboBox.addActionListener(dbtypeActionListener); + this.dbtypeComboBox.setSelectedItem(this.dbtypeComboBox.getSelectedItem()); this.driverComboBox.setSelectedItem(jdbcDatabase.getDriver()); this.urlTextField.setText(jdbcDatabase.getURL()); this.userNameTextField.setText(jdbcDatabase.getUser()); this.passwordTextField.setText(jdbcDatabase.getPassword()); + this.originalCharSet = jdbcDatabase.getOriginalCharsetName(); + if (StringUtils.isBlank(originalCharSet)) { + this.charSetComboBox.setSelectedItem(Toolkit.i18nText("Fine-Design_Encode_Auto")); + } else { + this.charSetComboBox.setSelectedItem(jdbcDatabase.getOriginalCharsetName()); + } + } + + protected JDBCDatabaseConnection getJDBCDatabase() { + return this.jdbcDatabase; + } - DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); - if (dbcpAttr == null) { - dbcpAttr = new DBCPConnectionPoolAttr(); - jdbcDatabase.setDbcpAttr(dbcpAttr); - this.jdbcDatabase.setDbcpAttr(dbcpAttr); + private void changePane(Object dbType) { + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {p, f, 22}; + if (ComparatorUtils.equals(dbType, OTHER_DB) || ComparatorUtils.equals(dbType, "Access") || ComparatorUtils.equals(dbType, "SQLite")) { + if (this.centerPanel.getComponentCount() != partComponents.length * 2) { + centerPanel.removeAll(); + TableLayoutHelper.addComponent2ResultPane(partComponents, new double[]{p, p, p, p, p}, columnSize, centerPanel); + } + } else if (this.centerPanel.getComponentCount() != allComponents.length * 2) { + centerPanel.removeAll(); + TableLayoutHelper.addComponent2ResultPane(allComponents, new double[]{p, p, p, p, p, p, p, p}, columnSize, centerPanel); } - this.DBCP_INITIAL_SIZE.setValue(dbcpAttr.getInitialSize()); - this.DBCP_MAX_ACTIVE.setValue(dbcpAttr.getMaxActive()); - this.DBCP_MAX_IDLE.setValue(dbcpAttr.getMaxIdle()); - this.DBCP_MAX_WAIT.setValue(dbcpAttr.getMaxWait()); - this.DBCP_MIN_IDLE.setValue(dbcpAttr.getMinIdle()); - this.DBCP_VALIDATION_QUERY.setText(dbcpAttr.getValidationQuery()); - this.DBCP_TESTONBORROW.setSelectedIndex(dbcpAttr.isTestOnBorrow() ? 1 : 0); - this.DBCP_TESTONRETURN.setSelectedIndex(dbcpAttr.isTestOnReturn() ? 1 : 0); - this.DBCP_TESTWHILEIDLE.setSelectedIndex(dbcpAttr.isTestWhileIdle() ? 1 : 0); - this.DBCP_MINEVICTABLEIDLETIMEMILLIS.setValue(dbcpAttr.getMinEvictableIdleTimeMillis() / TIME_MULTIPLE); - this.DBCP_NUMTESTSPEREVICTIONRUN.setValue(dbcpAttr.getNumTestsPerEvictionRun()); - this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.setValue(dbcpAttr.getTimeBetweenEvictionRunsMillis()); } public JDBCDatabaseConnection update() { @@ -265,25 +294,14 @@ public class JDBCDefPane extends JPanel { jdbcDatabase.setURL(this.urlTextField.getText().trim()); jdbcDatabase.setUser(this.userNameTextField.getText().trim()); jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim()); - - DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); - if (dbcpAttr == null) { - dbcpAttr = new DBCPConnectionPoolAttr(); - jdbcDatabase.setDbcpAttr(dbcpAttr); + jdbcDatabase.setOriginalCharsetName(this.originalCharSet); + if (this.charSetComboBox.getSelectedIndex() == 0) { + jdbcDatabase.setNewCharsetName(null); + jdbcDatabase.setOriginalCharsetName(null); + } else { + jdbcDatabase.setNewCharsetName(EncodeConstants.ENCODING_GBK); + jdbcDatabase.setOriginalCharsetName(((String) this.charSetComboBox.getSelectedItem())); } - dbcpAttr.setInitialSize(this.DBCP_INITIAL_SIZE.getValue().intValue()); - dbcpAttr.setMaxActive(this.DBCP_MAX_ACTIVE.getValue().intValue()); - dbcpAttr.setMaxIdle(this.DBCP_MAX_IDLE.getValue().intValue()); - dbcpAttr.setMaxWait(this.DBCP_MAX_WAIT.getValue().intValue()); - dbcpAttr.setMinIdle(this.DBCP_MIN_IDLE.getValue().intValue()); - dbcpAttr.setValidationQuery(this.DBCP_VALIDATION_QUERY.getText()); - dbcpAttr.setTestOnBorrow(this.DBCP_TESTONBORROW.getSelectedIndex() == 0 ? false : true); - dbcpAttr.setTestOnReturn(this.DBCP_TESTONRETURN.getSelectedIndex() == 0 ? false : true); - dbcpAttr.setTestWhileIdle(this.DBCP_TESTWHILEIDLE.getSelectedIndex() == 0 ? false : true); - dbcpAttr.setMinEvictableIdleTimeMillis(((Number) this.DBCP_MINEVICTABLEIDLETIMEMILLIS.getValue()).intValue() * TIME_MULTIPLE); - dbcpAttr.setNumTestsPerEvictionRun(((Number) this.DBCP_NUMTESTSPEREVICTIONRUN.getValue()).intValue()); - dbcpAttr.setTimeBetweenEvictionRunsMillis(((Number) this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.getValue()).intValue()); - return jdbcDatabase; } @@ -307,6 +325,7 @@ public class JDBCDefPane extends JPanel { } // 更改数据库类型后 数据库名称置空和之前逻辑保持一致 jdbcDatabase.setDatabase(StringUtils.EMPTY); + changePane(dbtypeComboBox.getSelectedItem()); } }; @@ -365,49 +384,154 @@ public class JDBCDefPane extends JPanel { } }; - private JDialog createJDialog() { - return new DBCPAttrPane().showWindow(SwingUtilities.getWindowAncestor(JDBCDefPane.this)); + InputMethodListener portInputMethodListener = new InputMethodListener() { + @Override + public void inputMethodTextChanged(InputMethodEvent event) { + char ch = event.getText().current(); + if (!(ch >= '0' && ch <= '9')) { + event.consume(); + } + } + + @Override + public void caretPositionChanged(InputMethodEvent event) { + + } + }; + + DocumentListener updateParaListener = new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + updatePara(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + updatePara(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + updatePara(); + } + }; + + private void updatePara() { + String dbType = dbtypeComboBox.getSelectedItem().toString(); + if (ComparatorUtils.equals(dbType, OTHER_DB) || ComparatorUtils.equals(dbType, "Access") || ComparatorUtils.equals(dbType, "SQLite")) { + return; + } + disableSubDocListener(); + String url = urlTextField.getText().trim(); + Matcher matcher = ORACLE_URL.matcher(url); + if (matcher.find()) { + if (matcher.group(1) != null) { + hostTextField.setText(matcher.group(1)); + } else { + hostTextField.setText(StringUtils.EMPTY); + } + if (matcher.group(3) != null) { + portTextField.setText(matcher.group(3)); + } else { + portTextField.setText(StringUtils.EMPTY); + } + if (matcher.group(5) != null) { + dbNameTextField.setText(matcher.group(5)); + } else { + dbNameTextField.setText(StringUtils.EMPTY); + } + enableSubDocListener(); + return; + } + matcher = GENERAL_URL.matcher(url); + if (matcher.find()) { + if (matcher.group(2) != null) { + hostTextField.setText(matcher.group(2)); + } else { + hostTextField.setText(StringUtils.EMPTY); + } + if (matcher.group(4) != null) { + portTextField.setText(matcher.group(4)); + } else { + portTextField.setText(StringUtils.EMPTY); + } + if (matcher.group(7) != null) { + dbNameTextField.setText(matcher.group(7)); + } else { + dbNameTextField.setText(StringUtils.EMPTY); + } + enableSubDocListener(); + } + } + + private void enableSubDocListener() { + this.dbNameTextField.getDocument().addDocumentListener(updateURLListener); + this.hostTextField.getDocument().addDocumentListener(updateURLListener); + } + + private void disableSubDocListener() { + this.dbNameTextField.getDocument().removeDocumentListener(updateURLListener); + this.hostTextField.getDocument().removeDocumentListener(updateURLListener); + } + + KeyListener portKeyListener = new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + String port = portTextField.getText().trim(); + if (isPortValid(port)) { + updateURL(); + } else { + portTextField.setText(port.replaceAll(e.getKeyChar() + "", "")); + } + } + }; + + private boolean isPortValid(String port) { + return PORT.matcher(port).find(); } - class DBCPAttrPane extends BasicPane { - public DBCPAttrPane() { - JPanel defaultPane = this; - - // JPanel northFlowPane - JPanel northFlowPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); - defaultPane.add(northFlowPane, BorderLayout.NORTH); - - DBCP_VALIDATION_QUERY.setColumns(15); - // ContextPane - - double f = TableLayout.FILL; - // double p = TableLayout.PREFERRED; - double[] rowSize = {f, f, f, f, f, f, f, f, f, f, f, f}; - double[] columnSize = {f, f}; - Component[][] comps = { - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Initial_Size") + ":", SwingConstants.RIGHT), DBCP_INITIAL_SIZE}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Idle") + ":", SwingConstants.RIGHT), DBCP_MAX_IDLE}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Min_Idle") + ":", SwingConstants.RIGHT), DBCP_MIN_IDLE}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Max_Wait_Time") + ":", SwingConstants.RIGHT), DBCP_MAX_WAIT}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Borrow") + ":", SwingConstants.RIGHT), DBCP_TESTONBORROW}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Return") + ":", SwingConstants.RIGHT), DBCP_TESTONRETURN}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_While_Idle") + ":", SwingConstants.RIGHT), DBCP_TESTWHILEIDLE}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Evictionruns_millis") + ":", SwingConstants.RIGHT), - DBCP_TIMEBETWEENEVICTIONRUNSMILLS}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Num_Test_Per_Evction_Run") + ":", SwingConstants.RIGHT), DBCP_NUMTESTSPEREVICTIONRUN}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Mix_Evictable_Idle_Time_Millis") + ":", SwingConstants.RIGHT), - DBCP_MINEVICTABLEIDLETIMEMILLIS}}; - - JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSize, columnSize, 10, 4); - contextPane.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, UIConstants.LINE_COLOR)); - northFlowPane.add(contextPane); + DocumentListener updateURLListener = new DocumentListener() { + + @Override + public void insertUpdate(DocumentEvent e) { + updateURL(); } @Override - protected String title4PopupWindow() { - return Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr"); + public void removeUpdate(DocumentEvent e) { + updateURL(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + updateURL(); + } + }; + + private void updateURL() { + String dbType = dbtypeComboBox.getSelectedItem().toString(); + if (!ComparatorUtils.equals(dbType, OTHER_DB) && !ComparatorUtils.equals(dbType, "Access") && !ComparatorUtils.equals(dbType, "SQLite")) { + urlTextField.getDocument().removeDocumentListener(updateParaListener); + DriverURLName[] driverURLNames = jdbcMap.get(dbType); + String defaultURL = null; + for (DriverURLName driverURLName : driverURLNames) { + if (ComparatorUtils.equals(driverURLName.getDriver(), driverComboBox.getSelectedItem().toString())) { + defaultURL = driverURLName.getURL(); + } + } + if (defaultURL != null) { + String host = hostTextField.getText().trim(); + String port = portTextField.getText().trim(); + String dbName = dbNameTextField.getText().trim(); + defaultURL = defaultURL.replace("localhost", host).replace(":port", ComparatorUtils.equals(port, "") ? "" : ":" + port); + if (defaultURL.startsWith("jdbc:sqlserver")) { + defaultURL = defaultURL.replace("=databaseName", "=" + dbName); + } else { + defaultURL = defaultURL.replace("databaseName", dbName); + } + } + urlTextField.setText(defaultURL); + urlTextField.getDocument().addDocumentListener(updateParaListener); } } diff --git a/designer-base/src/main/java/com/fr/design/layout/TableLayoutHelper.java b/designer-base/src/main/java/com/fr/design/layout/TableLayoutHelper.java index d394f43ee7..e664524026 100644 --- a/designer-base/src/main/java/com/fr/design/layout/TableLayoutHelper.java +++ b/designer-base/src/main/java/com/fr/design/layout/TableLayoutHelper.java @@ -233,7 +233,7 @@ public class TableLayoutHelper { container.repaint(); } - private static void addComponent2ResultPane(Component[][] components, double[] rowSize, double[] columnSize, JPanel resultPane) { + public static void addComponent2ResultPane(Component[][] components, double[] rowSize, double[] columnSize, JPanel resultPane) { for (int i = 0; i < components.length; i++) { if (i >= rowSize.length) {