简体   繁体   中英

e4 Set ESelectionService Null

After my execute method I want to set the current selection null . I got this far but it won't work. After that, selection still holds the a value, which is not null.

    @Inject
    private ESelectionService selection;

    @Execute
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Foo foo, Shell shell) {
        if (true) {
           //do something!
           final Object NULL_OBJECT = new Object();
           selection.setSelection(NULL_OBJECT);
        }
    }

There are multiple selection services, one per context ( IEclipseContext ). You may be setting the selection in the wrong context.

Injecting the ESelectionService as a field of your class may mean you end up with the wrong service. Always inject this as a parameter of the execute method.

... no field injection

@Execute
public void execute(ESelectionService selection, @Named(IServiceConstants.ACTIVE_SELECTION) Foo foo, Shell shell) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM