javaeclipse-pluginswtworking-set

Adding function to existing gui component in Eclipse


So currently I'm developing an Eclipse Plug-In that works with working sets. These custom working sets are being created with a wizard, which also creates a .properties file with all required settings. Those working sets can be deleted via Select Working Sets...> Remove in the eclipse project explorer, but the button only deletes the working set itself, not the file.

I've already implemented a handler that can remove the file but I wanted to ask if there is any way to bind that function to the 'Remove' button of the Select Working Set... dialog. I've already found out, that WorkingSetSelectionDialog implements the remove functionality, but I'm kind of stuck there.

Is there an extension point or something like where I can add that functionality?


Solution

  • The 'Remove' button on that dialog only marks the working set for removal, it is not actually removed until the OK button is pressed (so that 'Cancel' can work).

    The removal is done by a call to the working set manager. You can listen to working set changes made by the manager using the IWorkingSetManager.addPropertyChangeListener listener:

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

    The listener implements IPropertyChangeListener. The event parameter tells you what property changed. For remove the property is IWorkingSetManager.CHANGE_WORKING_SET_REMOVE

    So something like:

    public void propertyChange(PropertyChangeEvent event)
    {
      if (event.getProperty().equals(IWorkingSetManager.CHANGE_WORKING_SET_REMOVE)) {
        IWorkingSet removed = (IWorkingSet)event.getOldValue();
    
        ...
      }
    }