0

How do you give the part containing a ContentOutlineView focus correctly when clicking on the TreeViewer?

I am creating my own Outline like view and when clicking on the TreeViewer in a ContentOutlinePage when the (view)part is not in focus does not correctly fire selection events. I need to click on the tab to bring the part into focus before the TreeViewer's selection events fire.

I have created my own FooBarOutlineView that extends PageBookView. I am creating pages only for FooBarModelView parts and instantiating either a FooOutlinePage or a BarOutlinePage that extends ContentOutlinePage

My BarOutlinePage overloads the createControl method to add a content provider to the TreeViewer:

public class BarOutlinePage extends ContentOutlinePage {

    @Override
    public void createControl(Composite parent) {
        super.createControl(parent);
        getTreeViewer().setContentProvider(new MyContentProvider(new MyTreeModel()));
        getTreeViewer().setLabelProvider(new MyViewLabelProvider());
        getTreeViewer().setInput("root");
    }
}

My FooBarOutlineView (trimmed for brevity) looks like:

public class FooBarOutlineView extends PageBookView {

    @Override
    protected IPage createDefaultPage(PageBook book) {
        MessagePage defaultPage = new MessagePage();
        initPage(defaultPage);
        defaultPage.setMessage("An outline is not available. (default page)");
        defaultPage.createControl(book);
        return defaultPage;
    }

    @Override
    protected PageRec doCreatePage(IWorkbenchPart part) {
        IPageBookViewPage page = null;
        if (part instanceof FooModelView)
            page = new FooOutlinePage();
        else if (part instanceof BarModelView)
            page = new BarOutlinePage();
        initPage(page);
        page.createControl(getPageBook());
        return new PageRec(part, page);
    }

    @Override
    protected boolean isImportant(IWorkbenchPart part) {
        return (part instanceof FooBarModelView);
    }
}

Any insights warmly welcomed!

janh
  • 1,926
  • 2
  • 11
  • 13
  • Is there a reason you are not using the standard content outline view using the `ContentOutline` class? – greg-449 Apr 27 '14 at 07:38
  • My FooBarOutlineView is responding to View's, not editors. I would be quite happy to put my outline pages into the existing Outline, if you can explain how? (I see I may be able to override the isImportant method) – janh Apr 27 '14 at 08:47
  • @greg-449 I switched my ``FooBarOutlineView`` to extend ``ContentOutline`` and implemented getAdapter in my Views. Much neater (thanks!) but same focus problem exists. – janh Apr 27 '14 at 09:30

1 Answers1

0

The normal ContentOutline class has this method override which I think you need in your FooBarOutlineView:

public void partBroughtToTop(IWorkbenchPart part) {
     partActivated(part);
}
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • I've added this, but I still see the same behaviour. Selecting the TreeViewer when it is not in focus does not bring the tab into focus. – janh Apr 27 '14 at 09:12
  • What platform is this? On my Mac selecting anything in a view gives it focus immediately. – greg-449 Apr 27 '14 at 09:38
  • Windows 64bit JVM. I'll try the same code on my Macbook soon. – janh Apr 27 '14 at 09:42
  • I'm seeing the same behaviour on either Mac or Win, also see the same behavious in ContentOutline in general – janh May 04 '14 at 10:14