code cleanup

This commit is contained in:
anhefti 2020-02-20 16:21:21 +01:00
parent 69772b2310
commit fd75881cac
11 changed files with 57 additions and 80 deletions

View file

@ -10,8 +10,6 @@ package ch.ethz.seb.sebserver.gui.content;
import java.util.Collection; import java.util.Collection;
import ch.ethz.seb.sebserver.gbl.model.session.ExtendedClientEvent;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.logs.GetExtendedClientEventPage;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -27,6 +25,7 @@ import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus;
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData;
import ch.ethz.seb.sebserver.gbl.model.session.ClientEvent; import ch.ethz.seb.sebserver.gbl.model.session.ClientEvent;
import ch.ethz.seb.sebserver.gbl.model.session.ExtendedClientEvent;
import ch.ethz.seb.sebserver.gbl.model.user.UserRole; import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gbl.util.Utils;
@ -43,8 +42,8 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExam; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExam;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetIndicators; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetIndicators;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.logs.GetExtendedClientEventPage;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetClientConnectionData; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetClientConnectionData;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetClientEventPage;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser;
import ch.ethz.seb.sebserver.gui.service.session.ClientConnectionDetails; import ch.ethz.seb.sebserver.gui.service.session.ClientConnectionDetails;
import ch.ethz.seb.sebserver.gui.service.session.InstructionProcessor; import ch.ethz.seb.sebserver.gui.service.session.InstructionProcessor;
@ -173,13 +172,12 @@ public class MonitoringClientConnection implements TemplateComposer {
CustomVariant.TEXT_H3, CustomVariant.TEXT_H3,
EVENT_LIST_TITLE_KEY); EVENT_LIST_TITLE_KEY);
PageService.PageActionBuilder actionBuilder = this.pageService final PageService.PageActionBuilder actionBuilder = this.pageService
.pageActionBuilder( .pageActionBuilder(
pageContext pageContext
.clearAttributes() .clearAttributes()
.clearEntityKeys()); .clearEntityKeys());
// client event table for this connection // client event table for this connection
this.pageService.entityTableBuilder(restService.getRestCall(GetExtendedClientEventPage.class)) this.pageService.entityTableBuilder(restService.getRestCall(GetExtendedClientEventPage.class))
.withEmptyMessage(EMPTY_LIST_TEXT_KEY) .withEmptyMessage(EMPTY_LIST_TEXT_KEY)
@ -229,13 +227,13 @@ public class MonitoringClientConnection implements TemplateComposer {
.withDefaultAction(t -> actionBuilder .withDefaultAction(t -> actionBuilder
.newAction(ActionDefinition.LOGS_SEB_CLIENT_SHOW_DETAILS) .newAction(ActionDefinition.LOGS_SEB_CLIENT_SHOW_DETAILS)
.withExec(action -> sebClientLogDetailsPopup.showDetails(action, t.getSingleSelectedROWData())) .withExec(action -> this.sebClientLogDetailsPopup.showDetails(action,
t.getSingleSelectedROWData()))
.noEventPropagation() .noEventPropagation()
.create()) .create())
.compose(pageContext.copyOf(content)); .compose(pageContext.copyOf(content));
actionBuilder actionBuilder
.newAction(ActionDefinition.MONITOR_EXAM_BACK_TO_OVERVIEW) .newAction(ActionDefinition.MONITOR_EXAM_BACK_TO_OVERVIEW)
.withEntityKey(parentEntityKey) .withEntityKey(parentEntityKey)

View file

@ -8,7 +8,6 @@
package ch.ethz.seb.sebserver.gui.content; package ch.ethz.seb.sebserver.gui.content;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -19,7 +18,6 @@ import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.client.service.UrlLauncher; import org.eclipse.rap.rwt.client.service.UrlLauncher;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -209,7 +207,6 @@ public class SebExamConfigPropForm implements TemplateComposer {
? this.restService.getRestCall(NewExamConfig.class) ? this.restService.getRestCall(NewExamConfig.class)
: this.restService.getRestCall(SaveExamConfig.class)); : this.restService.getRestCall(SaveExamConfig.class));
final boolean settingsReadonly = examConfig.status == ConfigurationStatus.IN_USE;
final UrlLauncher urlLauncher = RWT.getClient().getService(UrlLauncher.class); final UrlLauncher urlLauncher = RWT.getClient().getService(UrlLauncher.class);
final PageContext actionContext = formContext.clearEntityKeys(); final PageContext actionContext = formContext.clearEntityKeys();
final PageActionBuilder actionBuilder = this.pageService.pageActionBuilder(actionContext); final PageActionBuilder actionBuilder = this.pageService.pageActionBuilder(actionContext);
@ -350,7 +347,8 @@ public class SebExamConfigPropForm implements TemplateComposer {
.newAction(ActionDefinition.EXAM_VIEW_FROM_LIST) .newAction(ActionDefinition.EXAM_VIEW_FROM_LIST)
.withSelectionSupplier(() -> { .withSelectionSupplier(() -> {
final ExamConfigurationMap selectedROWData = getSelectedExamMapping(table); final ExamConfigurationMap selectedROWData = getSelectedExamMapping(table);
return new HashSet<>(Collections.singletonList(new EntityKey(selectedROWData.examId, EntityType.EXAM))); return new HashSet<>(
Collections.singletonList(new EntityKey(selectedROWData.examId, EntityType.EXAM)));
}) })
.withExec(PageAction::applySingleSelectionAsEntityKey) .withExec(PageAction::applySingleSelectionAsEntityKey)
.create(); .create();

View file

@ -10,7 +10,6 @@ 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;
@ -21,6 +20,7 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
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.WidgetFactory; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory;
import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.CustomVariant; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.CustomVariant;
@ -132,7 +132,7 @@ public abstract class FieldBuilder<T> {
final boolean hasTooltip = (fieldBuilder.tooltip != null && final boolean hasTooltip = (fieldBuilder.tooltip != null &&
StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltip, ""))); StringUtils.isNotBlank(builder.i18nSupport.getText(fieldBuilder.tooltip, "")));
final Label label = labelLocalized( labelLocalized(
builder.widgetFactory, builder.widgetFactory,
infoGrid, infoGrid,
fieldBuilder.label, fieldBuilder.label,
@ -149,16 +149,6 @@ public abstract class FieldBuilder<T> {
info.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); 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,

View file

@ -12,10 +12,8 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import ch.ethz.seb.sebserver.gbl.util.Cryptor;
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;
@ -27,6 +25,7 @@ import org.slf4j.LoggerFactory;
import ch.ethz.seb.sebserver.gbl.model.Entity; import ch.ethz.seb.sebserver.gbl.model.Entity;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.util.Cryptor;
import ch.ethz.seb.sebserver.gbl.util.Tuple; import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport; 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.LocTextKey;

View file

@ -8,6 +8,16 @@
package ch.ethz.seb.sebserver.gui.service.examconfig.impl; package ch.ethz.seb.sebserver.gui.service.examconfig.impl;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType; import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
@ -20,25 +30,12 @@ import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.widget.PasswordInput; import ch.ethz.seb.sebserver.gui.widget.PasswordInput;
import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory;
import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.CustomVariant; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.CustomVariant;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Lazy @Lazy
@Component @Component
@GuiProfile @GuiProfile
public class PasswordFieldBuilder implements InputFieldBuilder { public class PasswordFieldBuilder implements InputFieldBuilder {
private static final Logger log = LoggerFactory.getLogger(PasswordFieldBuilder.class);
private static final LocTextKey VAL_CONFIRM_PWD_TEXT_KEY = private static final LocTextKey VAL_CONFIRM_PWD_TEXT_KEY =
new LocTextKey("sebserver.examconfig.props.validation.password.confirm"); new LocTextKey("sebserver.examconfig.props.validation.password.confirm");
@ -76,11 +73,11 @@ public class PasswordFieldBuilder implements InputFieldBuilder {
final Composite innerGrid = InputFieldBuilder final Composite innerGrid = InputFieldBuilder
.createInnerGrid(parent, attribute, orientation); .createInnerGrid(parent, attribute, orientation);
final PasswordInput passwordInput = new PasswordInput(innerGrid, widgetFactory); final PasswordInput passwordInput = new PasswordInput(innerGrid, this.widgetFactory);
final GridData passwordInputLD = new GridData(SWT.FILL, SWT.FILL, true, true); final GridData passwordInputLD = new GridData(SWT.FILL, SWT.FILL, true, true);
passwordInput.setLayoutData(passwordInputLD); passwordInput.setLayoutData(passwordInputLD);
final PasswordInput confirmInput = new PasswordInput(innerGrid, widgetFactory); final PasswordInput confirmInput = new PasswordInput(innerGrid, this.widgetFactory);
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.verticalIndent = 14; gridData.verticalIndent = 14;
confirmInput.setLayoutData(gridData); confirmInput.setLayoutData(gridData);
@ -92,7 +89,7 @@ public class PasswordFieldBuilder implements InputFieldBuilder {
passwordInput, passwordInput,
confirmInput, confirmInput,
FieldBuilder.createErrorLabel(innerGrid), FieldBuilder.createErrorLabel(innerGrid),
cryptor); this.cryptor);
if (viewContext.readonly) { if (viewContext.readonly) {
passwordInput.setEditable(false); passwordInput.setEditable(false);
@ -157,7 +154,7 @@ public class PasswordFieldBuilder implements InputFieldBuilder {
@Override @Override
protected void setValueToControl(final String value) { protected void setValueToControl(final String value) {
if (StringUtils.isNotBlank(value)) { if (StringUtils.isNotBlank(value)) {
CharSequence pwd = cryptor.decrypt(value); final CharSequence pwd = this.cryptor.decrypt(value);
this.control.setValue(pwd.toString()); this.control.setValue(pwd.toString());
this.confirm.setValue(pwd.toString()); this.confirm.setValue(pwd.toString());
} else { } else {
@ -170,7 +167,7 @@ public class PasswordFieldBuilder implements InputFieldBuilder {
public String getValue() { public String getValue() {
final CharSequence pwd = this.control.getValue(); final CharSequence pwd = this.control.getValue();
if (StringUtils.isNotBlank(pwd)) { if (StringUtils.isNotBlank(pwd)) {
return cryptor.encrypt(pwd).toString(); return this.cryptor.encrypt(pwd).toString();
} }
return StringUtils.EMPTY; return StringUtils.EMPTY;

View file

@ -11,7 +11,6 @@ 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;
@ -180,8 +179,7 @@ public interface I18nSupport {
/** Indicates if there is a localized text defined for a specified LocTextKey /** Indicates if there is a localized text defined for a specified LocTextKey
* *
* @param locTextKey the LocTextKey instance * @param locTextKey the LocTextKey instance
* @return true if there is a localized text defined for a specified LocTextKey, false otherwise * @return true if there is a localized text defined for a specified LocTextKey, false otherwise */
*/
boolean hasText(LocTextKey locTextKey); boolean hasText(LocTextKey locTextKey);
} }

View file

@ -31,7 +31,6 @@ import ch.ethz.seb.sebserver.gui.service.ResourceService;
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.PageContext; 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.PageService;
import ch.ethz.seb.sebserver.gui.service.push.ServerPushContext;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall;
import ch.ethz.seb.sebserver.gui.service.session.IndicatorData.ThresholdColor; import ch.ethz.seb.sebserver.gui.service.session.IndicatorData.ThresholdColor;

View file

@ -26,7 +26,6 @@ import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.tomcat.util.bcel.Const;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
@ -160,11 +159,10 @@ public final class ClientConnectionTable {
CONNECTION_STATUS_TEXT_KEY, CONNECTION_STATUS_TEXT_KEY,
CONNECTION_STATUS_TOOLTIP_TEXT_KEY); CONNECTION_STATUS_TOOLTIP_TEXT_KEY);
for (final Indicator indDef : indicators) { for (final Indicator indDef : indicators) {
TableColumn tableColumn = widgetFactory.tableColumnLocalized( final TableColumn tableColumn = this.widgetFactory.tableColumnLocalized(
this.table, this.table,
new LocTextKey(INDICATOR_NAME_TEXT_KEY_PREFIX + indDef.name), new LocTextKey(INDICATOR_NAME_TEXT_KEY_PREFIX + indDef.name),
new LocTextKey(INDICATOR_NAME_TEXT_KEY_PREFIX + indDef.type.name) new LocTextKey(INDICATOR_NAME_TEXT_KEY_PREFIX + indDef.type.name));
);
tableColumn.setText(indDef.name); tableColumn.setText(indDef.name);
} }
@ -256,7 +254,7 @@ public final class ClientConnectionTable {
} }
} }
public ClientConnectionTable withSelectionListener(Consumer<Set<EntityKey>> selectionListener) { public ClientConnectionTable withSelectionListener(final Consumer<Set<EntityKey>> selectionListener) {
this.selectionListener = selectionListener; this.selectionListener = selectionListener;
return this; return this;
} }

View file

@ -14,8 +14,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import ch.ethz.seb.sebserver.gbl.util.Tuple3;
import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport;
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;
@ -26,6 +24,7 @@ import org.eclipse.swt.widgets.Listener;
import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.util.Tuple; import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gbl.util.Tuple3;
import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.PageService;
@ -72,7 +71,8 @@ public final class MultiSelectionCheckbox extends Composite implements Selection
}); });
this.checkboxes.put(tuple._1, button); this.checkboxes.put(tuple._1, button);
Tuple3<String> tuple3 = tuple.adaptTo(Tuple3.class); @SuppressWarnings("unchecked")
final Tuple3<String> tuple3 = tuple.adaptTo(Tuple3.class);
if (tuple3 != null && StringUtils.isNotBlank(tuple3._3)) { if (tuple3 != null && StringUtils.isNotBlank(tuple3._3)) {
button.setToolTipText(tuple3._3); button.setToolTipText(tuple3._3);
} }

View file

@ -8,9 +8,6 @@
package ch.ethz.seb.sebserver.gui.widget; package ch.ethz.seb.sebserver.gui.widget;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
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;
@ -21,12 +18,17 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
public class PasswordInput extends Composite { public class PasswordInput extends Composite {
private static final long serialVersionUID = 2228580383280478542L;
public static final LocTextKey PLAIN_TEXT_VIEW_TOOLTIP_KEY = public static final LocTextKey PLAIN_TEXT_VIEW_TOOLTIP_KEY =
new LocTextKey("sebserver.overall.action.showPassword.tooltip"); new LocTextKey("sebserver.overall.action.showPassword.tooltip");
private final Composite inputAnchor; private final Composite inputAnchor;
private final Label visibilityButton; private final Label visibilityButton;
@ -45,24 +47,24 @@ public class PasswordInput extends Composite {
this.setLayout(gridLayout); this.setLayout(gridLayout);
this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
inputAnchor = new Composite(this, SWT.NONE); this.inputAnchor = new Composite(this, SWT.NONE);
gridLayout = new GridLayout(1, false); gridLayout = new GridLayout(1, false);
gridLayout.horizontalSpacing = 0; gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0; gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = 0; gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0; gridLayout.marginWidth = 0;
inputAnchor.setLayout(gridLayout); this.inputAnchor.setLayout(gridLayout);
inputAnchor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); this.inputAnchor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
visibilityButton = widgetFactory.imageButton( this.visibilityButton = widgetFactory.imageButton(
WidgetFactory.ImageIcon.VISIBILITY, WidgetFactory.ImageIcon.VISIBILITY,
this, this,
PLAIN_TEXT_VIEW_TOOLTIP_KEY, PLAIN_TEXT_VIEW_TOOLTIP_KEY,
event -> changePasswordView()); event -> changePasswordView());
GridData ld = new GridData(SWT.RIGHT, SWT.BOTTOM, false, false); final GridData ld = new GridData(SWT.RIGHT, SWT.BOTTOM, false, false);
ld.heightHint = 22; ld.heightHint = 22;
ld.horizontalIndent = 5; ld.horizontalIndent = 5;
visibilityButton.setLayoutData(ld); this.visibilityButton.setLayoutData(ld);
changePasswordView(); changePasswordView();
@ -76,18 +78,18 @@ public class PasswordInput extends Composite {
PageService.clearComposite(this.inputAnchor); PageService.clearComposite(this.inputAnchor);
} }
Text passwordInput = new Text( final Text passwordInput = new Text(
inputAnchor, this.inputAnchor,
SWT.LEFT | SWT.BORDER | (buildPassword ? SWT.PASSWORD : SWT.NONE)); SWT.LEFT | SWT.BORDER | (buildPassword ? SWT.PASSWORD : SWT.NONE));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
passwordInput.setLayoutData(gridData); passwordInput.setLayoutData(gridData);
passwordInput.setText(value != null ? value : StringUtils.EMPTY); passwordInput.setText(value != null ? value : StringUtils.EMPTY);
if (!buildPassword) { if (!buildPassword) {
passwordInput.setEditable(false); passwordInput.setEditable(false);
} else { } else {
passwordInput.setEditable(isEditable); passwordInput.setEditable(this.isEditable);
passwordInput.setData(RWT.CUSTOM_VARIANT, WidgetFactory.CustomVariant.CONFIG_INPUT_READONLY.key); passwordInput.setData(RWT.CUSTOM_VARIANT, WidgetFactory.CustomVariant.CONFIG_INPUT_READONLY.key);
if (!isEditable) { if (!this.isEditable) {
gridData.heightHint = 21; gridData.heightHint = 21;
} }
} }
@ -107,19 +109,19 @@ public class PasswordInput extends Composite {
super.layout(true, true); super.layout(true, true);
} }
private void changeEvent(int eventType, Event event) { private void changeEvent(final int eventType, final Event event) {
if (!this.visibilityButton.isEnabled() && !StringUtils.endsWith( if (!this.visibilityButton.isEnabled() && !StringUtils.endsWith(
this.passwordInput.getText(), this.passwordInput.getText(),
Constants.IMPORTED_PASSWORD_MARKER)) { Constants.IMPORTED_PASSWORD_MARKER)) {
visibilityButton.setEnabled(true); this.visibilityButton.setEnabled(true);
} }
super.notifyListeners(eventType, event); super.notifyListeners(eventType, event);
} }
public void setValue(CharSequence value) { public void setValue(final CharSequence value) {
if (passwordInput != null) { if (this.passwordInput != null) {
passwordInput.setText(value != null ? value.toString() : StringUtils.EMPTY); this.passwordInput.setText(value != null ? value.toString() : StringUtils.EMPTY);
if (StringUtils.endsWith(value, Constants.IMPORTED_PASSWORD_MARKER)) { if (StringUtils.endsWith(value, Constants.IMPORTED_PASSWORD_MARKER)) {
this.visibilityButton.setEnabled(false); this.visibilityButton.setEnabled(false);
} }
@ -127,15 +129,14 @@ public class PasswordInput extends Composite {
} }
public CharSequence getValue() { public CharSequence getValue() {
if (passwordInput != null) { if (this.passwordInput != null) {
return passwordInput.getText(); return this.passwordInput.getText();
} }
return null; return null;
} }
public void setEditable(final boolean editable) {
public void setEditable(boolean editable) {
this.isEditable = editable; this.isEditable = editable;
this.isPlainText = !this.isPlainText; this.isPlainText = !this.isPlainText;
this.changePasswordView(); this.changePasswordView();

View file

@ -10,7 +10,6 @@ package ch.ethz.seb.sebserver.webservice.weblayer;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource; import javax.sql.DataSource;