Commit 2bb7d972 authored by Adrien's avatar Adrien Committed by GitHub
Browse files

fix(editors) Cancel operations when save fails (#2279)

* On export and deploy operation, the user has the possibility to save
dirty editors. If the save operation fails (i.e the editor is still
dirty), the operation is cancelled, else the wrong version will be
exported / deployed.

[STUDIO-3531](https://bonitasoft.atlassian.net/browse/STUDIO-3531)
parent 03662c95
......@@ -16,6 +16,7 @@ package org.bonitasoft.studio.application.handler;
import java.util.Optional;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.filestore.AbstractFileStore;
......@@ -28,7 +29,9 @@ import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
public class DeployHandler extends AbstractHandler {
......@@ -43,6 +46,11 @@ public class DeployHandler extends AbstractHandler {
DeployStrategy choice = SaveBeforeDeployDialog.open(((AbstractFileStore) deployable).getName());
if (choice == DeployStrategy.SAVE_AND_DEPLOY) {
((AbstractFileStore) deployable).saveOpenedEditor();
if (((AbstractFileStore) deployable).isDirty()) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(),
Messages.deployCancelTitle, Messages.deployCancel);
return;
}
} else if (choice == DeployStrategy.CANCEL) {
return; // cancel
}
......
......@@ -329,4 +329,6 @@ bdmValidMessage=The Business Data Model is valid.
bdmDeployRequired=The Business Data Model has been modified. You must deploy it to take those changes into account.
explore=Explore
exploreTooltip=Explore the BDM schema with a graphQL voyager. BDM must have been deployed!
bdmVoyager=Business Data Model voyager
\ No newline at end of file
bdmVoyager=Business Data Model voyager
deployCancelTitle=Deploy cancel
deployCancel=Unable to save the model, the deploy operation has been cancelled.
\ No newline at end of file
......@@ -26,6 +26,7 @@ import org.bonitasoft.studio.ui.dialog.SaveBeforeDeployDialog;
import org.bonitasoft.studio.ui.dialog.SaveBeforeDeployDialog.DeployStrategy;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ToolBar;
......@@ -59,6 +60,11 @@ public class DeployContributionItem extends ContributionItem {
DeployStrategy choice = SaveBeforeDeployDialog.open(name);
if (choice == DeployStrategy.SAVE_AND_DEPLOY) {
formPage.getEditor().doSave(new NullProgressMonitor());
if (formPage.getEditor().isDirty()) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.deployCancelTitle,
Messages.deployCancel);
return;
}
} else if (choice == DeployStrategy.CANCEL) {
return;
}
......
......@@ -506,6 +506,8 @@ public class Messages extends NLS {
public static String explore;
public static String exploreTooltip;
public static String bdmVoyager;
public static String deployCancelTitle;
public static String deployCancel;
private Messages() {
}
......
......@@ -31,4 +31,6 @@ deleteConfirmationMessage=You are about to delete this file from your workspace:
saveAndDeploy=Save and deploy
deployCurrent=Deploy current version
seeDetails=See details
skipValidation=Skip validation >>
\ No newline at end of file
skipValidation=Skip validation >>
exportCancelTitle=Export cancel
exportCancel=Unable to save the model, the export operation has been cancelled.
\ No newline at end of file
......@@ -49,6 +49,10 @@ public abstract class AbstractExportContributionItem<T extends AbstractFormPage>
&& MessageDialog.openQuestion(shell, Messages.saveBeforeTitle,
String.format(Messages.saveBeforeMessage, formPage.getEditor().getEditorInput().getName()))) {
formPage.getEditor().doSave(new NullProgressMonitor());
if (formPage.getEditor().isDirty()) {
MessageDialog.openInformation(shell, Messages.exportCancelTitle, Messages.exportCancel);
return;
}
}
exportAction(shell);
}
......
......@@ -56,5 +56,7 @@ public class Messages extends NLS {
public static String deployCurrent;
public static String seeDetails;
public static String skipValidation;
public static String exportCancel;
public static String exportCancelTitle;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment