added tooltips for input fields in forms

This commit is contained in:
anhefti 2020-02-20 13:55:16 +01:00
parent 7238369550
commit 7c092d6e12
17 changed files with 204 additions and 132 deletions

View file

@ -82,7 +82,7 @@ public class SebClientConfigForm implements TemplateComposer {
private static final LocTextKey FALLBACK_PASSWORD_TEXT_KEY = private static final LocTextKey FALLBACK_PASSWORD_TEXT_KEY =
new LocTextKey("sebserver.clientconfig.form.sebServerFallbackPasswordHash"); new LocTextKey("sebserver.clientconfig.form.sebServerFallbackPasswordHash");
private static final LocTextKey FALLBACK_PASSWORD_CONFIRM_TEXT_KEY = 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 = private static final LocTextKey QUIT_PASSWORD_TEXT_KEY =
new LocTextKey("sebserver.clientconfig.form.hashedQuitPassword"); new LocTextKey("sebserver.clientconfig.form.hashedQuitPassword");
private static final LocTextKey QUIT_PASSWORD_CONFIRM_TEXT_KEY = private static final LocTextKey QUIT_PASSWORD_CONFIRM_TEXT_KEY =
@ -314,7 +314,14 @@ public class SebClientConfigForm implements TemplateComposer {
.addListener(SWT.Selection, event -> { .addListener(SWT.Selection, event -> {
formHandle.process( formHandle.process(
FALLBACK_ATTRIBUTES::contains, 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);
}
}
); );
}); });

View file

@ -8,17 +8,14 @@
package ch.ethz.seb.sebserver.gui.form; 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.apache.commons.lang3.BooleanUtils;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; 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<String> { public class CheckboxFieldBuilder extends FieldBuilder<String> {
@ -48,6 +45,11 @@ public class CheckboxFieldBuilder extends FieldBuilder<String> {
checkbox.setEnabled(false); checkbox.setEnabled(false);
} }
if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) {
builder.pageService.getPolyglotPageService().injectI18nTooltip(
checkbox, this.tooltip);
}
builder.form.putField(this.name, titleLabel, checkbox); builder.form.putField(this.name, titleLabel, checkbox);
} }

View file

