启用和禁用FieldEditors

时间:2016-07-19 12:45:37

标签: java swt eclipse-rcp jface

我怀疑插件开发中的FieldEditors的相关用法。我有一个首选项页面,它基本上由一些StringFieldEditors,booleanFieldEditors,RadioGroupFieldEditors等组成。

我面临的问题如下:

我有一个名为“完整详细信息”的booleanFiledEditor。代码如下:

BooleanFieldEditor fullDetails = new BooleanFieldEditor("fullDetails", "Full Details", org.eclipse.swt.SWT.NONE, getFieldEditorParent()); 
addField(fullDetails); 

一旦用户检查了这个布尔字段,就应该启用跟随此booleanFieldEditor的StringFieldEditors。否则他们应该保持禁用状态其他StringFieldEditors的代码如下:

StringFieldEditor machineName = new StringFieldEditor("machineName", "Host name", getFieldEditorParent()); 
addField(machineName);

StringFieldEditor ipaddress = new StringFieldEditor("ipaddress", "IP Address", getFieldEditorParent()); 
addField(ipaddress); 

StringFieldEditor cpuinfo = new StringFieldEditor("cpuinfo", "CPU Info", getFieldEditorParent()); 
addField(cpuinfo); 

如果有人能就如何做到这一点给出一些指示,将会非常有帮助。

1 个答案:

答案 0 :(得分:0)

您可以使用布尔字段编辑器的setPropertyChangeListener方法在字段更改时执行操作。类似的东西:

fullDetails.setPropertyChangeListener(new IPropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent event) {
        boolean newValue = ((Boolean) event.getNewValue()).booleanValue();

        // Enable/disable other fields

        machineName.setEnabled(newValue, getFieldEditorParent());
        .... other fields ....
    });