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));