@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.form;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -27,8 +28,6 @@ public abstract class FieldBuilder<T> {
public static final LocTextKey MANDATORY_TEXT_KEY = new LocTextKey("sebserver.form.mandatory"); 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_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 spanLabel = -1;
int spanInput = -1; int spanInput = -1;
@ -43,18 +42,14 @@ public abstract class FieldBuilder<T> {
final String name; final String name;
final LocTextKey label; final LocTextKey label;
final LocTextKey tooltipLabel; final LocTextKey tooltip;
final LocTextKey tooltipKeyLeft;
final LocTextKey tooltipKeyRight;
final T value; final T value;
protected FieldBuilder(final String name, final LocTextKey label, final T value) { protected FieldBuilder(final String name, final LocTextKey label, final T value) {
this.name = name; this.name = name;
this.label = label; this.label = label;
this.value = value; this.value = value;
this.tooltipLabel = (label != null) ? new LocTextKey(label.name + TOOLTIP_KEY_SUFFIX_LABEL) : null; this.tooltip = (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;
} }
public FieldBuilder<T> withDefaultLabel(final String defaultLabel) { public FieldBuilder<T> withDefaultLabel(final String defaultLabel) {
@ -134,28 +129,36 @@ public abstract class FieldBuilder<T> {
gridData.horizontalSpan = (fieldBuilder.spanLabel > 0) ? fieldBuilder.spanLabel : 1; gridData.horizontalSpan = (fieldBuilder.spanLabel > 0) ? fieldBuilder.spanLabel : 1;
infoGrid.setLayoutData(gridData); infoGrid.setLayoutData(gridData);
if (fieldBuilder.tooltipKeyLeft != null && final boolean hasTooltip = (fieldBuilder.tooltip != null &&
StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltipKeyLeft, ""))) { StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltip, "")));
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 Label label = labelLocalized( final Label label = labelLocalized(
builder.widgetFactory, builder.widgetFactory,
infoGrid, infoGrid,
fieldBuilder.label, fieldBuilder.label,
fieldBuilder.defaultLabel, fieldBuilder.defaultLabel,
(hasLabelTooltip) ? fieldBuilder.tooltipLabel : null, (hasTooltip) ? fieldBuilder.tooltip : null,
1, 1,
fieldBuilder.titleValign); 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) { if (fieldBuilder.isMandatory) {
final Label mandatory = builder.widgetFactory.imageButton( final Label mandatory = builder.widgetFactory.imageButton(
WidgetFactory.ImageIcon.MANDATORY, WidgetFactory.ImageIcon.MANDATORY,
@ -164,16 +167,6 @@ public abstract class FieldBuilder<T> {
mandatory.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); 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; return infoGrid;
} }

View file

@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.form;
import java.util.Collection; import java.util.Collection;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
@ -48,6 +49,11 @@ public class FileUploadFieldBuilder extends FieldBuilder<String> {
final Label errorLabel = createErrorLabel(fieldGrid); final Label errorLabel = createErrorLabel(fieldGrid);
builder.form.putField(this.name, titleLabel, fileUpload, errorLabel); builder.form.putField(this.name, titleLabel, fileUpload, errorLabel);
builder.setFieldVisible(this.visible, this.name); builder.setFieldVisible(this.visible, this.name);
if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) {
builder.pageService.getPolyglotPageService().injectI18nTooltip(
fileUpload, this.tooltip);
}
} }
} }

View file

@ -512,6 +512,10 @@ public final class Form implements FormBinding {
this.jsonValueAdapter.accept(new Tuple<>(key, getStringValue()), objectRoot); this.jsonValueAdapter.accept(new Tuple<>(key, getStringValue()), objectRoot);
} }
public boolean hasError() {
return this.hasError;
}
public void setError(final String errorMessage) { public void setError(final String errorMessage) {
if (this.errorLabel == null) { if (this.errorLabel == null) {
return; return;

View file

@ -101,7 +101,7 @@ public class FormHandle<T extends Entity> {
// reset all errors that may still be displayed // reset all errors that may still be displayed
this.form.process( this.form.process(
Utils.truePredicate(), Utils.truePredicate(),
fieldAccessor -> fieldAccessor.resetError()); FormFieldAccessor::resetError);
// post // post
return this.post return this.post
@ -165,10 +165,11 @@ public class FormHandle<T extends Entity> {
return this.form.hasAnyError(); return this.form.hasAnyError();
} }
private final void showValidationError( private void showValidationError(
final FormFieldAccessor fieldAccessor, final FormFieldAccessor fieldAccessor,
final FieldValidationError valError) { final FieldValidationError valError) {
//noinspection RedundantCast
fieldAccessor.setError(this.i18nSupport.getText(new LocTextKey( fieldAccessor.setError(this.i18nSupport.getText(new LocTextKey(
FIELD_VALIDATION_LOCTEXT_PREFIX + valError.errorType, FIELD_VALIDATION_LOCTEXT_PREFIX + valError.errorType,
(Object[]) valError.getAttributes()))); (Object[]) valError.getAttributes())));

View file

@ -8,6 +8,7 @@
package ch.ethz.seb.sebserver.gui.form; 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.SWT;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
@ -53,6 +54,11 @@ public final class ImageUploadFieldBuilder extends FieldBuilder<String> {
final Label errorLabel = createErrorLabel(fieldGrid); final Label errorLabel = createErrorLabel(fieldGrid);
builder.form.putField(this.name, titleLabel, imageUpload, errorLabel); builder.form.putField(this.name, titleLabel, imageUpload, errorLabel);
builder.setFieldVisible(this.visible, this.name); builder.setFieldVisible(this.visible, this.name);
if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) {
builder.pageService.getPolyglotPageService().injectI18nTooltip(
imageUpload, this.tooltip);
}
} }
} }

View file

@ -9,6 +9,7 @@
package ch.ethz.seb.sebserver.gui.form; package ch.ethz.seb.sebserver.gui.form;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; 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 ch.ethz.seb.sebserver.gui.widget.PasswordInput;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
@ -33,6 +34,11 @@ public class PasswordFieldBuilder extends FieldBuilder<CharSequence> {
? builder.cryptor.decrypt(this.value) ? builder.cryptor.decrypt(this.value)
: this.value); : this.value);
if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) {
builder.pageService.getPolyglotPageService().injectI18nTooltip(
input, this.tooltip);
}
final Label errorLabel = createErrorLabel(fieldGrid); final Label errorLabel = createErrorLabel(fieldGrid);
builder.form.putField(this.name, titleLabel, input, errorLabel); builder.form.putField(this.name, titleLabel, input, errorLabel);
} }

