eclipse首选项没有Java,Eclipse:以编程方式创建首选项页面

I'm trying to create a preference page programmatically, I need to work with preference pages without define preferencePage extension point in plugin.xml

I'm very close to solution, I'm able to load page and save the value the first time application loads,

the core of my code is

PreferenceManager pmngr= PlatformUI.getWorkbench().getPreferenceManager();

//this come from other plugins that implements my personal IPreferences

PreferencePageRCP page =new PreferencePageRCP((IPreferences) element.createExecutableExtension("class"));

PreferenceNodeRCP node= new PreferenceNodeRCP(page.getId(), page.getTitle(),null,PreferencePageRCP.class.getName());

node.setPage(page);

pmngr.addToRoot(node);

where PreferencePageRCP is my Custom PreferencePage so a this point I have my PreferencePage working!!!

but when I go a second time to preference window I got an error on PreferenceNode.createPage, so now I did my own PreferenceNode class overriding createPage but now I got an UI error

Problems occurred when invoking code from plug-in: "org.eclipse.jface".

!STACK 0

org.eclipse.swt.SWTException: Widget is disposed

at org.eclipse.swt.SWT.error(SWT.java:4083)

at org.eclipse.swt.SWT.error(SWT.java:3998)

at org.eclipse.swt.SWT.error(SWT.java:3969)

at org.eclipse.swt.widgets.Widget.error(Widget.java:468)

at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)

at org.eclipse.swt.widgets.Control.setVisible(Control.java:3370)

at org.eclipse.jface.dialogs.DialogPage.setVisible(DialogPage.java:470)

at org.eclipse.jface.preference.FieldEditorPreferencePage.setVisible(FieldEditorPreferencePage.java:374)

at org.eclipse.jface.preference.PreferenceDialog.showPage(PreferenceDialog.java:1323)

at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.showPage(FilteredPreferenceDialog.java:673)

at org.eclipse.jface.preference.PreferenceDialog$10.run(PreferenceDialog.java:708)

at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)

andContributionItem.java:796

.................

So the second time there is something missing in UI

I at this point I'm not able to fix my code, there is someone who had success in create Preference Page Programmatically???

解决方案

Here is the java code, which allows the creation of a preference Page programmatically:

//create an instance of the custom MyPreference class

IPreferencePage page = new MyPreference();

page.setTitle("Custom Configurations");

//create a new PreferenceNode that will appear in the Preference window

PreferenceNode node = new PreferenceNode("1", page);

//use workbenches's preference manager

PreferenceManager pm= PlatformUI.getWorkbench().getPreferenceManager();

pm.addToRoot(node); //add the node in the PreferenceManager

Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

//instantiate the PreferenceDialog

PreferenceDialog pd = new PreferenceDialog(shell, pm);

//this line is important, it tell's the PreferenceDialog which preference-store it should write to

pd.setPreferenceStore(Activator.getDefault().getPreferenceStore());

pd.create();

pd.open();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值