[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform] ISelectionListener not being called on selection change

Hi all,

I have a TreeViewer, which is registered as a selection provider. I also have an instance of ISelectionListener which is added to the selection service. When I make a selection in the various views, 2 selection changed events are thrown - this is normal; first the view is selected, then the element in the view.

However, when I click around through the various elements in the view, the listener no longer picks up the event. I have to click another view (thus generating 2 events), then click back into my tree viewer, generating another 2 events.

Does anyone know why the listener is not picking up changes in selection within the tree view?

Example scenario:
Load up
Click a blank space in the tree view
  Prints out "selection changed" and "selection changed in tree"
Click a blank space in the navigator
  Prints out "selection changed"
Click a blank space in the tree view
  Prints out "selection changed" and "selection changed in tree"
Click another item in the tree
  Prints out "selection changed" and "selection changed in tree"
Click another item in the tree
  Nothing happens anymore
Click the navigator
  Prints out "selection changed"
Click a different item in the tree
  Prints out "selection changed" and "selection changed in tree" TWICE
Click another item in the tree
  Nothing happens anymore


Code snippet:

public class MyTreeViewer extends ViewPart {
  private TreeViewer _viewer;

  public void createPartControl(Composite parent) {
    _viewer = new TreeViewer...
    getSite().setSelectionProvider(_viewer);
    getSite.getWorkbenchWindow().getSelectionService()
        .addSelectionListener(_listener);
    ...
  }

  private ISelectionListener _listener = new ISelectionListener() {
    public void selectionChanged(
        IWorkbenchPart sourcepart, ISelection selection) {

      System.out.println("selection changed");

      if(sourcepart.getTitle().equals("my tree")) {
        System.out.println("selection changed in tree");
      }
    }
  }
}