From 162fd67b4ac7de544a33a1d22c6f4429a10f728b Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Tue, 3 Sep 2024 13:13:51 +0200 Subject: [PATCH] use cancel confirmation on measurement upload dialog --- .../MessageSourceNotificationFactory.java | 2 +- .../project/measurements/MeasurementMain.java | 18 ++++++++++--- .../MeasurementMetadataUploadDialog.java | 26 +++++++------------ .../messages/dialog-messages.properties | 4 +++ 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/user-interface/src/main/java/life/qbic/datamanager/views/notifications/MessageSourceNotificationFactory.java b/user-interface/src/main/java/life/qbic/datamanager/views/notifications/MessageSourceNotificationFactory.java index eda4c1aac..665b4e7fc 100644 --- a/user-interface/src/main/java/life/qbic/datamanager/views/notifications/MessageSourceNotificationFactory.java +++ b/user-interface/src/main/java/life/qbic/datamanager/views/notifications/MessageSourceNotificationFactory.java @@ -179,7 +179,7 @@ private MessageType parseMessageType(String key, Locale locale) { EMPTY_PARAMETERS, locale).strip().toUpperCase(); return MessageType.valueOf(messageType); } catch (NoSuchMessageException e) { - throw new RuntimeException("No message type specified for " + key, e); + throw new RuntimeException("No message type specified for %s.message.type".formatted(key), e); } } diff --git a/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/measurements/MeasurementMain.java b/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/measurements/MeasurementMain.java index 8f296b3db..a487b13b0 100644 --- a/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/measurements/MeasurementMain.java +++ b/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/measurements/MeasurementMain.java @@ -35,6 +35,7 @@ import life.qbic.datamanager.views.general.Main; import life.qbic.datamanager.views.general.download.DownloadProvider; import life.qbic.datamanager.views.general.download.MeasurementTemplateDownload; +import life.qbic.datamanager.views.notifications.CancelConfirmationDialogFactory; import life.qbic.datamanager.views.notifications.ErrorMessage; import life.qbic.datamanager.views.notifications.StyledNotification; import life.qbic.datamanager.views.projects.project.experiments.ExperimentMainLayout; @@ -99,6 +100,7 @@ public class MeasurementMain extends Main implements BeforeEnterObserver { private final DownloadProvider ngsDownloadProvider; private final DownloadProvider proteomicsDownloadProvider; private final ProjectInformationService projectInformationService; + private final CancelConfirmationDialogFactory cancelConfirmationDialogFactory; private transient Context context; public MeasurementMain( @@ -108,7 +110,8 @@ public MeasurementMain( @Autowired MeasurementService measurementService, @Autowired MeasurementPresenter measurementPresenter, @Autowired MeasurementValidationService measurementValidationService, - ProjectInformationService projectInformationService) { + ProjectInformationService projectInformationService, + CancelConfirmationDialogFactory cancelConfirmationDialogFactory) { Objects.requireNonNull(measurementTemplateListComponent); Objects.requireNonNull(measurementDetailsComponent); Objects.requireNonNull(measurementService); @@ -123,6 +126,9 @@ public MeasurementMain( this.proteomicsDownloadProvider = new DownloadProvider(proteomicsMeasurementContentProvider); this.measurementValidationService = measurementValidationService; this.sampleInformationService = Objects.requireNonNull(sampleInformationService); + this.projectInformationService = projectInformationService; + this.cancelConfirmationDialogFactory = cancelConfirmationDialogFactory; + measurementTemplateDownload = new MeasurementTemplateDownload(); measurementTemplateListComponent.addDownloadMeasurementTemplateClickListener( this::onDownloadMeasurementTemplateClicked); @@ -147,7 +153,7 @@ public MeasurementMain( getClass().getSimpleName(), System.identityHashCode(this), measurementTemplateListComponent.getClass().getSimpleName(), System.identityHashCode(measurementTemplateListComponent))); - this.projectInformationService = projectInformationService; + } private static String convertErrorCodeToMessage(MeasurementService.ErrorCode errorCode) { @@ -325,7 +331,9 @@ private void triggerMeasurementRegistration( } private void openEditMeasurementDialog() { - var dialog = new MeasurementMetadataUploadDialog(measurementValidationService, MODE.EDIT, + var dialog = new MeasurementMetadataUploadDialog(measurementValidationService, + cancelConfirmationDialogFactory, + MODE.EDIT, context.projectId().orElse(null)); setupDialog(dialog); dialog.open(); @@ -513,7 +521,9 @@ private void onDownloadMeasurementTemplateClicked( } private void openRegisterMeasurementDialog() { - var dialog = new MeasurementMetadataUploadDialog(measurementValidationService, MODE.ADD, + var dialog = new MeasurementMetadataUploadDialog(measurementValidationService, + cancelConfirmationDialogFactory, + MODE.ADD, context.projectId().orElse(null)); setupDialog(dialog); dialog.open(); diff --git a/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/measurements/MeasurementMetadataUploadDialog.java b/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/measurements/MeasurementMetadataUploadDialog.java index 91ea13832..d2f6955f8 100644 --- a/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/measurements/MeasurementMetadataUploadDialog.java +++ b/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/measurements/MeasurementMetadataUploadDialog.java @@ -38,8 +38,8 @@ import life.qbic.datamanager.parser.xlsx.XLSXParser; import life.qbic.datamanager.views.general.InfoBox; import life.qbic.datamanager.views.general.WizardDialogWindow; +import life.qbic.datamanager.views.notifications.CancelConfirmationDialogFactory; import life.qbic.datamanager.views.notifications.ErrorMessage; -import life.qbic.datamanager.views.notifications.NotificationDialog; import life.qbic.datamanager.views.notifications.StyledNotification; import life.qbic.datamanager.views.projects.EditableMultiFileMemoryBuffer; import life.qbic.projectmanagement.application.measurement.MeasurementMetadata; @@ -68,6 +68,8 @@ public class MeasurementMetadataUploadDialog extends WizardDialogWindow { private static final long serialVersionUID = -8253078073427291947L; private static final String VAADIN_FILENAME_EVENT = "event.detail.file.name"; private final MeasurementValidationService measurementValidationService; + private final CancelConfirmationDialogFactory cancelConfirmationDialogFactory; + private final EditableMultiFileMemoryBuffer uploadBuffer; private final transient List> measurementMetadataUploads; private final transient List measurementFileItems; @@ -77,7 +79,9 @@ public class MeasurementMetadataUploadDialog extends WizardDialogWindow { private final UploadItemsDisplay uploadItemsDisplay; public MeasurementMetadataUploadDialog(MeasurementValidationService measurementValidationService, + CancelConfirmationDialogFactory cancelConfirmationDialogFactory, MODE mode, ProjectId projectId) { + this.cancelConfirmationDialogFactory = requireNonNull(cancelConfirmationDialogFactory); this.projectId = requireNonNull(projectId, "projectId cannot be null"); this.measurementValidationService = requireNonNull(measurementValidationService, "measurementValidationExecutor must not be null"); @@ -332,22 +336,10 @@ private void showErrorNotification(String title, String description) { } private void onCanceled() { - - NotificationDialog dialog = NotificationDialog.warningDialog() - .withTitle("Discard uploaded information?") - .withContent(new Span("Uploaded information has not yet been saved.")); - dialog.setCancelable(true); - dialog.setCancelText("Continue Editing"); - Button redButton = new Button("Discard upload"); - redButton.addClassName("danger"); - dialog.setConfirmButton(redButton); - dialog.addConfirmListener(event -> { - event.getSource().close(); - fireEvent(new CancelEvent(this, true)); - }); - dialog.addCancelListener(event -> event.getSource().close()); - dialog.open(); - + cancelConfirmationDialogFactory.cancelConfirmationDialog( + it -> fireEvent(new CancelEvent(this, it.isFromClient())), + "measurement.metadata.upload", getLocale()) + .open(); } @Override diff --git a/user-interface/src/main/resources/messages/dialog-messages.properties b/user-interface/src/main/resources/messages/dialog-messages.properties index 0ac84cd3a..f231fb2bf 100644 --- a/user-interface/src/main/resources/messages/dialog-messages.properties +++ b/user-interface/src/main/resources/messages/dialog-messages.properties @@ -28,3 +28,7 @@ experiment.edit.cancel-confirmation.title=Discard experiment changes? experiment.edit.cancel-confirmation.message.type=text experiment.edit.cancel-confirmation.message.text=You will lose all changes made to this experiment. experiment.edit.cancel-confirmation.confirm-text=Discard changes +measurement.metadata.upload.cancel-confirmation.title=Discard uploaded information? +measurement.metadata.upload.cancel-confirmation.message.type=text +measurement.metadata.upload.cancel-confirmation.message.text=Uploaded information has not yet been saved. +measurement.metadata.upload.cancel-confirmation.confirm-text=Discard upload