How do I make preferences dialog to open up on a particular page? Doing this opens pref. dialog on the first page by default :
如何在特定页面上打开首选项对话框?这样做会打开pref。默认情况下,第一页上的对话框:
OpenPreferencesAction action = new OpenPreferencesAction();
action.run();
How can I tell it to display some other page from preferences tree?
如何告诉它显示首选项树中的其他页面?
2 个解决方案
#1
You need to create your own action extending OpenPreferencesAction and overriding the run() method, passing the id of the page to be opened. If you look at OpenPreferencesAction you'll see the run method is like this:
您需要创建自己的操作,扩展OpenPreferencesAction并覆盖run()方法,传递要打开的页面的id。如果你看一下OpenPreferencesAction,你会发现run方法是这样的:
public void run() {
if (workbenchWindow == null) {
// action has been dispose
return;
}
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, null, null, null);
dialog.open();
}
The second and third parameters determine the id of the page to display and the filtering criteria.
第二个和第三个参数确定要显示的页面的ID和过滤条件。
#2
Open Preference page Dialog (click menu button) in Eclipse RCP.
在Eclipse RCP中打开“首选项”页面对话框(单击“菜单”按钮)。
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import com_demo.PreferencePage.PreferencePage_Dialog;
public class Preferences_Dialog_cmd extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),PreferencePage_Dialog.ID , null, null);
if (pref != null)
pref.open();
return null;
}
}
public class PreferencePage_Dialog extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
{
public static final String ID="custom_bill.PreferencePage_Dialog";
@Override
protected void createFieldEditors() {
//..........
}
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
}
}
#1
You need to create your own action extending OpenPreferencesAction and overriding the run() method, passing the id of the page to be opened. If you look at OpenPreferencesAction you'll see the run method is like this:
您需要创建自己的操作,扩展OpenPreferencesAction并覆盖run()方法,传递要打开的页面的id。如果你看一下OpenPreferencesAction,你会发现run方法是这样的:
public void run() {
if (workbenchWindow == null) {
// action has been dispose
return;
}
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, null, null, null);
dialog.open();
}
The second and third parameters determine the id of the page to display and the filtering criteria.
第二个和第三个参数确定要显示的页面的ID和过滤条件。
#2
Open Preference page Dialog (click menu button) in Eclipse RCP.
在Eclipse RCP中打开“首选项”页面对话框(单击“菜单”按钮)。
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import com_demo.PreferencePage.PreferencePage_Dialog;
public class Preferences_Dialog_cmd extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),PreferencePage_Dialog.ID , null, null);
if (pref != null)
pref.open();
return null;
}
}
public class PreferencePage_Dialog extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
{
public static final String ID="custom_bill.PreferencePage_Dialog";
@Override
protected void createFieldEditors() {
//..........
}
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
}
}