|
Re: Injecting IServiceConstants.ACTIVE_SELECTION to implement a selection listener [message #634070 is a reply to message #633992] |
Wed, 20 October 2010 12:14 |
|
karins.spam@gmail.com wrote:
> public class View {
>
> @Inject
> void updateFolder(@Named(IServiceConstants.ACTIVE_SELECTION) IFolder
> folder) {
> // Do something when selection changes
> }
> }
>
We support both injection (@Inject, @PostConstruct, @PreDestroy,
@Optional, @Named) usually tied to instantiating contributions and we
support invocation (@Execute, @CanExecute) which we use when invoking a
method against the IEclipseContext. The difference between injection
and invocation is invocation is a one-shot deal and injection creates a
tracker that will re-inject any changed values.
@Inject
void updateFolder(@Optional @Named(IServiceConstants.ACTIVE_SELECTION)
IFolder folder)
So in your example, any time IServiceConstants.ACTIVE_SELECTION changes
in the visible set of IEclipseContexts, this method gets called.
Without the @Optional, you can't accept null and injection will fail (as
the selection is a product of the runtime, and can be nothing).
If you *were* going to use ACTIVE_SELECTION, you would be using the
ESelectionService, since the selection itself is more complicated than
just setting a value in your view. The selection is posted to the
MWindow level, so what good would it do to post a Button.
But you can do this with your own constant and your view
IEclipseContext, you don't need to use ACTIVE_SELECTION, if you wanted
to. However, for a button and button listener, I probably wouldn't use
the context (which is for passing data, not really for events).
PW
--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03413 seconds