How do I add a preferences page programatically at run time? [message #330517] |
Wed, 30 July 2008 21:17 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: dlacerte.counterpath.com
I have a preference page that is added the usual way with an entry in the
plugin.xml file as in all the examples. Unfortunately this preference page
should not be shown at all for some situations so at run time when the
plugin launches I want to decide whether it should be shown or not. Can I
add a preference page programatically instead of using the plugin.xml
mechanism?
|
|
|
Re: How do I add a preferences page programatically at run time? [message #330518 is a reply to message #330517] |
Wed, 30 July 2008 23:24 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: dlacerte.counterpath.com
To replace this plugin.xml entry:
<extension
point = "org.eclipse.ui.preferencePages">
<page id="CounterPath.Preferences.Accounts.AccountsPage"
class="CounterPath.Preferences.Accounts.AccountsPage"
name="Telephony Accounts">
</page>
</extension>
I tried the following code:
org.eclipse.jface.preference.PreferenceNode node =
new org.eclipse.jface.preference.PreferenceNode(
"CounterPath.Preferences.Accounts.AccountsPage", "Telephony Accounts",
null, "CounterPath.Preferences.Accounts.AccountsPage");
org.eclipse.jface.preference.PreferenceManager mgr =
org.eclipse.ui.PlatformUI.getWorkbench().getPreferenceManage r();
mgr.addToRoot(node);
Which results in an entry for the page being created but when I click on
it I get the following:
SEVERE: Problems occurred when invoking code from plug-in:
"org.eclipse.jface".
java.lang.NullPointerException
at
org.eclipse.jface.preference.PreferenceNode.createPage(Prefe renceNode.java:161)
at
org.eclipse.jface.preference.PreferenceDialog.createPage(Pre ferenceDialog.java:1241)
at
org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.cre atePage(FilteredPreferenceDialog.java:315)
at
org.eclipse.jface.preference.PreferenceDialog.showPage(Prefe renceDialog.java:1134)
at
org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.sho wPage(FilteredPreferenceDialog.java:438)
at
org.eclipse.jface.preference.PreferenceDialog$8.selectionCha nged(PreferenceDialog.java:661)
at
org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredV iewer.java:839)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:843)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:44)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:14 9)
at
org.eclipse.jface.viewers.StructuredViewer.firePostSelection Changed(StructuredViewer.java:837)
at
org.eclipse.jface.viewers.StructuredViewer.setSelection(Stru cturedViewer.java:1578)
at
org.eclipse.jface.preference.PreferenceDialog.selectSavedIte m(PreferenceDialog.java:958)
at
org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.sel ectSavedItem(FilteredPreferenceDialog.java:481)
at
org.eclipse.jface.preference.PreferenceDialog$3.run(Preferen ceDialog.java:345)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:67)
at
org.eclipse.jface.preference.PreferenceDialog.createContents (PreferenceDialog.java:341)
at org.eclipse.jface.window.Window.create(Window.java:426)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1111)
at
org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.cr eateDialogOn(WorkbenchPreferenceDialog.java:96)
at
org.eclipse.ui.dialogs.PreferencesUtil.createPreferenceDialo gOn(PreferencesUtil.java:85)
at
CounterPath.Preferences.Accounts.AccountsPage.Show(AccountsP age.java:91)
at
CounterPath.SidePanel.Toolbar.ActionsButtonAction$2.widgetSe lected(ActionsButtonAction.java:102)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:227)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1932)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1896)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:424)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
com.ibm.rcp.personality.framework.internal.RCPApplication.ru n(RCPApplication.java:72)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
|
|
|
Re: How do I add a preferences page programatically at run time? [message #330519 is a reply to message #330518] |
Thu, 31 July 2008 01:21 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: lifesting.gmail.com
Dominique wrote:
> To replace this plugin.xml entry:
> <extension
> point = "org.eclipse.ui.preferencePages">
> <page id="CounterPath.Preferences.Accounts.AccountsPage"
> class="CounterPath.Preferences.Accounts.AccountsPage"
> name="Telephony Accounts">
> </page>
> </extension>
>
> I tried the following code:
>
> org.eclipse.jface.preference.PreferenceNode node = new
> org.eclipse.jface.preference.PreferenceNode(
> "CounterPath.Preferences.Accounts.AccountsPage", "Telephony
> Accounts", null, "CounterPath.Preferences.Accounts.AccountsPage");
> org.eclipse.jface.preference.PreferenceManager mgr =
> org.eclipse.ui.PlatformUI.getWorkbench().getPreferenceManage r();
> mgr.addToRoot(node);
>
>
> Which results in an entry for the page being created but when I click on
> it I get the following:
>
> SEVERE: Problems occurred when invoking code from plug-in:
> "org.eclipse.jface".
> java.lang.NullPointerException
> at
> org.eclipse.jface.preference.PreferenceNode.createPage(Prefe renceNode.java:161)
>
> at
> org.eclipse.jface.preference.PreferenceDialog.createPage(Pre ferenceDialog.java:1241)
>
> at
> org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.cre atePage(FilteredPreferenceDialog.java:315)
>
> at
> org.eclipse.jface.preference.PreferenceDialog.showPage(Prefe renceDialog.java:1134)
>
> at
> org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.sho wPage(FilteredPreferenceDialog.java:438)
>
> at
> org.eclipse.jface.preference.PreferenceDialog$8.selectionCha nged(PreferenceDialog.java:661)
>
> at
> org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredV iewer.java:839)
> at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
> at org.eclipse.core.runtime.Platform.run(Platform.java:843)
> at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:44)
> at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:14 9)
> at
> org.eclipse.jface.viewers.StructuredViewer.firePostSelection Changed(StructuredViewer.java:837)
>
> at
> org.eclipse.jface.viewers.StructuredViewer.setSelection(Stru cturedViewer.java:1578)
>
> at
> org.eclipse.jface.preference.PreferenceDialog.selectSavedIte m(PreferenceDialog.java:958)
>
> at
> org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.sel ectSavedItem(FilteredPreferenceDialog.java:481)
>
> at
> org.eclipse.jface.preference.PreferenceDialog$3.run(Preferen ceDialog.java:345)
>
> at
> org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:67)
> at
> org.eclipse.jface.preference.PreferenceDialog.createContents (PreferenceDialog.java:341)
>
> at org.eclipse.jface.window.Window.create(Window.java:426)
> at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1111)
> at
> org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.cr eateDialogOn(WorkbenchPreferenceDialog.java:96)
>
> at
> org.eclipse.ui.dialogs.PreferencesUtil.createPreferenceDialo gOn(PreferencesUtil.java:85)
>
> at
> CounterPath.Preferences.Accounts.AccountsPage.Show(AccountsP age.java:91)
> at
> CounterPath.SidePanel.Toolbar.ActionsButtonAction$2.widgetSe lected(ActionsButtonAction.java:102)
>
> at
> org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:227)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3682)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3293)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1932)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1896)
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:424)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
> at
> com.ibm.rcp.personality.framework.internal.RCPApplication.ru n(RCPApplication.java:72)
>
> at
> org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:618)
> at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
> at org.eclipse.core.launcher.Main.run(Main.java:977)
> at org.eclipse.core.launcher.Main.main(Main.java:952)
>
>
You'd better use IExtensionRegistry to add contributions dynamically at
runtime, e.g:
IExtensionRegistryTracker tracker = .....
IExtensionRegistry reg = tracer.getService(IExtensionRegistry.class...)
reg.addContribution(xxx,xxx)
|
|
|
|
|
Re: How do I add a preferences page programatically at run time? [message #330539 is a reply to message #330518] |
Thu, 31 July 2008 19:25 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: dlacerte.counterpath.com
I also tried the following:
org.eclipse.core.runtime.IExtensionRegistry registry =
org.eclipse.core.runtime.Platform.getExtensionRegistry();
org.eclipse.core.runtime.IExtensionPoint point =
registry.getExtensionPoint("org.eclipse.ui.preferencePages");
boolean success = false;
if (point != null)
{
InputStream is = new StringBufferInputStream(
" <plugin><extension" +
" point = 'org.eclipse.ui.preferencePages'>" +
" <page id='CounterPath.Preferences.Accounts.AccountsPage'" +
" class='CounterPath.Preferences.Accounts.AccountsPage'" +
" name='Telephony Accounts'>" +
" </page>" +
" </extension></plugin>");
success = registry.addContribution(is, point.getContributor(), false,
"Telephony Accounts", null, null);
}
Which executed fine but when I try to show the preferences page I get an
error saying "Plugin org.eclipse.ui was unable to load class
CounterPath.Preferences.Accounts.AccountsPage." This class is there and
this works fine when I put the XML in the plugin.xml file. Do I need to
somehow register the class so it is found?
|
|
|
|
|
|
|
Re: How do I add a preferences page programatically at run time? [message #330563 is a reply to message #330543] |
Fri, 01 August 2008 20:23 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: dlacerte.counterpath.com
Thanks for the pointer, this gets me most of the way there! The only
problem I have is when I disable the preference page I get two copies of
the buttons on my toolbar. Seems like the toolbar is being parsed a second
time when I disable the page. Weird since the toolbar is in a different
plugin. Even more weird is that if I repeatedly enable/disable the page I
still only get two copies of my toolbar buttons.
Here is my preference page XML:
<!-- Preferences "Telephony Accounts" page -->
<extension
point = "org.eclipse.ui.preferencePages">
<page id="CounterPath.Preferences.Accounts.AccountsPage"
class="CounterPath.Preferences.Accounts.AccountsPage"
name="Telephony Accounts">
</page>
</extension>
<!-- An activity to allow us to show/hide the "Telephony Accounts" page
-->
<extension
point="org.eclipse.ui.activities">
<activity
name="Telephony Accounts"
description="Telephony Accounts Preferences"
id="CounterPath.Preferences.AccountsPageActivity">
</activity>
<activityPatternBinding
activityId="CounterPath.Preferences.AccountsPageActivity"
pattern="PALS/CounterPath\.Preferences\.Accounts\.AccountsPage ">
</activityPatternBinding>
<!-- <defaultEnablement id="CounterPath.Preferences.AccountsPageActivity"
/> -->
</extension>
And the toolabr XML in the other plugin:
<!-- Notes toolbar -->
<extension
point="com.ibm.rcp.ui.controlSets">
<controlSet
align="left"
id="CounterPath.NotesToolbar.ToolbarContribution.set"
label="SMC Plug-in Toolbar"
visible="true">
<toolBar
id="CounterPath.NotesToolbar.ToolbarContribution.bar"
path="BEGIN_GROUP"/>
<control
class="CounterPath.NotesToolbar.ToolbarContribution"
id="CounterPath.NotesToolbar.ToolbarContribution"
toolbarPath="CounterPath.NotesToolbar.ToolbarContribution.bar "/>
</controlSet>
</extension>
And my code to disable the preference page:
org.eclipse.ui.activities.IWorkbenchActivitySupport
workbenchActivitySupport =
org.eclipse.ui.PlatformUI.getWorkbench().getActivitySupport( );
org.eclipse.ui.activities.IActivityManager activityManager =
workbenchActivitySupport.getActivityManager();
HashSet enabledIds = new HashSet(activityManager.getEnabledActivityIds());
if (enabledIds.remove("CounterPath.Preferences.AccountsPageActivity "))
workbenchActivitySupport.setEnabledActivityIds(enabledIds);
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04523 seconds