Reputation: 341
I created a plug-in action which shows a view & hides a view. Here is my code:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.showView("com.sample.views.Example");
page.hideView(page.findView("com.sample.views.Example"));
But how can I check whether this view is in present foreground or if it is closed?
Upvotes: 1
Views: 2294
Reputation: 572
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editors = page.getEditorReferences();
// How many editor open..
// System.out.println("Len : "+editors.length);
if(editors.length==0){
System.out.println("View is not visible");
}
else{
System.out.println("View is visible");
System.out.println("View or Editor Name is :: "+page.getActiveEditor().getTitle());
}
Current working view or window name display
IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();
MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(
event).getShell(), "Current Workbench Window", service.getActivePart().getTitle()+"");
Upvotes: 0
Reputation: 111142
IWorkbenchPage.findView
will return null
if the view is not open.
IWorkbenchPage.getActivePart()
returns the active part (this might be an editor or a view).
You can also use IWorkbenchPage.addPartListener
to listen for changes to the parts.
Upvotes: 1