Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Reading and acting on preferences on startup / plugin load
Reading and acting on preferences on startup / plugin load [message #685160] Thu, 16 June 2011 23:54 Go to next message
Martin F.Friend
Messages: 12
Registered: January 2011
Junior Member
Hi,

I have created a plugin which contributes a wizard and some preference pages to the Eclipse UI.
Now after the user has selected the option(s) on the preference page as he/she wished for example, they are being saved successfully.

My question is: Is there any way to execute certain code upon startup of Eclipse (at/after loading of the plugin) which makes use of the preference store without requiring the user to visit preference page? (because that it what already works, my code is executed when the pref-page is loaded)
The init methods are only being called after the user visits the preference page and therefore the plug-in preference store is accessed. How can i tell Eclipse/my plugin to access that store on load and perform an action based on a preference right away?

I already found out that an activator is executed when a plugin starts, but I can't load the preferenceStore at that early point, so activator does not seem to be an option. But where do I need to put my code to get it executed on startup then?

Thank you.

[Updated on: Thu, 16 June 2011 23:56]

Report message to a moderator

Re: Reading and acting on resukt of preferences [message #685279 is a reply to message #685160] Fri, 17 June 2011 07:16 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 17.06.2011 01:54, forums-noreply@eclipse.org wrote:
> Hi,
> I have created a plugin which contributes a wizard and some preference
> pages to the Eclipse UI.
> Now after the user has selected the option(s) on the preference page
> as he/she wished for example, they are being saved successfully.
>
> My question is: Is there any way to execute certain code upon startup
> of Eclipse (at/after loading of the plugin) which makes use of the
> preference store without requiring the user to visit preference page?
> (because that it what already works, my code is executed when the
> pref-page is loaded)
> The init methods are only being called after the user visits the
> preference page and therefore the plug-in preference store is
> accessed. How can i tell Eclipse/my plugin to access that store on
> load and perform an action based on a preference right away?
>
> I already found out that an activator is executed when a plugin
> starts, but I can't load the preferenceStore at that early point, so
> activator does not seem to be an option.
Why not? We access the store in
org.osgi.framework.BundleActivator.start(BundleContext).

What exactly do you try to do?

Dani
> But where do I need to put my code to get it executed on startup then?
>
> Thank you.
>
Re: Reading and acting on resukt of preferences [message #685366 is a reply to message #685279] Fri, 17 June 2011 11:15 Go to previous messageGo to next message
Martin F.Friend
Messages: 12
Registered: January 2011
Junior Member
Dani Megert wrote on Fri, 17 June 2011 09:16
On 17.06.2011 01:54, forums-noreply@eclipse.org wrote:
>> How can i tell Eclipse/my plugin to access that store on
>> load and perform an action based on a preference right away?
>>
>> I already found out that an activator is executed when a plugin
>> starts, but I can't load the preferenceStore at that early point, so
>> activator does not seem to be an option.
>
> Why not? We access the store in
> org.osgi.framework.BundleActivator.start(BundleContext).
>
> What exactly do you try to do?


I'm trying to read a boolean pref and - depending on the value - start a service in the background:

btServer = BluetoothServer.getInstance();
if (store.getBoolean("BtServer"))
{
	if (!btServer.isBtServerRunning())
	{
		// if server is not running, fire it up
		btServer.startServer();
	}
}
else // this is the case that the BT-server should be turned off
{
	if (btServer.isBtServerRunning())
	{
		// pause it
		btServer.pauseServer();
	}
}


My fault was trying to do that the constructor of the Activator. So using a method public void start(BundleContext context) in the Activator allows to access the Preference store. Now I have two methods in my Activator: public void start(BundleContext context) and public void stop(BundleContext context)
But unfortunately that start()-Method is also only executed when I open my preference page and not on startup. (tried to perform a simple Logging-Output in there, to verify this) How can I achieve the desired execution onload?
Thanks.
Re: Reading and acting on resukt of preferences [message #685553 is a reply to message #685366] Fri, 17 June 2011 18:22 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Mtchr.schmusemail.de wrote on Fri, 17 June 2011 07:15

My fault was trying to do that the constructor of the Activator. So using a method public void start(BundleContext context) in the Activator allows to access the Preference store. Now I have two methods in my Activator: public void start(BundleContext context) and public void stop(BundleContext context)
But unfortunately that start()-Method is also only executed when I open my preference page and not on startup. (tried to perform a simple Logging-Output in there, to verify this) How can I achieve the desired execution onload?
Thanks.


In general in eclipse a plugin is only started the first time a class is accessed. ex: the user shows one of your views. That's the behaviour you are seeing.

In an RCP app, you can use your org.eclipse.ui.application.WorkbenchAdvisor.postStartup() method to check your preference and then start up the server.

PW


Re: Reading and acting on resukt of preferences [message #708736 is a reply to message #685553] Wed, 03 August 2011 06:09 Go to previous message
newbie  is currently offline newbie Friend
Messages: 5
Registered: July 2011
Junior Member
Hi,
I am facing a similar kind of problem. I want to close all editors at the time of launch. Since mine is a plugin project but is not an RCP application, i am not sure how and where do i override org.eclipse.ui.application.WorkbenchAdvisor.postStartup() method. I added following piece of code in start method of activator.

PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (IWorkbenchWindow iWorkbenchWindow : windows) {
if (iWorkbenchWindow.getActivePage() != null) {
break;
}
iWorkbenchWindow.close();
}
but this is of no use. I added above code to one of the methods of class implementing AbstractUIPlugin. It is closing all the editors at the time of eclipse luanch but throwd a NullPoiner Exception as well. Please fond the stack trace below:


java.lang.NullPointerException
at org.eclipse.ui.internal.menus.WorkbenchMenuService.releaseContributions(WorkbenchMenuService.java:854)
at org.eclipse.ui.internal.WorkbenchWindow.hardClose(WorkbenchWindow.java:1682)
at org.eclipse.ui.internal.WorkbenchWindow.busyClose(WorkbenchWindow.java:723)
at org.eclipse.ui.internal.WorkbenchWindow.access$0(WorkbenchWindow.java:699)
at org.eclipse.ui.internal.WorkbenchWindow$5.run(WorkbenchWindow.java:815)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.close(WorkbenchWindow.java:813)
at org.eclipse.ui.internal.Workbench$61.runWithException(Workbench.java:3402)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3855)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3476)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$28.runWithException(Workbench.java:1384)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3855)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3476)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2316)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)


Please help.

thanks
Previous Topic:Adding context sensitive Help
Next Topic:Product RCP export problem
Goto Forum:
  


Current Time: Fri Mar 29 15:30:12 GMT 2024

Powered by FUDForum. Page generated in 0.02885 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top