Close and Open a View
From JWic
Check View State
Views and editors are managed by the site using PartHandle objects. To find out if a view is loaded, simply call Site.getViewHandle(VIEW_ID). If this method returns null, the view is not loaded.
PartHandle handle = site.getViewHandle(MyView.ID_VIEW);
if (handle != null) {
MyView myView = (MyView)handle.getPart();
}
Note: A View that is loaded might not be visible in the current perspective! To find out if a view is visible in the active perspective, use the following code:
PartHandle handle = site.getViewHandle(MyView.ID_VIEW);
if (handle != null) {
if (site.getActivePerspective().isVisible(handle)) {
// the view is visible
...
}
}
Close a View
There are several ways how to close a view. The easiest way is to call the .close() method on the view.
// prefered way:
PartHandle handle = site.getViewHandle(MyView.ID_VIEW);
if (handle != null) {
MyView myView = (MyView)handle.getPart();
myView.close();
}
// other way:
handle.getArea().closePart(handle);
Open a View
Always use the Site.openView(..) method to open or activate a view. This method checks if the view is already loaded. If it is already loaded, it is activated. Otherwise the view is initialized and moved to the correct position.
site.openView(Area.POS_RIGHT, MyView.ID_VIEW);
Note: A view can be loaded only once per session. If it is requested to open a view in a different location then the currently loaded one is, the view is closed and opened again in the new location.

