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 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<FormHandle<ConfigurationNode>> {
private static final class ImportFormContext implements ModalInputDialogComposer<FormHandle<ConfigurationNode>> {
private final PageService pageService;
private final PageContext pageContext;

View file

@ -59,7 +59,7 @@ public class ModalInputDialog<T> 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<T> extends Dialog {
finishUp(this.shell);
}
public void open(
final LocTextKey title,
final Predicate<T> okCallback,
final Runnable cancelCallback,
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
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<T> 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<T> 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);
}

View file

@ -49,7 +49,7 @@ public class ModalInputWizard<T> 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;
}

View file

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