|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package com.fr.design.data.datapane.connect; |
|
|
|
|
|
|
|
|
|
import com.fr.base.GraphHelper; |
|
|
|
|
import com.fr.data.driver.DriverLoader; |
|
|
|
|
import com.fr.data.driver.config.DriverLoaderConfig; |
|
|
|
|
import com.fr.data.impl.JDBCDatabaseConnection; |
|
|
|
|
import com.fr.design.border.UITitledBorder; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
@ -21,6 +23,8 @@ import com.fr.general.ComparatorUtils;
|
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.third.guava.collect.HashBiMap; |
|
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
|
import javax.swing.JFileChooser; |
|
|
|
@ -45,6 +49,7 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
@ -101,8 +106,123 @@ public class JDBCDefPane extends JPanel {
|
|
|
|
|
|
|
|
|
|
private JDBCDatabaseConnection jdbcDatabase; |
|
|
|
|
private boolean needRefresh = true; |
|
|
|
|
ActionListener driverListener = new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
if (driverComboBox.getSelectedItem() == null || ComparatorUtils.equals(driverComboBox.getSelectedItem(), StringUtils.EMPTY)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
odbcTipsLink.setVisible(ComparatorUtils.equals("sun.jdbc.odbc.JdbcOdbcDriver", driverComboBox.getSelectedItem())); // 选择的如果是ODBC就显示提示
|
|
|
|
|
Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator(); |
|
|
|
|
while (jdbc.hasNext()) { |
|
|
|
|
Entry<String, DriverURLName[]> entry = jdbc.next(); |
|
|
|
|
DriverURLName[] dus = entry.getValue(); |
|
|
|
|
for (int i = 0, len = dus.length; i < len; i++) { |
|
|
|
|
if (ComparatorUtils.equals(dus[i].getDriver(), (driverComboBox.getSelectedItem()))) { |
|
|
|
|
urlTextField.setText(dus[i].getURL()); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
ActionListener dbtypeButtonActionListener = new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
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"))) { |
|
|
|
|
// ben:这个能不能换种处理方案- -
|
|
|
|
|
JFileChooser filechooser = new JFileChooser(); |
|
|
|
|
filechooser.setDialogTitle(Toolkit.i18nText("Fine-Design_Basic_Open")); |
|
|
|
|
filechooser.setMultiSelectionEnabled(false); |
|
|
|
|
filechooser.addChoosableFileFilter(new ChooseFileFilter(new String[]{"accdb", "mdb"}, "Microsoft Office Access")); |
|
|
|
|
int result = filechooser.showOpenDialog(DesignerContext.getDesignerFrame()); |
|
|
|
|
File selectedfile = null; |
|
|
|
|
|
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
KeyListener portKeyListener = new KeyAdapter() { |
|
|
|
|
@Override |
|
|
|
|
public void keyReleased(KeyEvent e) { |
|
|
|
|
String port = portTextField.getText(); |
|
|
|
|
if (isPortValid(port)) { |
|
|
|
|
updateURL(); |
|
|
|
|
} else { |
|
|
|
|
portTextField.setText(port.replaceAll(getCharNeedReplace(e.getKeyChar()), "")); |
|
|
|
|
if (!isPortValid(portTextField.getText())) { |
|
|
|
|
portTextField.setText(StringUtils.EMPTY); |
|
|
|
|
updateURL(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
private UIComboBox driverManageBox; |
|
|
|
|
private ActionLabel driverManageLabel; |
|
|
|
|
private UIComboBox driverLoaderBox; |
|
|
|
|
ActionListener driverManageListener = new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
boolean selectSelfDefine = isSelfDefine(); |
|
|
|
|
driverManageLabel.setVisible(selectSelfDefine); |
|
|
|
|
driverLoaderBox.setVisible(selectSelfDefine); |
|
|
|
|
driverComboBox.setVisible(!selectSelfDefine); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
ActionListener dbtypeActionListener = new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
|
|
|
|
|
urlTextField.setText(StringUtils.EMPTY); |
|
|
|
|
driverComboBox.removeAllItems(); |
|
|
|
|
driverManageBox.setSelectedItem(Toolkit.i18nText("Fine-Design_Driver_Manage_Default")); |
|
|
|
|
if (driverLoaderBox.getItemCount() > 0) { |
|
|
|
|
driverLoaderBox.setSelectedIndex(0); |
|
|
|
|
} |
|
|
|
|
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) { |
|
|
|
|
driverComboBox.setSelectedItem(StringUtils.EMPTY); |
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 更改数据库类型后 数据库名称置空和之前逻辑保持一致
|
|
|
|
|
if (needRefresh) { |
|
|
|
|
jdbcDatabase.setDatabase(StringUtils.EMPTY); |
|
|
|
|
} |
|
|
|
|
changePane(dbtypeComboBox.getSelectedItem()); |
|
|
|
|
JDBCConnectionDef.getInstance().setConnection((String) dbtypeComboBox.getSelectedItem(), jdbcDatabase); |
|
|
|
|
DatabaseConnectionPane.JDBC.getAdvancedAttrPane().populate(jdbcDatabase); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
private HashBiMap<String, String> nameAndRepresent; |
|
|
|
|
|
|
|
|
|
public JDBCDefPane() { |
|
|
|
|
initMap(); |
|
|
|
|
this.setBorder(UITitledBorder.createBorderWithTitle("JDBC" + ":")); |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createLabelFlowLayout()); |
|
|
|
|
JPanel innerthis = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); |
|
|
|
@ -115,7 +235,14 @@ public class JDBCDefPane extends JPanel {
|
|
|
|
|
} |
|
|
|
|
dbtypeComboBox.addActionListener(dbtypeActionListener); |
|
|
|
|
dbtypeComboBox.setMaximumRowCount(10); |
|
|
|
|
|
|
|
|
|
driverLoaderBox = new UIComboBox(); |
|
|
|
|
refreshDriverLoader(); |
|
|
|
|
driverLoaderBox.setEditable(false); |
|
|
|
|
driverManageBox = new UIComboBox(); |
|
|
|
|
refreshDriverManage(true); |
|
|
|
|
driverManageBox.setEditable(false); |
|
|
|
|
driverManageBox.addActionListener(driverManageListener); |
|
|
|
|
driverLoaderBox.setVisible(isSelfDefine()); |
|
|
|
|
driverComboBox = new UIComboBox(); |
|
|
|
|
driverComboBox.setEditable(true); |
|
|
|
|
driverComboBox.addActionListener(driverListener); |
|
|
|
@ -155,17 +282,39 @@ public class JDBCDefPane extends JPanel {
|
|
|
|
|
_gfx.drawLine(0, this.getHeight() - 1, GraphHelper.getWidth(this.getText()), this.getHeight() - 1); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
odbcTipsPane.add(odbcTipsLink); |
|
|
|
|
odbcTipsLink.setPreferredSize(new Dimension(GraphHelper.getWidth(Toolkit.i18nText("Fine-Design_Basic_Odbc_Tips")), odbcTipsLink.getPreferredSize().height)); |
|
|
|
|
odbcTipsLink.addActionListener(new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
String url = CloudCenter.getInstance().acquireUrlByKind("odbc.help"); |
|
|
|
|
BrowseUtils.browser(url); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
driverManageLabel = new ActionLabel(Toolkit.i18nText("Fine-Design_Driver_Manage_Add_Driver")) { |
|
|
|
|
@Override |
|
|
|
|
public void paintComponent(Graphics _gfx) { |
|
|
|
|
super.paintComponent(_gfx); |
|
|
|
|
_gfx.setColor(Color.blue); |
|
|
|
|
_gfx.drawLine(0, this.getHeight() - 1, GraphHelper.getWidth(this.getText()), this.getHeight() - 1); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
driverManageLabel.setPreferredSize(new Dimension(GraphHelper.getWidth(Toolkit.i18nText("Fine-Design_Driver_Manage_Add_Driver")), driverManageLabel.getPreferredSize().height)); |
|
|
|
|
driverManageLabel.setVisible(isSelfDefine()); |
|
|
|
|
driverManageLabel.addActionListener(new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
String url = CloudCenter.getInstance().acquireUrlByKind("driver.add.help"); |
|
|
|
|
BrowseUtils.browser(url); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
odbcTipsPane.add(driverManageLabel); |
|
|
|
|
odbcTipsPane.add(odbcTipsLink); |
|
|
|
|
JPanel driverComboBoxAndTips = new JPanel(new BorderLayout()); |
|
|
|
|
driverComboBoxAndTips.add(driverComboBox, BorderLayout.WEST); |
|
|
|
|
JPanel normalFlowInnerContainer_s_pane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
normalFlowInnerContainer_s_pane.add(driverManageBox); |
|
|
|
|
normalFlowInnerContainer_s_pane.add(driverComboBox); |
|
|
|
|
normalFlowInnerContainer_s_pane.add(driverLoaderBox); |
|
|
|
|
driverComboBoxAndTips.add(normalFlowInnerContainer_s_pane, BorderLayout.WEST); |
|
|
|
|
driverComboBoxAndTips.add(odbcTipsPane, BorderLayout.CENTER); |
|
|
|
|
|
|
|
|
|
JPanel hostPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); |
|
|
|
@ -225,48 +374,21 @@ public class JDBCDefPane extends JPanel {
|
|
|
|
|
innerthis.add(centerPanel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void populate(JDBCDatabaseConnection jdbcDatabase) { |
|
|
|
|
needRefresh = false; |
|
|
|
|
if (jdbcDatabase == null) { |
|
|
|
|
jdbcDatabase = new JDBCDatabaseConnection(); |
|
|
|
|
} |
|
|
|
|
this.jdbcDatabase = jdbcDatabase; |
|
|
|
|
if (ComparatorUtils.equals(jdbcDatabase.getDriver(), "sun.jdbc.odbc.JdbcOdbcDriver") |
|
|
|
|
&& jdbcDatabase.getURL().startsWith("jdbc:odbc:Driver={Microsoft")) { |
|
|
|
|
this.dbtypeComboBox.setSelectedItem("Access"); |
|
|
|
|
} else { |
|
|
|
|
Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator(); |
|
|
|
|
boolean out = false; |
|
|
|
|
while (jdbc.hasNext()) { |
|
|
|
|
Entry<String, DriverURLName[]> entry = jdbc.next(); |
|
|
|
|
DriverURLName[] dus = entry.getValue(); |
|
|
|
|
for (int i = 0, len = dus.length; i < len; i++) { |
|
|
|
|
if (ComparatorUtils.equals(dus[i].getDriver(), jdbcDatabase.getDriver())) { |
|
|
|
|
this.dbtypeComboBox.setSelectedItem(entry.getKey()); |
|
|
|
|
out = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (out) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!out) { |
|
|
|
|
this.dbtypeComboBox.setSelectedItem(OTHER_DB); |
|
|
|
|
private void initMap() { |
|
|
|
|
Map<String, DriverLoader> driverLoaders = DriverLoaderConfig.getInstance().getDriverLoaders(); |
|
|
|
|
nameAndRepresent = getDriverLoaderAndRepresent(driverLoaders); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private HashBiMap<String, String> getDriverLoaderAndRepresent(Map<String, DriverLoader> driverLoaders) { |
|
|
|
|
HashBiMap<String, String> driverHashBiMap = HashBiMap.create(); |
|
|
|
|
if (WorkContext.getCurrent().isWarDeploy()) { |
|
|
|
|
return driverHashBiMap; |
|
|
|
|
} |
|
|
|
|
this.jdbcDatabase.setIdentity(jdbcDatabase.getIdentity()); |
|
|
|
|
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()); |
|
|
|
|
// name 是唯一的,name+driver自然也是唯一的
|
|
|
|
|
for (DriverLoader driverLoader : driverLoaders.values()) { |
|
|
|
|
driverHashBiMap.put(driverLoader.getName(), getRepresent(driverLoader.getDriverClass(), driverLoader.getName())); |
|
|
|
|
} |
|
|
|
|
needRefresh = false; |
|
|
|
|
return driverHashBiMap; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected JDBCDatabaseConnection getJDBCDatabase() { |
|
|
|
@ -288,108 +410,29 @@ public class JDBCDefPane extends JPanel {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public JDBCDatabaseConnection update() { |
|
|
|
|
if (jdbcDatabase == null) { |
|
|
|
|
jdbcDatabase = new JDBCDatabaseConnection(); |
|
|
|
|
} |
|
|
|
|
Object driveItem = this.driverComboBox.getSelectedItem(); |
|
|
|
|
jdbcDatabase.setDriver(driveItem == null ? null : driveItem.toString().trim()); |
|
|
|
|
jdbcDatabase.setURL(this.urlTextField.getText().trim()); |
|
|
|
|
jdbcDatabase.setUser(this.userNameTextField.getText().trim()); |
|
|
|
|
jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim()); |
|
|
|
|
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())); |
|
|
|
|
} |
|
|
|
|
return jdbcDatabase; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ActionListener dbtypeActionListener = new ActionListener() { |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
|
|
|
|
|
urlTextField.setText(StringUtils.EMPTY); |
|
|
|
|
driverComboBox.removeAllItems(); |
|
|
|
|
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) { |
|
|
|
|
driverComboBox.setSelectedItem(StringUtils.EMPTY); |
|
|
|
|
return; |
|
|
|
|
private String getRepresent(String driverClass, String driverName) { |
|
|
|
|
return driverClass + "(" + driverName + ")"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 更改数据库类型后 数据库名称置空和之前逻辑保持一致
|
|
|
|
|
if (needRefresh) { |
|
|
|
|
jdbcDatabase.setDatabase(StringUtils.EMPTY); |
|
|
|
|
private boolean isSelfDefine() { |
|
|
|
|
return ComparatorUtils.equals(Toolkit.i18nText("Fine-Design_Driver_Manage_Self_Define"), driverManageBox.getSelectedItem()); |
|
|
|
|
} |
|
|
|
|
changePane(dbtypeComboBox.getSelectedItem()); |
|
|
|
|
JDBCConnectionDef.getInstance().setConnection((String) dbtypeComboBox.getSelectedItem(), jdbcDatabase); |
|
|
|
|
DatabaseConnectionPane.JDBC.getAdvancedAttrPane().populate(jdbcDatabase); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
ActionListener driverListener = new ActionListener() { |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
if (driverComboBox.getSelectedItem() == null || ComparatorUtils.equals(driverComboBox.getSelectedItem(), StringUtils.EMPTY)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
odbcTipsLink.setVisible(ComparatorUtils.equals("sun.jdbc.odbc.JdbcOdbcDriver", driverComboBox.getSelectedItem())); // 选择的如果是ODBC就显示提示
|
|
|
|
|
Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator(); |
|
|
|
|
while (jdbc.hasNext()) { |
|
|
|
|
Entry<String, DriverURLName[]> entry = jdbc.next(); |
|
|
|
|
DriverURLName[] dus = entry.getValue(); |
|
|
|
|
for (int i = 0, len = dus.length; i < len; i++) { |
|
|
|
|
if (ComparatorUtils.equals(dus[i].getDriver(), (driverComboBox.getSelectedItem()))) { |
|
|
|
|
urlTextField.setText(dus[i].getURL()); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
private void refreshDriverLoader() { |
|
|
|
|
Set<String> representSet = nameAndRepresent.values(); |
|
|
|
|
driverLoaderBox.clearBoxItems(); |
|
|
|
|
for (String represent : representSet) { |
|
|
|
|
driverLoaderBox.addItem(represent); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
ActionListener dbtypeButtonActionListener = new ActionListener() { |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
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"))) { |
|
|
|
|
// ben:这个能不能换种处理方案- -
|
|
|
|
|
JFileChooser filechooser = new JFileChooser(); |
|
|
|
|
filechooser.setDialogTitle(Toolkit.i18nText("Fine-Design_Basic_Open")); |
|
|
|
|
filechooser.setMultiSelectionEnabled(false); |
|
|
|
|
filechooser.addChoosableFileFilter(new ChooseFileFilter(new String[]{"accdb", "mdb"}, "Microsoft Office Access")); |
|
|
|
|
int result = filechooser.showOpenDialog(DesignerContext.getDesignerFrame()); |
|
|
|
|
File selectedfile = null; |
|
|
|
|
|
|
|
|
|
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()); |
|
|
|
|
private void refreshDriverManage(boolean addSelfDefine) { |
|
|
|
|
driverManageBox.clearBoxItems(); |
|
|
|
|
driverManageBox.addItem(Toolkit.i18nText("Fine-Design_Driver_Manage_Default")); |
|
|
|
|
if (addSelfDefine) { |
|
|
|
|
driverManageBox.addItem(Toolkit.i18nText("Fine-Design_Driver_Manage_Self_Define")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
InputMethodListener portInputMethodListener = new InputMethodListener() { |
|
|
|
|
@Override |
|
|
|
@ -426,6 +469,109 @@ public class JDBCDefPane extends JPanel {
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public void populate(JDBCDatabaseConnection jdbcDatabase) { |
|
|
|
|
// 单例对象,重新打开的时候并不会新建,但是由于driverloaderbox里面需要是动态内容,因此需要进行刷新动作
|
|
|
|
|
initMap(); |
|
|
|
|
refreshDriverLoader(); |
|
|
|
|
needRefresh = false; |
|
|
|
|
if (jdbcDatabase == null) { |
|
|
|
|
jdbcDatabase = new JDBCDatabaseConnection(); |
|
|
|
|
} |
|
|
|
|
this.jdbcDatabase = jdbcDatabase; |
|
|
|
|
if (ComparatorUtils.equals(jdbcDatabase.getDriver(), "sun.jdbc.odbc.JdbcOdbcDriver") |
|
|
|
|
&& jdbcDatabase.getURL().startsWith("jdbc:odbc:Driver={Microsoft")) { |
|
|
|
|
this.dbtypeComboBox.setSelectedItem("Access"); |
|
|
|
|
} else { |
|
|
|
|
Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator(); |
|
|
|
|
boolean out = false; |
|
|
|
|
while (jdbc.hasNext()) { |
|
|
|
|
Entry<String, DriverURLName[]> entry = jdbc.next(); |
|
|
|
|
DriverURLName[] dus = entry.getValue(); |
|
|
|
|
for (int i = 0, len = dus.length; i < len; i++) { |
|
|
|
|
if (ComparatorUtils.equals(dus[i].getDriver(), jdbcDatabase.getDriver())) { |
|
|
|
|
this.dbtypeComboBox.setSelectedItem(entry.getKey()); |
|
|
|
|
out = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (out) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!out) { |
|
|
|
|
this.dbtypeComboBox.setSelectedItem(OTHER_DB); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.jdbcDatabase.setIdentity(jdbcDatabase.getIdentity()); |
|
|
|
|
// jdbcDatabase.getDriverSource() 只会是空或者是有值,但是为了保险起见,还是应该做个处理
|
|
|
|
|
String driverSource = jdbcDatabase.getDriverSource(); |
|
|
|
|
if (driverSource == null) { |
|
|
|
|
driverSource = StringUtils.EMPTY; |
|
|
|
|
} |
|
|
|
|
if (driverSource.isEmpty()) { |
|
|
|
|
refreshDriverManage(!nameAndRepresent.isEmpty()); |
|
|
|
|
this.driverManageBox.setSelectedItem(Toolkit.i18nText("Fine-Design_Driver_Manage_Default")); |
|
|
|
|
this.driverComboBox.setSelectedItem(jdbcDatabase.getDriver()); |
|
|
|
|
} else { |
|
|
|
|
refreshDriverManage(true); |
|
|
|
|
this.driverManageBox.setSelectedItem(Toolkit.i18nText("Fine-Design_Driver_Manage_Self_Define")); |
|
|
|
|
String represent = getRepresent(jdbcDatabase.getDriver(), jdbcDatabase.getDriverSource()); |
|
|
|
|
this.driverLoaderBox.removeItem(represent); |
|
|
|
|
this.driverLoaderBox.addItem(represent); |
|
|
|
|
this.driverLoaderBox.setSelectedItem(represent); |
|
|
|
|
} |
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
needRefresh = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public JDBCDatabaseConnection update() { |
|
|
|
|
if (jdbcDatabase == null) { |
|
|
|
|
jdbcDatabase = new JDBCDatabaseConnection(); |
|
|
|
|
} |
|
|
|
|
jdbcDatabase.setURL(this.urlTextField.getText().trim()); |
|
|
|
|
jdbcDatabase.setUser(this.userNameTextField.getText().trim()); |
|
|
|
|
jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim()); |
|
|
|
|
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())); |
|
|
|
|
} |
|
|
|
|
String driverLoader = (String) this.driverLoaderBox.getSelectedItem(); |
|
|
|
|
if (driverLoader == null) { |
|
|
|
|
driverLoader = StringUtils.EMPTY; |
|
|
|
|
} |
|
|
|
|
if (isSelfDefine()) { |
|
|
|
|
String[] split = driverLoader.split("\\("); |
|
|
|
|
if (split.length > 1) { |
|
|
|
|
String name = split[1]; |
|
|
|
|
if (name.length() > 0) { |
|
|
|
|
jdbcDatabase.setDriverSource(name.substring(0, name.length() - 1)); |
|
|
|
|
} else { |
|
|
|
|
jdbcDatabase.setDriverSource(StringUtils.EMPTY); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
jdbcDatabase.setDriverSource(StringUtils.EMPTY); |
|
|
|
|
} |
|
|
|
|
jdbcDatabase.setDriver(split[0]); |
|
|
|
|
} else { |
|
|
|
|
Object driveItem = this.driverComboBox.getSelectedItem(); |
|
|
|
|
jdbcDatabase.setDriver(driveItem == null ? null : driveItem.toString().trim()); |
|
|
|
|
jdbcDatabase.setDriverSource(StringUtils.EMPTY); |
|
|
|
|
} |
|
|
|
|
return jdbcDatabase; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updatePara() { |
|
|
|
|
String dbType = dbtypeComboBox.getSelectedItem().toString(); |
|
|
|
|
if (ComparatorUtils.equals(dbType, OTHER_DB) || ComparatorUtils.equals(dbType, "Access") || ComparatorUtils.equals(dbType, "SQLite")) { |
|
|
|
@ -489,21 +635,6 @@ public class JDBCDefPane extends JPanel {
|
|
|
|
|
this.hostTextField.getDocument().removeDocumentListener(updateURLListener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
KeyListener portKeyListener = new KeyAdapter() { |
|
|
|
|
@Override |
|
|
|
|
public void keyReleased(KeyEvent e) { |
|
|
|
|
String port = portTextField.getText(); |
|
|
|
|
if (isPortValid(port)) { |
|
|
|
|
updateURL(); |
|
|
|
|
} else { |
|
|
|
|
portTextField.setText(port.replaceAll(getCharNeedReplace(e.getKeyChar()) , "")); |
|
|
|
|
if (!isPortValid(portTextField.getText())) { |
|
|
|
|
portTextField.setText(StringUtils.EMPTY); |
|
|
|
|
updateURL(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
private boolean isPortValid(String port) { |
|
|
|
|
return PORT.matcher(port).find(); |
|
|
|
|