diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebClientConfigForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebClientConfigForm.java index 17b355ca..f3b41a1a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebClientConfigForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebClientConfigForm.java @@ -82,7 +82,7 @@ public class SebClientConfigForm implements TemplateComposer { private static final LocTextKey FALLBACK_PASSWORD_TEXT_KEY = new LocTextKey("sebserver.clientconfig.form.sebServerFallbackPasswordHash"); private static final LocTextKey FALLBACK_PASSWORD_CONFIRM_TEXT_KEY = - new LocTextKey("sebserver.clientconfig.form.sebServerFallbackPasswordHash"); + new LocTextKey("sebserver.clientconfig.form.sebServerFallbackPasswordHash.confirm"); private static final LocTextKey QUIT_PASSWORD_TEXT_KEY = new LocTextKey("sebserver.clientconfig.form.hashedQuitPassword"); private static final LocTextKey QUIT_PASSWORD_CONFIRM_TEXT_KEY = @@ -314,7 +314,14 @@ public class SebClientConfigForm implements TemplateComposer { .addListener(SWT.Selection, event -> { formHandle.process( FALLBACK_ATTRIBUTES::contains, - ffa -> ffa.setVisible(((Button) event.widget).getSelection()) + ffa -> { + boolean selected = ((Button) event.widget).getSelection(); + ffa.setVisible(selected); + if (!selected && ffa.hasError()) { + ffa.resetError(); + ffa.setStringValue(StringUtils.EMPTY); + } + } ); }); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/CheckboxFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/CheckboxFieldBuilder.java index 8c2ba7d5..668c8263 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/CheckboxFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/CheckboxFieldBuilder.java @@ -8,17 +8,14 @@ package ch.ethz.seb.sebserver.gui.form; +import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import org.apache.commons.lang3.BooleanUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; - -import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; - -import java.util.function.Consumer; public class CheckboxFieldBuilder extends FieldBuilder { @@ -48,6 +45,11 @@ public class CheckboxFieldBuilder extends FieldBuilder { checkbox.setEnabled(false); } + if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) { + builder.pageService.getPolyglotPageService().injectI18nTooltip( + checkbox, this.tooltip); + } + builder.form.putField(this.name, titleLabel, checkbox); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/FieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/FieldBuilder.java index 6eeb226e..64f6f40a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/FieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/FieldBuilder.java @@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.form; import java.util.function.BooleanSupplier; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import org.apache.commons.lang3.StringUtils; import org.eclipse.rap.rwt.RWT; import org.eclipse.swt.SWT; @@ -27,8 +28,6 @@ public abstract class FieldBuilder { public static final LocTextKey MANDATORY_TEXT_KEY = new LocTextKey("sebserver.form.mandatory"); public static final String TOOLTIP_KEY_SUFFIX_LABEL = ".tooltip"; - public static final String TOOLTIP_KEY_SUFFIX_LEFT = ".tooltip.left"; - public static final String TOOLTIP_KEY_SUFFIX_RIGHT = ".tooltip.right"; int spanLabel = -1; int spanInput = -1; @@ -43,18 +42,14 @@ public abstract class FieldBuilder { final String name; final LocTextKey label; - final LocTextKey tooltipLabel; - final LocTextKey tooltipKeyLeft; - final LocTextKey tooltipKeyRight; + final LocTextKey tooltip; final T value; protected FieldBuilder(final String name, final LocTextKey label, final T value) { this.name = name; this.label = label; this.value = value; - this.tooltipLabel = (label != null) ? new LocTextKey(label.name + TOOLTIP_KEY_SUFFIX_LABEL) : null; - this.tooltipKeyLeft = (label != null) ? new LocTextKey(label.name + TOOLTIP_KEY_SUFFIX_LEFT) : null; - this.tooltipKeyRight = (label != null) ? new LocTextKey(label.name + TOOLTIP_KEY_SUFFIX_RIGHT) : null; + this.tooltip = (label != null) ? new LocTextKey(label.name + TOOLTIP_KEY_SUFFIX_LABEL) : null; } public FieldBuilder withDefaultLabel(final String defaultLabel) { @@ -134,28 +129,36 @@ public abstract class FieldBuilder { gridData.horizontalSpan = (fieldBuilder.spanLabel > 0) ? fieldBuilder.spanLabel : 1; infoGrid.setLayoutData(gridData); - if (fieldBuilder.tooltipKeyLeft != null && - StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltipKeyLeft, ""))) { - - final Label info = builder.widgetFactory.imageButton( - WidgetFactory.ImageIcon.HELP, - infoGrid, - fieldBuilder.tooltipKeyLeft); - info.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); - } - - final boolean hasLabelTooltip = (fieldBuilder.tooltipLabel != null && - StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltipLabel, ""))); + final boolean hasTooltip = (fieldBuilder.tooltip != null && + StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltip, ""))); final Label label = labelLocalized( builder.widgetFactory, infoGrid, fieldBuilder.label, fieldBuilder.defaultLabel, - (hasLabelTooltip) ? fieldBuilder.tooltipLabel : null, + (hasTooltip) ? fieldBuilder.tooltip : null, 1, fieldBuilder.titleValign); + if (hasTooltip && builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.LEFT) { + final Label info = builder.widgetFactory.imageButton( + WidgetFactory.ImageIcon.HELP, + infoGrid, + fieldBuilder.tooltip); + info.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); + } + +// if (fieldBuilder.tooltipKeyRight != null && +// StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltipKeyRight, ""))) { +// +// final Label info = builder.widgetFactory.imageButton( +// WidgetFactory.ImageIcon.HELP, +// infoGrid, +// fieldBuilder.tooltipKeyRight); +// info.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); +// } + if (fieldBuilder.isMandatory) { final Label mandatory = builder.widgetFactory.imageButton( WidgetFactory.ImageIcon.MANDATORY, @@ -164,16 +167,6 @@ public abstract class FieldBuilder { mandatory.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); } - if (fieldBuilder.tooltipKeyRight != null && - StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltipKeyRight, ""))) { - - final Label info = builder.widgetFactory.imageButton( - WidgetFactory.ImageIcon.HELP, - infoGrid, - fieldBuilder.tooltipKeyRight); - info.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); - } - return infoGrid; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/FileUploadFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/FileUploadFieldBuilder.java index 595b26e2..0b0c166b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/FileUploadFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/FileUploadFieldBuilder.java @@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.form; import java.util.Collection; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; @@ -48,6 +49,11 @@ public class FileUploadFieldBuilder extends FieldBuilder { final Label errorLabel = createErrorLabel(fieldGrid); builder.form.putField(this.name, titleLabel, fileUpload, errorLabel); builder.setFieldVisible(this.visible, this.name); + + if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) { + builder.pageService.getPolyglotPageService().injectI18nTooltip( + fileUpload, this.tooltip); + } } } 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 b93dec48..06a5cfda 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 @@ -512,6 +512,10 @@ public final class Form implements FormBinding { this.jsonValueAdapter.accept(new Tuple<>(key, getStringValue()), objectRoot); } + public boolean hasError() { + return this.hasError; + } + public void setError(final String errorMessage) { if (this.errorLabel == null) { return; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java index 92e7375c..cb8e12c5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java @@ -101,7 +101,7 @@ public class FormHandle { // reset all errors that may still be displayed this.form.process( Utils.truePredicate(), - fieldAccessor -> fieldAccessor.resetError()); + FormFieldAccessor::resetError); // post return this.post @@ -165,10 +165,11 @@ public class FormHandle { return this.form.hasAnyError(); } - private final void showValidationError( + private void showValidationError( final FormFieldAccessor fieldAccessor, final FieldValidationError valError) { + //noinspection RedundantCast fieldAccessor.setError(this.i18nSupport.getText(new LocTextKey( FIELD_VALIDATION_LOCTEXT_PREFIX + valError.errorType, (Object[]) valError.getAttributes()))); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/ImageUploadFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/ImageUploadFieldBuilder.java index a19286be..9d900479 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/ImageUploadFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/ImageUploadFieldBuilder.java @@ -8,6 +8,7 @@ package ch.ethz.seb.sebserver.gui.form; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; @@ -53,6 +54,11 @@ public final class ImageUploadFieldBuilder extends FieldBuilder { final Label errorLabel = createErrorLabel(fieldGrid); builder.form.putField(this.name, titleLabel, imageUpload, errorLabel); builder.setFieldVisible(this.visible, this.name); + + if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) { + builder.pageService.getPolyglotPageService().injectI18nTooltip( + imageUpload, this.tooltip); + } } } \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/PasswordFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/PasswordFieldBuilder.java index 4aa310c1..a7eb6b24 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/PasswordFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/PasswordFieldBuilder.java @@ -9,6 +9,7 @@ package ch.ethz.seb.sebserver.gui.form; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.widget.PasswordInput; import org.apache.commons.lang3.StringUtils; import org.eclipse.swt.widgets.Composite; @@ -33,6 +34,11 @@ public class PasswordFieldBuilder extends FieldBuilder { ? builder.cryptor.decrypt(this.value) : this.value); + if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) { + builder.pageService.getPolyglotPageService().injectI18nTooltip( + input, this.tooltip); + } + final Label errorLabel = createErrorLabel(fieldGrid); builder.form.putField(this.name, titleLabel, input, errorLabel); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/SelectionFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/SelectionFieldBuilder.java index 400638bd..a586d5c8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/SelectionFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/SelectionFieldBuilder.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.function.Consumer; import java.util.function.Supplier; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import org.apache.commons.lang3.StringUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -72,7 +73,7 @@ public final class SelectionFieldBuilder extends FieldBuilder { this.type, fieldGrid, this.itemsSupplier, - null, + (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) ? tooltip : null, null, actionKey); @@ -84,9 +85,7 @@ public final class SelectionFieldBuilder extends FieldBuilder { builder.form.putField(this.name, titleLabel, selection, errorLabel); if (this.selectionListener != null) { - ((Control) selection).addListener(SWT.Selection, e -> { - this.selectionListener.accept(builder.form); - }); + ((Control) selection).addListener(SWT.Selection, e -> this.selectionListener.accept(builder.form)); } builder.setFieldVisible(this.visible, this.name); @@ -97,7 +96,6 @@ public final class SelectionFieldBuilder extends FieldBuilder { if (this.type == Type.MULTI || this.type == Type.MULTI_COMBO || this.type == Type.MULTI_CHECKBOX) { final Composite composite = new Composite(builder.formParent, SWT.NONE); final GridLayout gridLayout = new GridLayout(1, true); - //gridLayout.verticalSpacing = 5; gridLayout.marginBottom = 5; gridLayout.horizontalSpacing = 0; gridLayout.marginLeft = 0; @@ -117,18 +115,23 @@ public final class SelectionFieldBuilder extends FieldBuilder { .stream() .filter(tuple -> keys.contains(tuple._1)) .map(tuple -> tuple._1) - .forEach(v -> buildReadonlyLabel(composite, v, 1)); + .forEach(v -> buildReadonlyLabel(builder, composite, v, 1)); } } else { builder.form.putReadonlyField( this.name, titleLabel, - buildReadonlyLabel(builder.formParent, this.value, this.spanInput)); + buildReadonlyLabel(builder, builder.formParent, this.value, this.spanInput)); builder.setFieldVisible(this.visible, this.name); } } - private Text buildReadonlyLabel(final Composite composite, final String valueKey, final int hspan) { + private Text buildReadonlyLabel( + final FormBuilder builder, + final Composite composite, + final String valueKey, + final int hspan) { + final Text label = new Text(composite, SWT.READ_ONLY); final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, true, hspan, 1); gridData.verticalIndent = 0; @@ -144,6 +147,11 @@ public final class SelectionFieldBuilder extends FieldBuilder { label.setText(valueSupplier.get()); label.setData(PolyglotPageService.POLYGLOT_WIDGET_FUNCTION_KEY, updateFunction); + if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) { + builder.pageService.getPolyglotPageService().injectI18nTooltip( + label, this.tooltip); + } + return label; } 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 8ca8d24c..431e0460 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 @@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.form; import java.util.function.Consumer; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import org.apache.commons.lang3.StringUtils; import org.eclipse.rap.rwt.RWT; import org.eclipse.swt.SWT; @@ -104,6 +105,11 @@ public final class TextFieldBuilder extends FieldBuilder { browser.setText(Constants.EMPTY_NOTE); } builder.form.putReadonlyField(this.name, titleLabel, browser); + + if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) { + builder.pageService.getPolyglotPageService().injectI18nTooltip( + browser, this.tooltip); + } return; } @@ -113,6 +119,11 @@ public final class TextFieldBuilder extends FieldBuilder { ? builder.widgetFactory.textAreaInput(fieldGrid, readonly) : builder.widgetFactory.textInput(fieldGrid, this.isPassword, readonly); + if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) { + builder.pageService.getPolyglotPageService().injectI18nTooltip( + textInput, this.tooltip); + } + final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, true); if (this.isArea) { gridData.minimumHeight = this.areaMinHeight; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/ThresholdListBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/ThresholdListBuilder.java index 1483da3c..f0bf4fae 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/ThresholdListBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/ThresholdListBuilder.java @@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.gui.form; import java.util.Collection; import java.util.stream.Collectors; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import org.apache.commons.lang3.StringUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -67,11 +68,16 @@ public class ThresholdListBuilder extends FieldBuilder> { final Label errorLabel = createErrorLabel(fieldGrid); builder.form.putField(this.name, titleLabel, thresholdList, errorLabel); builder.setFieldVisible(this.visible, this.name); + + if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) { + builder.pageService.getPolyglotPageService().injectI18nTooltip( + thresholdList, this.tooltip); + } } } - public static final String thresholdsToFormURLEncodedStringValue(final Collection thresholds) { + public static String thresholdsToFormURLEncodedStringValue(final Collection thresholds) { if (thresholds == null || thresholds.isEmpty()) { return null; } @@ -80,7 +86,7 @@ public class ThresholdListBuilder extends FieldBuilder> { return StringUtils.join(thresholds.stream() .map(t -> Domain.THRESHOLD.REFERENCE_NAME + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR - + String.valueOf(t.getValue()) + + t.getValue() + Constants.EMBEDDED_LIST_SEPARATOR + t.getColor()) .collect(Collectors.toList()), diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/I18nSupport.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/I18nSupport.java index 1376f307..c47cacb9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/I18nSupport.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/I18nSupport.java @@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.gui.service.i18n; import java.util.Collection; import java.util.Locale; +import org.eclipse.swt.widgets.Text; import org.joda.time.DateTime; import ch.ethz.seb.sebserver.gbl.util.Utils; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/PolyglotPageService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/PolyglotPageService.java index 25bf2e53..93da8fa5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/PolyglotPageService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/PolyglotPageService.java @@ -1,80 +1,72 @@ -/* - * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package ch.ethz.seb.sebserver.gui.service.i18n; - -import java.util.Locale; - -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.TabFolder; -import org.eclipse.swt.widgets.TabItem; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; - -import ch.ethz.seb.sebserver.gui.service.page.PageContext; -import ch.ethz.seb.sebserver.gui.widget.ImageUploadSelection; - -public interface PolyglotPageService { - - String POLYGLOT_WIDGET_FUNCTION_KEY = "POLYGLOT_WIDGET_FUNCTION"; - String POLYGLOT_ITEM_TEXT_DATA_KEY = "POLYGLOT_ITEM_TEXT_DATA"; - String POLYGLOT_ITEM_TOOLTIP_DATA_KEY = "POLYGLOT_ITEM_TOOLTIP_DATA"; - - /** Gets the underling I18nSupport - * - * @return the underling I18nSupport */ - I18nSupport getI18nSupport(); - - /** The default locale for the page. - * Uses I18nSupport.getCurrentLocale to do so. - * - * @param root the root Composite of the page to change the language */ - void setDefaultPageLocale(Composite root); - - /** Sets the given Locale and if needed, updates the page language according to the - * given Locale - * - * @param root root the root Composite of the page to change the language - * @param locale the Locale to set */ - void setPageLocale(Composite root, Locale locale); - - void injectI18n(ImageUploadSelection imageUpload, LocTextKey locTextKey); - - void injectI18n(Label label, LocTextKey locTextKey); - - void injectI18n(Label label, LocTextKey locTextKey, LocTextKey locToolTipKey); - - void injectI18n(Group group, LocTextKey locTextKey, LocTextKey locTooltipKey); - - void injectI18n(Button button, LocTextKey locTextKey); - - void injectI18n(Button button, LocTextKey locTextKey, LocTextKey locToolTipKey); - - void injectI18n(Tree tree); - - void injectI18n(TreeItem treeItem, LocTextKey locTextKey); - - void injectI18n(Table table); - - void injectI18n(TabFolder tabFolder); - - void injectI18n(TableColumn tableColumn, LocTextKey locTextKey, LocTextKey locTooltipKey); - - void injectI18n(TableItem tableItem, LocTextKey... locTextKey); - - void injectI18n(TabItem tabItem, LocTextKey locTextKey, LocTextKey locTooltipKey); - - void createLanguageSelector(PageContext composerCtx); - +/* + * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gui.service.i18n; + +import java.util.Locale; + +import org.eclipse.swt.widgets.*; + +import ch.ethz.seb.sebserver.gui.service.page.PageContext; +import ch.ethz.seb.sebserver.gui.widget.ImageUploadSelection; + +public interface PolyglotPageService { + + String POLYGLOT_WIDGET_FUNCTION_KEY = "POLYGLOT_WIDGET_FUNCTION"; + String POLYGLOT_ITEM_TEXT_DATA_KEY = "POLYGLOT_ITEM_TEXT_DATA"; + String POLYGLOT_ITEM_TOOLTIP_DATA_KEY = "POLYGLOT_ITEM_TOOLTIP_DATA"; + + /** Gets the underling I18nSupport + * + * @return the underling I18nSupport */ + I18nSupport getI18nSupport(); + + /** The default locale for the page. + * Uses I18nSupport.getCurrentLocale to do so. + * + * @param root the root Composite of the page to change the language */ + void setDefaultPageLocale(Composite root); + + /** Sets the given Locale and if needed, updates the page language according to the + * given Locale + * + * @param root root the root Composite of the page to change the language + * @param locale the Locale to set */ + void setPageLocale(Composite root, Locale locale); + + void injectI18n(ImageUploadSelection imageUpload, LocTextKey locTextKey); + + void injectI18n(Label label, LocTextKey locTextKey); + + void injectI18n(Label label, LocTextKey locTextKey, LocTextKey locToolTipKey); + + void injectI18n(Group group, LocTextKey locTextKey, LocTextKey locTooltipKey); + + void injectI18n(Button button, LocTextKey locTextKey); + + void injectI18n(Button button, LocTextKey locTextKey, LocTextKey locToolTipKey); + + void injectI18n(Tree tree); + + void injectI18n(TreeItem treeItem, LocTextKey locTextKey); + + void injectI18n(Table table); + + void injectI18n(TabFolder tabFolder); + + void injectI18n(TableColumn tableColumn, LocTextKey locTextKey, LocTextKey locTooltipKey); + + void injectI18n(TableItem tableItem, LocTextKey... locTextKey); + + void injectI18n(TabItem tabItem, LocTextKey locTextKey, LocTextKey locTooltipKey); + + void injectI18nTooltip(Control control, LocTextKey locTooltipKey); + + void createLanguageSelector(PageContext composerCtx); + } \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/impl/PolyglotPageServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/impl/PolyglotPageServiceImpl.java index 3e3d5a5d..45590602 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/impl/PolyglotPageServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/impl/PolyglotPageServiceImpl.java @@ -188,6 +188,18 @@ public final class PolyglotPageServiceImpl implements PolyglotPageService { } } + @Override + public void injectI18nTooltip(Control control, LocTextKey locTooltipKey) { + if (locTooltipKey == null || control == null) { + return; + } + + if (this.i18nSupport.hasText(locTooltipKey) && StringUtils.isNotBlank(this.i18nSupport.getText(locTooltipKey, ""))) { + control.setData(POLYGLOT_ITEM_TOOLTIP_DATA_KEY, locTooltipKey); + control.setToolTipText(Utils.formatLineBreaks(this.i18nSupport.getText(locTooltipKey))); + } + } + @Override public void createLanguageSelector(final PageContext composerCtx) { for (final Locale locale : this.i18nSupport.supportedLanguages()) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java index 9570c79d..e21a7a08 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java @@ -58,6 +58,12 @@ import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; * with forms and tables as well as dealing with page actions */ public interface PageService { + enum FormTooltipMode { + RIGHT, + INPUT, + LEFT, + } + Logger log = LoggerFactory.getLogger(PageService.class); /** Get the WidgetFactory service @@ -105,6 +111,11 @@ public interface PageService { * @return PageState of the current user. */ PageState getCurrentState(); + /** Get the configured tooltip mode for input forms + * + * @return the configured tooltip mode for input forms */ + FormTooltipMode getFormTooltipMode(); + /** Get a PageAction function to go back to the current state. * * @return a PageAction function to go back to the current state. */ diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java index 570f90a9..e276f578 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java @@ -162,6 +162,12 @@ public class PageServiceImpl implements PageService { } } + @Override + public FormTooltipMode getFormTooltipMode() { + // TODO make this configurable + return FormTooltipMode.INPUT; + } + @Override @SuppressWarnings("unchecked") public void firePageEvent(final T event, final PageContext pageContext) { diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 62094802..01a888a3 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -236,7 +236,7 @@ sebserver.useraccount.form.language.tooltip=The users language. sebserver.useraccount.form.timezone=Time Zone sebserver.useraccount.form.timezone.tooltip=The time-zone of the user.

