SEBSERV-163 fixed read-only fields and labels

This commit is contained in:
anhefti 2022-09-14 10:41:54 +02:00
parent 43d8129006
commit a6334bc436
4 changed files with 17 additions and 17 deletions

View file

@ -123,12 +123,12 @@ public final class Form implements FormBinding {
return this.formFields.containsKey(fieldName); return this.formFields.containsKey(fieldName);
} }
Form putReadonlyField(final String name, final Control label, final Text field) { Form putLabel(final String name, final Control label, final Label field) {
this.formFields.add(name, createReadonlyAccessor(label, field)); this.formFields.add(name, createLabelAccessor(label, field));
return this; 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)); this.formFields.add(name, createReadonlyAccessor(label, field));
return this; return this;
} }
@ -313,13 +313,13 @@ public final class Form implements FormBinding {
//@formatter:off //@formatter:off
private FormFieldAccessor createReadonlyAccessor(final Control label, final Text field) { private FormFieldAccessor createReadonlyAccessor(final Control label, final Text field) {
return new FormFieldAccessor(label, field, null) { 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); } @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) { 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); } @Override public void setStringValue(final String value) { field.setText( (value == null) ? StringUtils.EMPTY : value); }
}; };
} }

View file

@ -39,7 +39,7 @@ public final class TextFieldBuilder extends FieldBuilder<String> {
int areaMinHeight = WidgetFactory.TEXT_AREA_INPUT_MIN_HEIGHT; int areaMinHeight = WidgetFactory.TEXT_AREA_INPUT_MIN_HEIGHT;
boolean isColorBox = false; boolean isColorBox = false;
boolean isHTML = false; boolean isHTML = false;
boolean isMarkup = false; boolean isMarkupLabel = false;
TextFieldBuilder(final String name, final LocTextKey label, final String value) { TextFieldBuilder(final String name, final LocTextKey label, final String value) {
super(name, label, value); super(name, label, value);
@ -77,11 +77,6 @@ public final class TextFieldBuilder extends FieldBuilder<String> {
return this; return this;
} }
public TextFieldBuilder asMarkup() {
this.isMarkup = true;
return this;
}
public TextFieldBuilder asHTML(final int minHeight) { public TextFieldBuilder asHTML(final int minHeight) {
this.isHTML = true; this.isHTML = true;
this.areaMinHeight = minHeight; this.areaMinHeight = minHeight;
@ -93,6 +88,11 @@ public final class TextFieldBuilder extends FieldBuilder<String> {
return this; return this;
} }
public TextFieldBuilder asMarkupLabel() {
this.isMarkupLabel = true;
return this;
}
public TextFieldBuilder asColorBox() { public TextFieldBuilder asColorBox() {
this.isColorBox = true; this.isColorBox = true;
return this; return this;
@ -124,12 +124,12 @@ public final class TextFieldBuilder extends FieldBuilder<String> {
return; return;
} }
if (readonly && this.isMarkup) { if (readonly && this.isMarkupLabel) {
final Label label = new Label(fieldGrid, SWT.NONE); final Label label = new Label(fieldGrid, SWT.NONE);
label.setData(RWT.MARKUP_ENABLED, Boolean.TRUE); label.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
label.setText(this.value); label.setText(this.value);
label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true)); 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; return;
} }

View file

@ -121,7 +121,7 @@ public class ClientConnectionDetails {
ClientConnectionData.ATTR_CLIENT_GROUPS, ClientConnectionData.ATTR_CLIENT_GROUPS,
CONNECTION_GROUP_TEXT_KEY, CONNECTION_GROUP_TEXT_KEY,
Constants.EMPTY_NOTE) Constants.EMPTY_NOTE)
.asMarkup()) .asMarkupLabel())
.addField(FormBuilder.text( .addField(FormBuilder.text(
ClientConnection.ATTR_INFO, ClientConnection.ATTR_INFO,
CONNECTION_INFO_TEXT_KEY, CONNECTION_INFO_TEXT_KEY,

View file

@ -86,8 +86,8 @@ public class MockCourseAccessAPI implements CourseAccessAPI {
"http://lms.mockup.com/api/")); "http://lms.mockup.com/api/"));
this.mockups.add(new QuizData( this.mockups.add(new QuizData(
"quiz11", institutionId, lmsSetupId, lmsType, "Demo Quiz 11 (MOCKUP)", "quiz11", institutionId, lmsSetupId, lmsType, "Demo Quiz 11 (MOCKUP)",
"Starts in a minute and ends never", "Starts in five minutes and ends never",
DateTime.now(DateTimeZone.UTC).plus(Constants.MINUTE_IN_MILLIS) DateTime.now(DateTimeZone.UTC).plus(Constants.MINUTE_IN_MILLIS * 5)
.toString(Constants.DEFAULT_DATE_TIME_FORMAT), .toString(Constants.DEFAULT_DATE_TIME_FORMAT),
null, null,
"http://lms.mockup.com/api/")); "http://lms.mockup.com/api/"));