How to use non-Part as - or similar to - ISelectionProvider?

54 views Asked by At

I'm trying to get my custom IOConsole fire a selectionChanged() event, but as it is not a ViewPart or EditorPart, the registered SelectionListeners catch nothing, even when notified programatically.

Is this possible at all? Or is there another way to (programatically) notify a view of a change in my IOConsole so it can refresh one of its widgets? Oh, this should work for loosely coupled components as well, as none of the components really know of each other.

1

There are 1 answers

2
RĂ¼diger Herrmann On

If your console inherits from org.eclipse.ui.console.IOConsole, the IOConsole registers the text area (a SourceViewer) as a selection provider at the part site.

If you are certain that you want to override this behavior, you need to register your own ISelectionProvider at the part site. You can override createPage and change the selection provider after the page was created:

class MyConsole extends IOConsole {
  @Override
  public IPageBookViewPage createPage( IConsoleView view ) {
    IPageBookViewPage consolePage = super.createPage( view );
    consolePage.getSite().setSelectionProvider( ... );  
    return consolePage;
  }
}

Note that overriding the IOConsole's selection provider this may result in an unintuitive behavior or interfere with assumptions that the IOConsole implementation makes.