From 6d47e8f803a9a242a6ae121bba1a8ab27a743a84 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 25 Jan 2024 09:51:16 +0100 Subject: [PATCH] SEBSERV-414 lock screen color selector --- .../gbl/model/sebconfig/AttributeType.java | 2 + .../impl/ColorSelectorFieldBuilder.java | 121 ++++++++++++++++++ .../examconfig/impl/TextFieldBuilder.java | 3 +- .../sebserver/gui/widget/ColorSelection.java | 2 +- .../impl/converter/StringConverter.java | 3 +- .../V27__exam_config_gui_additions_v1_6.sql | 13 ++ src/main/resources/messages.properties | 4 +- 7 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ColorSelectorFieldBuilder.java diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/AttributeType.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/AttributeType.java index 0734c811..2821a4c3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/AttributeType.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/AttributeType.java @@ -43,6 +43,8 @@ public enum AttributeType { /** Multiple selection with checkbox type */ MULTI_CHECKBOX_SELECTION(LIST), + COLOR_SELECTOR(TEXT), + FILE_UPLOAD(BASE64_BINARY), /** Table type is a list of a composite of single types */ diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ColorSelectorFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ColorSelectorFieldBuilder.java new file mode 100644 index 00000000..b108e855 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ColorSelectorFieldBuilder.java @@ -0,0 +1,121 @@ +package ch.ethz.seb.sebserver.gui.service.examconfig.impl; + +import ch.ethz.seb.sebserver.gbl.Constants; +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.Orientation; +import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; +import ch.ethz.seb.sebserver.gui.form.FieldBuilder; +import ch.ethz.seb.sebserver.gui.service.examconfig.ExamConfigurationService; +import ch.ethz.seb.sebserver.gui.service.examconfig.InputField; +import ch.ethz.seb.sebserver.gui.service.examconfig.InputFieldBuilder; +import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport; +import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; +import ch.ethz.seb.sebserver.gui.widget.ColorSelection; +import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Lazy +@Component +@GuiProfile +public class ColorSelectorFieldBuilder implements InputFieldBuilder { + + private final WidgetFactory widgetFactory; + + public ColorSelectorFieldBuilder(final WidgetFactory widgetFactory) { + this.widgetFactory = widgetFactory; + } + + + @Override + public void init(final InputFieldBuilderSupplier inputFieldBuilderSupplier) { + InputFieldBuilder.super.init(inputFieldBuilderSupplier); + } + + @Override + public boolean builderFor(final ConfigurationAttribute attribute, final Orientation orientation) { + if (attribute == null) { + return false; + } + + return attribute.type == AttributeType.COLOR_SELECTOR; + } + + @Override + public InputField createInputField( + final Composite parent, + final ConfigurationAttribute attribute, + final ViewContext viewContext) { + + final I18nSupport i18nSupport = viewContext.getI18nSupport(); + final Orientation orientation = viewContext + .getOrientation(attribute.id); + final Composite innerGrid = InputFieldBuilder + .createInnerGrid(parent, attribute, orientation); + + final LocTextKey toolTipKey = ExamConfigurationService.getToolTipKey( + attribute, + i18nSupport); + final ColorSelection colorSelector = new ColorSelection( + innerGrid, + widgetFactory, + toolTipKey != null ? toolTipKey.name: null); + + colorSelector.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + final ColorSelectionInputField singleSelectionInputField = new ColorSelectionInputField( + attribute, + orientation, + colorSelector, + FieldBuilder.createErrorLabel(innerGrid)); + + if (viewContext.readonly) { + colorSelector.setEnabled(false); + } else { + colorSelector.setSelectionListener(event -> { + singleSelectionInputField.clearError(); + viewContext.getValueChangeListener().valueChanged( + viewContext, + attribute, + singleSelectionInputField.getValue(), + singleSelectionInputField.listIndex); + }); + } + + return singleSelectionInputField; + } + + static final class ColorSelectionInputField extends AbstractInputField { + + protected ColorSelectionInputField( + final ConfigurationAttribute attribute, + final Orientation orientation, + final ColorSelection control, + final Label errorLabel) { + + super(attribute, orientation, control, errorLabel); + } + + @Override + public String getValue() { + final String selection = this.control.getSelectionValue(); + if (selection == null) { + return null; + } + return Constants.HASH_TAG + selection; + } + + @Override + protected void setValueToControl(final String value) { + if (value != null && value.startsWith(Constants.HASH_TAG.toString())) { + this.control.select(value.substring(1)); + } else { + this.control.select(value); + } + } + } +} diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java index 04960109..22016159 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java @@ -53,7 +53,8 @@ public class TextFieldBuilder implements InputFieldBuilder { return attribute.type == AttributeType.TEXT_FIELD || attribute.type == AttributeType.TEXT_AREA || attribute.type == AttributeType.INTEGER || - attribute.type == AttributeType.DECIMAL; + attribute.type == AttributeType.DECIMAL || + attribute.type == AttributeType.COLOR_SELECTOR; } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java index b221a4ae..ebabfa34 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java @@ -51,7 +51,7 @@ public final class ColorSelection extends Composite implements Selection { private Listener listener = null; - ColorSelection( + public ColorSelection( final Composite parent, final WidgetFactory widgetFactory, final String tooltipKeyPrefix) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/StringConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/StringConverter.java index 594f30c9..7c4cf1cd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/StringConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/StringConverter.java @@ -42,7 +42,8 @@ public class StringConverter implements AttributeValueConverter { AttributeType.TEXT_AREA, AttributeType.PASSWORD_FIELD, AttributeType.DECIMAL, - AttributeType.COMBO_SELECTION))); + AttributeType.COMBO_SELECTION, + AttributeType.COLOR_SELECTOR))); private static final String XML_TEMPLATE = "%s%s"; private static final String XML_TEMPLATE_EMPTY = "%s"; diff --git a/src/main/resources/config/sql/base/V27__exam_config_gui_additions_v1_6.sql b/src/main/resources/config/sql/base/V27__exam_config_gui_additions_v1_6.sql index 9e433d24..53180f7e 100644 --- a/src/main/resources/config/sql/base/V27__exam_config_gui_additions_v1_6.sql +++ b/src/main/resources/config/sql/base/V27__exam_config_gui_additions_v1_6.sql @@ -175,3 +175,16 @@ INSERT IGNORE INTO orientation (config_attribute_id, template_id, view_id, group (1563, 0, 3, 'mediaPlaybackCapture', 9, 19, 3, 1, 'NONE') ; +-- ---------------------------------------------------------------- +-- Add Lock screen color (SEBSERV-414) +-- ---------------------------------------------------------------- + +INSERT IGNORE INTO configuration_attribute VALUES + (1595, 'lockScreenBackgroundColor', 'COLOR_SELECTOR', null, null, null, null, '#FF0000') +; + +INSERT IGNORE INTO orientation (config_attribute_id, template_id, view_id, group_id, x_position, y_position, width, height, title) VALUES + (1595, 0, 2, null, 7, 9, 5, 2, 'TOP') +; + +UPDATE orientation SET height=1 WHERE config_attribute_id=8 AND template_id=0; \ No newline at end of file diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 80a1eed4..a33cf1dd 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -1293,7 +1293,8 @@ sebserver.examconfig.props.label.allowSpellCheckDictionary.fr-FR=French (France) sebserver.examconfig.props.label.allowSpellCheckDictionary.pt-PT=Portuguese (Portugal) (pt-PT) sebserver.examconfig.props.label.allowSpellCheckDictionary.sv-SE=Swedish (Sweden) sebserver.examconfig.props.label.allowSpellCheckDictionary.sv-FI=Swedish (Finland) - +sebserver.examconfig.props.label.lockScreenBackgroundColor=Lock screen background color +sebserver.examconfig.props.label.lockScreenBackgroundColor.tooltip= sebserver.examconfig.props.group.newBrowserWindow=Links requesting to be opened in a new browser window (Mac) sebserver.examconfig.props.label.newBrowserWindowByLinkPolicy.0=get generally blocked sebserver.examconfig.props.label.newBrowserWindowByLinkPolicy.1=open in same window @@ -1633,7 +1634,6 @@ sebserver.examconfig.props.label.allowSiri=Allow to use Siri sebserver.examconfig.props.label.allowSiri.tooltip=If enabled, Siri can be used by tapping the menu bar icon, Touch Bar icon or shortcut set in System Preferences/Siri (default: hold command space). The Siri window won't be displayed though sebserver.examconfig.props.label.detectStoppedProcess=Detect when SEB process was stopped sebserver.examconfig.props.label.detectStoppedProcess.tooltip=SEB displays a lock screen (requiring to enter the quit/unlock password) if it detects its process was stopped, which can indicate manipulation -sebserver.examconfig.props.label.detectStoppedProcess.tooltip=SEB displays a lock screen (requiring to enter the quit/unlock password) if it detects its process was stopped, which can indicate manipulation sebserver.examconfig.props.label.allowDisplayMirroring=Allow display mirroring (affects also AirPlay Display) sebserver.examconfig.props.label.allowDisplayMirroring.tooltip=If not selected, SEB prevents to mirror the main display to another sebserver.examconfig.props.label.allowedDisplaysMaxNumber=Maximum allowed number of connected displays