Robert F
Robert F

Reputation: 451

How to enable global save functionality in Eclipse RCP plugin

I have an RCP application based on the 3.x platform. The application enables the user to view and modify a single data set. Some ViewParts are only observers of part of the data set, whilst other can modify data. When a ViewPart modifies same data I want to be able to save the data set, preferably using the standard org.eclipse.ui.file.save command, independent of which ViewPart that currently has focus.

My approach is to define extensions to the plugin.xml like so:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="toolbar:org.eclipse.ui.main.toolbar">
         <toolbar
               id="se.file.maintoolbar"
               label="File Toolbar">
            <command
                  commandId="org.eclipse.ui.file.save"
                  label="&amp;Save Project"
                  style="push"
                  tooltip="Save the project">
            </command>
         </toolbar>
      </menuContribution>
   </extension>
.
.
.
</plugin>

In my implementation of ActionBarAdvisor I register actions:

@Override
protected void makeActions(IWorkbenchWindow window) {
    saveProjectAction = ActionFactory.SAVE.create(window);
    register(saveProjectAction);
}

My ViewParts, three kinds, all implements the ISaveablePart2, it feels wrong, but haven't seen any other approach. Two of the views control their isDirty() function, so save buttons are enabled when they have focus and if they are dirty, but if one of them is dirty, save should be enabled in all views, not just the dirty view. Enabling save functionality for the third view, without indicating dirty, seems impossible.

Anybody know a better approach? I guess I can create my own handling of saving, but would be good to use standard as much as possible.

Upvotes: 0

Views: 835

Answers (1)

greg-449
greg-449

Reputation: 111142

You could call firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY) in all the views that should be shown as dirty.

Upvotes: 1

Related Questions