Zoom gui
This commit is contained in:
parent
357251d40b
commit
7cd2d3566d
4 changed files with 125 additions and 108 deletions
|
@ -23,7 +23,6 @@ import org.slf4j.LoggerFactory;
|
|||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Utils;
|
||||
import ch.ethz.seb.sebserver.gui.service.examconfig.impl.CellFieldBuilderAdapter.ExpandBarCellFieldBuilderAdapter;
|
||||
|
||||
public class AttributeMapping {
|
||||
|
||||
|
@ -163,7 +162,7 @@ public class AttributeMapping {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final String expandGroupKey = ExpandBarCellFieldBuilderAdapter.getExpandGroupKey(orientation.groupId);
|
||||
final String expandGroupKey = ViewGridBuilder.getExpandGroupKey(orientation.groupId);
|
||||
if (expandGroupKey == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
|
@ -12,24 +12,19 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.ExpandBar;
|
||||
import org.eclipse.swt.widgets.ExpandItem;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.Constants;
|
||||
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.TitleOrientation;
|
||||
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.service.i18n.LocTextKey;
|
||||
import ch.ethz.seb.sebserver.gui.widget.WidgetFactory;
|
||||
|
||||
|
@ -51,31 +46,6 @@ interface CellFieldBuilderAdapter {
|
|||
default void balanceGrid(final CellFieldBuilderAdapter[][] grid, final int x, final int y) {
|
||||
}
|
||||
|
||||
static CellFieldBuilderAdapter fieldBuilderAdapter(
|
||||
final InputFieldBuilder inputFieldBuilder,
|
||||
final ConfigurationAttribute attribute) {
|
||||
|
||||
return new CellFieldBuilderAdapter() {
|
||||
@Override
|
||||
public void createCell(final ViewGridBuilder builder) {
|
||||
|
||||
final InputField inputField = inputFieldBuilder.createInputField(
|
||||
builder.parent,
|
||||
attribute,
|
||||
builder.viewContext);
|
||||
|
||||
if (inputField != null) {
|
||||
builder.viewContext.registerInputField(inputField);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[FIELD]";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static CellFieldBuilderAdapter labelBuilder(
|
||||
final ConfigurationAttribute attribute,
|
||||
final Orientation orientation) {
|
||||
|
@ -234,8 +204,6 @@ interface CellFieldBuilderAdapter {
|
|||
|
||||
class ExpandBarCellFieldBuilderAdapter implements CellFieldBuilderAdapter {
|
||||
|
||||
public final static Pattern EXPAND_BAR_GROUP_PATTERN = Pattern.compile("\\[(.*?)\\]");
|
||||
|
||||
final Map<String, Collection<Orientation>> orientationsOfExpandBar;
|
||||
|
||||
int x = 100;
|
||||
|
@ -243,58 +211,11 @@ interface CellFieldBuilderAdapter {
|
|||
int width = 1;
|
||||
int height = 1;
|
||||
|
||||
public static final String getExpandKey(final String groupId) {
|
||||
final Matcher matcher = EXPAND_BAR_GROUP_PATTERN.matcher(groupId);
|
||||
if (matcher.find()) {
|
||||
String expandableGroup = matcher.group();
|
||||
expandableGroup = expandableGroup.substring(1, expandableGroup.length() - 1);
|
||||
return expandableGroup;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final String getExpandGroupKey(final String groupId) {
|
||||
String expandKey = getExpandKey(groupId);
|
||||
if (expandKey == null) {
|
||||
if (StringUtils.isNotBlank(groupId) && groupId.contains(Constants.EMBEDDED_LIST_SEPARATOR)) {
|
||||
expandKey = groupId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final String[] split = StringUtils.split(expandKey, Constants.EMBEDDED_LIST_SEPARATOR);
|
||||
if (split != null && split.length > 0) {
|
||||
return split[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final String getExpandItemKey(final String groupId) {
|
||||
String expandKey = getExpandKey(groupId);
|
||||
if (expandKey == null) {
|
||||
if (StringUtils.isNotBlank(groupId) && groupId.contains(Constants.EMBEDDED_LIST_SEPARATOR)) {
|
||||
expandKey = groupId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final String[] split = StringUtils.split(expandKey, Constants.EMBEDDED_LIST_SEPARATOR);
|
||||
if (split != null && split.length > 1) {
|
||||
return split[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
ExpandBarCellFieldBuilderAdapter(final Collection<Orientation> orientationsOfExpandBar) {
|
||||
this.orientationsOfExpandBar = new HashMap<>();
|
||||
|
||||
for (final Orientation o : orientationsOfExpandBar) {
|
||||
final String expandKey = getExpandKey(o.groupId);
|
||||
final String expandKey = ViewGridBuilder.getExpandKey(o.groupId);
|
||||
if (expandKey == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -323,7 +244,7 @@ interface CellFieldBuilderAdapter {
|
|||
.stream()
|
||||
.findFirst()
|
||||
.map(key -> {
|
||||
final String expandGroupKey = getExpandGroupKey(key);
|
||||
final String expandGroupKey = ViewGridBuilder.getExpandGroupKey(key);
|
||||
return new LocTextKey(
|
||||
ExamConfigurationService.TOOL_TIP_SUFFIX + expandGroupKey,
|
||||
expandGroupKey);
|
||||
|
@ -332,23 +253,25 @@ interface CellFieldBuilderAdapter {
|
|||
final ExpandBar expandBar = widgetFactory.expandBarLocalized(
|
||||
builder.parent,
|
||||
expandTooltipText);
|
||||
expandBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, this.width, this.height));
|
||||
expandBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, this.width, this.height + 2));
|
||||
|
||||
for (final Map.Entry<String, Collection<Orientation>> entry : this.orientationsOfExpandBar.entrySet()) {
|
||||
|
||||
final String expandItemKey = getExpandItemKey(entry.getKey());
|
||||
final String expandItemKey = ViewGridBuilder.getExpandItemKey(entry.getKey());
|
||||
final Collection<Orientation> value = entry.getValue();
|
||||
final LocTextKey labelKey = new LocTextKey(
|
||||
ExamConfigurationService.GROUP_LABEL_LOC_TEXT_PREFIX + expandItemKey,
|
||||
expandItemKey);
|
||||
|
||||
final Composite expandItem = widgetFactory.expandItemLocalized(
|
||||
final ExpandItem expandItem = widgetFactory.expandItemLocalized(
|
||||
expandBar,
|
||||
this.width,
|
||||
labelKey);
|
||||
|
||||
expandItem.setHeight(this.height * 25);
|
||||
final Composite body = (Composite) expandItem.getControl();
|
||||
final ViewGridBuilder expandBuilder = new ViewGridBuilder(
|
||||
expandItem,
|
||||
body,
|
||||
builder.viewContext,
|
||||
this,
|
||||
builder.examConfigurationService);
|
||||
|
@ -361,4 +284,5 @@ interface CellFieldBuilderAdapter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -11,6 +11,8 @@ package ch.ethz.seb.sebserver.gui.service.examconfig.impl;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -21,10 +23,12 @@ import org.eclipse.swt.widgets.Label;
|
|||
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.gbl.model.sebconfig.ConfigurationAttribute;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
|
||||
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.service.examconfig.impl.CellFieldBuilderAdapter.ExpandBarCellFieldBuilderAdapter;
|
||||
import ch.ethz.seb.sebserver.gui.service.examconfig.impl.CellFieldBuilderAdapter.GroupCellFieldBuilderAdapter;
|
||||
|
@ -33,6 +37,8 @@ public class ViewGridBuilder {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(ViewGridBuilder.class);
|
||||
|
||||
public static Pattern EXPAND_BAR_GROUP_PATTERN = Pattern.compile("\\[(.*?)\\]");
|
||||
|
||||
final ExamConfigurationService examConfigurationService;
|
||||
final Composite parent;
|
||||
final ViewContext viewContext;
|
||||
|
@ -101,6 +107,95 @@ public class ViewGridBuilder {
|
|||
this.registeredExpandables = null;
|
||||
}
|
||||
|
||||
public static String getGroupKey(final String groupId) {
|
||||
if (groupId == null || !groupId.contains(Constants.SQUARE_BRACE_OPEN.toString())) {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
if (groupId.startsWith(Constants.SQUARE_BRACE_OPEN.toString())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String[] split = StringUtils.split(groupId, Constants.SQUARE_BRACE_OPEN);
|
||||
if (split != null && split.length > 0) {
|
||||
return split[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getExpandKey(final String groupId) {
|
||||
final Matcher matcher = EXPAND_BAR_GROUP_PATTERN.matcher(groupId);
|
||||
if (matcher.find()) {
|
||||
String expandableGroup = matcher.group();
|
||||
expandableGroup = expandableGroup.substring(1, expandableGroup.length() - 1);
|
||||
return expandableGroup;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getExpandGroupKey(final String groupId) {
|
||||
String expandKey = getExpandKey(groupId);
|
||||
if (expandKey == null) {
|
||||
if (StringUtils.isNotBlank(groupId) && groupId.contains(Constants.EMBEDDED_LIST_SEPARATOR)) {
|
||||
expandKey = groupId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final String[] split = StringUtils.split(expandKey, Constants.EMBEDDED_LIST_SEPARATOR);
|
||||
if (split != null && split.length > 0) {
|
||||
return split[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getExpandItemKey(final String groupId) {
|
||||
String expandKey = getExpandKey(groupId);
|
||||
if (expandKey == null) {
|
||||
if (StringUtils.isNotBlank(groupId) && groupId.contains(Constants.EMBEDDED_LIST_SEPARATOR)) {
|
||||
expandKey = groupId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final String[] split = StringUtils.split(expandKey, Constants.EMBEDDED_LIST_SEPARATOR);
|
||||
if (split != null && split.length > 1) {
|
||||
return split[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CellFieldBuilderAdapter fieldBuilderAdapter(
|
||||
final InputFieldBuilder inputFieldBuilder,
|
||||
final ConfigurationAttribute attribute) {
|
||||
|
||||
return new CellFieldBuilderAdapter() {
|
||||
@Override
|
||||
public void createCell(final ViewGridBuilder builder) {
|
||||
|
||||
final InputField inputField = inputFieldBuilder.createInputField(
|
||||
builder.parent,
|
||||
attribute,
|
||||
builder.viewContext);
|
||||
|
||||
if (inputField != null) {
|
||||
builder.viewContext.registerInputField(inputField);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[FIELD]";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ViewGridBuilder add(final ConfigurationAttribute attribute) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Add SEB Configuration Attribute: " + attribute);
|
||||
|
@ -121,7 +216,7 @@ public class ViewGridBuilder {
|
|||
// create group builder
|
||||
if (StringUtils.isNotBlank(orientation.groupId)) {
|
||||
|
||||
final String expandGroupKey = ExpandBarCellFieldBuilderAdapter.getExpandGroupKey(orientation.groupId);
|
||||
final String expandGroupKey = getExpandGroupKey(orientation.groupId);
|
||||
if (!this.isExpandBarBuilder && !this.isGroupBuilder && expandGroupKey != null) {
|
||||
if (this.registeredExpandables.contains(expandGroupKey)) {
|
||||
return this;
|
||||
|
@ -137,27 +232,26 @@ public class ViewGridBuilder {
|
|||
}
|
||||
|
||||
if (!this.isGroupBuilder) {
|
||||
if (this.registeredGroups.contains(orientation.groupId)) {
|
||||
final String groupKey = getGroupKey(orientation.groupId);
|
||||
if (groupKey != null) {
|
||||
if (this.registeredGroups.contains(groupKey)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
final GroupCellFieldBuilderAdapter groupBuilder =
|
||||
new GroupCellFieldBuilderAdapter(this.viewContext.getOrientationsOfGroup(attribute));
|
||||
|
||||
final int xpos = groupBuilder.x - this.xOffset;
|
||||
final int ypos = groupBuilder.y - this.yOffset;
|
||||
|
||||
fillDummy(xpos, ypos, groupBuilder.width, groupBuilder.height);
|
||||
this.grid[ypos][xpos] = groupBuilder;
|
||||
this.registeredGroups.add(groupKey);
|
||||
return this;
|
||||
}
|
||||
|
||||
final GroupCellFieldBuilderAdapter groupBuilder =
|
||||
new GroupCellFieldBuilderAdapter(this.viewContext.getOrientationsOfGroup(attribute));
|
||||
|
||||
final int xpos = groupBuilder.x - this.xOffset;
|
||||
final int ypos = groupBuilder.y - this.yOffset;
|
||||
|
||||
fillDummy(xpos, ypos, groupBuilder.width, groupBuilder.height);
|
||||
this.grid[ypos][xpos] = groupBuilder;
|
||||
this.registeredGroups.add(orientation.groupId);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isExpandBarBuilder) {
|
||||
System.out.print("**************** attr:" + attribute.name);
|
||||
}
|
||||
|
||||
// create single input field with label
|
||||
final int xpos = orientation.xpos() - this.xOffset;
|
||||
final int ypos = orientation.ypos() - this.yOffset;
|
||||
|
@ -170,7 +264,7 @@ public class ViewGridBuilder {
|
|||
attribute,
|
||||
orientation);
|
||||
|
||||
this.grid[ypos][xpos] = CellFieldBuilderAdapter.fieldBuilderAdapter(
|
||||
this.grid[ypos][xpos] = fieldBuilderAdapter(
|
||||
inputFieldBuilder,
|
||||
attribute);
|
||||
|
||||
|
|
|
@ -533,7 +533,7 @@ public class WidgetFactory {
|
|||
return expandBar;
|
||||
}
|
||||
|
||||
public Composite expandItemLocalized(
|
||||
public ExpandItem expandItemLocalized(
|
||||
final ExpandBar parent,
|
||||
final int columns,
|
||||
final LocTextKey locTextKey) {
|
||||
|
@ -548,7 +548,7 @@ public class WidgetFactory {
|
|||
expandItem.setControl(body);
|
||||
|
||||
this.polyglotPageService.injectI18n(expandItem, locTextKey);
|
||||
return body;
|
||||
return expandItem;
|
||||
}
|
||||
|
||||
public Tree treeLocalized(final Composite parent, final int style) {
|
||||
|
|
Loading…
Reference in a new issue