Note that this also defines the exact time and date that is displayed to the user. sebserver.useraccount.form.roles=User Roles -sebserver.useraccount.form.roles.tooltip=Select the roles for the user.
A user can have more then one role but must have at least one.

Please use the tooltip on the role name for more information about a specific role. +sebserver.useraccount.form.roles.tooltip=The roles of the user.
A user can have more then one role but must have at least one.

In Edit mode, please use the tooltip on the role name for more information about a specific role. sebserver.useraccount.form.password=Password sebserver.useraccount.form.password.tooltip=The password of the user account sebserver.useraccount.form.password.confirm=Confirm Password @@ -607,11 +607,11 @@ sebserver.clientconfig.form.sebServerFallbackAttemptInterval=Interval sebserver.clientconfig.form.sebServerFallbackAttemptInterval.tooltip=The interval (in milli-seconds) between connection attempts a SEB client shall use. sebserver.clientconfig.form.sebServerFallbackPasswordHash=Fallback Password sebserver.clientconfig.form.sebServerFallbackPasswordHash.tooltip=A password if set a SEB Client user must provide before the SEB client starts the fallback procedure. -sebserver.clientconfig.form.sebServerFallbackPasswordHash.confirm=Confirm Fallback Password +sebserver.clientconfig.form.sebServerFallbackPasswordHash.confirm=Confirm Password sebserver.clientconfig.form.sebServerFallbackPasswordHash.tooltip.confirm=Please confirm the fallback password sebserver.clientconfig.form.hashedQuitPassword=Quit Password sebserver.clientconfig.form.hashedQuitPassword.tooltip=A password if set a SEB client user must provide to be able to quit the SEB client. -sebserver.clientconfig.form.hashedQuitPassword.confirm=Confirm Quit Password +sebserver.clientconfig.form.hashedQuitPassword.confirm=Confirm Password sebserver.clientconfig.form.hashedQuitPassword.tooltip.confirm=Please confirm the quit password sebserver.clientconfig.form.date=Creation Date