Search code examples
eclipsepluginsworking-set

How to get a Workspace's working sets information in a plugin?


I want to get the runtime working sets information of the current workspace. I have tried the method: IWorkingSet[] getWorkingSets() of the IWorkbenchPage

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
      if (page != null) { IWorkingSet[] sets = page.getWorkingSets();} 

but when I debug the code, the method returns nothing.

I am wondering am I use the right method to get a workspace's working sets information? If not, how to get the data?


Solution

  • The IWorkbenchPage getWorkingSets() method returns the 'Window Working Sets' in use for the page - this option is not enabled by default so returns null.

    If you want all the working sets defined in the workbench you use:

    IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
    
    IWorkingSet [] allSets = manager.getAllWorkingSets();
    

    The working set manager has many other methods for handling working sets.