Reputation: 4128
How do I make preferences dialog to open up on a particular page? Doing this opens pref. dialog on the first page by default :
OpenPreferencesAction action = new OpenPreferencesAction();
action.run();
How can I tell it to display some other page from preferences tree?
Upvotes: 4
Views: 2027
Reputation: 572
Open Preference page Dialog (click menu button) in 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());
}
}
Upvotes: 0
Reputation: 84068
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:
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.
Upvotes: 9