public class TodoDetailsPart { @Inject ESelectionService s; @Inject public void updateSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Person p) { System.out.println(" value " + p); } @PostConstruct public void createPartControls(Composite parent) { parent.setLayout(new GridLayout(1, false)); btnLoadData = new Button(parent, SWT.NONE); btnLoadData.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println("sending null selection"); // set new selection to NULL -> no event propagated to #updateSelection(). s.setSelection(null); } }); ... }}
public class MySelectionConstants { /** * Use this object to remove the current selection. */ public static final Object NULL_OBJECT = new Object(); }
@Inject public void updateSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object sel) { if (sel == MySelectionConstants.NULL_OBJECT) ; // Handle the removal of the active selection // Type check! else if (sel instanceof Person) { // You business logic Person p = (Person) sel; System.out.println(" value " + p); } }
... public static final Person NULL_PERSON = new Person(); } @Inject public void updateSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Person sel) { if (sel == MySelectionConstants.NULL_PERSON) ; // Handle the removal of the active selection // No type check else { ...
selectionService.setSelection(new Person[] {});