eclipseeclipse-plugineclipse-neonworking-set

Eclipse Plugin Development: Adding items to a working set with the path of the item?


Hello, I'm an eclipse plugin development newbie looking for pointers to get me started on a particular project.

I am trying to build an eclipse plugin that will automatically construct a working set from a text file that simply consists of a list of file path names. The files/items need not share any parent directories. The rough idea is represented in the following diagram:

Diagram of the plugin's goal

I am not asking for the solution to this task. That's the over-arching goal. To achieve that goal, I want to conquer some smaller goals first.

With that in mind, here's the smaller goal I'm currently trying to tackle:

In Eclipse, how can I prompt the user for a single file's path, and then add that file to an existing working set?

I'm not sure where to start. Should I work directly off of the existing org.eclipse.ui.workingSets extension point? Or should I use a collection of other extension points? How do I convert strings into something that can be added to a working set? Do I write code that directly modifies the workingsets.xml file?

Even with a much simpler goal, I still feel quite overwhelmed with the vastness of eclipse extension options. There are probably many ways to go about implementing something like this, but I just need one to get started.

Thanks a bunch!


Solution

  • To manipulate working sets you use the working set manager interface IWorkingSetManager. Get this with:

    IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
    

    From this you can get a particular working by name with:

    IWorkingSet workingSet = manager.getWorkingSet("name");
    

    The contents of a working set is an array of IAdaptable objects:

    IAdaptable [] contents = workingSet.getElements();
    

    You add to the contents by adding to this array and setting the contents:

    IAdaptable [] newContents 
    
    .... get new array with old contents + new contents
    
    workingSet.setElements(newContents);
    

    A lot of Eclipse objects implement IAdaptable, for a file in the workspace you would use IFile. You can use dialogs such as ResourceSelectionDialog to select resources from the workspace.