Eclipse RCP Preferences

葛景龙
2023-12-01
1.显示Preferences窗口,首先preferenceAction是一个标准Command,把它创建出来并注册,然后加到菜单中就可以了
preferenceAction = ActionFactory.PREFERENCES.create(window);

2.获得所有的Preferences项,得到后可以将部分项隐藏起来
PreferenceManager mgr = PlatformUI.getWorkbench().getPreferenceManager();
IPreferenceNode[] nodes = mgr.getRootSubNodes();

隐藏的办法有2个,一个是修改ApplicationWorkbenchWindowAdvisor
public void preWindowOpen() {
PreferenceManager mgr = PlatformUI.getWorkbench().getPreferenceManager();
mgr.remove("org.eclipse.help.ui.browsersPreferencePage");//去掉帮助的Preference
第二个是创建自己的preferenceAction,加入
PreferenceManager mgr = PlatformUI.getWorkbench().getPreferenceManager();
IPreferenceNode[] nodes = mgr.getRootSubNodes();
/*for ( int i=0; i<nodes.length; i++){
System.out.println(nodes[i].getLabelText());
System.out.println(nodes[i].getId());
}*/
try{
mgr.remove("org.eclipse.ui.preferencePages.Workbench");//去掉这个结点
mgr.remove("org.eclipse.update.internal.ui.preferences.MainPreferencePage");

PreferenceDialog dlg = new PreferenceDialog(window.getShell(), mgr);
dlg.open();
}catch(Exception e){
e.printStackTrace();
}
}

3.打开Preferences窗口的其他方法
打开PreferencePageDialog:
PreferenceManager manager = window.getWorkbench().getPreferenceManager();
PreferenceDialog dialog = new PreferenceDialog(window.getShell(), manager);
dialog.open();

打开PropertyPageDialog:
PropertyDialog dialog = PropertyDialog.createDialogOn(shell, null, element);
dialog.open();

打开只有选定首选项页的Dialog:
WorkbenchPreferenceDialog dialog = WorkbenchPreferenceDialog.createDialogOn(parent.getShell(), id);
dialog.showOnly(new String[] { id });
dialog.open();

4.代码实现具体功能可参考http://blog.csdn.net/moneyice/archive/2006/04/07/653557.aspx

5.参考资料
http://www.eclipselight.org/general/94/
http://www.eclipse.org/articles/Article-Field-Editors/field_editors.html
http://www.eclipse.org/articles/Article-Mutatis-mutandis/overlay-pages.html
http://www.eclipse.org/articles/Article-Preferences/preferences.htm
 类似资料:

相关阅读

相关文章

相关问答