我制作了一个自定义PreferencePage,它会自动创建“Restore Defaults”和“Apply”按钮,但是,它们不会停留在“OK”和“Cancel”按钮正上方的右下角在Eclipse IDE首选项中执行。他们只是在我创建的最后一个小部件后立即停靠。
如何让这些按钮停留在右下角?
以下是我的代码:
public class MVPrefPage extends PreferencePage实现了IWorkbenchPreferencePage {
List<FieldEditor> editors = new ArrayList<>();
public MVPrefPage() {
}
public MVPrefPage(String title) {
super(title);
}
public MVPrefPage(String title, ImageDescriptor image) {
super(title, image);
}
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(MatrixVisualizationActivator.getDefault().getPreferenceStore());
}
@Override
protected Control createContents(Composite parent) {
editors.add(new BooleanFieldEditor(MatrixSettings.TITLE_ON_PROPERTY, "Show title", parent));
editors.add(new BooleanFieldEditor(MatrixSettings.SHOW_ROW_HEADERS_PROPERTY, "Show row headers", parent));
editors.add(new BooleanFieldEditor(MatrixSettings.SHOW_COLUMN_HEADERS_PROPERTY, "Show column headers", parent));
editors.add(new BooleanFieldEditor(MatrixSettings.SHOW_HIDDEN_VALUES_PROPERTY, "Show hidden values", parent));
editors.add(new BooleanFieldEditor(MatrixSettings.SHOW_MATRIX_ELEMENT_DISPLAY_NAMES_PROPERTY,
"Show matrix element display names", parent));
editors.add(new BooleanFieldEditor(MatrixSettings.CHART_SYNC_HIGHLIGHTER_PROPERTY,
"Highlight view with chart sync", parent));
editors.add(new BooleanFieldEditor(MatrixSettings.CHART_SYNC_SCROLL_PROPERTY, "Scroll view with chart sync",
parent));
editors.add(new BooleanFieldEditor(MatrixSettings.VIEW_SCROLLBAR_SYNC_PROPERTY, "Add scrollbar to synchronizer",
parent));
String[][] entryNamesAndValues = { { "Left", "LEFT" }, { "Right", "RIGHT" }, { "Center", "CENTER" } };
editors.add(new ComboFieldEditor(MatrixSettings.VIEW_SNAP_PROPERTY, "Grid snap setting", entryNamesAndValues,
parent));
editors.stream().forEach(fe -> {
fe.setPreferenceStore(getPreferenceStore());
fe.fillIntoGrid(parent, 2);
fe.load();
});
return parent;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
*/
@Override
protected void performDefaults() {
editors.stream().forEach(fe -> fe.loadDefault());
super.performDefaults();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.PreferencePage#performOk()
*/
@Override
public boolean performOk() {
editors.stream().forEach(fe -> fe.store());
return super.performOk();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.PreferencePage#performApply()
*/
@Override
protected void performApply() {
super.performApply();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.DialogPage#dispose()
*/
@Override
public void dispose() {
editors.stream().forEach(fe -> fe.dispose());
super.dispose();
}
答案 0 :(得分:0)
您不能在BooleanFieldEditor
之外使用FieldEditorPreferencePage
这样的字段编辑器类,因为字段编辑希望能够调整页面布局并且它不会被激活不在FieldEditorPreferencePage
时才能正常工作。