if (canceled) {
return false;
}
// Use a simpler dialog if there's only one
if (modelsToSave.size() == 1) {
Saveable model = (Saveable) modelsToSave.get(0);
String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, model.getName());
// Show a dialog.
String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
MessageDialog d = new MessageDialog(
shellProvider.getShell(), WorkbenchMessages.Save_Resource,
null, message, MessageDialog.QUESTION, buttons, 0);
int choice = SaveableHelper.testGetAutomatedResponse();
if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) {
choice = d.open();
}
// Branch on the user choice.
// The choice id is based on the order of button labels
// above.
switch (choice) {
case ISaveablePart2.YES: // yes
break;
case ISaveablePart2.NO: // no
return true;
default:
case ISaveablePart2.CANCEL: // cancel
return false;
}
}
else {
ListSelectionDialog dlg = new ListSelectionDialog(
shellProvider.getShell(), modelsToSave,
new ArrayContentProvider(),
new WorkbenchPartLabelProvider(), RESOURCES_TO_SAVE_MESSAGE);
dlg.setInitialSelections(modelsToSave.toArray());
dlg.setTitle(SAVE_RESOURCES_TITLE);
// this "if" statement aids in testing.
if (SaveableHelper.testGetAutomatedResponse()==SaveableHelper.USER_RESPONSE) {
int result = dlg.open();
//Just return false to prevent the operation continuing
if (result == IDialogConstants.CANCEL_ID) {
return false;
}
modelsToSave = Arrays.asList(dlg.getResult());
}
}
}
else {
modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources);
}
// If the editor list is empty return.
if (modelsToSave.isEmpty()) {
return true;
}
// Create save block.
final List finalModels = modelsToSave;
IRunnableWithProgress progressOp = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
IProgressMonitor monitorWrap = new EventLoopProgressMonitor(
monitor);
monitorWrap.beginTask("", finalModels.size()); //$NON-NLS-1$
for (Iterator i = finalModels.iterator(); i.hasNext();) {
Saveable model = (Saveable) i.next();
// handle case where this model got saved as a result of saving another
if (!model.isDirty()) {
monitor.worked(1);
continue;
}
SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, closing || confirm);
if (monitorWrap.isCanceled()) {