From 12b4776b87e1b7552ebdee9d80455eeeb6bd0e25 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 14 Nov 2019 12:44:16 +0100 Subject: [PATCH] fixed import of InlineTable and added new icons --- .../gui/content/action/ActionDefinition.java | 10 +-- .../seb/sebserver/gui/widget/GridTable.java | 14 ---- .../sebserver/gui/widget/WidgetFactory.java | 7 +- .../impl/ExamConfigImportHandler.java | 61 +++++++++++++++++- src/main/resources/messages.properties | 22 +++---- .../resources/static/images/indicator.png | Bin 0 -> 170 bytes .../resources/static/images/institution.png | Bin 0 -> 182 bytes src/main/resources/static/images/lmssetup.png | Bin 0 -> 179 bytes src/main/resources/static/images/template.png | Bin 0 -> 148 bytes src/main/resources/static/images/user.png | Bin 0 -> 190 bytes 10 files changed, 82 insertions(+), 32 deletions(-) create mode 100644 src/main/resources/static/images/indicator.png create mode 100644 src/main/resources/static/images/institution.png create mode 100644 src/main/resources/static/images/lmssetup.png create mode 100644 src/main/resources/static/images/template.png create mode 100644 src/main/resources/static/images/user.png diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java index c9974eb0..5dfe49f3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java @@ -24,7 +24,7 @@ public enum ActionDefinition { PageStateDefinitionImpl.INSTITUTION_VIEW), INSTITUTION_NEW( new LocTextKey("sebserver.institution.action.new"), - ImageIcon.NEW, + ImageIcon.INSTITUTION, PageStateDefinitionImpl.INSTITUTION_EDIT), INSTITUTION_VIEW_FROM_LIST( new LocTextKey("sebserver.institution.action.list.view"), @@ -70,7 +70,7 @@ public enum ActionDefinition { PageStateDefinitionImpl.USER_ACCOUNT_VIEW), USER_ACCOUNT_NEW( new LocTextKey("sebserver.useraccount.action.new"), - ImageIcon.NEW, + ImageIcon.USER, PageStateDefinitionImpl.USER_ACCOUNT_EDIT), USER_ACCOUNT_VIEW_FROM_LIST( new LocTextKey("sebserver.useraccount.action.view"), @@ -123,7 +123,7 @@ public enum ActionDefinition { PageStateDefinitionImpl.LMS_SETUP_LIST), LMS_SETUP_NEW( new LocTextKey("sebserver.lmssetup.action.new"), - ImageIcon.NEW, + ImageIcon.LMS_SETUP, PageStateDefinitionImpl.LMS_SETUP_EDIT), LMS_SETUP_VIEW_FROM_LIST( new LocTextKey("sebserver.lmssetup.action.list.view"), @@ -279,7 +279,7 @@ public enum ActionDefinition { EXAM_INDICATOR_NEW( new LocTextKey("sebserver.exam.indicator.action.list.new"), - ImageIcon.NEW, + ImageIcon.INDICATOR, PageStateDefinitionImpl.INDICATOR_EDIT, ActionCategory.INDICATOR_LIST), EXAM_INDICATOR_MODIFY_FROM_LIST( @@ -441,7 +441,7 @@ public enum ActionDefinition { SEB_EXAM_CONFIG_TEMPLATE_NEW( new LocTextKey("sebserver.configtemplate.action.list.new"), - ImageIcon.NEW, + ImageIcon.TEMPLATE, PageStateDefinitionImpl.SEB_EXAM_CONFIG_TEMPLATE_EDIT, ActionCategory.VARIA), SEB_EXAM_CONFIG_TEMPLATE_VIEW_FROM_LIST( 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 f89824bc..1190511b 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 @@ -203,20 +203,6 @@ public class GridTable extends Composite { private void adaptColumnWidth(final Event event) { try { - - // TODO the computeSize seems not to correspond with the width of of parent when display -// final Point computeSize = this.computeSize(SWT.DEFAULT, SWT.DEFAULT); -// final int widthUnits = this.columns -// .stream() -// .reduce( -// 0, -// (acc, c) -> acc + c.columnDef.widthFactor, -// (acc1, acc2) -> acc1 + acc2); -// final int widthUnit = computeSize.x / widthUnits; -// this.columns -// .stream() -// .forEach(c -> c.header.widthHint = c.columnDef.widthFactor * widthUnit); - this.columns.get(0).header.widthHint = 50; this.columns.get(1).header.widthHint = 200; 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 fe39f5fc..c7b0677b 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 @@ -89,7 +89,12 @@ public class WidgetFactory { DELETE("delete.png"), SEARCH("lens.png"), UNDO("undo.png"), - COLOR("color.png"); + COLOR("color.png"), + USER("user.png"), + INSTITUTION("institution.png"), + LMS_SETUP("lmssetup.png"), + INDICATOR("indicator.png"), + TEMPLATE("template.png"); private String fileName; private ImageData image = null; diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigImportHandler.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigImportHandler.java index ec2d1af8..c3df48d0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigImportHandler.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigImportHandler.java @@ -41,6 +41,9 @@ public class ExamConfigImportHandler extends DefaultHandler { Constants.XML_PLIST_DATA, Constants.XML_PLIST_INTEGER)); + private static final Set KNOWN_INLINE_TABLES = new HashSet<>(Arrays.asList( + "arguments")); + private final Consumer valueConsumer; private final Function attributeResolver; private final Long institutionId; @@ -126,6 +129,7 @@ public class ExamConfigImportHandler extends DefaultHandler { final PListNode array = new PListNode(type); switch (top.type) { case KEY: { + array.inlineTable = isInlineTable(top.name); array.name = top.name; array.listIndex = top.listIndex; this.stack.pop(); @@ -137,6 +141,10 @@ public class ExamConfigImportHandler extends DefaultHandler { } } + private boolean isInlineTable(final String name) { + return KNOWN_INLINE_TABLES.contains(name); + } + private void startDict(final Type type, final PListNode top) { final PListNode dict = new PListNode(type); switch (top.type) { @@ -218,7 +226,7 @@ public class ExamConfigImportHandler extends DefaultHandler { final PListNode grandParent = this.stack.peek(); this.stack.push(parent); - // if we are in an values-array + // if we are in a values-array if (parent.type == Type.ARRAY) { if (StringUtils.isBlank(parent.value)) { parent.value = top.value; @@ -228,6 +236,21 @@ public class ExamConfigImportHandler extends DefaultHandler { return; } + // if we are in an inline table array + if (grandParent.type == Type.ARRAY && grandParent.inlineTable) { + if (StringUtils.isBlank(grandParent.value)) { + grandParent.value = top.value; + } else { + grandParent.value += "," + top.value; + } + if (StringUtils.isBlank(grandParent.valueName)) { + grandParent.valueName = top.name; + } else { + grandParent.valueName += "," + top.name; + } + return; + } + final String attrName = (parent.type == Type.DICT && grandParent.type == Type.ARRAY) ? parent.name + "." + top.name : top.name; @@ -251,6 +274,11 @@ public class ExamConfigImportHandler extends DefaultHandler { return; } + if (top.inlineTable) { + createInlineTableValue(top, attrName, attribute); + return; + } + // check if we have a simple values array if (attribute.type == AttributeType.MULTI_CHECKBOX_SELECTION || attribute.type == AttributeType.MULTI_SELECTION) { @@ -263,6 +291,35 @@ public class ExamConfigImportHandler extends DefaultHandler { } } + private void createInlineTableValue( + final PListNode top, + final String attrName, + final ConfigurationAttribute attribute) { + + final String[] names = StringUtils.split(top.valueName, Constants.LIST_SEPARATOR); + final String[] values = StringUtils.split(top.value, Constants.LIST_SEPARATOR); + final String[] columns = StringUtils.split(attribute.getResources(), Constants.EMBEDDED_LIST_SEPARATOR); + final int numColumns = columns.length; + if (names.length != values.length) { + throw new IllegalArgumentException( + "Failed to import InlineTable values. value/name array length mismatch"); + } + + String val = ""; + for (int i = 0; i < names.length; i++) { + if (i != 0) { + if (i % numColumns == 0) { + val = val + Constants.LIST_SEPARATOR; + } else { + val = val + Constants.EMBEDDED_LIST_SEPARATOR; + } + } + val = val + names[i] + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR + values[i]; + } + + saveValue(attrName, attribute, top.listIndex, val); + } + @Override public void characters( final char[] ch, @@ -390,9 +447,11 @@ public class ExamConfigImportHandler extends DefaultHandler { } final Type type; + boolean inlineTable = false; String name; int arrayCounter = 0; int listIndex = 0; + String valueName; String value; boolean saveNullValueAsBlank = false; diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index f9192337..643ef227 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -368,9 +368,9 @@ sebserver.exam.indicator.type.ERROR_COUNT=Error Count sebserver.exam.indicator.info.pleaseSelect=Please select an indicator first -sebserver.exam.indicator.action.list.new=New -sebserver.exam.indicator.action.list.modify=Edit Selected -sebserver.exam.indicator.action.list.delete=Delete Selected +sebserver.exam.indicator.action.list.new=Add Indicator +sebserver.exam.indicator.action.list.modify=Edit Selected Indicator +sebserver.exam.indicator.action.list.delete=Delete Selected Indicator sebserver.exam.indicator.action.save=Save sebserver.exam.indicator.form.title=Indicator @@ -458,7 +458,7 @@ sebserver.examconfig.action.undo.success=Successfully reverted to last saved sta sebserver.examconfig.action.copy=Copy Configuration sebserver.examconfig.action.export.plainxml=Export Configuration sebserver.examconfig.action.get-config-key=Export Config-Key -sebserver.examconfig.action.import-config=Import Configuration +sebserver.examconfig.action.import-config=Import Exam Configuration sebserver.examconfig.action.import-file-select=Import From File sebserver.examconfig.action.import-file-password=Password sebserver.examconfig.action.import-config.confirm=Configuration successfully imported @@ -953,17 +953,17 @@ sebserver.configtemplate.list.actions=Selected Template sebserver.configtemplate.info.pleaseSelect=Please select an exam configuration template first -sebserver.configtemplate.action.list.new=Add Template -sebserver.configtemplate.action.list.view=View Template -sebserver.configtemplate.action.view=View Template -sebserver.configtemplate.action.list.modify=Edit Template -sebserver.configtemplate.action.modify=Edit Template +sebserver.configtemplate.action.list.new=Add Configuration Template +sebserver.configtemplate.action.list.view=View Configuration Template +sebserver.configtemplate.action.view=View Configuration Template +sebserver.configtemplate.action.list.modify=Edit Configuration Template +sebserver.configtemplate.action.modify=Edit Configuration Template -sebserver.configtemplate.form.title.new=Add Template +sebserver.configtemplate.form.title.new=Add Configuration Template sebserver.configtemplate.form.title=Configuration Template sebserver.configtemplate.form.name=Name sebserver.configtemplate.form.description=Description -sebserver.configtemplate.action.save=Save Template +sebserver.configtemplate.action.save=Save Configuration Template sebserver.configtemplate.attr.type.TEXT_FIELD=Text Field sebserver.configtemplate.attr.type.PASSWORD_FIELD=Password Field diff --git a/src/main/resources/static/images/indicator.png b/src/main/resources/static/images/indicator.png new file mode 100644 index 0000000000000000000000000000000000000000..42556a5202864835ac2aaed4f0328c560359359b GIT binary patch literal 170 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@RheLQfaRkP61Dmm66R7zngJ>=P+S5XUhH*x`orPJ#3$1-(^}cSU8tBgi;3Ch(B?^Ca{As$=FrN2y^25ed%v{%yt#Qn`PQYl9v=hqZ#_LG U{IN`JK+73CUHx3vIVCg!0FNa_IRF3v literal 0 HcmV?d00001 diff --git a/src/main/resources/static/images/institution.png b/src/main/resources/static/images/institution.png new file mode 100644 index 0000000000000000000000000000000000000000..8f7c90413c331c9220ca98d0773623361b4d73a5 GIT binary patch literal 182 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|mYCT;XLn;`P4=@z*urzQTE^7PF z^IS5gKyyOcjH4geSFkXBH;`DQEs*vi@dx8nw*y~!UU8__@ytKiG~YZ zBDXNKK2a_IG*!eQw~S>YSIn8L1rz5?oX(fVTQIq1&XakQv=7`)GRkRdFSM1>nj2qs d@b139jF%spHD9Spb^*GA!PC{xWt~$(698TyL^}Wg literal 0 HcmV?d00001 diff --git a/src/main/resources/static/images/template.png b/src/main/resources/static/images/template.png new file mode 100644 index 0000000000000000000000000000000000000000..813d30a7f3c41dc5a7c194ebedbd05c01171d963 GIT binary patch literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|mqCH(4Ln;`P7f3!xT#1vX8H!v@4u8_nP~gguDbdLwqH&6SlE*&gPm2uC3M9_xUzB0Q%)U#> w#No!GIuTQjZVt^u{2!uQ7-ooFi_@% literal 0 HcmV?d00001 diff --git a/src/main/resources/static/images/user.png b/src/main/resources/static/images/user.png new file mode 100644 index 0000000000000000000000000000000000000000..b3c0e507869977bf6774530f20e3a3fd66f34e44 GIT binary patch literal 190 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|mT0LDHLn;`L9%N)Y6u`i6LHq@S z;x3{I^k1)L zS=ztmmgJnPo3=G2%e;9KS$(wCrpM>;#GcOP_66O|yPG?wEWLL5-kmdtP92TT*1Whw q>X&)hWsefA*;~BSFQ$Hb$gZMh87=(qz#*W67(8A5T-G@yGywp;)lDq` literal 0 HcmV?d00001