From fecedefe93e6f58f24a0327ac6956b1921cb0417 Mon Sep 17 00:00:00 2001 From: anhefti Date: Fri, 24 May 2019 09:26:49 +0200 Subject: [PATCH] finished arguments dyn table --- .../impl/InlineTableFieldBuilder.java | 4 +- .../examconfig/impl/TableRowFormBuilder.java | 46 ++++--------- .../gui/service/page/PageService.java | 66 +++++++++++++++++++ .../service/page/impl/ModalInputDialog.java | 4 -- .../seb/sebserver/gui/widget/GridTable.java | 27 ++------ .../sebserver/gui/widget/WidgetFactory.java | 3 + src/main/resources/messages.properties | 6 +- 7 files changed, 94 insertions(+), 62 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/InlineTableFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/InlineTableFieldBuilder.java index fca45130..9c744087 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/InlineTableFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/InlineTableFieldBuilder.java @@ -72,7 +72,7 @@ public class InlineTableFieldBuilder implements InputFieldBuilder { Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)) .collect(Collectors.toMap( valueMap -> valueMap[0], - valueMap -> (valueMap.length > 1) ? valueMap[1] : "")); + valueMap -> (valueMap.length > 1) ? valueMap[1] : StringUtils.EMPTY)); final List columns = Arrays.asList(StringUtils.split( attribute.getResources(), @@ -84,7 +84,7 @@ public class InlineTableFieldBuilder implements InputFieldBuilder { final GridTable gridTable = new GridTable( innerGrid, columns, - ExamConfigurationService.ATTRIBUTE_LABEL_LOC_TEXT_PREFIX, + ExamConfigurationService.ATTRIBUTE_LABEL_LOC_TEXT_PREFIX + attribute.name + ".", this.widgetFactory); final InlineTableInputField inlineTableInputField = new InlineTableInputField( diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TableRowFormBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TableRowFormBuilder.java index 7a55fdfa..dbcd62c1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TableRowFormBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TableRowFormBuilder.java @@ -17,9 +17,6 @@ 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; @@ -35,6 +32,7 @@ import ch.ethz.seb.sebserver.gui.service.examconfig.InputFieldBuilder; import ch.ethz.seb.sebserver.gui.service.examconfig.impl.TableFieldBuilder.TableInputField; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.page.ModalInputDialogComposer; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.CustomVariant; public class TableRowFormBuilder implements ModalInputDialogComposer> { @@ -56,39 +54,19 @@ public class TableRowFormBuilder implements ModalInputDialogComposer> 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 Composite grid = PageService.createManagedVScrolledComposite( + parent, + scrolledComposite -> { + final Composite result = this.tableContext + .getWidgetFactory() + .formGrid(scrolledComposite, 2); + final GridLayout layout = (GridLayout) result.getLayout(); + layout.verticalSpacing = 0; + return result; + }, + false); final List inputFields = new ArrayList<>(); - final Composite grid = this.tableContext - .getWidgetFactory() - .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); inputFields.add(createInputField(grid, attribute)); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java index 3c6c77e6..b9d39822 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java @@ -14,6 +14,10 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -157,6 +161,68 @@ public interface PageService { return action; } + /** Key to store the ScrolledComposite update function within Control data map */ + static String SCROLLED_COMPOSITE_UPDATE = "SCROLLED_COMPOSITE_UPDATE"; + + /** Creates a ScrolledComposite with content supplied the given content creation function. + * The content creation function is used to create the content Composite as a child of the + * newly created ScrolledComposite. + * Also adds an update function within the ScrolledComposite Data mapping. If a child inside + * the ScrolledComposite changes its dimensions the method updateScrolledComposite must be + * called to update the ScrolledComposite scrolled content. + * + * @param parent the parent Composite of the ScrolledComposite + * @param contentFunction the content creation function + * @param showScrollbars indicates whether the scrollbar shall always be shown + * @return the child composite that is scrolled by the newly created ScrolledComposite */ + static Composite createManagedVScrolledComposite( + final Composite parent, + final Function contentFunction, + final boolean showScrollbars) { + + final ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL); + scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true)); + + final Composite content = contentFunction.apply(scrolledComposite); + scrolledComposite.setContent(content); + scrolledComposite.setExpandHorizontal(true); + scrolledComposite.setExpandVertical(true); + scrolledComposite.setSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + if (showScrollbars) { + scrolledComposite.setAlwaysShowScrollBars(true); + } + + final Runnable update = () -> { + scrolledComposite.setMinSize(content.computeSize(SWT.DEFAULT - 20, SWT.DEFAULT)); + ; + }; + + scrolledComposite.addListener(SWT.Resize, event -> update.run()); + scrolledComposite.setData(SCROLLED_COMPOSITE_UPDATE, update); + + return content; + } + + /** Used to update the crolledComposite when some if its content has dynamically changed + * its dimensions. + * + * @param composite The Component that changed its dimensions */ + static void updateScrolledComposite(final Composite composite) { + if (composite == null) { + return; + } + + Composite parent = composite.getParent(); + while (parent != null) { + final Object update = parent.getData(SCROLLED_COMPOSITE_UPDATE); + if (update != null) { + ((Runnable) update).run(); + return; + } + parent = parent.getParent(); + } + } + public class PageActionBuilder { private final PageService pageService; private final PageContext originalPageContext; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputDialog.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputDialog.java index 93d936ea..1962703e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputDialog.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ModalInputDialog.java @@ -13,8 +13,6 @@ 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; @@ -78,9 +76,7 @@ public class ModalInputDialog extends Dialog { 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 valueSuppier = contentComposer.compose(main); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/GridTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/GridTable.java index 09cf97d6..4621501c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/GridTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/GridTable.java @@ -19,7 +19,6 @@ 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; @@ -34,6 +33,7 @@ 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.service.page.PageService; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.ImageIcon; public class GridTable extends Composite { @@ -66,21 +66,17 @@ public class GridTable extends Composite { final GridLayout gridLayout = new GridLayout(columnDefs.size() + 1, false); gridLayout.verticalSpacing = 1; gridLayout.marginLeft = 0; - gridLayout.marginHeight = 0; + gridLayout.marginHeight = 5; 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 Label label = 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)); } @@ -88,7 +84,7 @@ public class GridTable extends Composite { this.addAction = widgetFactory.imageButton( ImageIcon.ADD_BOX, this, - new LocTextKey(locTextKeyPrefix + "addAction"), + new LocTextKey(locTextKeyPrefix + "removeAction"), this::addRow); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); gridData.widthHint = ACTION_COLUMN_WIDTH; @@ -118,16 +114,7 @@ public class GridTable extends Composite { 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)); - } + PageService.updateScrolledComposite(this); } void addRow(final String values) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java index 46e07dd5..5ba371c1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java @@ -511,6 +511,9 @@ public class WidgetFactory { 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 imageUploadFunction = iu -> { if (locTextKey != null) { diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 07e2af78..42c5cb8e 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -558,8 +558,10 @@ sebserver.examconfig.props.label.permittedProcesses.originalName=Original Name sebserver.examconfig.props.label.permittedProcesses.allowedExecutables=Window handling process sebserver.examconfig.props.label.permittedProcesses.path=Path sebserver.examconfig.props.label.permittedProcesses.arguments=Arguments -sebserver.examconfig.props.label.arguments.active=Activity -sebserver.examconfig.props.label.arguments.argument=Argument +sebserver.examconfig.props.label.permittedProcesses.arguments.active=Active +sebserver.examconfig.props.label.permittedProcesses.arguments.argument=Argument +sebserver.examconfig.props.label.permittedProcesses.arguments.addAction=Add new argument +sebserver.examconfig.props.label.permittedProcesses.arguments.removeAction=Remove this argument sebserver.examconfig.props.label.permittedProcesses.identifier=Identifier sebserver.examconfig.props.label.permittedProcesses.iconInTaskbar=Icon in taskbar sebserver.examconfig.props.label.permittedProcesses.autostart=Autostart