kerry
3 years ago
4 changed files with 181 additions and 33 deletions
@ -0,0 +1,147 @@ |
|||||||
|
package com.fr.design.data.datapane.connect; |
||||||
|
|
||||||
|
import com.fr.data.impl.JDBCDatabaseConnection; |
||||||
|
import com.fr.data.pool.DBCPConnectionPoolAttr; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
|
import com.fr.design.editor.editor.IntegerEditor; |
||||||
|
import com.fr.design.gui.icombobox.UIComboBox; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.SwingConstants; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.event.FocusEvent; |
||||||
|
import java.awt.event.FocusListener; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author xiqiu |
||||||
|
* @date 2021/11/22 |
||||||
|
* @description |
||||||
|
*/ |
||||||
|
public class AdvancePane extends BasicPane { |
||||||
|
private IntegerEditor DBCP_MAX_ACTIVE = new IntegerEditor(); |
||||||
|
private UIComboBox DBCP_TESTONBORROW = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); |
||||||
|
private IntegerEditor DBCP_MAX_WAIT = new IntegerEditor(); |
||||||
|
private SpecialUITextField DBCP_VALIDATION_QUERY = new SpecialUITextField(); |
||||||
|
|
||||||
|
|
||||||
|
public AdvancePane() { |
||||||
|
|
||||||
|
DBCP_VALIDATION_QUERY.addFocusListener(new JTextFieldHintListener(DBCP_VALIDATION_QUERY)); |
||||||
|
; |
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
DBCP_VALIDATION_QUERY.setColumns(15); |
||||||
|
double[] rowSizeDbcp = {p, p, p, p}; |
||||||
|
double[] columnDbcp = {p, p}; |
||||||
|
Component[][] comps = { |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE}, |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY}, |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Borrow") + ":", SwingConstants.RIGHT), DBCP_TESTONBORROW}, |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Max_Wait_Time") + ":", SwingConstants.RIGHT), DBCP_MAX_WAIT} |
||||||
|
}; |
||||||
|
|
||||||
|
JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSizeDbcp, columnDbcp, 11, 11); |
||||||
|
this.add(contextPane); |
||||||
|
this.setPreferredSize(new Dimension(630, 120)); |
||||||
|
this.setLayout(FRGUIPaneFactory.createLeftZeroVgapNormalHgapLayout()); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void populate(JDBCDatabaseConnection jdbcDatabase) { |
||||||
|
DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); |
||||||
|
if (dbcpAttr == null) { |
||||||
|
dbcpAttr = new DBCPConnectionPoolAttr(); |
||||||
|
jdbcDatabase.setDbcpAttr(dbcpAttr); |
||||||
|
} |
||||||
|
this.DBCP_MAX_ACTIVE.setValue(dbcpAttr.getMaxActive()); |
||||||
|
this.DBCP_MAX_WAIT.setValue(dbcpAttr.getMaxWait()); |
||||||
|
this.DBCP_VALIDATION_QUERY.setText(dbcpAttr.getValidationQuery()); |
||||||
|
this.DBCP_TESTONBORROW.setSelectedIndex(dbcpAttr.isTestOnBorrow() ? 1 : 0); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void update(JDBCDatabaseConnection jdbcDatabase) { |
||||||
|
DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); |
||||||
|
if (dbcpAttr == null) { |
||||||
|
dbcpAttr = new DBCPConnectionPoolAttr(); |
||||||
|
jdbcDatabase.setDbcpAttr(dbcpAttr); |
||||||
|
} |
||||||
|
dbcpAttr.setMaxActive(this.DBCP_MAX_ACTIVE.getValue().intValue()); |
||||||
|
dbcpAttr.setMaxWait(this.DBCP_MAX_WAIT.getValue().intValue()); |
||||||
|
dbcpAttr.setValidationQuery(this.DBCP_VALIDATION_QUERY.getText()); |
||||||
|
dbcpAttr.setTestOnBorrow(this.DBCP_TESTONBORROW.getSelectedIndex() == 0 ? false : true); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return Toolkit.i18nText("Fine-Design_Basic_Advanced_Setup"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private class JTextFieldHintListener implements FocusListener { |
||||||
|
private SpecialUITextField textField; |
||||||
|
|
||||||
|
public JTextFieldHintListener(SpecialUITextField jTextField) { |
||||||
|
this.textField = jTextField; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void focusGained(FocusEvent e) { |
||||||
|
//获取焦点时,清空提示内容
|
||||||
|
String temp = textField.getText(); |
||||||
|
textField.setForeground(Color.BLACK); |
||||||
|
textField.setTextOrigin(temp); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void focusLost(FocusEvent e) { |
||||||
|
//失去焦点时,没有输入内容,显示提示内容
|
||||||
|
String temp = textField.getTextOrigin(); |
||||||
|
textField.setText(temp); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private class SpecialUITextField extends UITextField { |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getText() { |
||||||
|
String text = super.getText(); |
||||||
|
if (isUseless(text)) { |
||||||
|
return StringUtils.EMPTY; |
||||||
|
} |
||||||
|
return text; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setText(String text) { |
||||||
|
if (isUseless(text)) { |
||||||
|
this.setForeground(Color.GRAY); |
||||||
|
super.setText(Toolkit.i18nText("Fine-Design_Dbcp_Default_Query")); |
||||||
|
} else { |
||||||
|
this.setForeground(Color.BLACK); |
||||||
|
super.setText(text); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public String getTextOrigin() { |
||||||
|
return super.getText(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setTextOrigin(String text) { |
||||||
|
super.setText(text); |
||||||
|
} |
||||||
|
|
||||||
|
private boolean isUseless(String text) { |
||||||
|
return text == null || text.isEmpty() || Toolkit.i18nText("Fine-Design_Dbcp_Default_Query").equals(text); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue