@ -7,6 +7,10 @@ import com.fr.data.impl.Connection;
import com.fr.data.impl.JDBCDatabaseConnection ;
import com.fr.data.impl.JDBCDatabaseConnection ;
import com.fr.data.impl.JNDIDatabaseConnection ;
import com.fr.data.impl.JNDIDatabaseConnection ;
import com.fr.data.operator.DataOperator ;
import com.fr.data.operator.DataOperator ;
import com.fr.data.solution.ExceptionSolutionSelector ;
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.beans.BasicBeanPane ;
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 ;
@ -15,7 +19,6 @@ import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory ;
import com.fr.design.layout.FRGUIPaneFactory ;
import com.fr.design.scrollruler.ModLineBorder ;
import com.fr.design.scrollruler.ModLineBorder ;
import com.fr.design.utils.gui.GUICoreUtils ;
import com.fr.design.utils.gui.GUICoreUtils ;
import com.fr.log.FineLoggerFactory ;
import com.fr.log.FineLoggerFactory ;
import com.fr.stable.ArrayUtils ;
import com.fr.stable.ArrayUtils ;
import com.fr.stable.EncodeConstants ;
import com.fr.stable.EncodeConstants ;
@ -25,19 +28,28 @@ import javax.swing.BorderFactory;
import javax.swing.BoxLayout ;
import javax.swing.BoxLayout ;
import javax.swing.JDialog ;
import javax.swing.JDialog ;
import javax.swing.JPanel ;
import javax.swing.JPanel ;
import javax.swing.JScrollPane ;
import javax.swing.JTextArea ;
import javax.swing.SwingUtilities ;
import javax.swing.SwingUtilities ;
import javax.swing.SwingWorker ;
import javax.swing.SwingWorker ;
import javax.swing.UIManager ;
import javax.swing.UIManager ;
import javax.swing.event.ChangeEvent ;
import javax.swing.event.ChangeListener ;
import java.awt.BorderLayout ;
import java.awt.BorderLayout ;
import java.awt.Color ;
import java.awt.Cursor ;
import java.awt.Desktop ;
import java.awt.Dialog ;
import java.awt.Dialog ;
import java.awt.Dimension ;
import java.awt.Dimension ;
import java.awt.FlowLayout ;
import java.awt.FlowLayout ;
import java.awt.GridLayout ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import java.awt.event.ActionListener ;
import java.awt.event.MouseAdapter ;
import java.awt.event.MouseEvent ;
import java.awt.event.WindowAdapter ;
import java.awt.event.WindowAdapter ;
import java.awt.event.WindowEvent ;
import java.awt.event.WindowEvent ;
import java.util.HashMap ;
import java.net.URI ;
import java.util.Map ;
import java.util.concurrent.ExecutionException ;
import java.util.concurrent.ExecutionException ;
/ * *
/ * *
@ -50,6 +62,11 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
private UIButton cancelButton ;
private UIButton cancelButton ;
private JDialog dialog ;
private JDialog dialog ;
private UILabel uiLabel ;
private UILabel uiLabel ;
private UILabel directUiLabel ;
private UILabel detailLabel ;
private JPanel midPane ;
private JPanel hiddenPanel ;
// 编码转换.
// 编码转换.
private UIComboBox charSetComboBox ;
private UIComboBox charSetComboBox ;
private String originalCharSet = null ;
private String originalCharSet = null ;
@ -59,151 +76,272 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
this . initComponents ( ) ;
this . initComponents ( ) ;
}
}
protected void initComponents ( ) {
ActionListener testConnectionActionListener = new ActionListener ( ) {
message = new UILabel ( ) ;
private boolean firstCreate = true ;
uiLabel = new UILabel ( ) ;
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 ( ) ;
this . add ( northPane , BorderLayout . NORTH ) ;
// 按钮.
JPanel testPane = FRGUIPaneFactory . createNormalFlowInnerContainer_M_Pane ( ) ;
northPane . add ( testPane , BorderLayout . NORTH ) ;
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 ) ) ;
// Center
northPane . add ( mainPanel ( ) , BorderLayout . CENTER ) ;
// ChartSet
JPanel chartSetPane = FRGUIPaneFactory . createNColumnGridInnerContainer_S_Pane ( 2 ) ;
northPane . add ( chartSetPane ) ;
chartSetPane . setBorder ( BorderFactory . createTitledBorder (
new ModLineBorder ( ModLineBorder . TOP ) ,
Toolkit . i18nText ( "Fine-Design_Basic_Advanced" )
) ) ;
chartSetPane . add ( GUICoreUtils . createNamedPane ( charSetComboBox , Toolkit . i18nText ( "Fine-Design_Basic_Datasource_Charset" ) + ":" ) ) ;
}
protected abstract JPanel mainPanel ( ) ;
protected abstract boolean isFineBI ( ) ;
@Override
public void populateBean ( com . fr . data . impl . Connection ob ) {
this . originalCharSet = ob . getOriginalCharsetName ( ) ;
if ( StringUtils . isBlank ( originalCharSet ) ) {
this . charSetComboBox . setSelectedItem ( Toolkit . i18nText ( "Fine-Design_Encode_Auto" ) ) ;
} else {
this . charSetComboBox . setSelectedItem ( ob . getOriginalCharsetName ( ) ) ;
}
populateSubDatabaseConnectionBean ( ( E ) ob ) ;
}
protected abstract void populateSubDatabaseConnectionBean ( E ob ) ;
@Override
@Override
public com . fr . data . impl . Connection updateBean ( ) {
E ob = updateSubDatabaseConnectionBean ( ) ;
ob . setOriginalCharsetName ( this . originalCharSet ) ;
if ( this . charSetComboBox . getSelectedIndex ( ) = = 0 ) {
ob . setNewCharsetName ( null ) ;
ob . setOriginalCharsetName ( null ) ;
} else {
ob . setNewCharsetName ( EncodeConstants . ENCODING_GBK ) ;
ob . setOriginalCharsetName ( ( ( String ) this . charSetComboBox . getSelectedItem ( ) ) ) ;
}
return ob ;
}
protected abstract E updateSubDatabaseConnectionBean ( ) ;
ActionListener testConnectionActionListener = new ActionListener ( ) {
public void actionPerformed ( ActionEvent evt ) {
public void actionPerformed ( ActionEvent evt ) {
// Try the java connection.
// Try the java connection.
final SwingWorker < Boolean , Void > connectionThread = new SwingWorker < Boolean , Void > ( ) {
final SwingWorker < Void , Void > connectionThread = new SwingWorker < Void , Void > ( ) {
@Override
@Override
protected Boolean doInBackground ( ) throws Exception {
protected Void doInBackground ( ) throws Exception {
Connection database = DatabaseConnectionPane . this . updateBean ( ) ;
Connection database = DatabaseConnectionPane . this . updateBean ( ) ;
// 返回连接结果
// 返回连接结果
return DataOperator . getInstance ( ) . testConnection ( database ) ;
DriverPage . updateCache ( ) ;
DataOperator . getInstance ( ) . testConnectionWithException ( database ) ;
return null ;
}
}
@Override
@Override
protected void done ( ) {
protected void done ( ) {
try {
try {
boolean connect = get ( ) ;
get ( ) ;
dialog . setSize ( new Dimension ( 380 , 118 ) ) ;
okButton . setEnabled ( true ) ;
okButton . setEnabled ( true ) ;
if ( connect ) {
uiLabel . setIcon ( UIManager . getIcon ( "OptionPane.informationIcon" ) ) ;
uiLabel . setIcon ( UIManager . getIcon ( "OptionPane.informationIcon" ) ) ;
message . setText ( Toolkit . i18nText ( "Fine-Design_Basic_Datasource_Connection_Successfully" ) ) ;
message . setText ( Toolkit . i18nText ( "Fine-Design_Basic_Datasource_Connection_Successfully" ) ) ;
} else {
} catch ( InterruptedException e ) {
FineLoggerFactory . getLogger ( ) . error ( e . getMessage ( ) , e ) ;
} catch ( ExecutionException e ) {
dialog . setSize ( new Dimension ( 380 , 142 ) ) ;
midPane . setVisible ( true ) ;
hiddenPanel . setVisible ( false ) ;
okButton . setEnabled ( true ) ;
uiLabel . setIcon ( UIManager . getIcon ( "OptionPane.errorIcon" ) ) ;
uiLabel . setIcon ( UIManager . getIcon ( "OptionPane.errorIcon" ) ) ;
message . setText ( Toolkit . i18nText ( "Fine-Design_Basic_Connection_Failed" ) ) ;
message . setText ( Toolkit . i18nText ( "Fine-Design_Basic_Connection_Failed" ) ) ;
SolutionProcessor select = ExceptionSolutionSelector . get ( ) . select ( e ) ;
if ( select instanceof ClassNotFoundExceptionSolutionProcessor ) {
JPanel gridJpanel = new JPanel ( ) ;
gridJpanel . setLayout ( new GridLayout ( 5 , 1 , 0 , 5 ) ) ;
UILabel driverTips = new UILabel ( ) ;
driverTips . setText ( Toolkit . i18nText ( "Fine_Designer_Not_Found_Driver" ) ) ;
gridJpanel . add ( driverTips ) ;
UILabel deatail = new UILabel ( ) ;
String content = Toolkit . i18nText ( "Fine_Designer_Not_Found" ) + select . getResultException ( ) . getDetailMessage ( ) + Toolkit . i18nText ( "Fine_Designer_Driver" ) ;
deatail . setText ( content ) ;
deatail . setToolTipText ( content ) ;
gridJpanel . add ( deatail ) ;
String solution = select . getResultException ( ) . getSolution ( ) ;
UILabel redirect = new UILabel ( ) ;
if ( solution ! = null ) {
redirect . setText ( Toolkit . i18nText ( "Fine_Designer_Download_Driver" ) ) ;
redirect . setForeground ( Color . BLUE ) ;
redirect . addMouseListener ( new MouseAdapter ( ) {
@Override
public void mouseClicked ( MouseEvent e ) {
try {
Desktop . getDesktop ( ) . browse ( new URI ( solution ) ) ;
} catch ( Exception clickException ) {
FineLoggerFactory . getLogger ( ) . warn ( "can not open browser with {}" , solution ) ;
}
}
} catch ( InterruptedException | ExecutionException e ) {
FineLoggerFactory . getLogger ( ) . error ( e . getMessage ( ) , e ) ;
}
}
@Override
public void mouseEntered ( MouseEvent e ) {
redirect . setCursor ( Cursor . getPredefinedCursor ( Cursor . HAND_CURSOR ) ) ;
}
}
} ;
connectionThread . execute ( ) ;
@Override
public void mouseExited ( MouseEvent e ) {
redirect . setCursor ( Cursor . getDefaultCursor ( ) ) ;
}
} ) ;
} else {
redirect . setText ( Toolkit . i18nText ( "Fine_Designer_Not_Found_Driver_No_Solution" ) ) ;
}
gridJpanel . add ( redirect ) ;
hiddenPanel . add ( gridJpanel ) ;
gridJpanel . setBackground ( Color . WHITE ) ;
} else {
JPanel borderPanel = new JPanel ( ) ;
borderPanel . setLayout ( new BorderLayout ( ) ) ;
JTextArea jta = new JTextArea ( ) ;
JScrollPane jsp = new JScrollPane ( jta ) ;
jsp . setVerticalScrollBarPolicy ( JScrollPane . VERTICAL_SCROLLBAR_AS_NEEDED ) ;
jsp . setHorizontalScrollBarPolicy ( JScrollPane . HORIZONTAL_SCROLLBAR_AS_NEEDED ) ;
jta . append ( select . getResultException ( ) . getDetailMessage ( ) + "\n" ) ;
jta . append ( select . getResultException ( ) . getSolution ( ) ) ;
jta . setCaretPosition ( 0 ) ;
jta . setEditable ( false ) ;
jta . getCaret ( ) . addChangeListener ( new ChangeListener ( ) {
@Override
public void stateChanged ( ChangeEvent e ) {
jta . getCaret ( ) . setVisible ( true ) ;
}
} ) ;
borderPanel . add ( jsp , BorderLayout . CENTER ) ;
hiddenPanel . add ( borderPanel ) ;
}
okButton . setEnabled ( true ) ;
}
}
} ;
midPane . setVisible ( false ) ;
hiddenPanel . setVisible ( false ) ;
initDialogPane ( ) ;
initDialogPane ( ) ;
connectionThread . execute ( ) ;
// 老bug,initDialogPane 中的 dialog每次都是new的,所以可以重新添加 listener,但是其他的对象不行,会多次添加listener
if ( firstCreate ) {
okButton . addActionListener ( new ActionListener ( ) {
okButton . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent e ) {
public void actionPerformed ( ActionEvent e ) {
hiddenPanel . removeAll ( ) ;
dialog . dispose ( ) ;
dialog . dispose ( ) ;
}
}
} ) ;
} ) ;
cancelButton . addActionListener ( new ActionListener ( ) {
cancelButton . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent e ) {
public void actionPerformed ( ActionEvent e ) {
hiddenPanel . removeAll ( ) ;
dialog . dispose ( ) ;
dialog . dispose ( ) ;
connectionThread . cancel ( true ) ;
connectionThread . cancel ( true ) ;
}
}
} ) ;
} ) ;
detailLabel . addMouseListener ( new MouseAdapter ( ) {
@Override
public void mouseClicked ( MouseEvent e ) {
if ( hiddenPanel . isVisible ( ) ) {
hiddenPanel . setVisible ( false ) ;
dialog . setSize ( new Dimension ( 380 , 142 ) ) ;
detailLabel . setText ( Toolkit . i18nText ( "Fine_Designer_Look_Detail" ) ) ;
directUiLabel . setIcon ( UIManager . getIcon ( "OptionPane.narrow.right" ) ) ;
} else {
dialog . setSize ( new Dimension ( 380 , 260 ) ) ;
hiddenPanel . setVisible ( true ) ;
detailLabel . setText ( Toolkit . i18nText ( "Fine_Designer_Hide_Detail" ) ) ;
directUiLabel . setIcon ( UIManager . getIcon ( "OptionPane.narrow.down" ) ) ;
}
}
@Override
public void mouseEntered ( MouseEvent e ) {
detailLabel . setCursor ( Cursor . getPredefinedCursor ( Cursor . HAND_CURSOR ) ) ;
}
@Override
public void mouseExited ( MouseEvent e ) {
detailLabel . setCursor ( Cursor . getDefaultCursor ( ) ) ;
}
} ) ;
firstCreate = false ;
}
dialog . addWindowListener ( new WindowAdapter ( ) {
dialog . addWindowListener ( new WindowAdapter ( ) {
@Override
public void windowClosed ( WindowEvent e ) {
public void windowClosed ( WindowEvent e ) {
connectionThread . cancel ( true ) ;
connectionThread . cancel ( true ) ;
}
}
} ) ;
} ) ;
dialog . setVisible ( true ) ;
dialog . setVisible ( true ) ;
hiddenPanel . removeAll ( ) ;
dialog . dispose ( ) ;
dialog . dispose ( ) ;
}
}
} ;
} ;
protected abstract JPanel mainPanel ( ) ;
protected abstract boolean isFineBI ( ) ;
@Override
public void populateBean ( com . fr . data . impl . Connection ob ) {
this . originalCharSet = ob . getOriginalCharsetName ( ) ;
if ( StringUtils . isBlank ( originalCharSet ) ) {
this . charSetComboBox . setSelectedItem ( Toolkit . i18nText ( "Fine-Design_Encode_Auto" ) ) ;
} else {
this . charSetComboBox . setSelectedItem ( ob . getOriginalCharsetName ( ) ) ;
}
populateSubDatabaseConnectionBean ( ( E ) ob ) ;
}
protected abstract void populateSubDatabaseConnectionBean ( E ob ) ;
@Override
public com . fr . data . impl . Connection updateBean ( ) {
E ob = updateSubDatabaseConnectionBean ( ) ;
ob . setOriginalCharsetName ( this . originalCharSet ) ;
if ( this . charSetComboBox . getSelectedIndex ( ) = = 0 ) {
ob . setNewCharsetName ( null ) ;
ob . setOriginalCharsetName ( null ) ;
} else {
ob . setNewCharsetName ( EncodeConstants . ENCODING_GBK ) ;
ob . setOriginalCharsetName ( ( ( String ) this . charSetComboBox . getSelectedItem ( ) ) ) ;
}
return ob ;
}
protected abstract E updateSubDatabaseConnectionBean ( ) ;
protected void initComponents ( ) {
message = new UILabel ( ) ;
uiLabel = new UILabel ( ) ;
detailLabel = new UILabel ( ) ;
directUiLabel = new UILabel ( ) ;
hiddenPanel = new JPanel ( ) ;
midPane = new JPanel ( ) ;
midPane . add ( directUiLabel ) ;
midPane . add ( detailLabel ) ;
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 ( ) ;
this . add ( northPane , BorderLayout . NORTH ) ;
// 按钮.
JPanel testPane = FRGUIPaneFactory . createNormalFlowInnerContainer_M_Pane ( ) ;
northPane . add ( testPane , BorderLayout . NORTH ) ;
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 ) ) ;
// Center
northPane . add ( mainPanel ( ) , BorderLayout . CENTER ) ;
// ChartSet
JPanel chartSetPane = FRGUIPaneFactory . createNColumnGridInnerContainer_S_Pane ( 2 ) ;
northPane . add ( chartSetPane ) ;
chartSetPane . setBorder ( BorderFactory . createTitledBorder (
new ModLineBorder ( ModLineBorder . TOP ) ,
Toolkit . i18nText ( "Fine-Design_Basic_Advanced" )
) ) ;
chartSetPane . add ( GUICoreUtils . createNamedPane ( charSetComboBox , Toolkit . i18nText ( "Fine-Design_Basic_Datasource_Charset" ) + ":" ) ) ;
}
private void initDialogPane ( ) {
private void initDialogPane ( ) {
message . setText ( 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 ) ) ;
message . setBorder ( BorderFactory . createEmptyBorder ( 8 , 5 , 0 , 0 ) ) ;
okButton . setEnabled ( false ) ;
okButton . setEnabled ( false ) ;
dialog = new JDialog ( ( Dialog ) SwingUtilities . getWindowAncestor ( DatabaseConnectionPane . this ) , 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 ) ) ;
dialog . setSize ( new Dimension ( 380 , 118 ) ) ;
okButton . setEnabled ( false ) ;
okButton . setEnabled ( false ) ;
JPanel jp = new JPanel ( ) ;
JPanel jp = new JPanel ( ) ;
JPanel upPane = new JPanel ( ) ;
JPanel upPane = new JPanel ( ) ;
JPanel downPane = new JPanel ( ) ;
JPanel downPane = new JPanel ( ) ;
uiLabel = new UILabel ( UIManager . getIcon ( "OptionPane.informationIcon" ) ) ;
uiLabel = new UILabel ( UIManager . getIcon ( "OptionPane.informationIcon" ) ) ;
upPane . setLayout ( new FlowLayout ( FlowLayout . LEFT , 10 , 10 ) ) ;
upPane . setLayout ( new FlowLayout ( FlowLayout . LEFT , 10 , 10 ) ) ;
upPane . add ( uiLabel ) ;
upPane . add ( uiLabel ) ;
upPane . add ( message ) ;
upPane . add ( message ) ;
downPane . setLayout ( new FlowLayout ( FlowLayout . CENTER , 6 , 0 ) ) ;
midPane . setLayout ( new FlowLayout ( FlowLayout . LEFT , 10 , 0 ) ) ;
directUiLabel . setIcon ( UIManager . getIcon ( "OptionPane.narrow.right" ) ) ;
detailLabel . setText ( Toolkit . i18nText ( "Fine_Designer_Look_Detail" ) ) ;
detailLabel . setForeground ( Color . BLUE ) ;
hiddenPanel . setLayout ( new BorderLayout ( 10 , 0 ) ) ;
hiddenPanel . add ( new JPanel ( ) , BorderLayout . WEST ) ;
hiddenPanel . add ( new JPanel ( ) , BorderLayout . EAST ) ;
downPane . setLayout ( new FlowLayout ( FlowLayout . CENTER , 6 , 9 ) ) ;
downPane . add ( okButton ) ;
downPane . add ( okButton ) ;
downPane . add ( cancelButton ) ;
downPane . add ( cancelButton ) ;
jp . setLayout ( new BoxLayout ( jp , BoxLayout . Y_AXIS ) ) ;
jp . setLayout ( new BoxLayout ( jp , BoxLayout . Y_AXIS ) ) ;
jp . add ( upPane ) ;
jp . add ( upPane ) ;
jp . add ( midPane ) ;
jp . add ( hiddenPanel ) ;
jp . add ( downPane ) ;
jp . add ( downPane ) ;
dialog . add ( jp ) ;
dialog . add ( jp ) ;
dialog . setResizable ( false ) ;
dialog . setResizable ( false ) ;
@ -268,5 +406,4 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
return "JNDI" ;
return "JNDI" ;
}
}
}
}
}
}