Skip to content

Commit

Permalink
Merge branch 'development' into feature-642/#642-editing-registered-m…
Browse files Browse the repository at this point in the history
…etadata-to-add-confounding-variables
  • Loading branch information
KochTobi authored Jan 27, 2025
2 parents 867d0c7 + 9addc37 commit c09a8e3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.vaadin.flow.component.ShortcutRegistration;
import com.vaadin.flow.component.Shortcuts;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.server.Command;
import java.util.Objects;

Expand All @@ -15,7 +17,7 @@
* @see Dialog
* @since 1.4.0
*/
public class QbicDialog extends Dialog {
public class QbicDialog extends Dialog implements BeforeLeaveObserver {

private ShortcutRegistration escShortcut;

Expand All @@ -38,4 +40,9 @@ public void setEscAction(Command command) {
}
escShortcut = Shortcuts.addShortcutListener(this, command, Key.ESCAPE);
}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
this.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import java.util.Objects;
import java.util.Optional;
import life.qbic.datamanager.views.general.icon.IconFactory;
Expand All @@ -22,7 +24,7 @@
*
* @since 1.7.0
*/
public class AppDialog extends Dialog {
public class AppDialog extends Dialog implements BeforeLeaveObserver {

public static final String PADDING_LEFT_RIGHT_07 = "padding-left-right-07";
public static final String PADDING_TOP_BOTTOM_04 = "padding-top-bottom-04";
Expand Down Expand Up @@ -229,6 +231,16 @@ public void registerUserInput(UserInput userInput) {
this.userInput = Objects.requireNonNull(userInput);
}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
if (hasChanges()) {
event.postpone();
cancel();
} else {
this.close();
}
}


private interface Style {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.dom.Style.Display;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;

/**
* A dialog notifying the user of some event.
Expand All @@ -31,7 +33,7 @@
* <li>info-dialog</li>
* </ul>
*/
public class NotificationDialog extends ConfirmDialog {
public class NotificationDialog extends ConfirmDialog implements BeforeLeaveObserver {

private final H2 title;
private final NotificationLevel level;
Expand Down Expand Up @@ -191,4 +193,8 @@ public <T extends NotificationDialog> T withContent(Component... content) {
return withContent(hiddenCollectionDiv);
}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
this.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.vaadin.flow.dom.Style.Visibility;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
Expand Down Expand Up @@ -50,6 +52,7 @@
import life.qbic.logging.api.Logger;
import life.qbic.logging.service.LoggerFactory;
import life.qbic.projectmanagement.application.ProjectInformationService;
import life.qbic.projectmanagement.application.measurement.MeasurementMetadata;
import life.qbic.projectmanagement.application.measurement.MeasurementService;
import life.qbic.projectmanagement.application.measurement.MeasurementService.MeasurementDeletionException;
import life.qbic.projectmanagement.application.measurement.validation.MeasurementValidationService;
Expand All @@ -76,7 +79,7 @@
@UIScope
@Route(value = "projects/:projectId?/experiments/:experimentId?/measurements", layout = ExperimentMainLayout.class)
@PermitAll
public class MeasurementMain extends Main implements BeforeEnterObserver {
public class MeasurementMain extends Main implements BeforeEnterObserver, BeforeLeaveObserver {

public static final String PROJECT_ID_ROUTE_PARAMETER = "projectId";
public static final String EXPERIMENT_ID_ROUTE_PARAMETER = "experimentId";
Expand All @@ -103,6 +106,7 @@ public class MeasurementMain extends Main implements BeforeEnterObserver {
private final transient ProjectInformationService projectInformationService;
private final transient CancelConfirmationDialogFactory cancelConfirmationDialogFactory;
private final transient MessageSourceNotificationFactory messageFactory;
private MeasurementMetadataUploadDialog dialog;
private transient Context context;

public MeasurementMain(
Expand Down Expand Up @@ -157,7 +161,6 @@ public MeasurementMain(
getClass().getSimpleName(), System.identityHashCode(this),
measurementTemplateListComponent.getClass().getSimpleName(),
System.identityHashCode(measurementTemplateListComponent)));

}

private static String convertErrorCodeToMessage(MeasurementService.ErrorCode errorCode) {
Expand Down Expand Up @@ -359,7 +362,7 @@ private void triggerMeasurementRegistration(
}

private void openEditMeasurementDialog() {
var dialog = new MeasurementMetadataUploadDialog(measurementValidationService,
this.dialog = new MeasurementMetadataUploadDialog(measurementValidationService,
cancelConfirmationDialogFactory,
MODE.EDIT,
context.projectId().orElse(null));
Expand Down Expand Up @@ -549,7 +552,7 @@ private void onDownloadMeasurementTemplateClicked(
}

private void openRegisterMeasurementDialog() {
var dialog = new MeasurementMetadataUploadDialog(measurementValidationService,
this.dialog = new MeasurementMetadataUploadDialog(measurementValidationService,
cancelConfirmationDialogFactory,
MODE.ADD,
context.projectId().orElse(null));
Expand Down Expand Up @@ -601,4 +604,10 @@ static class HandledException extends RuntimeException {
}

}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
Optional.ofNullable(this.dialog).ifPresent(Dialog::close);
}

}

0 comments on commit c09a8e3

Please sign in to comment.