minor refactoring and code cleanup
This commit is contained in:
parent
a57f937724
commit
74306412e1
8 changed files with 335 additions and 252 deletions
|
@ -25,6 +25,7 @@ import org.springframework.stereotype.Component;
|
|||
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
|
||||
import ch.ethz.seb.sebserver.gui.content.activity.ActivitiesPane;
|
||||
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
|
||||
import ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService;
|
||||
import ch.ethz.seb.sebserver.gui.service.page.PageContext;
|
||||
import ch.ethz.seb.sebserver.gui.service.page.PageService;
|
||||
import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer;
|
||||
|
@ -52,13 +53,16 @@ public class MainPage implements TemplateComposer {
|
|||
private static final int[] OPENED_SASH_WEIGHTS = new int[] { 0, 100, 0 };
|
||||
|
||||
private final WidgetFactory widgetFactory;
|
||||
private final PolyglotPageService polyglotPageService;
|
||||
private final PageService pageStateService;
|
||||
|
||||
public MainPage(
|
||||
final WidgetFactory widgetFactory,
|
||||
final PolyglotPageService polyglotPageService,
|
||||
final PageService pageStateService) {
|
||||
|
||||
this.widgetFactory = widgetFactory;
|
||||
this.polyglotPageService = polyglotPageService;
|
||||
this.pageStateService = pageStateService;
|
||||
}
|
||||
|
||||
|
@ -105,7 +109,7 @@ public class MainPage implements TemplateComposer {
|
|||
mainSash.setWeights(DEFAULT_SASH_WEIGHTS);
|
||||
ib.setData("fullScreen", false);
|
||||
ib.setImage(WidgetFactory.ImageIcon.MAXIMIZE.getImage(ib.getDisplay()));
|
||||
this.widgetFactory.injectI18n(
|
||||
this.polyglotPageService.injectI18n(
|
||||
ib,
|
||||
null,
|
||||
new LocTextKey("sebserver.mainpage.maximize.tooltip"));
|
||||
|
@ -113,7 +117,7 @@ public class MainPage implements TemplateComposer {
|
|||
mainSash.setWeights(OPENED_SASH_WEIGHTS);
|
||||
ib.setData("fullScreen", true);
|
||||
ib.setImage(WidgetFactory.ImageIcon.MINIMIZE.getImage(ib.getDisplay()));
|
||||
this.widgetFactory.injectI18n(
|
||||
this.polyglotPageService.injectI18n(
|
||||
ib,
|
||||
null,
|
||||
new LocTextKey("sebserver.mainpage.minimize.tooltip"));
|
||||
|
|
|
@ -10,7 +10,20 @@ 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.ImageUpload;
|
||||
|
||||
public interface PolyglotPageService {
|
||||
|
||||
|
@ -36,4 +49,32 @@ public interface PolyglotPageService {
|
|||
* @param locale the Locale to set */
|
||||
void setPageLocale(Composite root, Locale locale);
|
||||
|
||||
void injectI18n(ImageUpload 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);
|
||||
|
||||
}
|
|
@ -11,15 +11,31 @@ package ch.ethz.seb.sebserver.gui.service.i18n.impl;
|
|||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.rap.rwt.RWT;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
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 org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
|
||||
import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport;
|
||||
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
|
||||
import ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService;
|
||||
import ch.ethz.seb.sebserver.gui.service.page.ComposerService;
|
||||
import ch.ethz.seb.sebserver.gui.service.page.PageContext;
|
||||
import ch.ethz.seb.sebserver.gui.widget.ImageUpload;
|
||||
|
||||
/** Service that supports page language change on the fly */
|
||||
@Lazy
|
||||
|
@ -55,4 +71,222 @@ public final class PolyglotPageServiceImpl implements PolyglotPageService {
|
|||
root.layout(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final ImageUpload imageUpload, final LocTextKey locTextKey) {
|
||||
final Consumer<ImageUpload> imageUploadFunction = iu -> {
|
||||
if (locTextKey != null) {
|
||||
iu.setSelectionText(this.i18nSupport.getText(locTextKey));
|
||||
}
|
||||
};
|
||||
imageUpload.setData(POLYGLOT_WIDGET_FUNCTION_KEY, imageUploadFunction);
|
||||
imageUploadFunction.accept(imageUpload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final Label label, final LocTextKey locTextKey) {
|
||||
injectI18n(label, locTextKey, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final Label label, final LocTextKey locTextKey, final LocTextKey locToolTipKey) {
|
||||
final Consumer<Label> labelFunction = labelFunction(locTextKey, locToolTipKey, this.i18nSupport);
|
||||
label.setData(POLYGLOT_WIDGET_FUNCTION_KEY, labelFunction);
|
||||
labelFunction.accept(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final Group group, final LocTextKey locTextKey, final LocTextKey locTooltipKey) {
|
||||
final Consumer<Group> groupFunction = groupFunction(locTextKey, locTooltipKey, this.i18nSupport);
|
||||
group.setData(POLYGLOT_WIDGET_FUNCTION_KEY, groupFunction);
|
||||
groupFunction.accept(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final Button button, final LocTextKey locTextKey) {
|
||||
injectI18n(button, locTextKey, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final Button button, final LocTextKey locTextKey, final LocTextKey locToolTipKey) {
|
||||
final Consumer<Button> buttonFunction = b -> {
|
||||
if (locTextKey != null) {
|
||||
b.setText(this.i18nSupport.getText(locTextKey));
|
||||
}
|
||||
if (locToolTipKey != null) {
|
||||
b.setToolTipText(this.i18nSupport.getText(locToolTipKey));
|
||||
}
|
||||
};
|
||||
button.setData(POLYGLOT_WIDGET_FUNCTION_KEY, buttonFunction);
|
||||
buttonFunction.accept(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final Tree tree) {
|
||||
tree.setData(
|
||||
POLYGLOT_WIDGET_FUNCTION_KEY,
|
||||
(Consumer<Tree>) t -> updateLocale(t.getItems(), this.i18nSupport));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final TreeItem treeItem, final LocTextKey locTextKey) {
|
||||
treeItem.setData(POLYGLOT_ITEM_TEXT_DATA_KEY, locTextKey);
|
||||
treeItem.setText(this.i18nSupport.getText(locTextKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final Table table) {
|
||||
table.setData(
|
||||
POLYGLOT_WIDGET_FUNCTION_KEY,
|
||||
(Consumer<Table>) t -> {
|
||||
updateLocale(t.getColumns(), this.i18nSupport);
|
||||
updateLocale(t.getItems(), this.i18nSupport);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final TabFolder tabFolder) {
|
||||
tabFolder.setData(
|
||||
POLYGLOT_WIDGET_FUNCTION_KEY,
|
||||
(Consumer<TabFolder>) t -> updateLocale(t.getItems(), this.i18nSupport));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final TableColumn tableColumn, final LocTextKey locTextKey, final LocTextKey locTooltipKey) {
|
||||
tableColumn.setData(POLYGLOT_ITEM_TEXT_DATA_KEY, locTextKey);
|
||||
tableColumn.setText(this.i18nSupport.getText(locTextKey));
|
||||
|
||||
if (locTooltipKey != null) {
|
||||
tableColumn.setData(POLYGLOT_ITEM_TOOLTIP_DATA_KEY, locTooltipKey);
|
||||
tableColumn.setToolTipText(this.i18nSupport.getText(locTooltipKey));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final TableItem tableItem, final LocTextKey... locTextKey) {
|
||||
if (locTextKey == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
tableItem.setData(POLYGLOT_ITEM_TEXT_DATA_KEY, locTextKey);
|
||||
for (int i = 0; i < locTextKey.length; i++) {
|
||||
tableItem.setText(i, this.i18nSupport.getText(locTextKey[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectI18n(final TabItem tabItem, final LocTextKey locTextKey, final LocTextKey locTooltipKey) {
|
||||
tabItem.setData(POLYGLOT_ITEM_TEXT_DATA_KEY, locTextKey);
|
||||
tabItem.setText(this.i18nSupport.getText(locTextKey));
|
||||
|
||||
if (locTooltipKey != null) {
|
||||
tabItem.setData(POLYGLOT_ITEM_TOOLTIP_DATA_KEY, locTooltipKey);
|
||||
tabItem.setToolTipText(this.i18nSupport.getText(locTooltipKey));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLanguageSelector(final PageContext composerCtx) {
|
||||
for (final Locale locale : this.i18nSupport.supportedLanguages()) {
|
||||
final Label languageSelection = new Label(composerCtx.getParent(), SWT.NONE);
|
||||
languageSelection.setData(
|
||||
POLYGLOT_WIDGET_FUNCTION_KEY,
|
||||
(Consumer<Label>) label -> label.setVisible(
|
||||
!this.i18nSupport.getCurrentLocale()
|
||||
.getLanguage()
|
||||
.equals(locale.getLanguage())));
|
||||
languageSelection.setData(RWT.CUSTOM_VARIANT, "header");
|
||||
languageSelection.setText("| " + locale.getLanguage().toUpperCase());
|
||||
languageSelection.addListener(SWT.MouseDown, event -> {
|
||||
this.setPageLocale(composerCtx.getRoot(), locale);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static final Consumer<Label> labelFunction(
|
||||
final LocTextKey locTextKey,
|
||||
final LocTextKey locToolTipKey,
|
||||
final I18nSupport i18nSupport) {
|
||||
|
||||
return label -> {
|
||||
if (locTextKey != null) {
|
||||
label.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
if (locToolTipKey != null) {
|
||||
label.setToolTipText(i18nSupport.getText(locToolTipKey));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static final Consumer<Group> groupFunction(
|
||||
final LocTextKey locTextKey,
|
||||
final LocTextKey locToolTipKey,
|
||||
final I18nSupport i18nSupport) {
|
||||
|
||||
return group -> {
|
||||
if (locTextKey != null) {
|
||||
group.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
if (locToolTipKey != null) {
|
||||
group.setToolTipText(i18nSupport.getText(locToolTipKey, StringUtils.EMPTY));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static final void updateLocale(final TabItem[] items, final I18nSupport i18nSupport) {
|
||||
if (items == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final TabItem childItem : items) {
|
||||
final LocTextKey locTextKey = (LocTextKey) childItem.getData(POLYGLOT_ITEM_TEXT_DATA_KEY);
|
||||
if (locTextKey != null) {
|
||||
childItem.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final void updateLocale(final TreeItem[] items, final I18nSupport i18nSupport) {
|
||||
if (items == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final TreeItem childItem : items) {
|
||||
final LocTextKey locTextKey = (LocTextKey) childItem.getData(POLYGLOT_ITEM_TEXT_DATA_KEY);
|
||||
if (locTextKey != null) {
|
||||
childItem.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
updateLocale(childItem.getItems(), i18nSupport);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLocale(final TableItem[] items, final I18nSupport i18nSupport) {
|
||||
if (items == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final TableItem childItem : items) {
|
||||
final LocTextKey[] locTextKey = (LocTextKey[]) childItem.getData(POLYGLOT_ITEM_TEXT_DATA_KEY);
|
||||
if (locTextKey != null) {
|
||||
for (int i = 0; i < locTextKey.length; i++) {
|
||||
if (locTextKey[i] != null) {
|
||||
childItem.setText(i, i18nSupport.getText(locTextKey[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLocale(final TableColumn[] columns, final I18nSupport i18nSupport) {
|
||||
if (columns == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final TableColumn childItem : columns) {
|
||||
final LocTextKey locTextKey = (LocTextKey) childItem.getData(POLYGLOT_ITEM_TEXT_DATA_KEY);
|
||||
if (locTextKey != null) {
|
||||
childItem.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ public class DefaultPageLayout implements TemplateComposer {
|
|||
langSupport.setLayout(rowLayout);
|
||||
|
||||
if (this.multilingual) {
|
||||
this.widgetFactory.createLanguageSelector(pageContext.copyOf(langSupport));
|
||||
this.polyglotPageService.createLanguageSelector(pageContext.copyOf(langSupport));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.ImageIcon;
|
|||
|
||||
public class GridTable extends Composite {
|
||||
|
||||
private static final long serialVersionUID = 8515260041931976458L;
|
||||
private static final Logger log = LoggerFactory.getLogger(GridTable.class);
|
||||
|
||||
public static final Set<AttributeType> SUPPORTED_TYPES = EnumSet.of(
|
||||
|
|
|
@ -43,6 +43,8 @@ public final class MultiSelectionCombo extends Composite implements Selection {
|
|||
|
||||
private final WidgetFactory widgetFactory;
|
||||
private final Combo combo;
|
||||
private final LocTextKey addTextKey;
|
||||
private final LocTextKey removeTextKey;
|
||||
|
||||
private final List<Tuple<Control>> selectionControls = new ArrayList<>();
|
||||
private final List<Tuple<String>> selectedValues = new ArrayList<>();
|
||||
|
@ -53,9 +55,20 @@ public final class MultiSelectionCombo extends Composite implements Selection {
|
|||
|
||||
private Listener listener = null;
|
||||
|
||||
MultiSelectionCombo(final Composite parent, final WidgetFactory widgetFactory) {
|
||||
MultiSelectionCombo(
|
||||
final Composite parent,
|
||||
final WidgetFactory widgetFactory,
|
||||
final String locTextPrefix) {
|
||||
|
||||
super(parent, SWT.NONE);
|
||||
this.widgetFactory = widgetFactory;
|
||||
this.addTextKey = (locTextPrefix != null)
|
||||
? new LocTextKey(locTextPrefix + ".add")
|
||||
: new LocTextKey("sebserver.overall.add");
|
||||
this.removeTextKey = (locTextPrefix != null)
|
||||
? new LocTextKey(locTextPrefix + ".remove")
|
||||
: new LocTextKey("sebserver.overall.remove");
|
||||
|
||||
final GridLayout gridLayout = new GridLayout(2, false);
|
||||
gridLayout.verticalSpacing = 1;
|
||||
gridLayout.marginLeft = 0;
|
||||
|
@ -73,7 +86,7 @@ public final class MultiSelectionCombo extends Composite implements Selection {
|
|||
final Label imageButton = widgetFactory.imageButton(
|
||||
ImageIcon.ADD_BOX,
|
||||
this,
|
||||
new LocTextKey("Add"),
|
||||
this.addTextKey,
|
||||
this::addComboSelection);
|
||||
this.actionCell = new GridData(SWT.LEFT, SWT.CENTER, true, false);
|
||||
this.actionCell.widthHint = ACTION_COLUMN_WIDTH;
|
||||
|
@ -176,7 +189,7 @@ public final class MultiSelectionCombo extends Composite implements Selection {
|
|||
final Label imageButton = this.widgetFactory.imageButton(
|
||||
ImageIcon.REMOVE_BOX,
|
||||
this,
|
||||
new LocTextKey("Remove"),
|
||||
this.removeTextKey,
|
||||
this::removeComboSelection);
|
||||
imageButton.setData(OPTION_VALUE, itemName);
|
||||
final GridData actionCell = new GridData(SWT.LEFT, SWT.CENTER, true, false);
|
||||
|
|
|
@ -8,16 +8,14 @@
|
|||
|
||||
package ch.ethz.seb.sebserver.gui.widget;
|
||||
|
||||
import static ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService.*;
|
||||
import static ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService.POLYGLOT_WIDGET_FUNCTION_KEY;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.rap.rwt.RWT;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Device;
|
||||
|
@ -34,7 +32,6 @@ 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.Text;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.swt.widgets.TreeItem;
|
||||
|
@ -50,7 +47,6 @@ import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
|
|||
import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport;
|
||||
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
|
||||
import ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService;
|
||||
import ch.ethz.seb.sebserver.gui.service.page.PageContext;
|
||||
import ch.ethz.seb.sebserver.gui.service.push.ServerPushService;
|
||||
|
||||
@Lazy
|
||||
|
@ -195,19 +191,19 @@ public class WidgetFactory {
|
|||
|
||||
public Button buttonLocalized(final Composite parent, final String locTextKey) {
|
||||
final Button button = new Button(parent, SWT.NONE);
|
||||
this.injectI18n(button, new LocTextKey(locTextKey));
|
||||
this.polyglotPageService.injectI18n(button, new LocTextKey(locTextKey));
|
||||
return button;
|
||||
}
|
||||
|
||||
public Button buttonLocalized(final Composite parent, final LocTextKey locTextKey) {
|
||||
final Button button = new Button(parent, SWT.NONE);
|
||||
this.injectI18n(button, locTextKey);
|
||||
this.polyglotPageService.injectI18n(button, locTextKey);
|
||||
return button;
|
||||
}
|
||||
|
||||
public Button buttonLocalized(final Composite parent, final CustomVariant variant, final String locTextKey) {
|
||||
final Button button = new Button(parent, SWT.NONE);
|
||||
this.injectI18n(button, new LocTextKey(locTextKey));
|
||||
this.polyglotPageService.injectI18n(button, new LocTextKey(locTextKey));
|
||||
button.setData(RWT.CUSTOM_VARIANT, variant.key);
|
||||
return button;
|
||||
}
|
||||
|
@ -219,7 +215,7 @@ public class WidgetFactory {
|
|||
final LocTextKey toolTipKey) {
|
||||
|
||||
final Button button = new Button(parent, type);
|
||||
this.injectI18n(button, locTextKey, toolTipKey);
|
||||
this.polyglotPageService.injectI18n(button, locTextKey, toolTipKey);
|
||||
return button;
|
||||
}
|
||||
|
||||
|
@ -231,19 +227,19 @@ public class WidgetFactory {
|
|||
|
||||
public Label labelLocalized(final Composite parent, final String locTextKey) {
|
||||
final Label label = new Label(parent, SWT.NONE);
|
||||
this.injectI18n(label, new LocTextKey(locTextKey));
|
||||
this.polyglotPageService.injectI18n(label, new LocTextKey(locTextKey));
|
||||
return label;
|
||||
}
|
||||
|
||||
public Label labelLocalized(final Composite parent, final LocTextKey locTextKey) {
|
||||
final Label label = new Label(parent, SWT.NONE);
|
||||
this.injectI18n(label, locTextKey);
|
||||
this.polyglotPageService.injectI18n(label, locTextKey);
|
||||
return label;
|
||||
}
|
||||
|
||||
public Label labelLocalized(final Composite parent, final CustomVariant variant, final LocTextKey locTextKey) {
|
||||
final Label label = new Label(parent, SWT.NONE);
|
||||
this.injectI18n(label, locTextKey);
|
||||
this.polyglotPageService.injectI18n(label, locTextKey);
|
||||
label.setData(RWT.CUSTOM_VARIANT, variant.key);
|
||||
return label;
|
||||
}
|
||||
|
@ -254,7 +250,7 @@ public class WidgetFactory {
|
|||
final LocTextKey locToolTextKey) {
|
||||
|
||||
final Label label = new Label(parent, SWT.NONE);
|
||||
this.injectI18n(label, locTextKey, locToolTextKey);
|
||||
this.polyglotPageService.injectI18n(label, locTextKey, locToolTextKey);
|
||||
return label;
|
||||
}
|
||||
|
||||
|
@ -265,7 +261,7 @@ public class WidgetFactory {
|
|||
final LocTextKey locToolTextKey) {
|
||||
|
||||
final Label label = new Label(parent, SWT.NONE);
|
||||
this.injectI18n(label, locTextKey, locToolTextKey);
|
||||
this.polyglotPageService.injectI18n(label, locTextKey, locToolTextKey);
|
||||
label.setData(RWT.CUSTOM_VARIANT, variant.key);
|
||||
return label;
|
||||
}
|
||||
|
@ -330,43 +326,43 @@ public class WidgetFactory {
|
|||
gridLayout.marginHeight = 0;
|
||||
group.setLayout(gridLayout);
|
||||
|
||||
this.injectI18n(group, locTextKey, locTooltipKey);
|
||||
this.polyglotPageService.injectI18n(group, locTextKey, locTooltipKey);
|
||||
return group;
|
||||
}
|
||||
|
||||
public Tree treeLocalized(final Composite parent, final int style) {
|
||||
final Tree tree = new Tree(parent, style);
|
||||
this.injectI18n(tree);
|
||||
this.polyglotPageService.injectI18n(tree);
|
||||
return tree;
|
||||
}
|
||||
|
||||
public TreeItem treeItemLocalized(final Tree parent, final String locTextKey) {
|
||||
final TreeItem item = new TreeItem(parent, SWT.NONE);
|
||||
this.injectI18n(item, new LocTextKey(locTextKey));
|
||||
this.polyglotPageService.injectI18n(item, new LocTextKey(locTextKey));
|
||||
return item;
|
||||
}
|
||||
|
||||
public TreeItem treeItemLocalized(final Tree parent, final LocTextKey locTextKey) {
|
||||
final TreeItem item = new TreeItem(parent, SWT.NONE);
|
||||
this.injectI18n(item, locTextKey);
|
||||
this.polyglotPageService.injectI18n(item, locTextKey);
|
||||
return item;
|
||||
}
|
||||
|
||||
public TreeItem treeItemLocalized(final TreeItem parent, final String locTextKey) {
|
||||
final TreeItem item = new TreeItem(parent, SWT.NONE);
|
||||
this.injectI18n(item, new LocTextKey(locTextKey));
|
||||
this.polyglotPageService.injectI18n(item, new LocTextKey(locTextKey));
|
||||
return item;
|
||||
}
|
||||
|
||||
public TreeItem treeItemLocalized(final TreeItem parent, final LocTextKey locTextKey) {
|
||||
final TreeItem item = new TreeItem(parent, SWT.NONE);
|
||||
this.injectI18n(item, locTextKey);
|
||||
this.polyglotPageService.injectI18n(item, locTextKey);
|
||||
return item;
|
||||
}
|
||||
|
||||
public Table tableLocalized(final Composite parent) {
|
||||
final Table table = new Table(parent, SWT.SINGLE | SWT.NO_SCROLL);
|
||||
this.injectI18n(table);
|
||||
this.polyglotPageService.injectI18n(table);
|
||||
return table;
|
||||
}
|
||||
|
||||
|
@ -376,13 +372,13 @@ public class WidgetFactory {
|
|||
final LocTextKey toolTipKey) {
|
||||
|
||||
final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
|
||||
this.injectI18n(tableColumn, locTextKey, toolTipKey);
|
||||
this.polyglotPageService.injectI18n(tableColumn, locTextKey, toolTipKey);
|
||||
return tableColumn;
|
||||
}
|
||||
|
||||
public TabFolder tabFolderLocalized(final Composite parent) {
|
||||
final TabFolder tabs = new TabFolder(parent, SWT.NONE);
|
||||
this.injectI18n(tabs);
|
||||
this.polyglotPageService.injectI18n(tabs);
|
||||
return tabs;
|
||||
}
|
||||
|
||||
|
@ -399,7 +395,7 @@ public class WidgetFactory {
|
|||
final LocTextKey toolTipKey) {
|
||||
|
||||
final TabItem tabItem = new TabItem(parent, SWT.NONE);
|
||||
this.injectI18n(tabItem, locTextKey, toolTipKey);
|
||||
this.polyglotPageService.injectI18n(tabItem, locTextKey, toolTipKey);
|
||||
return tabItem;
|
||||
}
|
||||
|
||||
|
@ -449,6 +445,17 @@ public class WidgetFactory {
|
|||
final LocTextKey toolTipTextKey,
|
||||
final Supplier<List<Tuple<String>>> itemsToolTipSupplier) {
|
||||
|
||||
return selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, itemsToolTipSupplier, null);
|
||||
}
|
||||
|
||||
public Selection selectionLocalized(
|
||||
final Selection.Type type,
|
||||
final Composite parent,
|
||||
final Supplier<List<Tuple<String>>> itemsSupplier,
|
||||
final LocTextKey toolTipTextKey,
|
||||
final Supplier<List<Tuple<String>>> itemsToolTipSupplier,
|
||||
final String actionLocTextPrefix) {
|
||||
|
||||
final Selection selection;
|
||||
switch (type) {
|
||||
case SINGLE:
|
||||
|
@ -464,7 +471,7 @@ public class WidgetFactory {
|
|||
selection = new MultiSelection(parent);
|
||||
break;
|
||||
case MULTI_COMBO:
|
||||
selection = new MultiSelectionCombo(parent, this);
|
||||
selection = new MultiSelectionCombo(parent, this, actionLocTextPrefix);
|
||||
break;
|
||||
case MULTI_CHECKBOX:
|
||||
selection = new MultiSelectionCheckbox(parent);
|
||||
|
@ -511,228 +518,8 @@ public class WidgetFactory {
|
|||
final boolean readonly) {
|
||||
|
||||
final ImageUpload imageUpload = new ImageUpload(parent, this.serverPushService, readonly);
|
||||
injectI18n(imageUpload, locTextKey);
|
||||
this.polyglotPageService.injectI18n(imageUpload, locTextKey);
|
||||
return imageUpload;
|
||||
}
|
||||
|
||||
// ************************************************************
|
||||
// TODO code from below should move to PolyglotPageService or a utility of that
|
||||
|
||||
public void injectI18n(final ImageUpload imageUpload, final LocTextKey locTextKey) {
|
||||
final Consumer<ImageUpload> imageUploadFunction = iu -> {
|
||||
if (locTextKey != null) {
|
||||
iu.setSelectionText(this.i18nSupport.getText(locTextKey));
|
||||
}
|
||||
};
|
||||
imageUpload.setData(POLYGLOT_WIDGET_FUNCTION_KEY, imageUploadFunction);
|
||||
imageUploadFunction.accept(imageUpload);
|
||||
}
|
||||
|
||||
public void injectI18n(final Label label, final LocTextKey locTextKey) {
|
||||
injectI18n(label, locTextKey, null);
|
||||
}
|
||||
|
||||
public void injectI18n(final Label label, final LocTextKey locTextKey, final LocTextKey locToolTipKey) {
|
||||
final Consumer<Label> labelFunction = labelFunction(locTextKey, locToolTipKey, this.i18nSupport);
|
||||
label.setData(POLYGLOT_WIDGET_FUNCTION_KEY, labelFunction);
|
||||
labelFunction.accept(label);
|
||||
}
|
||||
|
||||
public void injectI18n(final Group group, final LocTextKey locTextKey, final LocTextKey locTooltipKey) {
|
||||
final Consumer<Group> groupFunction = groupFunction(locTextKey, locTooltipKey, this.i18nSupport);
|
||||
group.setData(POLYGLOT_WIDGET_FUNCTION_KEY, groupFunction);
|
||||
groupFunction.accept(group);
|
||||
}
|
||||
|
||||
public void injectI18n(final Button button, final LocTextKey locTextKey) {
|
||||
injectI18n(button, locTextKey, null);
|
||||
}
|
||||
|
||||
public void injectI18n(final Button button, final LocTextKey locTextKey, final LocTextKey locToolTipKey) {
|
||||
final Consumer<Button> buttonFunction = b -> {
|
||||
if (locTextKey != null) {
|
||||
b.setText(this.i18nSupport.getText(locTextKey));
|
||||
}
|
||||
if (locToolTipKey != null) {
|
||||
b.setToolTipText(this.i18nSupport.getText(locToolTipKey));
|
||||
}
|
||||
};
|
||||
button.setData(POLYGLOT_WIDGET_FUNCTION_KEY, buttonFunction);
|
||||
buttonFunction.accept(button);
|
||||
}
|
||||
|
||||
public void injectI18n(final Tree tree) {
|
||||
tree.setData(
|
||||
POLYGLOT_WIDGET_FUNCTION_KEY,
|
||||
(Consumer<Tree>) t -> updateLocale(t.getItems(), this.i18nSupport));
|
||||
}
|
||||
|
||||
public void injectI18n(final TreeItem treeItem, final LocTextKey locTextKey) {
|
||||
treeItem.setData(POLYGLOT_ITEM_TEXT_DATA_KEY, locTextKey);
|
||||
treeItem.setText(this.i18nSupport.getText(locTextKey));
|
||||
}
|
||||
|
||||
public void injectI18n(final Table table) {
|
||||
table.setData(
|
||||
POLYGLOT_WIDGET_FUNCTION_KEY,
|
||||
(Consumer<Table>) t -> {
|
||||
updateLocale(t.getColumns(), this.i18nSupport);
|
||||
updateLocale(t.getItems(), this.i18nSupport);
|
||||
});
|
||||
}
|
||||
|
||||
public void injectI18n(final TabFolder tabFolder) {
|
||||
tabFolder.setData(
|
||||
POLYGLOT_WIDGET_FUNCTION_KEY,
|
||||
(Consumer<TabFolder>) t -> updateLocale(t.getItems(), this.i18nSupport));
|
||||
}
|
||||
|
||||
public void injectI18n(final TableColumn tableColumn, final LocTextKey locTextKey, final LocTextKey locTooltipKey) {
|
||||
tableColumn.setData(POLYGLOT_ITEM_TEXT_DATA_KEY, locTextKey);
|
||||
tableColumn.setText(this.i18nSupport.getText(locTextKey));
|
||||
|
||||
if (locTooltipKey != null) {
|
||||
tableColumn.setData(POLYGLOT_ITEM_TOOLTIP_DATA_KEY, locTooltipKey);
|
||||
tableColumn.setToolTipText(this.i18nSupport.getText(locTooltipKey));
|
||||
}
|
||||
}
|
||||
|
||||
public void injectI18n(final TableItem tableItem, final LocTextKey... locTextKey) {
|
||||
if (locTextKey == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
tableItem.setData(POLYGLOT_ITEM_TEXT_DATA_KEY, locTextKey);
|
||||
for (int i = 0; i < locTextKey.length; i++) {
|
||||
tableItem.setText(i, this.i18nSupport.getText(locTextKey[i]));
|
||||
}
|
||||
}
|
||||
|
||||
private void injectI18n(final TabItem tabItem, final LocTextKey locTextKey, final LocTextKey locTooltipKey) {
|
||||
tabItem.setData(POLYGLOT_ITEM_TEXT_DATA_KEY, locTextKey);
|
||||
tabItem.setText(this.i18nSupport.getText(locTextKey));
|
||||
|
||||
if (locTooltipKey != null) {
|
||||
tabItem.setData(POLYGLOT_ITEM_TOOLTIP_DATA_KEY, locTooltipKey);
|
||||
tabItem.setToolTipText(this.i18nSupport.getText(locTooltipKey));
|
||||
}
|
||||
}
|
||||
|
||||
public void createLanguageSelector(final PageContext composerCtx) {
|
||||
for (final Locale locale : this.i18nSupport.supportedLanguages()) {
|
||||
final Label languageSelection = new Label(composerCtx.getParent(), SWT.NONE);
|
||||
languageSelection.setData(
|
||||
POLYGLOT_WIDGET_FUNCTION_KEY,
|
||||
(Consumer<Label>) label -> label.setVisible(
|
||||
!this.i18nSupport.getCurrentLocale()
|
||||
.getLanguage()
|
||||
.equals(locale.getLanguage())));
|
||||
languageSelection.setData(RWT.CUSTOM_VARIANT, "header");
|
||||
languageSelection.setText("| " + locale.getLanguage().toUpperCase());
|
||||
//languageSelection.updateLocale(this.i18nSupport);
|
||||
languageSelection.addListener(SWT.MouseDown, event -> {
|
||||
this.polyglotPageService.setPageLocale(composerCtx.getRoot(), locale);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static final Consumer<Label> labelFunction(
|
||||
final LocTextKey locTextKey,
|
||||
final LocTextKey locToolTipKey,
|
||||
final I18nSupport i18nSupport) {
|
||||
|
||||
return label -> {
|
||||
if (locTextKey != null) {
|
||||
label.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
if (locToolTipKey != null) {
|
||||
label.setToolTipText(i18nSupport.getText(locToolTipKey));
|
||||
// TODO managing a tool-tip delay is not working as expected
|
||||
// is there another way to achieve this?
|
||||
// label.addListener(SWT.MouseEnter, event -> {
|
||||
// System.out.println("*************** set tooltip delay");
|
||||
// label.getDisplay().timerExec(1000, () -> {
|
||||
// System.out.println("*************** set tooltip");
|
||||
// label.setToolTipText(i18nSupport.getText(locToolTipKey));
|
||||
// });
|
||||
// });
|
||||
// label.addListener(SWT.MouseExit, event -> {
|
||||
// label.setToolTipText(null);
|
||||
// });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static final Consumer<Group> groupFunction(
|
||||
final LocTextKey locTextKey,
|
||||
final LocTextKey locToolTipKey,
|
||||
final I18nSupport i18nSupport) {
|
||||
|
||||
return group -> {
|
||||
if (locTextKey != null) {
|
||||
group.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
if (locToolTipKey != null) {
|
||||
group.setToolTipText(i18nSupport.getText(locToolTipKey, StringUtils.EMPTY));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static final void updateLocale(final TabItem[] items, final I18nSupport i18nSupport) {
|
||||
if (items == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final TabItem childItem : items) {
|
||||
final LocTextKey locTextKey = (LocTextKey) childItem.getData(POLYGLOT_ITEM_TEXT_DATA_KEY);
|
||||
if (locTextKey != null) {
|
||||
childItem.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final void updateLocale(final TreeItem[] items, final I18nSupport i18nSupport) {
|
||||
if (items == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final TreeItem childItem : items) {
|
||||
final LocTextKey locTextKey = (LocTextKey) childItem.getData(POLYGLOT_ITEM_TEXT_DATA_KEY);
|
||||
if (locTextKey != null) {
|
||||
childItem.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
updateLocale(childItem.getItems(), i18nSupport);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLocale(final TableItem[] items, final I18nSupport i18nSupport) {
|
||||
if (items == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final TableItem childItem : items) {
|
||||
final LocTextKey[] locTextKey = (LocTextKey[]) childItem.getData(POLYGLOT_ITEM_TEXT_DATA_KEY);
|
||||
if (locTextKey != null) {
|
||||
for (int i = 0; i < locTextKey.length; i++) {
|
||||
if (locTextKey[i] != null) {
|
||||
childItem.setText(i, i18nSupport.getText(locTextKey[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLocale(final TableColumn[] columns, final I18nSupport i18nSupport) {
|
||||
if (columns == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final TableColumn childItem : columns) {
|
||||
final LocTextKey locTextKey = (LocTextKey) childItem.getData(POLYGLOT_ITEM_TEXT_DATA_KEY);
|
||||
if (locTextKey != null) {
|
||||
childItem.setText(i18nSupport.getText(locTextKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ sebserver.overall.action.category.varia=Varia
|
|||
sebserver.overall.status.active=Active
|
||||
sebserver.overall.status.inactive=Inactive
|
||||
|
||||
sebserver.overall.action.add=Add;
|
||||
sebserver.overall.action.remove=Remove
|
||||
|
||||
################################
|
||||
# Form validation and messages
|
||||
################################
|
||||
|
|
Loading…
Reference in a new issue