EH_Aurrera
EH_Aurrera

Reputation: 33

RCP Perspective with two views

I have a perspective with two views created via "extensions" . First view has a table and the second has a tree. I want to show only the first view when the application is open and when the user selects an item from the table, put this item name in the second view´s text field and hide the first view while the second view is open.I want also hide the second view and show the first view when the user push a button. Is that possible?.

I've managed to put item name in the second view but i´m not able to coordinate showing and hiding the views.

Upvotes: 2

Views: 3939

Answers (1)

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51445

Yes, it's possible to show and hide views.

1) Each view has to have a unique ID. This ID has to match the id in the view extension of the plugin.xml.

Here's one of my plugin.xml view extensions.

  <view
        class="gov.bop.rabid.ui.views.PrefetchView"
        icon="icons/folder_user.png"
        id="gov.bop.rabid.ui.views.PrefetchView"
        name="Prefetch"
        restorable="true">
  </view>

And here's the ID definition in the PrefetchView.

public static final String ID = "gov.bop.rabid.ui.views.PrefetchView";

Generally, I make the ID the same as the class name. It's less confusing for me.

2) In the Perspective class, the createInitialLayout method, you have to define an IFolderLayout with placeholders. Again, here's my code.

    IFolderLayout consoleFolder = layout.createFolder(CONSOLE_ID, 
            IPageLayout.BOTTOM, 0.75f, editorArea);
    consoleFolder.addPlaceholder(PrefetchedInmatesView.ID);
    consoleFolder.addPlaceholder(FoundInmatesView.ID);
    consoleFolder.addView(ProcessedInmatesView.ID);

    setClosable(layout, FoundInmatesView.ID, false);
    setClosable(layout, PrefetchedInmatesView.ID, false);
    setClosable(layout, ProcessedInmatesView.ID, false);

3) You need a static method that allows you to access any view from inside any other view. I put this static method in my Activator class, but you can put it anywhere you want.

public static IViewPart getView(IWorkbenchWindow window, String viewId) {
    IViewReference[] refs = window.getActivePage().getViewReferences();
    for (IViewReference viewReference : refs) {
        if (viewReference.getId().equals(viewId)) {
            return viewReference.getView(true);
        }
    }
    return null;
}

4) Finally, you show and hide views from your event code. Here's an example.

        final PhotoView view = (PhotoView) RabidPlugin.getView(window,
                PhotoView.ID);
        if (view == null)
            return;

                    *** Do stuff with the other view ***

        IWorkbenchPage page = window.getActivePage();
        page.hideView(page.findView(FoundInmatesView.ID));

Upvotes: 2

Related Questions