Browse Source

Pull request #6597: REPORT-53615 重新添加驱动管理功能

Merge in DESIGN/design from ~XIQIU/design:release/11.0 to release/11.0

* commit 'c9acbb95a809c218384ad81696a0db864a5b7c1c':
  REPORT-53615   重新添加驱动管理功能
bugfix/11.0
Xiqiu 3 years ago
parent
commit
41c7f7e63b
  1. 260
      designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java

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

@ -1,10 +1,13 @@
package com.fr.design.data.datapane.connect; package com.fr.design.data.datapane.connect;
import com.fr.base.GraphHelper; 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.data.impl.JDBCDatabaseConnection;
import com.fr.design.border.UITitledBorder; import com.fr.design.border.UITitledBorder;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxUI;
import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.ActionLabel;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ipasswordfield.UIPasswordFieldWithFixedLength; import com.fr.design.gui.ipasswordfield.UIPasswordFieldWithFixedLength;
@ -21,6 +24,8 @@ import com.fr.general.ComparatorUtils;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.EncodeConstants; import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.third.guava.collect.HashBiMap;
import com.fr.workspace.WorkContext;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
@ -28,6 +33,8 @@ import javax.swing.JPanel;
import javax.swing.JPasswordField; import javax.swing.JPasswordField;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.basic.ComboPopup;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
@ -45,6 +52,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -101,8 +109,60 @@ public class JDBCDefPane extends JPanel {
private JDBCDatabaseConnection jdbcDatabase; private JDBCDatabaseConnection jdbcDatabase;
private boolean needRefresh = true; private boolean needRefresh = true;
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);
// 选中自定义的话,将odbc的屏蔽,选中默认的话,重新触发一次driverComboBox的事件
if (selectSelfDefine) {
odbcTipsLink.setVisible(false);
} else {
driverComboBox.setSelectedItem(driverComboBox.getSelectedItem());
}
}
};
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() { public JDBCDefPane() {
initMap();
this.setBorder(UITitledBorder.createBorderWithTitle("JDBC" + ":")); this.setBorder(UITitledBorder.createBorderWithTitle("JDBC" + ":"));
this.setLayout(FRGUIPaneFactory.createLabelFlowLayout()); this.setLayout(FRGUIPaneFactory.createLabelFlowLayout());
JPanel innerthis = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); JPanel innerthis = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane();
@ -115,7 +175,15 @@ public class JDBCDefPane extends JPanel {
} }
dbtypeComboBox.addActionListener(dbtypeActionListener); dbtypeComboBox.addActionListener(dbtypeActionListener);
dbtypeComboBox.setMaximumRowCount(10); dbtypeComboBox.setMaximumRowCount(10);
driverLoaderBox = new SpecialUIComboBox();
refreshDriverLoader();
driverLoaderBox.setPreferredSize(new Dimension(200, driverLoaderBox.getPreferredSize().height));
driverLoaderBox.setEditable(false);
driverManageBox = new UIComboBox();
refreshDriverManage(true);
driverManageBox.setEditable(false);
driverManageBox.addActionListener(driverManageListener);
driverLoaderBox.setVisible(isSelfDefine());
driverComboBox = new UIComboBox(); driverComboBox = new UIComboBox();
driverComboBox.setEditable(true); driverComboBox.setEditable(true);
driverComboBox.addActionListener(driverListener); driverComboBox.addActionListener(driverListener);
@ -163,9 +231,33 @@ public class JDBCDefPane extends JPanel {
BrowseUtils.browser(url); 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()); JPanel driverComboBoxAndTips = new JPanel(new BorderLayout());
driverComboBoxAndTips.add(driverComboBox, BorderLayout.WEST); JPanel normalFlowInnerContainer_s_pane = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(0, 5, 0);
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); driverComboBoxAndTips.add(odbcTipsPane, BorderLayout.CENTER);
JPanel hostPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); JPanel hostPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
@ -225,7 +317,71 @@ public class JDBCDefPane extends JPanel {
innerthis.add(centerPanel); innerthis.add(centerPanel);
} }
private void refreshDriverLoader() {
Set<String> representSet = nameAndRepresent.values();
driverLoaderBox.clearBoxItems();
for (String represent : representSet) {
driverLoaderBox.addItem(represent);
}
}
private String getRepresent(String driverClass, String driverName) {
return driverClass + "(" + driverName + ")";
}
private boolean isSelfDefine() {
return ComparatorUtils.equals(Toolkit.i18nText("Fine-Design_Driver_Manage_Self_Define"), driverManageBox.getSelectedItem());
}
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"));
}
}
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;
}
// name 是唯一的,name+driver自然也是唯一的
for (DriverLoader driverLoader : driverLoaders.values()) {
driverHashBiMap.put(driverLoader.getName(), getRepresent(driverLoader.getDriverClass(), driverLoader.getName()));
}
return driverHashBiMap;
}
protected JDBCDatabaseConnection getJDBCDatabase() {
return this.jdbcDatabase;
}
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);
}
}
public void populate(JDBCDatabaseConnection jdbcDatabase) { public void populate(JDBCDatabaseConnection jdbcDatabase) {
// 单例对象,重新打开的时候并不会新建,但是由于driverloaderbox里面需要是动态内容,因此需要进行刷新动作
initMap();
refreshDriverLoader();
needRefresh = false; needRefresh = false;
if (jdbcDatabase == null) { if (jdbcDatabase == null) {
jdbcDatabase = new JDBCDatabaseConnection(); jdbcDatabase = new JDBCDatabaseConnection();
@ -255,7 +411,24 @@ public class JDBCDefPane extends JPanel {
this.dbtypeComboBox.setSelectedItem(OTHER_DB); this.dbtypeComboBox.setSelectedItem(OTHER_DB);
} }
} }
// 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()); 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());
if (!nameAndRepresent.containsValue(represent)) {
this.driverLoaderBox.addItem(represent);
}
this.driverLoaderBox.setSelectedItem(represent);
}
this.urlTextField.setText(jdbcDatabase.getURL()); this.urlTextField.setText(jdbcDatabase.getURL());
this.userNameTextField.setText(jdbcDatabase.getUser()); this.userNameTextField.setText(jdbcDatabase.getUser());
this.passwordTextField.setText(jdbcDatabase.getPassword()); this.passwordTextField.setText(jdbcDatabase.getPassword());
@ -268,31 +441,10 @@ public class JDBCDefPane extends JPanel {
needRefresh = false; needRefresh = false;
} }
protected JDBCDatabaseConnection getJDBCDatabase() {
return this.jdbcDatabase;
}
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);
}
}
public JDBCDatabaseConnection update() { public JDBCDatabaseConnection update() {
if (jdbcDatabase == null) { if (jdbcDatabase == null) {
jdbcDatabase = new JDBCDatabaseConnection(); jdbcDatabase = new JDBCDatabaseConnection();
} }
Object driveItem = this.driverComboBox.getSelectedItem();
jdbcDatabase.setDriver(driveItem == null ? null : driveItem.toString().trim());
jdbcDatabase.setURL(this.urlTextField.getText().trim()); jdbcDatabase.setURL(this.urlTextField.getText().trim());
jdbcDatabase.setUser(this.userNameTextField.getText().trim()); jdbcDatabase.setUser(this.userNameTextField.getText().trim());
jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim()); jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim());
@ -304,36 +456,30 @@ public class JDBCDefPane extends JPanel {
jdbcDatabase.setNewCharsetName(EncodeConstants.ENCODING_GBK); jdbcDatabase.setNewCharsetName(EncodeConstants.ENCODING_GBK);
jdbcDatabase.setOriginalCharsetName(((String) this.charSetComboBox.getSelectedItem())); jdbcDatabase.setOriginalCharsetName(((String) this.charSetComboBox.getSelectedItem()));
} }
return jdbcDatabase; String driverLoader = (String) this.driverLoaderBox.getSelectedItem();
if (driverLoader == null) {
driverLoader = StringUtils.EMPTY;
} }
if (isSelfDefine()) {
ActionListener dbtypeActionListener = new ActionListener() { String[] split = driverLoader.split("\\(");
public void actionPerformed(ActionEvent evt) { if (split.length > 1) {
String name = split[1];
urlTextField.setText(StringUtils.EMPTY); if (name.length() > 0) {
driverComboBox.removeAllItems(); jdbcDatabase.setDriverSource(name.substring(0, name.length() - 1));
if (ComparatorUtils.equals(dbtypeComboBox.getSelectedItem(), StringUtils.EMPTY)) { } else {
driverComboBox.setSelectedItem(StringUtils.EMPTY); jdbcDatabase.setDriverSource(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());
} }
} else {
jdbcDatabase.setDriverSource(StringUtils.EMPTY);
} }
// 更改数据库类型后 数据库名称置空和之前逻辑保持一致 jdbcDatabase.setDriver(split[0]);
if (needRefresh) { } else {
jdbcDatabase.setDatabase(StringUtils.EMPTY); Object driveItem = this.driverComboBox.getSelectedItem();
jdbcDatabase.setDriver(driveItem == null ? null : driveItem.toString().trim());
jdbcDatabase.setDriverSource(StringUtils.EMPTY);
} }
changePane(dbtypeComboBox.getSelectedItem()); return jdbcDatabase;
JDBCConnectionDef.getInstance().setConnection((String) dbtypeComboBox.getSelectedItem(), jdbcDatabase);
DatabaseConnectionPane.JDBC.getAdvancedAttrPane().populate(jdbcDatabase);
} }
};
ActionListener driverListener = new ActionListener() { ActionListener driverListener = new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -579,4 +725,22 @@ public class JDBCDefPane extends JPanel {
private String driver; private String driver;
private String url; private String url;
} }
private static class SpecialUIComboBox extends UIComboBox {
@Override
public ComboBoxUI getUIComboBoxUI() {
return new SpecialUIComboBoxUI();
}
}
private static class SpecialUIComboBoxUI extends UIComboBoxUI {
@Override
public ComboPopup createPopup() {
return createHorizontalNeverUIComboPopUp();
}
}
} }

Loading…
Cancel
Save