From a6334bc436a9d551c52fa730357681860a00c58b Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 14 Sep 2022 10:41:54 +0200 Subject: [PATCH] SEBSERV-163 fixed read-only fields and labels --- .../ch/ethz/seb/sebserver/gui/form/Form.java | 12 ++++++------ .../seb/sebserver/gui/form/TextFieldBuilder.java | 16 ++++++++-------- .../service/session/ClientConnectionDetails.java | 2 +- .../lms/impl/mockup/MockCourseAccessAPI.java | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/Form.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/Form.java index d6c55b94..3e4a6a57 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/Form.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/Form.java @@ -123,12 +123,12 @@ public final class Form implements FormBinding { return this.formFields.containsKey(fieldName); } - Form putReadonlyField(final String name, final Control label, final Text field) { - this.formFields.add(name, createReadonlyAccessor(label, field)); + Form putLabel(final String name, final Control label, final Label field) { + this.formFields.add(name, createLabelAccessor(label, field)); return this; } - Form putReadonlyField(final String name, final Control label, final Label field) { + Form putReadonlyField(final String name, final Control label, final Text field) { this.formFields.add(name, createReadonlyAccessor(label, field)); return this; } @@ -313,13 +313,13 @@ public final class Form implements FormBinding { //@formatter:off private FormFieldAccessor createReadonlyAccessor(final Control label, final Text field) { return new FormFieldAccessor(label, field, null) { - @Override public String getStringValue() { return field.getText(); } + @Override public String getStringValue() { return null; } // ensures that read-only fields do not send diplay values to the back-end @Override public void setStringValue(final String value) { field.setText( (value == null) ? StringUtils.EMPTY : value); } }; } - private FormFieldAccessor createReadonlyAccessor(final Control label, final Label field) { + private FormFieldAccessor createLabelAccessor(final Control label, final Label field) { return new FormFieldAccessor(label, field, null) { - @Override public String getStringValue() { return field.getText(); } + @Override public String getStringValue() { return field.getText(); } // read-only labels a are not API attributes. @Override public void setStringValue(final String value) { field.setText( (value == null) ? StringUtils.EMPTY : value); } }; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/TextFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/TextFieldBuilder.java index 9a236efa..6ec5b91b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/TextFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/TextFieldBuilder.java @@ -39,7 +39,7 @@ public final class TextFieldBuilder extends FieldBuilder { int areaMinHeight = WidgetFactory.TEXT_AREA_INPUT_MIN_HEIGHT; boolean isColorBox = false; boolean isHTML = false; - boolean isMarkup = false; + boolean isMarkupLabel = false; TextFieldBuilder(final String name, final LocTextKey label, final String value) { super(name, label, value); @@ -77,11 +77,6 @@ public final class TextFieldBuilder extends FieldBuilder { return this; } - public TextFieldBuilder asMarkup() { - this.isMarkup = true; - return this; - } - public TextFieldBuilder asHTML(final int minHeight) { this.isHTML = true; this.areaMinHeight = minHeight; @@ -93,6 +88,11 @@ public final class TextFieldBuilder extends FieldBuilder { return this; } + public TextFieldBuilder asMarkupLabel() { + this.isMarkupLabel = true; + return this; + } + public TextFieldBuilder asColorBox() { this.isColorBox = true; return this; @@ -124,12 +124,12 @@ public final class TextFieldBuilder extends FieldBuilder { return; } - if (readonly && this.isMarkup) { + if (readonly && this.isMarkupLabel) { final Label label = new Label(fieldGrid, SWT.NONE); label.setData(RWT.MARKUP_ENABLED, Boolean.TRUE); label.setText(this.value); label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true)); - builder.form.putReadonlyField(this.name, titleLabel, label); + builder.form.putLabel(this.name, titleLabel, label); return; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionDetails.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionDetails.java index 4c493757..b8383662 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionDetails.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionDetails.java @@ -121,7 +121,7 @@ public class ClientConnectionDetails { ClientConnectionData.ATTR_CLIENT_GROUPS, CONNECTION_GROUP_TEXT_KEY, Constants.EMPTY_NOTE) - .asMarkup()) + .asMarkupLabel()) .addField(FormBuilder.text( ClientConnection.ATTR_INFO, CONNECTION_INFO_TEXT_KEY, diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockCourseAccessAPI.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockCourseAccessAPI.java index acbecb47..7e16e634 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockCourseAccessAPI.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockCourseAccessAPI.java @@ -86,8 +86,8 @@ public class MockCourseAccessAPI implements CourseAccessAPI { "http://lms.mockup.com/api/")); this.mockups.add(new QuizData( "quiz11", institutionId, lmsSetupId, lmsType, "Demo Quiz 11 (MOCKUP)", - "Starts in a minute and ends never", - DateTime.now(DateTimeZone.UTC).plus(Constants.MINUTE_IN_MILLIS) + "Starts in five minutes and ends never", + DateTime.now(DateTimeZone.UTC).plus(Constants.MINUTE_IN_MILLIS * 5) .toString(Constants.DEFAULT_DATE_TIME_FORMAT), null, "http://lms.mockup.com/api/"));