|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
*/ |
|
|
|
|
package com.fr.design.data.datapane.connect; |
|
|
|
|
|
|
|
|
|
import com.fr.data.impl.Connection; |
|
|
|
|
import com.fr.data.impl.JDBCDatabaseConnection; |
|
|
|
|
import com.fr.data.impl.JNDIDatabaseConnection; |
|
|
|
|
import com.fr.data.operator.DataOperator; |
|
|
|
@ -10,6 +11,7 @@ import com.fr.design.beans.BasicBeanPane;
|
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.icombobox.UIComboBox; |
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
|
|
|
import com.fr.design.scrollruler.ModLineBorder; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
@ -19,12 +21,24 @@ import com.fr.stable.ArrayUtils;
|
|
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
|
import javax.swing.BoxLayout; |
|
|
|
|
import javax.swing.JDialog; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.SwingWorker; |
|
|
|
|
import javax.swing.UIManager; |
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.Dialog; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.FlowLayout; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.awt.event.WindowAdapter; |
|
|
|
|
import java.awt.event.WindowEvent; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Database Connection pane. |
|
|
|
@ -48,9 +62,9 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
|
|
|
|
|
protected void initComponents() { |
|
|
|
|
message = new UILabel(); |
|
|
|
|
uiLabel = new UILabel(); |
|
|
|
|
okButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_OK")); |
|
|
|
|
cancelButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel")); |
|
|
|
|
String[] defaultEncode = new String[] {com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Encode_Auto")}; |
|
|
|
|
okButton = new UIButton(Toolkit.i18nText("Fine-Design_Report_OK")); |
|
|
|
|
cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")); |
|
|
|
|
String[] defaultEncode = new String[] {Toolkit.i18nText("Fine-Design_Encode_Auto")}; |
|
|
|
|
charSetComboBox = new UIComboBox(ArrayUtils.addAll(defaultEncode, EncodeConstants.ENCODING_ARRAY)); |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
JPanel northPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); |
|
|
|
@ -59,7 +73,7 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
|
|
|
|
|
// 按钮.
|
|
|
|
|
JPanel testPane = FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane(); |
|
|
|
|
northPane.add(testPane, BorderLayout.NORTH); |
|
|
|
|
UIButton testButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection")); |
|
|
|
|
UIButton testButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection")); |
|
|
|
|
testPane.add(testButton); |
|
|
|
|
testButton.addActionListener(testConnectionActionListener); |
|
|
|
|
testPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 4)); |
|
|
|
@ -71,9 +85,9 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
|
|
|
|
|
northPane.add(chartSetPane); |
|
|
|
|
chartSetPane.setBorder(BorderFactory.createTitledBorder( |
|
|
|
|
new ModLineBorder(ModLineBorder.TOP), |
|
|
|
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Advanced") |
|
|
|
|
Toolkit.i18nText("Fine-Design_Basic_Advanced") |
|
|
|
|
)); |
|
|
|
|
chartSetPane.add(GUICoreUtils.createNamedPane(charSetComboBox, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Charset") + ":")); |
|
|
|
|
chartSetPane.add(GUICoreUtils.createNamedPane(charSetComboBox, Toolkit.i18nText("Fine-Design_Basic_Datasource_Charset") + ":")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected abstract JPanel mainPanel(); |
|
|
|
@ -84,7 +98,7 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
|
|
|
|
|
public void populateBean(com.fr.data.impl.Connection ob) { |
|
|
|
|
this.originalCharSet = ob.getOriginalCharsetName(); |
|
|
|
|
if (StringUtils.isBlank(originalCharSet)) { |
|
|
|
|
this.charSetComboBox.setSelectedItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Encode_Auto")); |
|
|
|
|
this.charSetComboBox.setSelectedItem(Toolkit.i18nText("Fine-Design_Encode_Auto")); |
|
|
|
|
} else { |
|
|
|
|
this.charSetComboBox.setSelectedItem(ob.getOriginalCharsetName()); |
|
|
|
|
} |
|
|
|
@ -117,24 +131,29 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
|
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
|
|
|
|
|
// Try the java connection.
|
|
|
|
|
final SwingWorker connectionThread = new SwingWorker() { |
|
|
|
|
protected Object doInBackground() throws Exception { |
|
|
|
|
final SwingWorker<Boolean, Void> connectionThread = new SwingWorker<Boolean, Void>() { |
|
|
|
|
@Override |
|
|
|
|
protected Boolean doInBackground() throws Exception { |
|
|
|
|
Connection database = DatabaseConnectionPane.this.updateBean(); |
|
|
|
|
// 返回连接结果
|
|
|
|
|
return DataOperator.getInstance().testConnection(database); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void done() { |
|
|
|
|
try { |
|
|
|
|
com.fr.data.impl.Connection database = DatabaseConnectionPane.this.updateBean(); |
|
|
|
|
boolean connect = DataOperator.getInstance().testConnection(database); |
|
|
|
|
boolean connect = get(); |
|
|
|
|
okButton.setEnabled(true); |
|
|
|
|
message.setText(database.connectMessage(connect)); |
|
|
|
|
if (connect) { |
|
|
|
|
uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon")); |
|
|
|
|
message.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully")); |
|
|
|
|
message.setText(Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully")); |
|
|
|
|
}else{ |
|
|
|
|
uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon")); |
|
|
|
|
message.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Failed")); |
|
|
|
|
message.setText(Toolkit.i18nText("Fine-Design_Basic_Connection_Failed")); |
|
|
|
|
} |
|
|
|
|
} catch (Exception exp) { |
|
|
|
|
FineLoggerFactory.getLogger().error(exp.getMessage(), exp); |
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -158,18 +177,18 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
dialog.show(); |
|
|
|
|
dialog.setVisible(true); |
|
|
|
|
dialog.dispose(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
private void initDialogPane() { |
|
|
|
|
|
|
|
|
|
message.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection") + "..."); |
|
|
|
|
message.setText(Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection") + "..."); |
|
|
|
|
message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0)); |
|
|
|
|
okButton.setEnabled(false); |
|
|
|
|
|
|
|
|
|
dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(DatabaseConnectionPane.this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection"), true); |
|
|
|
|
dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(DatabaseConnectionPane.this), Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection"), true); |
|
|
|
|
dialog.setSize(new Dimension(268, 118)); |
|
|
|
|
okButton.setEnabled(false); |
|
|
|
|
JPanel jp = new JPanel(); |
|
|
|
|