Browse Source

REPORT-33236

feature/big-screen
Jimmy.Zheng 4 years ago
parent
commit
57662d4bfb
  1. 719
      designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java

719
designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java

@ -1,5 +1,6 @@
package com.fr.design.data.datapane.connect; package com.fr.design.data.datapane.connect;
import com.fr.base.GraphHelper;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.pool.DBCPConnectionPoolAttr; import com.fr.data.pool.DBCPConnectionPoolAttr;
@ -16,7 +17,9 @@ import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.editor.editor.IntegerEditor; import com.fr.design.editor.editor.IntegerEditor;
import com.fr.design.utils.BrowseUtils;
import com.fr.file.filter.ChooseFileFilter; import com.fr.file.filter.ChooseFileFilter;
import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -32,351 +35,375 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public class JDBCDefPane extends JPanel { public class JDBCDefPane extends JPanel {
public static final String DRIVER_TYPE = "driver_type"; public static final String DRIVER_TYPE = "driver_type";
public static final String USER_NAME = "user_name"; public static final String USER_NAME = "user_name";
public static final int TIME_MULTIPLE = 1000; public static final int TIME_MULTIPLE = 1000;
private static final String OTHER_DB = "Others"; private static final String OTHER_DB = "Others";
private static Map<String, DriverURLName[]> jdbcMap = new HashMap<String, DriverURLName[]>(); private static Map<String, DriverURLName[]> jdbcMap = new HashMap<String, DriverURLName[]>();
static { static {
jdbcMap.put(OTHER_DB, new DriverURLName[]{new DriverURLName("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:"), jdbcMap.put(OTHER_DB, new DriverURLName[]{new DriverURLName("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:"),
new DriverURLName("org.hsqldb.jdbcDriver", "jdbc:hsqldb:file:[PATH_TO_DB_FILES]"), new DriverURLName("com.inet.tds.TdsDriver", "jdbc:inetdae7:localhost:1433/"), new DriverURLName("org.hsqldb.jdbcDriver", "jdbc:hsqldb:file:[PATH_TO_DB_FILES]"), new DriverURLName("com.inet.tds.TdsDriver", "jdbc:inetdae7:localhost:1433/"),
new DriverURLName("COM.cloudscape.JDBCDriver", "jdbc:cloudscape:/cloudscape/"), new DriverURLName("COM.cloudscape.JDBCDriver", "jdbc:cloudscape:/cloudscape/"),
new DriverURLName("com.internetcds.jdbc.tds.Driver", "jdbc:freetds:sqlserver://localhost/"), new DriverURLName("com.internetcds.jdbc.tds.Driver", "jdbc:freetds:sqlserver://localhost/"),
new DriverURLName("com.fr.swift.jdbc.Driver", "jdbc:swift:emb://default")}); 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"), 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")}); 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("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("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("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/"), jdbcMap.put("MySQL", new DriverURLName[]{new DriverURLName("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/"),
new DriverURLName("org.gjt.mm.mysql.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("Sybase", new DriverURLName[]{new DriverURLName("com.sybase.jdbc2.jdbc.SybDriver", "jdbc:sybase:Tds:localhost:5000/")});
jdbcMap.put("Access", new DriverURLName[]{new DriverURLName("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=")}); 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("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("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")}); jdbcMap.put("SQLite", new DriverURLName[]{new DriverURLName("org.sqlite.JDBC", "jdbc:sqlite://${ENV_HOME}/../help/FRDemo.db")});
} }
private UIButton dbtypeButton; private UIButton dbtypeButton;
private UIComboBox dbtypeComboBox; private UIComboBox dbtypeComboBox;
private UIComboBox driverComboBox; private UIComboBox driverComboBox;
private UITextField urlTextField; private UITextField urlTextField;
private UITextField userNameTextField; private UITextField userNameTextField;
private JPasswordField passwordTextField; private JPasswordField passwordTextField;
// 请不要改动dbtype,只应该最后添加 private ActionLabel odbcTipsLink;
private final String[] dbtype = {"Oracle", "DB2", "SQL Server", "MySQL", "Sybase", "Access", "Derby", "Postgre","SQLite","Inceptor", OTHER_DB}; // 请不要改动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(); // carl:DBCP的一些属性
private IntegerEditor DBCP_MAX_ACTIVE = new IntegerEditor(); private IntegerEditor DBCP_INITIAL_SIZE = new IntegerEditor();
private IntegerEditor DBCP_MAX_IDLE = new IntegerEditor(); private IntegerEditor DBCP_MAX_ACTIVE = new IntegerEditor();
private IntegerEditor DBCP_MIN_IDLE = new IntegerEditor(); private IntegerEditor DBCP_MAX_IDLE = new IntegerEditor();
private IntegerEditor DBCP_MAX_WAIT = new IntegerEditor(); private IntegerEditor DBCP_MIN_IDLE = new IntegerEditor();
private UITextField DBCP_VALIDATION_QUERY = new UITextField(); private IntegerEditor DBCP_MAX_WAIT = new IntegerEditor();
private UITextField DBCP_VALIDATION_QUERY = new UITextField();
private UIComboBox DBCP_TESTONBORROW = new UIComboBox(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_No"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes")});
private UIComboBox DBCP_TESTONRETURN = new UIComboBox(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_No"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes")}); private UIComboBox DBCP_TESTONBORROW = new UIComboBox(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_No"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes")});
private UIComboBox DBCP_TESTWHILEIDLE = new UIComboBox(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_No"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes")}); private UIComboBox DBCP_TESTONRETURN = new UIComboBox(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_No"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes")});
private UIComboBox DBCP_TESTWHILEIDLE = new UIComboBox(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_No"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes")});
private IntegerEditor DBCP_TIMEBETWEENEVICTIONRUNSMILLS = new IntegerEditor();
private IntegerEditor DBCP_NUMTESTSPEREVICTIONRUN = new IntegerEditor(); private IntegerEditor DBCP_TIMEBETWEENEVICTIONRUNSMILLS = new IntegerEditor();
private IntegerEditor DBCP_MINEVICTABLEIDLETIMEMILLIS = new IntegerEditor(); private IntegerEditor DBCP_NUMTESTSPEREVICTIONRUN = new IntegerEditor();
private IntegerEditor DBCP_MINEVICTABLEIDLETIMEMILLIS = new IntegerEditor();
public JDBCDefPane() {
this.setBorder(UITitledBorder.createBorderWithTitle("JDBC" + ":")); public JDBCDefPane() {
this.setLayout(FRGUIPaneFactory.createLabelFlowLayout()); this.setBorder(UITitledBorder.createBorderWithTitle("JDBC" + ":"));
JPanel innerthis = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); this.setLayout(FRGUIPaneFactory.createLabelFlowLayout());
innerthis.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); JPanel innerthis = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane();
this.add(innerthis); innerthis.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
dbtypeComboBox = new UIComboBox(); this.add(innerthis);
dbtypeComboBox.setName(DRIVER_TYPE); dbtypeComboBox = new UIComboBox();
for (int i = 0; i < dbtype.length; i++) { dbtypeComboBox.setName(DRIVER_TYPE);
dbtypeComboBox.addItem(dbtype[i]); for (int i = 0; i < dbtype.length; i++) {
} dbtypeComboBox.addItem(dbtype[i]);
dbtypeComboBox.addActionListener(dbtypeActionListener); }
dbtypeComboBox.setMaximumRowCount(10); dbtypeComboBox.addActionListener(dbtypeActionListener);
dbtypeComboBox.setMaximumRowCount(10);
driverComboBox = new UIComboBox();
driverComboBox.setEditable(true); driverComboBox = new UIComboBox();
driverComboBox.addActionListener(driverListener); driverComboBox.setEditable(true);
urlTextField = new UITextField(15); driverComboBox.addActionListener(driverListener);
userNameTextField = new UITextField(15); urlTextField = new UITextField(15);
userNameTextField.setName(USER_NAME); userNameTextField = new UITextField(15);
passwordTextField = new UIPassWordField(15); userNameTextField.setName(USER_NAME);
dbtypeButton = new UIButton("."); passwordTextField = new UIPassWordField(15);
dbtypeButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Click_Get_Default_URL")); dbtypeButton = new UIButton(".");
dbtypeButton.addActionListener(dbtypeButtonActionListener); dbtypeButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Click_Get_Default_URL"));
dbtypeButton.addActionListener(dbtypeButtonActionListener);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL; double p = TableLayout.PREFERRED;
JPanel dbtypePane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); double f = TableLayout.FILL;
dbtypePane.add(new UILabel((com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Database") + ":"))); JPanel dbtypePane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
JPanel dbtypeComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); dbtypePane.add(new UILabel((com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Database") + ":")));
Component[][] dbtypeComComponents = {{dbtypeComboBox}}; JPanel dbtypeComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
double[] dbtypeRowSize = {p}; Component[][] dbtypeComComponents = {{dbtypeComboBox}};
double[] dbtypeColumnSize = {p}; double[] dbtypeRowSize = {p};
dbtypeComPane = TableLayoutHelper.createTableLayoutPane(dbtypeComComponents, dbtypeRowSize, dbtypeColumnSize); double[] dbtypeColumnSize = {p};
dbtypeComPane = TableLayoutHelper.createTableLayoutPane(dbtypeComComponents, dbtypeRowSize, dbtypeColumnSize);
JPanel driverPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
driverPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Driver") + ":")); JPanel driverPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
driverPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Driver") + ":"));
JPanel urlPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); // 选择ODBC数据源的时候的提示链接
urlPane.add(new UILabel("URL:")); JPanel odbcTipsPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
JPanel urlComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); odbcTipsLink = new ActionLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Odbc_Tips")) {
Component[][] urlComComponents = {{urlTextField, dbtypeButton}}; @Override
double[] urlRowSize = {p}; public void paintComponent(Graphics _gfx) {
double[] urlColumnSize = {f, 21}; super.paintComponent(_gfx);
urlComPane = TableLayoutHelper.createCommonTableLayoutPane(urlComComponents, urlRowSize, urlColumnSize, 4); _gfx.setColor(Color.blue);
_gfx.drawLine(0, this.getHeight() - 1, GraphHelper.getWidth(this.getText()), this.getHeight() - 1);
JPanel userPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); }
userPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_UserName") + ":")); };
JPanel userComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); odbcTipsPane.add(odbcTipsLink);
Component[][] userComComponents = {{userNameTextField, new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Password") + ":"), passwordTextField}}; odbcTipsLink.setPreferredSize(new Dimension(GraphHelper.getWidth(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Odbc_Tips")), odbcTipsLink.getPreferredSize().height));
double[] userRowSize = {p}; odbcTipsLink.addActionListener(new ActionListener() {
double[] userColumnSize = {f, p, f}; public void actionPerformed(ActionEvent evt) {
userComPane = TableLayoutHelper.createCommonTableLayoutPane(userComComponents, userRowSize, userColumnSize, 4); String url = CloudCenter.getInstance().acquireUrlByKind("odbc.help");
BrowseUtils.browser(url);
JPanel passwordPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); }
passwordPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Password") + ":")); });
Component[][] components = {{dbtypePane, dbtypeComPane}, {driverPane, driverComboBox}, {urlPane, urlComPane}, {userPane, userComPane},}; JPanel driverComboBoxAndTips = new JPanel(new BorderLayout());
driverComboBoxAndTips.add(driverComboBox, BorderLayout.WEST);
double[] rowSize = {p, p, p, p}; driverComboBoxAndTips.add(odbcTipsPane, BorderLayout.CENTER);
double[] columnSize = {p, f, 22};
JPanel centerPanel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 0, 6); JPanel urlPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
innerthis.add(centerPanel); urlPane.add(new UILabel("URL:"));
JPanel southPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel urlComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
innerthis.add(southPanel); Component[][] urlComComponents = {{urlTextField, dbtypeButton}};
southPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 4, 20)); double[] urlRowSize = {p};
ActionLabel actionLabel = new ActionLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr")); double[] urlColumnSize = {f, 21};
southPanel.add(actionLabel, BorderLayout.EAST); urlComPane = TableLayoutHelper.createCommonTableLayoutPane(urlComComponents, urlRowSize, urlColumnSize, 4);
actionLabel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) { JPanel userPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
JDialog wDialog = createJDialog(); userPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_UserName") + ":"));
wDialog.setVisible(true); JPanel userComPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
} Component[][] userComComponents = {{userNameTextField, new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Password") + ":"), passwordTextField}};
}); double[] userRowSize = {p};
} double[] userColumnSize = {f, p, f};
userComPane = TableLayoutHelper.createCommonTableLayoutPane(userComComponents, userRowSize, userColumnSize, 4);
public void populate(JDBCDatabaseConnection jdbcDatabase) {
if (jdbcDatabase == null) { JPanel passwordPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
jdbcDatabase = new JDBCDatabaseConnection(); passwordPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Password") + ":"));
}
if (ComparatorUtils.equals(jdbcDatabase.getDriver(), "sun.jdbc.odbc.JdbcOdbcDriver") Component[][] components = {{dbtypePane, dbtypeComPane}, {driverPane, driverComboBoxAndTips}, {urlPane, urlComPane}, {userPane, userComPane},};
&& jdbcDatabase.getURL().startsWith("jdbc:odbc:Driver={Microsoft")) {
this.dbtypeComboBox.setSelectedItem("Access"); double[] rowSize = {p, p, p, p};
} else { double[] columnSize = {p, f, 22};
Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator(); JPanel centerPanel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 0, 6);
boolean out = false; innerthis.add(centerPanel);
while (jdbc.hasNext()) { JPanel southPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
Entry<String, DriverURLName[]> entry = jdbc.next(); innerthis.add(southPanel);
DriverURLName[] dus = entry.getValue(); southPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 4, 20));
for (int i = 0, len = dus.length; i < len; i++) { ActionLabel actionLabel = new ActionLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr"));
if (ComparatorUtils.equals(dus[i].getDriver(), jdbcDatabase.getDriver())) { southPanel.add(actionLabel, BorderLayout.EAST);
this.dbtypeComboBox.setSelectedItem(entry.getKey()); actionLabel.addActionListener(new ActionListener() {
out = true; public void actionPerformed(ActionEvent evt) {
break; JDialog wDialog = createJDialog();
} wDialog.setVisible(true);
} }
if (out) { });
break; }
}
} public void populate(JDBCDatabaseConnection jdbcDatabase) {
if (!out) { if (jdbcDatabase == null) {
this.dbtypeComboBox.setSelectedItem(OTHER_DB); jdbcDatabase = new JDBCDatabaseConnection();
} }
} if (ComparatorUtils.equals(jdbcDatabase.getDriver(), "sun.jdbc.odbc.JdbcOdbcDriver")
this.driverComboBox.setSelectedItem(jdbcDatabase.getDriver()); && jdbcDatabase.getURL().startsWith("jdbc:odbc:Driver={Microsoft")) {
this.urlTextField.setText(jdbcDatabase.getURL()); this.dbtypeComboBox.setSelectedItem("Access");
this.userNameTextField.setText(jdbcDatabase.getUser()); } else {
this.passwordTextField.setText(jdbcDatabase.getPassword()); Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator();
boolean out = false;
DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); while (jdbc.hasNext()) {
if (dbcpAttr == null) { Entry<String, DriverURLName[]> entry = jdbc.next();
dbcpAttr = new DBCPConnectionPoolAttr(); DriverURLName[] dus = entry.getValue();
jdbcDatabase.setDbcpAttr(dbcpAttr); for (int i = 0, len = dus.length; i < len; i++) {
} if (ComparatorUtils.equals(dus[i].getDriver(), jdbcDatabase.getDriver())) {
this.DBCP_INITIAL_SIZE.setValue(dbcpAttr.getInitialSize()); this.dbtypeComboBox.setSelectedItem(entry.getKey());
this.DBCP_MAX_ACTIVE.setValue(dbcpAttr.getMaxActive()); out = true;
this.DBCP_MAX_IDLE.setValue(dbcpAttr.getMaxIdle()); break;
this.DBCP_MAX_WAIT.setValue(dbcpAttr.getMaxWait()); }
this.DBCP_MIN_IDLE.setValue(dbcpAttr.getMinIdle()); }
this.DBCP_VALIDATION_QUERY.setText(dbcpAttr.getValidationQuery()); if (out) {
this.DBCP_TESTONBORROW.setSelectedIndex(dbcpAttr.isTestOnBorrow() ? 1 : 0); break;
this.DBCP_TESTONRETURN.setSelectedIndex(dbcpAttr.isTestOnReturn() ? 1 : 0); }
this.DBCP_TESTWHILEIDLE.setSelectedIndex(dbcpAttr.isTestWhileIdle() ? 1 : 0); }
this.DBCP_MINEVICTABLEIDLETIMEMILLIS.setValue(dbcpAttr.getMinEvictableIdleTimeMillis() / TIME_MULTIPLE); if (!out) {
this.DBCP_NUMTESTSPEREVICTIONRUN.setValue(dbcpAttr.getNumTestsPerEvictionRun()); this.dbtypeComboBox.setSelectedItem(OTHER_DB);
this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.setValue(dbcpAttr.getTimeBetweenEvictionRunsMillis()); }
} }
this.driverComboBox.setSelectedItem(jdbcDatabase.getDriver());
public JDBCDatabaseConnection update() { this.urlTextField.setText(jdbcDatabase.getURL());
JDBCDatabaseConnection jdbcDatabase = new JDBCDatabaseConnection(); this.userNameTextField.setText(jdbcDatabase.getUser());
Object driveItem = this.driverComboBox.getSelectedItem(); this.passwordTextField.setText(jdbcDatabase.getPassword());
jdbcDatabase.setDriver(driveItem == null ? null : driveItem.toString());
jdbcDatabase.setURL(this.urlTextField.getText().trim()); DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr();
jdbcDatabase.setUser(this.userNameTextField.getText().trim()); if (dbcpAttr == null) {
jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim()); dbcpAttr = new DBCPConnectionPoolAttr();
jdbcDatabase.setDbcpAttr(dbcpAttr);
DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); }
if (dbcpAttr == null) { this.DBCP_INITIAL_SIZE.setValue(dbcpAttr.getInitialSize());
dbcpAttr = new DBCPConnectionPoolAttr(); this.DBCP_MAX_ACTIVE.setValue(dbcpAttr.getMaxActive());
jdbcDatabase.setDbcpAttr(dbcpAttr); this.DBCP_MAX_IDLE.setValue(dbcpAttr.getMaxIdle());
} this.DBCP_MAX_WAIT.setValue(dbcpAttr.getMaxWait());
dbcpAttr.setInitialSize(this.DBCP_INITIAL_SIZE.getValue().intValue()); this.DBCP_MIN_IDLE.setValue(dbcpAttr.getMinIdle());
dbcpAttr.setMaxActive(this.DBCP_MAX_ACTIVE.getValue().intValue()); this.DBCP_VALIDATION_QUERY.setText(dbcpAttr.getValidationQuery());
dbcpAttr.setMaxIdle(this.DBCP_MAX_IDLE.getValue().intValue()); this.DBCP_TESTONBORROW.setSelectedIndex(dbcpAttr.isTestOnBorrow() ? 1 : 0);
dbcpAttr.setMaxWait(this.DBCP_MAX_WAIT.getValue().intValue()); this.DBCP_TESTONRETURN.setSelectedIndex(dbcpAttr.isTestOnReturn() ? 1 : 0);
dbcpAttr.setMinIdle(this.DBCP_MIN_IDLE.getValue().intValue()); this.DBCP_TESTWHILEIDLE.setSelectedIndex(dbcpAttr.isTestWhileIdle() ? 1 : 0);
dbcpAttr.setValidationQuery(this.DBCP_VALIDATION_QUERY.getText()); this.DBCP_MINEVICTABLEIDLETIMEMILLIS.setValue(dbcpAttr.getMinEvictableIdleTimeMillis() / TIME_MULTIPLE);
dbcpAttr.setTestOnBorrow(this.DBCP_TESTONBORROW.getSelectedIndex() == 0 ? false : true); this.DBCP_NUMTESTSPEREVICTIONRUN.setValue(dbcpAttr.getNumTestsPerEvictionRun());
dbcpAttr.setTestOnReturn(this.DBCP_TESTONRETURN.getSelectedIndex() == 0 ? false : true); this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.setValue(dbcpAttr.getTimeBetweenEvictionRunsMillis());
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()); public JDBCDatabaseConnection update() {
dbcpAttr.setTimeBetweenEvictionRunsMillis(((Number) this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.getValue()).intValue()); JDBCDatabaseConnection jdbcDatabase = new JDBCDatabaseConnection();
Object driveItem = this.driverComboBox.getSelectedItem();
return jdbcDatabase; jdbcDatabase.setDriver(driveItem == null ? null : driveItem.toString());
} jdbcDatabase.setURL(this.urlTextField.getText().trim());
jdbcDatabase.setUser(this.userNameTextField.getText().trim());
ActionListener dbtypeActionListener = new ActionListener() { jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim());
public void actionPerformed(ActionEvent evt) {
DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr();
urlTextField.setText(StringUtils.EMPTY); if (dbcpAttr == null) {
driverComboBox.removeAllItems(); dbcpAttr = new DBCPConnectionPoolAttr();
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) { jdbcDatabase.setDbcpAttr(dbcpAttr);
driverComboBox.setSelectedItem(StringUtils.EMPTY); }
return; dbcpAttr.setInitialSize(this.DBCP_INITIAL_SIZE.getValue().intValue());
} dbcpAttr.setMaxActive(this.DBCP_MAX_ACTIVE.getValue().intValue());
dbcpAttr.setMaxIdle(this.DBCP_MAX_IDLE.getValue().intValue());
DriverURLName[] dus = jdbcMap.get(dbtypeComboBox.getSelectedItem()); dbcpAttr.setMaxWait(this.DBCP_MAX_WAIT.getValue().intValue());
for (int i = 0, len = dus.length; i < len; i++) { dbcpAttr.setMinIdle(this.DBCP_MIN_IDLE.getValue().intValue());
driverComboBox.addItem(dus[i].getDriver()); dbcpAttr.setValidationQuery(this.DBCP_VALIDATION_QUERY.getText());
if (i == 0) { dbcpAttr.setTestOnBorrow(this.DBCP_TESTONBORROW.getSelectedIndex() == 0 ? false : true);
driverComboBox.setSelectedItem(dus[i].getDriver()); dbcpAttr.setTestOnReturn(this.DBCP_TESTONRETURN.getSelectedIndex() == 0 ? false : true);
urlTextField.setText(dus[i].getURL()); 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;
ActionListener driverListener = new ActionListener() { }
public void actionPerformed(ActionEvent e) {
if (driverComboBox.getSelectedItem() == null ||ComparatorUtils.equals(driverComboBox.getSelectedItem(), StringUtils.EMPTY)) { ActionListener dbtypeActionListener = new ActionListener() {
return; public void actionPerformed(ActionEvent evt) {
}
Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator(); urlTextField.setText(StringUtils.EMPTY);
while (jdbc.hasNext()) { driverComboBox.removeAllItems();
Entry<String, DriverURLName[]> entry = jdbc.next(); if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) {
DriverURLName[] dus = entry.getValue(); driverComboBox.setSelectedItem(StringUtils.EMPTY);
for (int i = 0, len = dus.length; i < len; i++) { return;
if (ComparatorUtils.equals(dus[i].getDriver(), (driverComboBox.getSelectedItem()))) { }
urlTextField.setText(dus[i].getURL());
return; DriverURLName[] dus = jdbcMap.get(dbtypeComboBox.getSelectedItem());
} for (int i = 0, len = dus.length; i < len; i++) {
} driverComboBox.addItem(dus[i].getDriver());
} if (i == 0) {
} driverComboBox.setSelectedItem(dus[i].getDriver());
urlTextField.setText(dus[i].getURL());
}; }
}
ActionListener dbtypeButtonActionListener = new ActionListener() { }
public void actionPerformed(ActionEvent evt) { };
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) {
return; ActionListener driverListener = new ActionListener() {
} public void actionPerformed(ActionEvent e) {
DriverURLName[] dus = jdbcMap.get(dbtypeComboBox.getSelectedItem()); if (driverComboBox.getSelectedItem() == null || ComparatorUtils.equals(driverComboBox.getSelectedItem(), StringUtils.EMPTY)) {
for (int i = 0, len = dus.length; i < len; i++) { return;
if (ComparatorUtils.equals(driverComboBox.getSelectedItem(), (dus[i].getDriver()))) { }
urlTextField.setText(dus[i].getURL()); odbcTipsLink.setVisible(ComparatorUtils.equals("sun.jdbc.odbc.JdbcOdbcDriver", driverComboBox.getSelectedItem())); // 选择的如果是ODBC就显示提示
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), ("Access"))) { Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator();
// ben:这个能不能换种处理方案- - while (jdbc.hasNext()) {
JFileChooser filechooser = new JFileChooser(); Entry<String, DriverURLName[]> entry = jdbc.next();
filechooser.setDialogTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Open")); DriverURLName[] dus = entry.getValue();
filechooser.setMultiSelectionEnabled(false); for (int i = 0, len = dus.length; i < len; i++) {
filechooser.addChoosableFileFilter(new ChooseFileFilter(new String[]{"accdb", "mdb"}, "Microsoft Office Access")); if (ComparatorUtils.equals(dus[i].getDriver(), (driverComboBox.getSelectedItem()))) {
int result = filechooser.showOpenDialog(DesignerContext.getDesignerFrame()); urlTextField.setText(dus[i].getURL());
File selectedfile = null; return;
}
if (result == JFileChooser.APPROVE_OPTION) { }
selectedfile = filechooser.getSelectedFile(); }
if (selectedfile != null) { }
String selectedName = selectedfile.getPath().substring(selectedfile.getPath().lastIndexOf('.') + 1);
if (selectedName.equalsIgnoreCase("mdb") || selectedName.equalsIgnoreCase("accdb")) { };
urlTextField.setText(urlTextField.getText() + selectedfile.getPath());
} ActionListener dbtypeButtonActionListener = new ActionListener() {
} public void actionPerformed(ActionEvent evt) {
} if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) {
} return;
break; }
} DriverURLName[] dus = jdbcMap.get(dbtypeComboBox.getSelectedItem());
} for (int i = 0, len = dus.length; i < len; i++) {
} if (ComparatorUtils.equals(driverComboBox.getSelectedItem(), (dus[i].getDriver()))) {
}; urlTextField.setText(dus[i].getURL());
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), ("Access"))) {
private JDialog createJDialog() { // ben:这个能不能换种处理方案- -
return new DBCPAttrPane().showWindow(SwingUtilities.getWindowAncestor(JDBCDefPane.this)); JFileChooser filechooser = new JFileChooser();
} filechooser.setDialogTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Open"));
filechooser.setMultiSelectionEnabled(false);
class DBCPAttrPane extends BasicPane { filechooser.addChoosableFileFilter(new ChooseFileFilter(new String[]{"accdb", "mdb"}, "Microsoft Office Access"));
public DBCPAttrPane() { int result = filechooser.showOpenDialog(DesignerContext.getDesignerFrame());
JPanel defaultPane = this; File selectedfile = null;
// JPanel northFlowPane if (result == JFileChooser.APPROVE_OPTION) {
JPanel northFlowPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); selectedfile = filechooser.getSelectedFile();
defaultPane.add(northFlowPane, BorderLayout.NORTH); if (selectedfile != null) {
String selectedName = selectedfile.getPath().substring(selectedfile.getPath().lastIndexOf('.') + 1);
DBCP_VALIDATION_QUERY.setColumns(15); if (selectedName.equalsIgnoreCase("mdb") || selectedName.equalsIgnoreCase("accdb")) {
// ContextPane urlTextField.setText(urlTextField.getText() + selectedfile.getPath());
}
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}; break;
Component[][] comps = { }
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Initial_Size") + ":", SwingConstants.RIGHT), DBCP_INITIAL_SIZE}, }
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE}, }
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Idle") + ":", SwingConstants.RIGHT), DBCP_MAX_IDLE}, };
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Min_Idle") + ":", SwingConstants.RIGHT), DBCP_MIN_IDLE},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Max_Wait_Time") + ":" , SwingConstants.RIGHT), DBCP_MAX_WAIT}, private JDialog createJDialog() {
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY}, return new DBCPAttrPane().showWindow(SwingUtilities.getWindowAncestor(JDBCDefPane.this));
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Borrow") + ":", SwingConstants.RIGHT), DBCP_TESTONBORROW}, }
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Return") + ":", SwingConstants.RIGHT), DBCP_TESTONRETURN},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_While_Idle") + ":", SwingConstants.RIGHT), DBCP_TESTWHILEIDLE}, class DBCPAttrPane extends BasicPane {
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Evictionruns_millis") + ":", SwingConstants.RIGHT), public DBCPAttrPane() {
DBCP_TIMEBETWEENEVICTIONRUNSMILLS}, JPanel defaultPane = this;
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Num_Test_Per_Evction_Run") + ":", SwingConstants.RIGHT), DBCP_NUMTESTSPEREVICTIONRUN},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Mix_Evictable_Idle_Time_Millis") + ":" , SwingConstants.RIGHT), // JPanel northFlowPane
DBCP_MINEVICTABLEIDLETIMEMILLIS}}; JPanel northFlowPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane();
defaultPane.add(northFlowPane, BorderLayout.NORTH);
JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSize, columnSize, 10, 4);
contextPane.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, UIConstants.LINE_COLOR)); DBCP_VALIDATION_QUERY.setColumns(15);
northFlowPane.add(contextPane); // ContextPane
}
double f = TableLayout.FILL;
@Override // double p = TableLayout.PREFERRED;
protected String title4PopupWindow() { double[] rowSize = {f, f, f, f, f, f, f, f, f, f, f, f};
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr"); double[] columnSize = {f, f};
} Component[][] comps = {
} {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Initial_Size") + ":", SwingConstants.RIGHT), DBCP_INITIAL_SIZE},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE},
private static class DriverURLName { {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Idle") + ":", SwingConstants.RIGHT), DBCP_MAX_IDLE},
public DriverURLName(String driver, String url) { {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Min_Idle") + ":", SwingConstants.RIGHT), DBCP_MIN_IDLE},
this.driver = driver; {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Max_Wait_Time") + ":", SwingConstants.RIGHT), DBCP_MAX_WAIT},
this.url = url; {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY},
} {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Borrow") + ":", SwingConstants.RIGHT), DBCP_TESTONBORROW},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Return") + ":", SwingConstants.RIGHT), DBCP_TESTONRETURN},
public String getDriver() { {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_While_Idle") + ":", SwingConstants.RIGHT), DBCP_TESTWHILEIDLE},
return this.driver; {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Evictionruns_millis") + ":", SwingConstants.RIGHT),
} DBCP_TIMEBETWEENEVICTIONRUNSMILLS},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dbcp_Num_Test_Per_Evction_Run") + ":", SwingConstants.RIGHT), DBCP_NUMTESTSPEREVICTIONRUN},
public String getURL() { {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Mix_Evictable_Idle_Time_Millis") + ":", SwingConstants.RIGHT),
return this.url; DBCP_MINEVICTABLEIDLETIMEMILLIS}};
}
JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSize, columnSize, 10, 4);
private String driver; contextPane.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, UIConstants.LINE_COLOR));
private String url; northFlowPane.add(contextPane);
} }
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr");
}
}
private static class DriverURLName {
public DriverURLName(String driver, String url) {
this.driver = driver;
this.url = url;
}
public String getDriver() {
return this.driver;
}
public String getURL() {
return this.url;
}
private String driver;
private String url;
}
} }

Loading…
Cancel
Save