Viewpoint 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 (for example, if the Collaborative mode is active, we have 3 choices instead of 2 : Save and commit, Save and keep changes local, Discard).
ISaveDialogExtension
interface
This interface allows to :
boolean isSaveDialogFor(Object objectToSave)
: allows to indicates whether this extension should be applied (condition on the Session for example)
Collection<String> getButtons();
: returns a collection of String corresponding to the available choices for a save dialog (do no override CANCEL, this will be added automatically if possible)
int reactToValue(Object objectToSave, int userChoice);
: defines the behavior to apply when faced to the given user choice.
ISaveDialogExtension
using the
fr.obeo.dsl.common.ui.savedialogextension
extension point
Please refer to this extension point documentation for more details.
package myPackage;
import java.util.Collection;
import org.eclipse.ui.ISaveablePart2;
import com.google.common.collect.Lists;
import fr.obeo.dsl.viewpoint.business.api.session.Session;
public class CustomSaveDialogExtension {
/**
*
* {@inheritDoc}
*
* @see fr.obeo.dsl.common.ui.tools.api.util.ISaveDialogExtension#isSaveDialogFor(java.lang.Object)
*/
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());
}
/**
*
* {@inheritDoc}
*
* @see fr.obeo.dsl.common.ui.tools.api.util.ISaveDialogExtension#getButtons()
*/
public Collection<String> getButtons() {
return Lists.newArrayList("Save", "Make something special", "Discard");
}
/**
*
* {@inheritDoc}
*
* @see fr.obeo.dsl.common.ui.tools.api.util.ISaveDialogExtension#reactToValue(java.lang.Object,
* int)
*/
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
break;
// Case 1 : "Make something special"
case 1:
makeSomethingSpecial(session);
// we will return CANCEL => nothing else willl be done
returnedValue = ISaveablePart2.CANCEL;
break;
// Case 2 : "Discard"
case 2:
// we return NO => changes will be discarded
returnedValue = ISaveablePart2.NO;
break;
// Default : "CANCEL" or any other
default:
returnedValue = ISaveablePart2.CANCEL;
break;
}
return returnedValue;
}
}