diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigImportPopup.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigImportPopup.java index b03a3809..7bf6c95a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigImportPopup.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigImportPopup.java @@ -14,14 +14,10 @@ import java.util.List; import java.util.function.*; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; -import ch.ethz.seb.sebserver.gbl.util.Cryptor; -import ch.ethz.seb.sebserver.gui.form.FieldBuilder; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.*; import ch.ethz.seb.sebserver.gui.widget.PasswordConfirmInput; -import ch.ethz.seb.sebserver.gui.widget.PasswordInput; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.*; import org.slf4j.Logger; @@ -196,7 +192,7 @@ public class SEBExamConfigImportPopup { .onError(error -> notifyErrorOnSave(error, context)); } - handleQuitPassword(configuration, context); + handleQuitPassword(configuration, newConfig, context); } else { handleImportError(formHandle, importResult); } @@ -217,7 +213,10 @@ public class SEBExamConfigImportPopup { } } - private void handleQuitPassword(final Configuration configuration, final PageContext context) { + private void handleQuitPassword( + final Configuration configuration, + final boolean newConfig, + final PageContext context) { try { final ConfigurationValue configurationValue = this.pageService.getRestService() .getBuilder(GetConfigurationValues.class) @@ -273,12 +272,13 @@ public class SEBExamConfigImportPopup { } else { deleteQuitPassword(context, configNodeId); } + if (!newConfig) { + reloadPage(newConfig, context); + } return true; }; - final Runnable cancel = () -> deleteQuitPassword(context, configNodeId); - - dialog.open(TITLE_QUIT_PASSWORD, callback, cancel, contentComposer); + dialog.open(TITLE_QUIT_PASSWORD, callback, null, false, contentComposer); } catch (final Exception e) { log.error("Failed to handle quit password for import: ", e); } @@ -389,7 +389,7 @@ public class SEBExamConfigImportPopup { - private final class ImportFormContext implements ModalInputDialogComposer> { + private static final class ImportFormContext implements ModalInputDialogComposer> { private final PageService pageService; private final PageContext pageContext; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputDialog.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputDialog.java index ce554350..c071e635 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputDialog.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputDialog.java @@ -59,7 +59,7 @@ public class ModalInputDialog extends Dialog { final Shell parent, final WidgetFactory widgetFactory) { - super(parent, SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL | SWT.CLOSE); + super(parent, SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL); this.widgetFactory = widgetFactory; } @@ -158,26 +158,33 @@ public class ModalInputDialog extends Dialog { finishUp(this.shell); } - public void open( final LocTextKey title, final Predicate okCallback, final Runnable cancelCallback, final ModalInputDialogComposer contentComposer) { + this.open(title, okCallback, cancelCallback, true, contentComposer); + } + public void open( + final LocTextKey title, + final Predicate okCallback, + final Runnable cancelCallback, + final boolean withCancel, + final ModalInputDialogComposer contentComposer) { // Create the selection dialog window this.shell = new Shell(getParent(), getStyle()); this.shell.setText(getText()); this.shell.setData(RWT.CUSTOM_VARIANT, CustomVariant.MESSAGE.key); this.shell.setText(this.widgetFactory.getI18nSupport().getText(title)); - this.shell.setLayout(new GridLayout(2, true)); + this.shell.setLayout(new GridLayout(withCancel ? 2 : 1, true)); final GridData gridData2 = new GridData(SWT.FILL, SWT.TOP, false, false); this.shell.setLayoutData(gridData2); final Composite main = new Composite(this.shell, SWT.NONE); main.setLayout(new GridLayout()); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData.horizontalSpan = 2; + gridData.horizontalSpan = withCancel ? 2 : 1; gridData.widthHint = this.dialogWidth; main.setLayoutData(gridData); @@ -185,7 +192,7 @@ public class ModalInputDialog extends Dialog { gridData.heightHint = calcDialogHeight(main); final Button ok = this.widgetFactory.buttonLocalized(this.shell, OK_TEXT_KEY); - GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END); + GridData data = new GridData(withCancel ? GridData.HORIZONTAL_ALIGN_END : GridData.HORIZONTAL_ALIGN_CENTER); data.widthHint = this.buttonWidth; ok.setLayoutData(data); ok.addListener(SWT.Selection, event -> { @@ -201,16 +208,18 @@ public class ModalInputDialog extends Dialog { this.shell.setDefaultButton(ok); - final Button cancel = this.widgetFactory.buttonLocalized(this.shell, CANCEL_TEXT_KEY); - data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - data.widthHint = this.buttonWidth; - cancel.setLayoutData(data); - cancel.addListener(SWT.Selection, event -> { - if (cancelCallback != null) { - cancelCallback.run(); - } - this.shell.close(); - }); + if (withCancel) { + final Button cancel = this.widgetFactory.buttonLocalized(this.shell, CANCEL_TEXT_KEY); + data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + data.widthHint = this.buttonWidth; + cancel.setLayoutData(data); + cancel.addListener(SWT.Selection, event -> { + if (cancelCallback != null) { + cancelCallback.run(); + } + this.shell.close(); + }); + } finishUp(this.shell); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputWizard.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputWizard.java index 2645356f..e8b7bc25 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputWizard.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputWizard.java @@ -49,7 +49,7 @@ public class ModalInputWizard extends Dialog { final Shell parent, final WidgetFactory widgetFactory) { - super(parent, SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL | SWT.CLOSE); + super(parent, SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL); this.widgetFactory = widgetFactory; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/PasswordConfirmInput.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/PasswordConfirmInput.java index e1f4a35e..50bc51e3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/PasswordConfirmInput.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/PasswordConfirmInput.java @@ -68,7 +68,7 @@ public class PasswordConfirmInput extends Composite { } public CharSequence getValue() { - if (!checkError()) { + if (checkError()) { return null; } final CharSequence value = password.getValue();