System.out.println("old value:" + event.getOldValue());
System.out.println("new value:" + event.getNewValue());
}
}
});
preferenceStore.setValue("Database", "sqlserver"); // 触发事件
18.3 显示首选项页面
1. 创建一个首选项页面
package www.swt.com.ch18;
import org.eclipse.jface.preference.IPreferenceStore;
public class SystemSettingPage extends PreferencePage {
public SystemSettingPage() {
}
private Text userName;
private Text password;
//该方法为必须实现的方法,在此方法中创建页面上的各种控件
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
//获取保存此页面的PreferenceStore对象
IPreferenceStore preferenceStore = getPreferenceStore();
new Label(composite, SWT.LEFT).setText("登录用户名:");
userName = new Text(composite, SWT.BORDER);
userName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
//设置用户名为保存在文件中的值
userName.setText(preferenceStore.getString(Constants.USER_NAME));
new Label(composite, SWT.LEFT).setText("登录密码:");
password = new Text(composite, SWT.BORDER);
password.setEchoChar('*');
password.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
//设置密码为保存在文件中的值
password.setText(preferenceStore.getString(Constants.PASSWORD));
评论0
最新资源