[英]Eclipse project property/preference page: How to find event of opening preference page in project property window(Eclipse)
我想在页面打开时在首选项页面上初始化一些字段值,并且我希望每次在Project属性window(Eclipse)中打开页面时都使用它。
Try to implement a property change listener. 尝试实现属性更改侦听器。
This may help- 这可能会帮助-
public class MyFieldEditorPreferencePage extends PropertyPage {
private Text text;
public void initialize() {
// TODO Auto-generated constructor stub
IProject project = (IProject) getElement().getAdapter(IProject.class);
final IPreferenceStore store = Activator
.getImpaktPreferenceStore(project);
store.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(
org.eclipse.jface.util.PropertyChangeEvent event) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
if (text != null && !text.isDisposed())
text.setText(store.getString("key"));
}
});
setPreferenceStore(store);
}
@Override
protected Control createContents(Composite parent) {
// TODO Auto-generated method stub
initialize();
GridLayout layout = new GridLayout(1, false);
parent.setLayout(layout);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
Composite container = new Composite(parent, 0);
container.setLayoutData(gridData);
GridLayout containerLayout = new GridLayout(2, false);
container.setLayout(containerLayout);
Label lbl = new Label(container, 0);
lbl.setText("Locale");
text = new Text(container, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
text.setText(getPreferenceStore().getString("impakt.properties.locale"));
return parent;
}
} }
org.eclipse.jface.preference.PreferencePage
has a setPreferenceStore
method that you should call in your preference page constructor. org.eclipse.jface.preference.PreferencePage
具有setPreferenceStore
方法,您应该在首选项页面构造函数中调用该方法。 The preference store specified often comes from the plugin activator, like this example from the compare plugin preferences: 指定的首选项存储通常来自插件激活器,例如来自比较插件首选项的以下示例:
setPreferenceStore(CompareUIPlugin.getDefault().getPreferenceStore());
There is a getPreferenceStore()
method to call to access this store. 有一个
getPreferenceStore()
方法getPreferenceStore()
用以访问此商店。
Override public void setVisible(boolean visible)
if you want to be notified each time the page becomes visible. 如果希望在每次页面可见时都收到通知,则重写
public void setVisible(boolean visible)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.