Browse Source

控件校验完善

master
kerry 8 years ago
parent
commit
4f8b8bba2b
  1. 202
      designer/src/com/fr/design/widget/ui/FieldEditorDefinePane.java

202
designer/src/com/fr/design/widget/ui/FieldEditorDefinePane.java

@ -8,6 +8,7 @@ import javax.swing.BorderFactory;
import com.fr.design.gui.frpane.TreeSettingPane; import com.fr.design.gui.frpane.TreeSettingPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
@ -22,105 +23,106 @@ import com.fr.general.Inter;
import com.fr.design.widget.DataModify; import com.fr.design.widget.DataModify;
public abstract class FieldEditorDefinePane<T extends FieldEditor> extends AbstractDataModify<T> { public abstract class FieldEditorDefinePane<T extends FieldEditor> extends AbstractDataModify<T> {
private UICheckBox allowBlankCheckBox; private UICheckBox allowBlankCheckBox;
// richer:错误信息,是所有控件共有的属性,所以放到这里来 // richer:错误信息,是所有控件共有的属性,所以放到这里来
private UITextField errorMsgTextField; private UITextField errorMsgTextField;
public FieldEditorDefinePane() { public FieldEditorDefinePane() {
this.initComponents(); this.initComponents();
} }
protected void initComponents() { protected void initComponents() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
//JPanel firstPanel = FRGUIPaneFactory.createBorderLayout_M_Pane(); //JPanel firstPanel = FRGUIPaneFactory.createBorderLayout_M_Pane();
allowBlankCheckBox = new UICheckBox(Inter.getLocText("Allow_Blank")); allowBlankCheckBox = new UICheckBox(Inter.getLocText("Allow_Blank"));
allowBlankCheckBox.addItemListener(new ItemListener() { allowBlankCheckBox.addItemListener(new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
errorMsgTextField.setEnabled(!allowBlankCheckBox.isSelected()); errorMsgTextField.setEnabled(!allowBlankCheckBox.isSelected());
} }
}); });
// 错误信息 // 错误信息
JPanel errorMsgPane = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); JPanel errorMsgPane = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane();
//目前只整改了文本、密码、文本域和数字四个控件 //目前只整改了文本、密码、文本域和数字四个控件
this.addAllowBlankPane(allowBlankCheckBox,errorMsgPane); this.addAllowBlankPane(allowBlankCheckBox, errorMsgPane);
errorMsgPane.add(new UILabel(Inter.getLocText(new String[]{"Error", "Tooltips"}) + ":")); errorMsgPane.add(new UILabel(Inter.getLocText(new String[]{"Error", "Tooltips"}) + ":"));
errorMsgTextField = new UITextField(16); errorMsgTextField = new UITextField(16);
errorMsgPane.add(errorMsgTextField); errorMsgPane.add(errorMsgTextField);
// richer:主要为了方便查看比较长的错误信息 // richer:主要为了方便查看比较长的错误信息
errorMsgTextField.getDocument().addDocumentListener(new DocumentListener() { errorMsgTextField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
errorMsgTextField.setToolTipText(errorMsgTextField.getText()); errorMsgTextField.setToolTipText(errorMsgTextField.getText());
} }
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
errorMsgTextField.setToolTipText(errorMsgTextField.getText()); errorMsgTextField.setToolTipText(errorMsgTextField.getText());
} }
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
errorMsgTextField.setToolTipText(errorMsgTextField.getText()); errorMsgTextField.setToolTipText(errorMsgTextField.getText());
} }
}); });
JPanel contentPane = this.setFirstContentPane(); JPanel contentPane = this.setFirstContentPane();
if (contentPane != null) { if (contentPane != null) {
//contentPane.add(firstPanel); //contentPane.add(firstPanel);
this.add(contentPane, BorderLayout.CENTER); this.add(contentPane, BorderLayout.CENTER);
} else { } else {
//this.add(firstPanel, BorderLayout.CENTER); //this.add(firstPanel, BorderLayout.CENTER);
} }
} }
@Override @Override
public void populateBean(T ob) { public void populateBean(T ob) {
this.allowBlankCheckBox.setSelected(ob.isAllowBlank()); this.allowBlankCheckBox.setSelected(ob.isAllowBlank());
errorMsgTextField.setEnabled(!allowBlankCheckBox.isSelected()); errorMsgTextField.setEnabled(!allowBlankCheckBox.isSelected());
this.errorMsgTextField.setText(ob.getErrorMessage()); this.errorMsgTextField.setText(ob.getErrorMessage());
populateSubFieldEditorBean(ob); populateSubFieldEditorBean(ob);
} }
protected abstract void populateSubFieldEditorBean(T ob); protected abstract void populateSubFieldEditorBean(T ob);
@Override @Override
public T updateBean() { public T updateBean() {
T e = updateSubFieldEditorBean(); T e = updateSubFieldEditorBean();
e.setAllowBlank(this.allowBlankCheckBox.isSelected()); e.setAllowBlank(this.allowBlankCheckBox.isSelected());
e.setErrorMessage(this.errorMsgTextField.getText()); e.setErrorMessage(this.errorMsgTextField.getText());
return e; return e;
} }
protected abstract T updateSubFieldEditorBean(); protected abstract T updateSubFieldEditorBean();
protected abstract JPanel setFirstContentPane(); protected abstract JPanel setFirstContentPane();
@Override @Override
public void checkValid() throws Exception { public void checkValid() throws Exception {
} }
public void addAllowBlankPane(UICheckBox allowBlankCheckBox,JPanel errorMsgPane){ public void addAllowBlankPane(UICheckBox allowBlankCheckBox, JPanel errorMsgPane) {
JPanel northPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); JPanel northPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane();
this.add(northPane, BorderLayout.NORTH); this.add(northPane, BorderLayout.NORTH);
JPanel firstPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); JPanel firstPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
firstPanel.setBorder(BorderFactory.createEmptyBorder(0, -2, 0, 0)); firstPanel.setBorder(BorderFactory.createEmptyBorder(0, -2, 0, 0));
firstPanel.add(allowBlankCheckBox); firstPanel.add(allowBlankCheckBox);
firstPanel.add(errorMsgPane); firstPanel.add(errorMsgPane);
northPane.add(firstPanel); northPane.add(firstPanel);
} }
public UICheckBox getAllowBlankCheckBox(){
return allowBlankCheckBox; public UICheckBox getAllowBlankCheckBox() {
} return allowBlankCheckBox;
}
public UITextField getErrorMsgTextField(){
return errorMsgTextField; public UITextField getErrorMsgTextField() {
} return errorMsgTextField;
}
} }
Loading…
Cancel
Save