Eclipse Search

Loading

May 31, 2008

How to add a new Resource to working sets?

You might probably seen the working set control in many of the New Wizards. Lets see how to add the control to your wizard.



You don't have to write too much of code to make that happen. The entire UI highlighted above is implemented in the class org.eclipse.ui.dialogs.WorkingSetGroup. Its not an internal class, so feel free to use it. All you have to do is, in your WizardPage.createControl() method, just add this:

workingSetGroup = new WorkingSetGroup(composite, selection, workingSetTypes);

The parameter workingSetTypes is a String[], which tells what are the types of working sets to be shown there. Few of the ids that you might be interested in:

Resource: org.eclipse.ui.resourceWorkingSetPage
Java (JDT): org.eclipse.jdt.ui.JavaWorkingSetPage
Plug-ins and Fragments (PDE): org.eclipse.pde.ui.pluginWorkingSet

To find the entire set of ids available, look at the implementations of the extension point org.eclipse.ui.workingSets (Use Plug-in Registry View)

The above code only gets you the UI. To get the newly created resource added to the working selected by the users, in the performFinish() method of your wizard, add these three lines:

IWorkingSet[] selectedWorkingSets = workingSetGroup.getSelectedWorkingSets();
IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
workingSetManager.addToWorkingSets(createdResource, selectedWorkingSets);


Just a 4 lines of code, your New Wizard will look a little consistent with many of the Eclipse Platform Wizards + you can please your Working-Set-savvy user like me :-)

0 comments:

Post a Comment