How to get the name of the current Active Active tab from eclipse?

I want to get the file name of the current open tab in the eclipse-IDE editor. I mainly develop a plugin with Java, and I want to programmatically extract the name of an open file from the eclipse-IDE editor.

+4
source share
1 answer

There may be a shorter way, but this code should do this:

IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); String name = activePage.getActiveEditor().getEditorInput().getName(); 

Of course, make sure you check for possible NULL values, etc.

EDIT: Run this from the user interface thread. For instance:

  final String[] name = new String[1]; UIJob job = new UIJob("Get active editor") //$NON-NLS-1$ { public IStatus runInUIThread(IProgressMonitor monitor) { try { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); name[0] = activePage.getActiveEditor().getEditorInput().getName(); } catch (Exception e) { // return some other status } return Status.OK_STATUS; } }; job.schedule(); job.join(); System.out.println(name[0]); 
+6
source

All Articles