Browse Source

Pull request #3934: REPORT-49023 数据连接界面报错优化

Merge in DESIGN/design from ~XIQIU/design:feature/10.0 to feature/10.0

* commit '4ddd6b5efef03e30ee14a6e05c31efbb7fdf4719':
  REPORT-49023   根据pr来修改代码
  REPORT-49023   数据连接界面报错优化
feature/10.0
Xiqiu 4 years ago
parent
commit
31248a912f
  1. 313
      designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java
  2. 8
      designer-base/src/main/java/com/fr/design/gui/UILookAndFeel.java
  3. BIN
      designer-base/src/main/resources/com/fr/design/images/lookandfeel/Icon_Narrow_Down_16x16.png
  4. BIN
      designer-base/src/main/resources/com/fr/design/images/lookandfeel/Icon_Narrow_Right_16x16.png
  5. BIN
      designer-base/src/main/resources/com/fr/design/images/lookandfeel/Information_Icon_Error_32x32.png

313
designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java

@ -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,36 +76,168 @@ 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);
// 按钮. @Override
JPanel testPane = FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane(); public void actionPerformed(ActionEvent evt) {
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 // Try the java connection.
northPane.add(mainPanel(), BorderLayout.CENTER); final SwingWorker<Void, Void> connectionThread = new SwingWorker<Void, Void>() {
// ChartSet @Override
JPanel chartSetPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(2); protected Void doInBackground() throws Exception {
northPane.add(chartSetPane); Connection database = DatabaseConnectionPane.this.updateBean();
chartSetPane.setBorder(BorderFactory.createTitledBorder( // 返回连接结果
new ModLineBorder(ModLineBorder.TOP), DriverPage.updateCache();
Toolkit.i18nText("Fine-Design_Basic_Advanced") DataOperator.getInstance().testConnectionWithException(database);
)); return null;
chartSetPane.add(GUICoreUtils.createNamedPane(charSetComboBox, Toolkit.i18nText("Fine-Design_Basic_Datasource_Charset") + ":")); }
}
@Override
protected void done() {
try {
get();
dialog.setSize(new Dimension(380, 118));
okButton.setEnabled(true);
uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon"));
message.setText(Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully"));
} 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"));
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);
}
}
@Override
public void mouseEntered(MouseEvent e) {
redirect.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
@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();
connectionThread.execute();
// 老bug,initDialogPane 中的 dialog每次都是new的,所以可以重新添加 listener,但是其他的对象不行,会多次添加listener
if (firstCreate) {
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
hiddenPanel.removeAll();
dialog.dispose();
}
});
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
hiddenPanel.removeAll();
dialog.dispose();
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() {
@Override
public void windowClosed(WindowEvent e) {
connectionThread.cancel(true);
}
});
dialog.setVisible(true);
hiddenPanel.removeAll();
dialog.dispose();
}
};
protected abstract JPanel mainPanel(); protected abstract JPanel mainPanel();
@ -127,83 +276,72 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
protected abstract E updateSubDatabaseConnectionBean(); protected abstract E updateSubDatabaseConnectionBean();
ActionListener testConnectionActionListener = new ActionListener() { protected void initComponents() {
public void actionPerformed(ActionEvent evt) { message = new UILabel();
uiLabel = new UILabel();
// Try the java connection. detailLabel = new UILabel();
final SwingWorker<Boolean, Void> connectionThread = new SwingWorker<Boolean, Void>() { directUiLabel = new UILabel();
@Override hiddenPanel = new JPanel();
protected Boolean doInBackground() throws Exception { midPane = new JPanel();
Connection database = DatabaseConnectionPane.this.updateBean(); midPane.add(directUiLabel);
// 返回连接结果 midPane.add(detailLabel);
return DataOperator.getInstance().testConnection(database); 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")};
@Override charSetComboBox = new UIComboBox(ArrayUtils.addAll(defaultEncode, EncodeConstants.ENCODING_ARRAY));
protected void done() { this.setLayout(FRGUIPaneFactory.createBorderLayout());
try { JPanel northPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane();
boolean connect = get(); this.add(northPane, BorderLayout.NORTH);
okButton.setEnabled(true);
if (connect) {
uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon"));
message.setText(Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully"));
}else{
uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon"));
message.setText(Toolkit.i18nText("Fine-Design_Basic_Connection_Failed"));
}
} catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
};
connectionThread.execute();
initDialogPane();
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
connectionThread.cancel(true);
}
});
dialog.addWindowListener(new WindowAdapter() { // 按钮.
public void windowClosed(WindowEvent e) { JPanel testPane = FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane();
connectionThread.cancel(true); 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));
dialog.setVisible(true); // Center
dialog.dispose(); 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";
} }
} }
} }

8
designer-base/src/main/java/com/fr/design/gui/UILookAndFeel.java

@ -30,10 +30,12 @@ import com.fr.design.gui.itoolbar.UIToolBarSeparatorUI;
import com.fr.design.gui.itooltip.UIToolTipBorder; import com.fr.design.gui.itooltip.UIToolTipBorder;
import com.fr.design.gui.itree.UITreeUI; import com.fr.design.gui.itree.UITreeUI;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.log.FineLoggerFactory;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import javax.swing.*; import javax.swing.ImageIcon;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.BorderUIResource;
@ -171,6 +173,8 @@ public class UILookAndFeel extends MetalLookAndFeel {
table.put("FileChooser.upFolderIcon", loadIcon("ParentDirectoryIcon.png", this)); table.put("FileChooser.upFolderIcon", loadIcon("ParentDirectoryIcon.png", this));
table.put("OptionPane.errorIcon", loadIcon("Information_Icon_Error_32x32.png", this)); table.put("OptionPane.errorIcon", loadIcon("Information_Icon_Error_32x32.png", this));
table.put("OptionPane.informationIcon", loadIcon("Information_Icon_OK_32x32.png", this)); table.put("OptionPane.informationIcon", loadIcon("Information_Icon_OK_32x32.png", this));
table.put("OptionPane.narrow.right", loadIcon("icon_narrow_right_16x16.png", this));
table.put("OptionPane.narrow.down", loadIcon("icon_narrow_down_16x16.png", this));
table.put("OptionPane.warningIcon", loadIcon("WarningIcon.png", this)); table.put("OptionPane.warningIcon", loadIcon("WarningIcon.png", this));
table.put("OptionPane.questionIcon", loadIcon("QuestionIcon.png", this)); table.put("OptionPane.questionIcon", loadIcon("QuestionIcon.png", this));
table.put("ScrollPane.border", new UIScrollPaneBorder()); table.put("ScrollPane.border", new UIScrollPaneBorder());

BIN
designer-base/src/main/resources/com/fr/design/images/lookandfeel/Icon_Narrow_Down_16x16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

BIN
designer-base/src/main/resources/com/fr/design/images/lookandfeel/Icon_Narrow_Right_16x16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

BIN
designer-base/src/main/resources/com/fr/design/images/lookandfeel/Information_Icon_Error_32x32.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 752 B

After

Width:  |  Height:  |  Size: 760 B

Loading…
Cancel
Save