View file

@ -14,6 +14,7 @@ import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
@ -72,7 +73,7 @@ public final class SelectionFieldBuilder extends FieldBuilder<String> {
this.type, this.type,
fieldGrid, fieldGrid,
this.itemsSupplier, this.itemsSupplier,
null, (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) ? tooltip : null,
null, null,
actionKey); actionKey);
@ -84,9 +85,7 @@ public final class SelectionFieldBuilder extends FieldBuilder<String> {
builder.form.putField(this.name, titleLabel, selection, errorLabel); builder.form.putField(this.name, titleLabel, selection, errorLabel);
if (this.selectionListener != null) { if (this.selectionListener != null) {
((Control) selection).addListener(SWT.Selection, e -> { ((Control) selection).addListener(SWT.Selection, e -> this.selectionListener.accept(builder.form));
this.selectionListener.accept(builder.form);
});
} }
builder.setFieldVisible(this.visible, this.name); builder.setFieldVisible(this.visible, this.name);
@ -97,7 +96,6 @@ public final class SelectionFieldBuilder extends FieldBuilder<String> {
if (this.type == Type.MULTI || this.type == Type.MULTI_COMBO || this.type == Type.MULTI_CHECKBOX) { 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 Composite composite = new Composite(builder.formParent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(1, true); final GridLayout gridLayout = new GridLayout(1, true);
//gridLayout.verticalSpacing = 5;
gridLayout.marginBottom = 5; gridLayout.marginBottom = 5;
gridLayout.horizontalSpacing = 0; gridLayout.horizontalSpacing = 0;
gridLayout.marginLeft = 0; gridLayout.marginLeft = 0;
@ -117,18 +115,23 @@ public final class SelectionFieldBuilder extends FieldBuilder<String> {
.stream() .stream()
.filter(tuple -> keys.contains(tuple._1)) .filter(tuple -> keys.contains(tuple._1))
.map(tuple -> tuple._1) .map(tuple -> tuple._1)
.forEach(v -> buildReadonlyLabel(composite, v, 1)); .forEach(v -> buildReadonlyLabel(builder, composite, v, 1));
} }
} else { } else {
builder.form.putReadonlyField( builder.form.putReadonlyField(
this.name, this.name,
titleLabel, titleLabel,
buildReadonlyLabel(builder.formParent, this.value, this.spanInput)); buildReadonlyLabel(builder, builder.formParent, this.value, this.spanInput));
builder.setFieldVisible(this.visible, this.name); 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 Text label = new Text(composite, SWT.READ_ONLY);
final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, true, hspan, 1); final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, true, hspan, 1);
gridData.verticalIndent = 0; gridData.verticalIndent = 0;
@ -144,6 +147,11 @@ public final class SelectionFieldBuilder extends FieldBuilder<String> {
label.setText(valueSupplier.get()); label.setText(valueSupplier.get());
label.setData(PolyglotPageService.POLYGLOT_WIDGET_FUNCTION_KEY, updateFunction); label.setData(PolyglotPageService.POLYGLOT_WIDGET_FUNCTION_KEY, updateFunction);
if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) {
builder.pageService.getPolyglotPageService().injectI18nTooltip(
label, this.tooltip);
}
return label; return label;
} }

View file

