0

我想在打开页面时在首选项页面上初始化一些字段值,并且我希望每次在项目属性窗口(Eclipse)中打开页面时都需要它。

4

2 回答 2

1

尝试实现属性更改侦听器。

这可能会有所帮助——

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;
}

}

于 2013-10-24T07:23:58.120 回答
0

org.eclipse.jface.preference.PreferencePage有一个setPreferenceStore你应该在你的偏好页面构造函数中调用的方法。指定的首选项存储通常来自插件激活器,例如来自比较插件首选项的示例:

setPreferenceStore(CompareUIPlugin.getDefault().getPreferenceStore());

有一个getPreferenceStore()方法可以调用来访问这个商店。

public void setVisible(boolean visible)如果您想在每次页面可见时收到通知,请覆盖。

于 2013-10-23T15:08:31.650 回答