-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
In addition to Display.asyncExec, you make want to put your code inside a runnable,
launched from
its own thread.
My reasoning:
The workbench can be started after some plugins have already been activated as such
getWorkbench().getActiveWorkbenchWindow() can be null even on the UI thread. Consequently,
I find
it prudent to create a polling thread that listens on getWorkbench().isStarting().
Returns true then delay
Returns false then the workbench window should exist as well as the Display thread and so
Display.asyncExec(addSelectionServiceRunnable) should be good to go.
Once control has been passed to the Display thread, the original polling thread will
finish and
disappear.
HTH
PGR
On 15/07/15 15:26, Fred Bricon wrote:
CC-ing to jbosstools-dev for more exposure
> Début du message réexpédié :
>
> *De: *Ian Stewart-Binks <istewart(a)redhat.com
<mailto:istewart@redhat.com>> *Objet: **Quick
> SWT Question* *Date: *15 juillet 2015 09:05:06 UTC?4 *À: *Denis Golovin
<degolovi(a)redhat.com
> <mailto:degolovi@redhat.com>> *Cc: *Fred Bricon <fbricon(a)redhat.com
> <mailto:fbricon@redhat.com>>
>
> Hi Denis,
>
> I'm the JBoss Tools intern here at Red Hat, working on an Eclipse plugin called
> Buildship[1].
>
> I have an SWT related question, and my mentor, Fred Bricon, has suggested that I ask
it to
> you.
>
> The plugin I'm working with makes a call to
getWorkbench().getActiveWorkbenchWindow() in the
> plugin's Activator's .start() method. This call returns null when it is not
run on the UI
> thread, so the code is assuming that the .start() method will always be run on the UI
thread.
> The AbstractUIPlugin[2] states that the deprecated method startup(), which start() is
meant
> to replace cannot assume that it is run on the UI thread. This may be a bit pedantic:
the
> specification for start() doesn't mention anything about the UI thread- is it
still the case
> that we can't assume the start() method is run on the UI thread?
>
> If it is the case that the start method can't assume that it's run on the UI
thread, I will
> need to change some of the code to ensure that this assumption is not made.
>
> The offending line attempts to register a selection listener. Here it is:
> ((ISelectionService)
>
getWorkbench().getActiveWorkbenchWindow().getService(ISelectionService.class)).addSelectionListen
er(this.contextActivatingSelectionListener);
>
>
>
Do you know of any other ways to register this listener?
org%2Feclipse%2Fui%2Fplugin%2FAbstractUIPlugin.html
>
_______________________________________________ jbosstools-dev mailing list
jbosstools-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jbosstools-dev
- --
Paul Richardson
* p.g.richardson(a)phantomjinx.co.uk
* p.g.richardson(a)redhat.com
* pgrichardson(a)linux.com
"I know exactly who reads the papers ...
* The Daily Mirror is read by people who think they run the country.
* The Guardian is read by people who think they ought to run the country.
* The Times is read by people who do actually run the country.
* The Daily Mail is read by the wives of the people who run the country.
* The Financial Times is read by the people who own the country.
* The Morning Star is read by the people who think the country ought to be run by
another country.
* The Daily Telegraph is read by the people who think it is."
Jim Hacker, Yes Minister
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iEYEARECAAYFAlWmehwACgkQcthLMIwdEb1rygCdECvm0duMrJpHjzzfgcEz4fT8
6MkAn2iIcYAU6CHLRRD8Q4rlj8yhD66/
=vSmD
-----END PGP SIGNATURE-----