@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.form;
import java.util.function.Consumer; import java.util.function.Consumer;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -104,6 +105,11 @@ public final class TextFieldBuilder extends FieldBuilder<String> {
browser.setText(Constants.EMPTY_NOTE); browser.setText(Constants.EMPTY_NOTE);
} }
builder.form.putReadonlyField(this.name, titleLabel, browser); builder.form.putReadonlyField(this.name, titleLabel, browser);
if (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) {
builder.pageService.getPolyglotPageService().injectI18nTooltip(
browser, this.tooltip);
}
return; return;
} }
@ -113,6 +119,11 @@ public final class TextFieldBuilder extends FieldBuilder<String> {
? builder.widgetFactory.textAreaInput(fieldGrid, readonly) ? builder.widgetFactory.textAreaInput(fieldGrid, readonly)
: builder.widgetFactory.textInput(fieldGrid, this.isPassword, 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); final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, true);
if (this.isArea) { if (this.isArea) {
gridData.minimumHeight = this.areaMinHeight; gridData.minimumHeight = this.areaMinHeight;

View file

@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.gui.form;
import java.util.Collection; import java.util.Collection;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
@ -67,11 +68,16 @@ public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> {
final Label errorLabel = createErrorLabel(fieldGrid); final Label errorLabel = createErrorLabel(fieldGrid);
builder.form.putField(this.name, titleLabel, thresholdList, errorLabel); builder.form.putField(this.name, titleLabel, thresholdList, errorLabel);
builder.setFieldVisible(this.visible, this.name); 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<Threshold> thresholds) { public static String thresholdsToFormURLEncodedStringValue(final Collection<Threshold> thresholds) {
if (thresholds == null || thresholds.isEmpty()) { if (thresholds == null || thresholds.isEmpty()) {
return null; return null;
} }
@ -80,7 +86,7 @@ public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> {
return StringUtils.join(thresholds.stream() return StringUtils.join(thresholds.stream()
.map(t -> Domain.THRESHOLD.REFERENCE_NAME .map(t -> Domain.THRESHOLD.REFERENCE_NAME
+ Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR
+ String.valueOf(t.getValue()) + t.getValue()
+ Constants.EMBEDDED_LIST_SEPARATOR + Constants.EMBEDDED_LIST_SEPARATOR
+ t.getColor()) + t.getColor())
.collect(Collectors.toList()), .collect(Collectors.toList()),

View file

@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.gui.service.i18n;
import java.util.Collection; import java.util.Collection;
import java.util.Locale; import java.util.Locale;
import org.eclipse.swt.widgets.Text;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gbl.util.Utils;

View file

@ -1,80 +1,72 @@
/* /*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
package ch.ethz.seb.sebserver.gui.service.i18n; package ch.ethz.seb.sebserver.gui.service.i18n;
import java.util.Locale; import java.util.Locale;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group; import ch.ethz.seb.sebserver.gui.service.page.PageContext;
import org.eclipse.swt.widgets.Label; import ch.ethz.seb.sebserver.gui.widget.ImageUploadSelection;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem; public interface PolyglotPageService {
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn; String POLYGLOT_WIDGET_FUNCTION_KEY = "POLYGLOT_WIDGET_FUNCTION";
import org.eclipse.swt.widgets.TableItem; String POLYGLOT_ITEM_TEXT_DATA_KEY = "POLYGLOT_ITEM_TEXT_DATA";
import org.eclipse.swt.widgets.Tree; String POLYGLOT_ITEM_TOOLTIP_DATA_KEY = "POLYGLOT_ITEM_TOOLTIP_DATA";
import org.eclipse.swt.widgets.TreeItem;
/** Gets the underling I18nSupport
import ch.ethz.seb.sebserver.gui.service.page.PageContext; *
import ch.ethz.seb.sebserver.gui.widget.ImageUploadSelection; * @return the underling I18nSupport */
I18nSupport getI18nSupport();
public interface PolyglotPageService {
/** The default locale for the page.
String POLYGLOT_WIDGET_FUNCTION_KEY = "POLYGLOT_WIDGET_FUNCTION"; * Uses I18nSupport.getCurrentLocale to do so.
String POLYGLOT_ITEM_TEXT_DATA_KEY = "POLYGLOT_ITEM_TEXT_DATA"; *
String POLYGLOT_ITEM_TOOLTIP_DATA_KEY = "POLYGLOT_ITEM_TOOLTIP_DATA"; * @param root the root Composite of the page to change the language */
void setDefaultPageLocale(Composite root);
/** Gets the underling I18nSupport
* /** Sets the given Locale and if needed, updates the page language according to the
* @return the underling I18nSupport */ * given Locale
I18nSupport getI18nSupport(); *
* @param root root the root Composite of the page to change the language
/** The default locale for the page. * @param locale the Locale to set */
* Uses I18nSupport.getCurrentLocale to do so. void setPageLocale(Composite root, Locale locale);
*
* @param root the root Composite of the page to change the language */ void injectI18n(ImageUploadSelection imageUpload, LocTextKey locTextKey);
void setDefaultPageLocale(Composite root);
void injectI18n(Label label, LocTextKey locTextKey);
/** Sets the given Locale and if needed, updates the page language according to the
* given Locale void injectI18n(Label label, LocTextKey locTextKey, LocTextKey locToolTipKey);
*
* @param root root the root Composite of the page to change the language void injectI18n(Group group, LocTextKey locTextKey, LocTextKey locTooltipKey);
* @param locale the Locale to set */
void setPageLocale(Composite root, Locale locale); void injectI18n(Button button, LocTextKey locTextKey);
void injectI18n(ImageUploadSelection imageUpload, LocTextKey locTextKey); void injectI18n(Button button, LocTextKey locTextKey, LocTextKey locToolTipKey);
void injectI18n(Label label, LocTextKey locTextKey); void injectI18n(Tree tree);
void injectI18n(Label label, LocTextKey locTextKey, LocTextKey locToolTipKey); void injectI18n(TreeItem treeItem, LocTextKey locTextKey);
void injectI18n(Group group, LocTextKey locTextKey, LocTextKey locTooltipKey); void injectI18n(Table table);
void injectI18n(Button button, LocTextKey locTextKey); void injectI18n(TabFolder tabFolder);
void injectI18n(Button button, LocTextKey locTextKey, LocTextKey locToolTipKey); void injectI18n(TableColumn tableColumn, LocTextKey locTextKey, LocTextKey locTooltipKey);
void injectI18n(Tree tree); void injectI18n(TableItem tableItem, LocTextKey... locTextKey);
void injectI18n(TreeItem treeItem, LocTextKey locTextKey); void injectI18n(TabItem tabItem, LocTextKey locTextKey, LocTextKey locTooltipKey);
void injectI18n(Table table); void injectI18nTooltip(Control control, LocTextKey locTooltipKey);
void injectI18n(TabFolder tabFolder); void createLanguageSelector(PageContext composerCtx);
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);
} }

View file

@ -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 @Override
public void createLanguageSelector(final PageContext composerCtx) { public void createLanguageSelector(final PageContext composerCtx) {
for (final Locale locale : this.i18nSupport.supportedLanguages()) { for (final Locale locale : this.i18nSupport.supportedLanguages()) {

View file

@ -58,6 +58,12 @@ import ch.ethz.seb.sebserver.gui.widget.WidgetFactory;
* with forms and tables as well as dealing with page actions */ * with forms and tables as well as dealing with page actions */
public interface PageService { public interface PageService {
enum FormTooltipMode {
RIGHT,
INPUT,
LEFT,
}
Logger log = LoggerFactory.getLogger(PageService.class); Logger log = LoggerFactory.getLogger(PageService.class);
/** Get the WidgetFactory service /** Get the WidgetFactory service
@ -105,6 +111,11 @@ public interface PageService {
* @return PageState of the current user. */ * @return PageState of the current user. */
PageState getCurrentState(); 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. /** Get a PageAction function to go back to the current state.
* *
* @return a PageAction function to go back to the current state. */ * @return a PageAction function to go back to the current state. */

View file

@ -162,6 +162,12 @@ public class PageServiceImpl implements PageService {
} }
} }
@Override
public FormTooltipMode getFormTooltipMode() {
// TODO make this configurable
return FormTooltipMode.INPUT;
}
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends PageEvent> void firePageEvent(final T event, final PageContext pageContext) { public <T extends PageEvent> void firePageEvent(final T event, final PageContext pageContext) {

View file

@ -236,7 +236,7 @@ sebserver.useraccount.form.language.tooltip=The users language.
sebserver.useraccount.form.timezone=Time Zone sebserver.useraccount.form.timezone=Time Zone
sebserver.useraccount.form.timezone.tooltip=The time-zone of the user.<br/><br/>Note that this also defines the exact time and date that is displayed to the user. sebserver.useraccount.form.timezone.tooltip=The time-zone of the user.<br/><br/>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=User Roles
sebserver.useraccount.form.roles.tooltip=Select the roles for the user.<br/>A user can have more then one role but must have at least one.<br/><br/>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.<br/>A user can have more then one role but must have at least one.<br/><br/>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=Password
sebserver.useraccount.form.password.tooltip=The password of the user account sebserver.useraccount.form.password.tooltip=The password of the user account
sebserver.useraccount.form.password.confirm=Confirm Password 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.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=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.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.sebServerFallbackPasswordHash.tooltip.confirm=Please confirm the fallback password
sebserver.clientconfig.form.hashedQuitPassword=Quit 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.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.hashedQuitPassword.tooltip.confirm=Please confirm the quit password
sebserver.clientconfig.form.date=Creation Date sebserver.clientconfig.form.date=Creation Date