Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[udig-devel] how to listen for selection changes _WITHOUT_ a view?

Hello NG,

 

i’ve been looking through the Workbench example with the SelectionListener from Eclipse.

In my case i do not want to use a View to listen for changes, i want to use an OSGi Service.

Therefore i have no getSite().getWorkbenchWindow() etc…

 

How can i gain access to the SelectionService mwithout a view?

 

I tried to get it via the Activator like this:

 

            Activator activator = Activator.getDefault();

            IWorkbench workbench = activator.getWorkbench();

            IWorkbenchWindow workbenchWindow =

            workbench.getActiveWorkbenchWindow();

            return workbenchWindow.getSelectionService();

 

this failed for me!

Then i tried to get it via PlatformUI:

 

ISelectionService selectionService = (ISelectionService) PlatformUI

                        .getWorkbench().getActiveWorkbenchWindow()

                        .getService(ISelectionService.class);

            return selectionService;

 

but also this fails.

 

i thought this might happen as my service tries to get the SelectionService too early when no WorkbenchWindow is active, so i retry and retry. But i NEVER get this service, in no way described above.

 

Why? How can i gain this Service properly without View?

 

Thanks in advance!

Ludwig

 

PS: why no view? Because it would need activation before i can use it. If i have a service running i can open the proper perspective/view when needed…


Back to the top