scrolling first time working but need to cleanup

This commit is contained in:
anhefti 2019-05-24 08:07:52 +02:00
parent eaf34ebeed
commit d717412c89
11 changed files with 679 additions and 32 deletions

View file

@ -135,9 +135,7 @@ public class SebClientConfigList implements TemplateComposer {
.withColumn(new ColumnDefinition<>(
Domain.SEB_CLIENT_CONFIGURATION.ATTR_ACTIVE,
ACTIVE_TEXT_KEY,
entity -> this.pageService
.getResourceService()
.localizedActivityResource().apply(entity.active),
entity -> entity.active,
true))
.withDefaultAction(pageActionBuilder
.newAction(ActionDefinition.SEB_CLIENT_CONFIG_VIEW_FROM_LIST)

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
*
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
@ -8,10 +8,119 @@
package ch.ethz.seb.sebserver.gui.service.examconfig.impl;
public class InlineTableFieldBuilder {
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public InlineTableFieldBuilder() {
// TODO Auto-generated constructor stub
import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.widgets.Composite;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gui.service.examconfig.ExamConfigurationService;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputField;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputFieldBuilder;
import ch.ethz.seb.sebserver.gui.widget.GridTable;
import ch.ethz.seb.sebserver.gui.widget.GridTable.ColumnDef;
import ch.ethz.seb.sebserver.gui.widget.WidgetFactory;
@Lazy
@Component
@GuiProfile
public class InlineTableFieldBuilder implements InputFieldBuilder {
private final WidgetFactory widgetFactory;
protected InlineTableFieldBuilder(final WidgetFactory widgetFactory) {
this.widgetFactory = widgetFactory;
}
@Override
public boolean builderFor(
final ConfigurationAttribute attribute,
final Orientation orientation) {
return attribute != null && attribute.type == AttributeType.INLINE_TABLE;
}
@Override
public InputField createInputField(
final Composite parent,
final ConfigurationAttribute attribute,
final ViewContext viewContext) {
final Orientation orientation = viewContext
.getOrientation(attribute.id);
final Composite innerGrid = InputFieldBuilder
.createInnerGrid(parent, attribute, orientation);
final Map<String, String> defaultValues = StringUtils.isBlank(attribute.defaultValue)
? Collections.emptyMap()
: Arrays.asList(StringUtils.split(
attribute.defaultValue,
Constants.EMBEDDED_LIST_SEPARATOR))
.stream()
.map(valueString -> StringUtils.split(
valueString,
Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR))
.collect(Collectors.toMap(
valueMap -> valueMap[0],
valueMap -> (valueMap.length > 1) ? valueMap[1] : ""));
final List<ColumnDef> columns = Arrays.asList(StringUtils.split(
attribute.getResources(),
Constants.EMBEDDED_LIST_SEPARATOR))
.stream()
.map(columnString -> ColumnDef.fromString(columnString, defaultValues))
.collect(Collectors.toList());
final GridTable gridTable = new GridTable(
innerGrid,
columns,
ExamConfigurationService.ATTRIBUTE_LABEL_LOC_TEXT_PREFIX,
this.widgetFactory);
final InlineTableInputField inlineTableInputField = new InlineTableInputField(
attribute,
viewContext.getOrientation(attribute.id),
gridTable);
gridTable.setListener(event -> viewContext.getValueChangeListener().valueChanged(
viewContext,
attribute,
inlineTableInputField.getValue(),
inlineTableInputField.listIndex));
return inlineTableInputField;
}
static final class InlineTableInputField extends AbstractInputField<GridTable> {
protected InlineTableInputField(
final ConfigurationAttribute attribute,
final Orientation orientation,
final GridTable control) {
super(attribute, orientation, control, null);
}
@Override
public String getValue() {
return this.control.getValue();
}
@Override
protected void setValueToControl(final String value) {
this.control.setValue(value);
}
}
}

View file

@ -317,19 +317,19 @@ public class TableFieldBuilder implements InputFieldBuilder {
this.attribute,
this.tableContext.getViewContext().i18nSupport),
values -> applyFormValues(values, selectionIndex),
() -> this.tableContext.getValueChangeListener()
.tableChanged(extractTableValue()),
builder);
}
private void applyFormValues(final Map<Long, TableValue> values, final int index) {
final Map<Long, TableValue> tableRowValues = this.tableContext.getTableRowValues(index);
if (tableRowValues == null || tableRowValues.isEmpty()) {
return;
if (values != null && !values.isEmpty()) {
this.values.remove(index);
this.values.add(index, values);
applyTableRowValues(index);
}
this.values.remove(index);
this.values.add(index, tableRowValues);
applyTableRowValues(index);
// send new values to web-service
// send values to web-service
this.tableContext.getValueChangeListener()
.tableChanged(extractTableValue());
}
@ -372,13 +372,12 @@ public class TableFieldBuilder implements InputFieldBuilder {
@Override
protected void setValueToControl(final String value) {
//throw new UnsupportedOperationException();
throw new UnsupportedOperationException();
}
@Override
public String getValue() {
return null;
//throw new UnsupportedOperationException();
throw new UnsupportedOperationException();
}
}

View file

@ -17,6 +17,9 @@ import java.util.stream.Collectors;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@ -53,13 +56,38 @@ public class TableRowFormBuilder implements ModalInputDialogComposer<Map<Long, T
@Override
public Supplier<Map<Long, TableValue>> compose(final Composite parent) {
final ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL);
final GridData gridData3 = new GridData(SWT.LEFT, SWT.TOP, true, true);
// gridData3.horizontalSpan = 2;
// gridData3.widthHint = 400;
// gridData3.heightHint = 400;
scrolledComposite.setLayoutData(gridData3);
final List<InputField> inputFields = new ArrayList<>();
final Composite grid = this.tableContext
.getWidgetFactory()
.formGrid(parent, 2);
.formGrid(scrolledComposite, 2);
grid.setBackground(new Color(grid.getDisplay(), new RGB(100, 100, 100)));
final GridLayout layout = (GridLayout) grid.getLayout();
layout.verticalSpacing = 0;
final GridData gridData = (GridData) grid.getLayoutData();
gridData.grabExcessVerticalSpace = false;
gridData.verticalAlignment = SWT.ON_TOP;
scrolledComposite.setContent(grid);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setSize(parent.computeSize(400, SWT.DEFAULT));
scrolledComposite.setAlwaysShowScrollBars(true);
scrolledComposite.addListener(SWT.Resize, event -> {
scrolledComposite.setMinSize(grid.computeSize(400, SWT.DEFAULT));
// main.setSize(shell.computeSize(this.dialogWidth, SWT.DEFAULT));
System.out.println("*************************");
});
grid.addListener(SWT.Resize, event -> {
// main.setSize(shell.computeSize(this.dialogWidth, SWT.DEFAULT));
System.out.println("*************************");
});
for (final ConfigurationAttribute attribute : this.tableContext.getRowAttributes()) {
createLabel(grid, attribute);
@ -122,7 +150,7 @@ public class TableRowFormBuilder implements ModalInputDialogComposer<Map<Long, T
final Label label = this.tableContext
.getWidgetFactory()
.labelLocalized(parent, locTextKey);
final GridData gridData = new GridData(SWT.LEFT, SWT.TOP, true, false);
final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
gridData.verticalIndent = 4;
label.setLayoutData(gridData);
label.setData(RWT.CUSTOM_VARIANT, CustomVariant.TITLE_LABEL.key);

View file

@ -13,6 +13,8 @@ import java.util.function.Supplier;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -47,6 +49,7 @@ public class ModalInputDialog<T> extends Dialog {
super(parent, SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL);
this.widgetFactory = widgetFactory;
}
public ModalInputDialog<T> setDialogWidth(final int dialogWidth) {
@ -57,6 +60,7 @@ public class ModalInputDialog<T> extends Dialog {
public void open(
final LocTextKey title,
final Consumer<T> callback,
final Runnable cancelCallback,
final ModalInputDialogComposer<T> contentComposer) {
// Create the selection dialog window
@ -65,15 +69,18 @@ public class ModalInputDialog<T> extends Dialog {
shell.setData(RWT.CUSTOM_VARIANT, CustomVariant.MESSAGE.key);
shell.setText(this.widgetFactory.getI18nSupport().getText(title));
shell.setLayout(new GridLayout(2, true));
shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final GridData gridData2 = new GridData(SWT.FILL, SWT.TOP, false, false);
gridData2.widthHint = this.dialogWidth;
shell.setLayoutData(gridData2);
final Composite main = new Composite(shell, SWT.NONE);
main.setLayout(new GridLayout());
final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, true);
final GridData gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
gridData.horizontalSpan = 2;
gridData.widthHint = this.dialogWidth;
// gridData.heightHint = 400;
main.setLayoutData(gridData);
main.setBackground(new Color(shell.getDisplay(), new RGB(1, 2, 3)));
final Supplier<T> valueSuppier = contentComposer.compose(main);
@ -84,11 +91,8 @@ public class ModalInputDialog<T> extends Dialog {
ok.addListener(SWT.Selection, event -> {
if (valueSuppier != null) {
final T result = valueSuppier.get();
if (result != null) {
callback.accept(result);
shell.close();
}
callback.accept(result);
shell.close();
} else {
shell.close();
}
@ -101,6 +105,9 @@ public class ModalInputDialog<T> extends Dialog {
data.widthHint = 100;
cancel.setLayoutData(data);
cancel.addListener(SWT.Selection, event -> {
if (cancelCallback != null) {
cancelCallback.run();
}
shell.close();
});

View file

@ -0,0 +1,427 @@
/*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package ch.ethz.seb.sebserver.gui.widget;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.ImageIcon;
public class GridTable extends Composite {
private static final Logger log = LoggerFactory.getLogger(GridTable.class);
public static final Set<AttributeType> SUPPORTED_TYPES = EnumSet.of(
AttributeType.CHECKBOX,
AttributeType.TEXT_FIELD);
private static final int ACTION_COLUMN_WIDTH = 20;
private final WidgetFactory widgetFactory;
private final List<Column> columns;
private final Label addAction;
private final List<Row> rows;
private final String locTextKeyPrefix;
private Listener listener;
public GridTable(
final Composite parent,
final List<ColumnDef> columnDefs,
final String locTextKeyPrefix,
final WidgetFactory widgetFactory) {
super(parent, SWT.NONE);
this.widgetFactory = widgetFactory;
this.locTextKeyPrefix = locTextKeyPrefix;
final GridLayout gridLayout = new GridLayout(columnDefs.size() + 1, false);
gridLayout.verticalSpacing = 1;
gridLayout.marginLeft = 0;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
this.setLayout(gridLayout);
// this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.columns = new ArrayList<>();
for (final ColumnDef columnDef : columnDefs) {
final Label label = new Label(this, SWT.NONE);
label.setText("column");
//widgetFactory.labelLocalized(
// this,
// new LocTextKey(locTextKeyPrefix + columnDef.name));
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
// gridData.widthHint = 50;
label.setLayoutData(gridData);
this.columns.add(new Column(columnDef, label, gridData));
}
this.addAction = widgetFactory.imageButton(
ImageIcon.ADD_BOX,
this,
new LocTextKey(locTextKeyPrefix + "addAction"),
this::addRow);
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.widthHint = ACTION_COLUMN_WIDTH;
this.addAction.setLayoutData(gridData);
this.rows = new ArrayList<>();
this.addListener(SWT.Resize, this::adaptColumnWidth);
}
public void setListener(final Listener listener) {
this.listener = listener;
}
void addRow(final Event event) {
final List<ControlAdapter> row = new ArrayList<>();
for (final Column column : this.columns) {
row.add(createCell(column, column.columnDef.defaultValue));
}
this.rows.add(new Row(row));
this.adaptLayout();
if (this.listener != null) {
this.listener.handleEvent(new Event());
}
}
public void adaptLayout() {
this.getParent().getParent().layout(true, true);
Composite parent = this.getParent();
while (parent != null && !(parent instanceof ScrolledComposite)) {
parent = parent.getParent();
}
System.out.println("********************** " + parent);
if (parent != null) {
((ScrolledComposite) parent).setMinSize(this.getParent().getParent().computeSize(400, SWT.DEFAULT));
}
}
void addRow(final String values) {
if (StringUtils.isBlank(values)) {
return;
}
final Map<String, String> nameValueMap = new HashMap<>();
for (final String valueMap : StringUtils.split(values, Constants.EMBEDDED_LIST_SEPARATOR)) {
final String[] nameValue = StringUtils.split(valueMap, Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR);
if (nameValue.length > 1) {
nameValueMap.put(nameValue[0], nameValue[1]);
} else {
nameValueMap.put(nameValue[0], null);
}
}
final List<ControlAdapter> row = new ArrayList<>();
for (final Column column : this.columns) {
row.add(createCell(column, nameValueMap.get(column.columnDef.name)));
}
this.rows.add(new Row(row));
}
void deleteRow(final Row row) {
if (this.rows.remove(row)) {
row.dispose();
}
this.adaptLayout();
}
public String getValue() {
return StringUtils.join(
this.rows
.stream()
.map(row -> row.getValue())
.collect(Collectors.toList()),
Constants.LIST_SEPARATOR);
}
public void setValue(final String value) {
clearTable();
if (StringUtils.isBlank(value)) {
return;
}
for (final String val : StringUtils.split(value, Constants.LIST_SEPARATOR)) {
addRow(val);
}
this.adaptLayout();
}
private ControlAdapter createCell(final Column column, final String value) {
switch (column.columnDef.type) {
case CHECKBOX: {
final CheckBox checkBox = new CheckBox(this, column.columnDef, this.listener);
checkBox.setValue(value);
return checkBox;
}
case TEXT_FIELD: {
final TextField textField = new TextField(this, column.columnDef, this.listener);
textField.setValue(value);
return textField;
}
default: {
return new Dummy(this, column.columnDef);
}
}
}
private void clearTable() {
for (final Row row : this.rows) {
row.dispose();
}
this.rows.clear();
}
private void adaptColumnWidth(final Event event) {
try {
// final int currentTableWidth = this.getClientArea().width;
// final int dynWidth = currentTableWidth - ACTION_COLUMN_WIDTH;
// final int colWidth = dynWidth / this.columns.size();
// for (final Column column : this.columns) {
// column.header.widthHint = 200;// colWidth;
// }
this.columns.get(0).header.widthHint = 50;
this.columns.get(1).header.widthHint = 150;
} catch (final Exception e) {
log.warn("Failed to adaptColumnWidth: ", e);
}
}
final class Row {
final List<ControlAdapter> cells;
final Label removeAction;
protected Row(final List<ControlAdapter> cells) {
this.cells = cells;
this.removeAction = GridTable.this.widgetFactory.imageButton(
ImageIcon.REMOVE_BOX,
GridTable.this,
new LocTextKey(GridTable.this.locTextKeyPrefix + "addAction"),
event -> deleteRow(this));
final GridData gridData = new GridData(SWT.LEFT, SWT.TOP, true, false);
this.removeAction.setLayoutData(gridData);
}
void dispose() {
for (final ControlAdapter cell : this.cells) {
cell.dispose();
}
this.removeAction.dispose();
}
String getValue() {
return StringUtils.join(
this.cells
.stream()
.map(cell -> cell.columnDef().name + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR
+ cell.getValue())
.collect(Collectors.toList()),
Constants.EMBEDDED_LIST_SEPARATOR);
}
}
public static final class ColumnDef {
final int widthFactor;
final String name;
final AttributeType type;
final String defaultValue;
protected ColumnDef(
final int widthFactor,
final String name,
final AttributeType type,
final String defaultValue) {
this.widthFactor = widthFactor;
this.name = name;
this.type = type;
this.defaultValue = defaultValue;
}
// 2:argument:TEXT_FIELD
public static final ColumnDef fromString(
final String string,
final Map<String, String> defaultValueMap) {
if (StringUtils.isBlank(string)) {
return null;
}
final String[] split = StringUtils.split(string, ':');
final AttributeType attributeType = AttributeType.valueOf(split[2]);
if (!SUPPORTED_TYPES.contains(attributeType)) {
throw new UnsupportedOperationException(
"The AttributeType : " + attributeType + " is not supported yet");
}
return new ColumnDef(
Integer.parseInt(split[0]),
split[1],
attributeType,
defaultValueMap.get(split[1]));
}
}
private static class Column {
final ColumnDef columnDef;
final Label label;
final GridData header;
protected Column(final ColumnDef columnDef, final Label label, final GridData header) {
this.columnDef = columnDef;
this.label = label;
this.header = header;
}
}
interface ControlAdapter {
String getValue();
void setValue(String value);
void dispose();
ColumnDef columnDef();
}
private class Dummy implements ControlAdapter {
private final Label label;
private final ColumnDef columnDef;
Dummy(final Composite parent, final ColumnDef columnDef) {
this.label = new Label(parent, SWT.NONE);
this.label.setText("unsupported");
this.columnDef = columnDef;
}
@Override
public String getValue() {
return null;
}
@Override
public void setValue(final String value) {
}
@Override
public void dispose() {
this.label.dispose();
}
@Override
public ColumnDef columnDef() {
return this.columnDef;
}
}
private class CheckBox implements ControlAdapter {
private final Button checkbox;
private final ColumnDef columnDef;
CheckBox(final Composite parent, final ColumnDef columnDef, final Listener listener) {
this.checkbox = new Button(parent, SWT.CHECK);
this.checkbox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.columnDef = columnDef;
if (listener != null) {
this.checkbox.addListener(SWT.Selection, listener);
}
}
@Override
public String getValue() {
return this.checkbox.getSelection()
? Constants.TRUE_STRING
: Constants.FALSE_STRING;
}
@Override
public void setValue(final String value) {
this.checkbox.setSelection(BooleanUtils.toBoolean(value));
}
@Override
public void dispose() {
this.checkbox.dispose();
}
@Override
public ColumnDef columnDef() {
return this.columnDef;
}
}
private class TextField implements ControlAdapter {
private final Text textField;
private final ColumnDef columnDef;
TextField(final Composite parent, final ColumnDef columnDef, final Listener listener) {
this.textField = new Text(parent, SWT.LEFT | SWT.BORDER);
this.textField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.columnDef = columnDef;
this.textField.addListener(SWT.FocusOut, listener);
this.textField.addListener(SWT.Traverse, listener);
}
@Override
public String getValue() {
return this.textField.getText();
}
@Override
public void setValue(final String value) {
this.textField.setText((value != null) ? value : "");
}
@Override
public void dispose() {
this.textField.dispose();
}
@Override
public ColumnDef columnDef() {
return this.columnDef;
}
}
}

View file

@ -158,7 +158,6 @@ public final class ThresholdList extends Composite {
private void adaptColumnWidth(final Event event) {
try {
// TODO
final int currentTableWidth = this.getClientArea().width;
final int dynWidth = currentTableWidth - ACTION_COLUMN_WIDTH;
final int colWidth = dynWidth / 2;

View file

@ -185,7 +185,7 @@ public class WidgetFactory {
layout.marginLeft = 10;
layout.marginTop = 0;
grid.setLayout(layout);
grid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
grid.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
return grid;
}

View file

@ -8,18 +8,32 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Set;
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.ConfigurationValue;
public interface XMLValueConverter {
Set<AttributeType> types();
String name();
void convertToXML(
OutputStream out,
ConfigurationAttribute attribute,
ConfigurationValue value);
ConfigurationValue value) throws IOException;
default String extractName(final ConfigurationAttribute attribute) {
final int lastIndexOf = attribute.name.lastIndexOf('.');
if (lastIndexOf > 0) {
return attribute.name.substring(lastIndexOf, attribute.name.length() - 1);
} else {
return attribute.name;
}
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.impl.converter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
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.ConfigurationValue;
import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.XMLValueConverter;
public class BooleanConverter implements XMLValueConverter {
public static final Set<AttributeType> SUPPORTED_TYPES = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList(
AttributeType.CHECKBOX)));
private static final StringBuilder BUILDER = new StringBuilder();
@Override
public String name() {
return StringUtils.EMPTY;
}
@Override
public Set<AttributeType> types() {
return SUPPORTED_TYPES;
}
@Override
public void convertToXML(
final OutputStream out,
final ConfigurationAttribute attribute,
final ConfigurationValue value) throws IOException {
BUILDER.setLength(0);
out.write(Utils.toByteArray(BUILDER.append("<key>")
.append(extractName(attribute))
.append("<")
.append((value.value != null) ? value.value : "false")
.append(" />")));
}
}

View file

@ -9,10 +9,13 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.impl.converter;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Set;
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.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
@ -23,13 +26,18 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.XMLValueConverter
@WebServiceProfile
public class KioskModeConverter implements XMLValueConverter {
public static final String NAME = "KioskModeConverter";
public static final String NAME = "kioskMode";
@Override
public String name() {
return NAME;
}
@Override
public Set<AttributeType> types() {
return Collections.emptySet();
}
@Override
public void convertToXML(
final OutputStream out,