Sirius – Provide custom save dialog


Sirius uses the same Save Dialog for any operation that implies to the end-user whether changes made on session should be saved or discarded (when closing a session through the CloseUISessionCommand, when controlling resources...).

Developer may need to extend this save dialog to propose other choices to the end-user.

Customize Sirius save dialogs

The ISaveDialogExtension interface

This interface allows to:

Provide your ISaveDialogExtension using the org.eclipse.sirius.common.ui.savedialogextension extension point

Please refer to this extension point documentation for more details.


package myPackage;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.ui.ISaveablePart2;

public class CustomSaveDialogExtension {

    public boolean isSaveDialogFor(Object objectToSave) {
        // This save dialog is active if
        // - the saved element is a session
        return (objectToSave instanceof Session)
        // - the session ID is "SaveSession"
                && "SaveSession".equals(((Session) objectToSave).getID());

    public Collection<String> getButtons() {
        return new ArrayList<String>(Arrays.asList("Save", "Make something special", "Discard"));

    public int reactToValue(Object objectToSave, int temporaryResult) {
        Session session = (Session) objectToSave;
        int returnedValue = ISaveablePart2.YES;

        switch (temporaryResult) {
        // Case 0 : "Save"
        case 0:
            // we will return ISaveablePart2.YES => the session will be saved
            // normally
        // Case 1 : "Make something special"
        case 1:
            // we will return CANCEL => nothing else willl be done
            returnedValue = ISaveablePart2.CANCEL;
        // Case 2 : "Discard"
        case 2:
            // we return NO => changes will be discarded
            returnedValue = ISaveablePart2.NO;
        // Default : "CANCEL" or any other
            returnedValue = ISaveablePart2.CANCEL;

        return returnedValue;