diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/InputField.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/InputField.java index 7c3e269a..3b6d8893 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/InputField.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/InputField.java @@ -10,8 +10,6 @@ package ch.ethz.seb.sebserver.gui.service.examconfig; import java.util.Collection; -import org.eclipse.swt.widgets.Control; - import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; @@ -24,8 +22,6 @@ public interface InputField { void initValue(Collection values); - Control getControl(); - void showError(String errorMessage); void clearError(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/InputFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/InputFieldBuilder.java index 74921bc5..d8c7a3ff 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/InputFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/InputFieldBuilder.java @@ -8,12 +8,17 @@ package ch.ethz.seb.sebserver.gui.service.examconfig; +import org.eclipse.rap.rwt.RWT; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gui.service.examconfig.impl.ViewContext; -import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; +import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.CustomVariant; public interface InputFieldBuilder { @@ -28,8 +33,31 @@ public interface InputFieldBuilder { final ConfigurationAttribute attribute, final ViewContext viewContext); - static LocTextKey createResourceBundleKey(final String paramName, final String value) { - return new LocTextKey(RES_BUNDLE_KEY_PREFIX + paramName + "." + value); + static Composite createInnerGrid( + final Composite parent, + final Orientation orientation) { + + final Composite comp = new Composite(parent, SWT.NONE); + final GridLayout gridLayout = new GridLayout(); + gridLayout.verticalSpacing = 0; + gridLayout.marginHeight = 1; + comp.setLayout(gridLayout); + + final GridData gridData = new GridData( + SWT.FILL, SWT.FILL, + true, false, + (orientation != null) ? orientation.width() : 1, + (orientation != null) ? orientation.height() : 1); + comp.setLayoutData(gridData); + return comp; + } + + static Label createErrorLabel(final Composite innerGrid) { + final Label errorLabel = new Label(innerGrid, SWT.NONE); + errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + errorLabel.setVisible(false); + errorLabel.setData(RWT.CUSTOM_VARIANT, CustomVariant.ERROR.key); + return errorLabel; } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ControlFieldAdapter.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractInputField.java similarity index 77% rename from src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ControlFieldAdapter.java rename to src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractInputField.java index e1c71960..04a36779 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ControlFieldAdapter.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractInputField.java @@ -18,14 +18,17 @@ import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gui.service.examconfig.InputField; -public abstract class ControlFieldAdapter implements InputField { +public abstract class AbstractInputField implements InputField { protected final ConfigurationAttribute attribute; protected final Orientation orientation; protected final T control; protected final Label errorLabel; - ControlFieldAdapter( + protected String initValue = ""; + protected int listIndex = 0; + + AbstractInputField( final ConfigurationAttribute attribute, final Orientation orientation, final T control, @@ -42,11 +45,6 @@ public abstract class ControlFieldAdapter implements InputFie return this.attribute; } - @Override - public final Control getControl() { - return this.control; - } - @Override public void disable() { if (this.control.isEnabled()) { @@ -89,7 +87,15 @@ public abstract class ControlFieldAdapter implements InputFie @Override public void initValue(final Collection values) { - // Does Nothing for default + values.stream() + .filter(a -> this.attribute.id.equals(a.attributeId)) + .findFirst() + .map(v -> { + this.initValue = v.value; + this.listIndex = (v.listIndex != null) ? v.listIndex : 0; + setDefaultValue(); + return this.initValue; + }); } protected abstract void setDefaultValue(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/CheckBoxBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/CheckBoxBuilder.java index cd9b03d0..4e85ad46 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/CheckBoxBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/CheckBoxBuilder.java @@ -8,7 +8,6 @@ package ch.ethz.seb.sebserver.gui.service.examconfig.impl; -import java.util.Collection; import java.util.Objects; import org.eclipse.swt.SWT; @@ -19,7 +18,6 @@ import org.springframework.stereotype.Component; import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; -import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gui.service.examconfig.InputField; @@ -72,9 +70,7 @@ public class CheckBoxBuilder implements InputFieldBuilder { checkbox); } - static final class CheckboxField extends ControlFieldAdapter