SEBSERV-495 only OK button (removed window close)

This commit is contained in:
anhefti 2024-01-16 15:38:11 +01:00
parent 065a4335dc
commit f267e9f1b3
4 changed files with 36 additions and 27 deletions

View file

@ -14,14 +14,10 @@ import java.util.List;
import java.util.function.*; import java.util.function.*;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; 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.service.remote.webservice.api.seb.examconfig.*;
import ch.ethz.seb.sebserver.gui.widget.PasswordConfirmInput; 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.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*; import org.eclipse.swt.widgets.*;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -196,7 +192,7 @@ public class SEBExamConfigImportPopup {
.onError(error -> notifyErrorOnSave(error, context)); .onError(error -> notifyErrorOnSave(error, context));
} }
handleQuitPassword(configuration, context); handleQuitPassword(configuration, newConfig, context);
} else { } else {
handleImportError(formHandle, importResult); 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 { try {
final ConfigurationValue configurationValue = this.pageService.getRestService() final ConfigurationValue configurationValue = this.pageService.getRestService()
.getBuilder(GetConfigurationValues.class) .getBuilder(GetConfigurationValues.class)
@ -273,12 +272,13 @@ public class SEBExamConfigImportPopup {
} else { } else {
deleteQuitPassword(context, configNodeId); deleteQuitPassword(context, configNodeId);
} }
if (!newConfig) {
reloadPage(newConfig, context);
}
return true; return true;
}; };
final Runnable cancel = () -> deleteQuitPassword(context, configNodeId); dialog.open(TITLE_QUIT_PASSWORD, callback, null, false, contentComposer);
dialog.open(TITLE_QUIT_PASSWORD, callback, cancel, contentComposer);
} catch (final Exception e) { } catch (final Exception e) {
log.error("Failed to handle quit password for import: ", e); log.error("Failed to handle quit password for import: ", e);
} }
@ -389,7 +389,7 @@ public class SEBExamConfigImportPopup {
private final class ImportFormContext implements ModalInputDialogComposer<FormHandle<ConfigurationNode>> { private static final class ImportFormContext implements ModalInputDialogComposer<FormHandle<ConfigurationNode>> {
private final PageService pageService; private final PageService pageService;
private final PageContext pageContext; private final PageContext pageContext;

View file

@ -59,7 +59,7 @@ public class ModalInputDialog<T> extends Dialog {
final Shell parent, final Shell parent,
final WidgetFactory widgetFactory) { 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; this.widgetFactory = widgetFactory;
} }
@ -158,26 +158,33 @@ public class ModalInputDialog<T> extends Dialog {
finishUp(this.shell); finishUp(this.shell);
} }
public void open( public void open(
final LocTextKey title, final LocTextKey title,
final Predicate<T> okCallback, final Predicate<T> okCallback,
final Runnable cancelCallback, final Runnable cancelCallback,
final ModalInputDialogComposer<T> contentComposer) { final ModalInputDialogComposer<T> contentComposer) {
this.open(title, okCallback, cancelCallback, true, contentComposer);
}
public void open(
final LocTextKey title,
final Predicate<T> okCallback,
final Runnable cancelCallback,
final boolean withCancel,
final ModalInputDialogComposer<T> contentComposer) {
// Create the selection dialog window // Create the selection dialog window
this.shell = new Shell(getParent(), getStyle()); this.shell = new Shell(getParent(), getStyle());
this.shell.setText(getText()); this.shell.setText(getText());
this.shell.setData(RWT.CUSTOM_VARIANT, CustomVariant.MESSAGE.key); this.shell.setData(RWT.CUSTOM_VARIANT, CustomVariant.MESSAGE.key);
this.shell.setText(this.widgetFactory.getI18nSupport().getText(title)); 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); final GridData gridData2 = new GridData(SWT.FILL, SWT.TOP, false, false);
this.shell.setLayoutData(gridData2); this.shell.setLayoutData(gridData2);
final Composite main = new Composite(this.shell, SWT.NONE); final Composite main = new Composite(this.shell, SWT.NONE);
main.setLayout(new GridLayout()); main.setLayout(new GridLayout());
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.horizontalSpan = 2; gridData.horizontalSpan = withCancel ? 2 : 1;
gridData.widthHint = this.dialogWidth; gridData.widthHint = this.dialogWidth;
main.setLayoutData(gridData); main.setLayoutData(gridData);
@ -185,7 +192,7 @@ public class ModalInputDialog<T> extends Dialog {
gridData.heightHint = calcDialogHeight(main); gridData.heightHint = calcDialogHeight(main);
final Button ok = this.widgetFactory.buttonLocalized(this.shell, OK_TEXT_KEY); 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; data.widthHint = this.buttonWidth;
ok.setLayoutData(data); ok.setLayoutData(data);
ok.addListener(SWT.Selection, event -> { ok.addListener(SWT.Selection, event -> {
@ -201,16 +208,18 @@ public class ModalInputDialog<T> extends Dialog {
this.shell.setDefaultButton(ok); this.shell.setDefaultButton(ok);
final Button cancel = this.widgetFactory.buttonLocalized(this.shell, CANCEL_TEXT_KEY); if (withCancel) {
data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); final Button cancel = this.widgetFactory.buttonLocalized(this.shell, CANCEL_TEXT_KEY);
data.widthHint = this.buttonWidth; data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
cancel.setLayoutData(data); data.widthHint = this.buttonWidth;
cancel.addListener(SWT.Selection, event -> { cancel.setLayoutData(data);
if (cancelCallback != null) { cancel.addListener(SWT.Selection, event -> {
cancelCallback.run(); if (cancelCallback != null) {
} cancelCallback.run();
this.shell.close(); }
}); this.shell.close();
});
}
finishUp(this.shell); finishUp(this.shell);
} }

View file

@ -49,7 +49,7 @@ public class ModalInputWizard<T> extends Dialog {
final Shell parent, final Shell parent,
final WidgetFactory widgetFactory) { 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; this.widgetFactory = widgetFactory;
} }

View file

@ -68,7 +68,7 @@ public class PasswordConfirmInput extends Composite {
} }
public CharSequence getValue() { public CharSequence getValue() {
if (!checkError()) { if (checkError()) {
return null; return null;
} }
final CharSequence value = password.getValue(); final CharSequence value = password.getValue();