From be87f006afb8f224afe57950d1b72cb4117a5835 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Thu, 8 Aug 2019 14:58:05 +0200 Subject: Refactor GUIBuilderConfiguration to support Map and List based property format --- .../gui/AbstractGUIFormBuilderConfiguration.java | 50 ++++++++++++++-------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'eaaf_core/src/main/java/at') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/gui/AbstractGUIFormBuilderConfiguration.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/gui/AbstractGUIFormBuilderConfiguration.java index c9c2ec0b..706c163d 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/gui/AbstractGUIFormBuilderConfiguration.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/gui/AbstractGUIFormBuilderConfiguration.java @@ -26,13 +26,17 @@ *******************************************************************************/ package at.gv.egiz.eaaf.core.impl.gui; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.gv.egiz.eaaf.core.api.gui.GroupDefinition; +import at.gv.egiz.eaaf.core.api.gui.GroupDefinition.TYPE; import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfiguration; /** @@ -42,11 +46,11 @@ import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfiguration; public abstract class AbstractGUIFormBuilderConfiguration implements IGUIBuilderConfiguration { private static final Logger log = LoggerFactory.getLogger(AbstractGUIFormBuilderConfiguration.class); - public static final String PARAM_GROUP_FORM = "form"; - public static final String PARAM_GROUP_ACTIONS = "actions"; - public static final String PARAM_GROUP_PARAMS = "params"; - public static final String PARAM_GROUP_UIOPTIONS = "uiOptions"; - public static final String PARAM_GROUP_MSG = "msg"; + public static final GroupDefinition PARAM_GROUP_FORM = GroupDefinition.getInstance("form", TYPE.MAP); + public static final GroupDefinition PARAM_GROUP_ACTIONS = GroupDefinition.getInstance("actions", TYPE.LIST); + public static final GroupDefinition PARAM_GROUP_PARAMS = GroupDefinition.getInstance("params", TYPE.MAP); + public static final GroupDefinition PARAM_GROUP_UIOPTIONS = GroupDefinition.getInstance("uiOptions", TYPE.MAP); + public static final GroupDefinition PARAM_GROUP_MSG = GroupDefinition.getInstance("msg", TYPE.MAP); public static final String PARAM_VIEWNAME = "viewName"; @@ -130,29 +134,40 @@ public abstract class AbstractGUIFormBuilderConfiguration implements IGUIBuilder /** * Get the Group for generic form elements * - * @return groupName or null if no groups are used + * @return {@link GroupDefinition} or null if no groups are used */ - abstract protected String getFromGroup(); + abstract protected GroupDefinition getFromGroup(); @SuppressWarnings("unchecked") - protected void setViewParameter(String group, String key, Object value) { + protected void setViewParameter(GroupDefinition groupDefinition, String key, Object value) { - if (StringUtils.isNotEmpty(group)) { + if (groupDefinition != null) { log.trace("Adding group object ... "); - Object groupMap = params.get(group); + Object groupMap = params.get(groupDefinition.getName()); if (groupMap == null) { - groupMap = new HashMap();; - log.trace("Build new group element"); + if (groupDefinition.getType().equals(TYPE.MAP)) { + groupMap = new HashMap();; + log.trace("Build new MAP based group element"); + + } else if (groupDefinition.getType().equals(TYPE.LIST)) { + groupMap = new ArrayList(); + log.trace("Build new List based group element"); + + } else + log.warn("GroupDefinition contains an unknown type: {}", groupDefinition.getType().name()); } - - if (groupMap instanceof Map) { + + params.put(groupDefinition.getName(), groupMap); + if (groupMap instanceof Map) ((Map) groupMap).put(key, value); - params.put(group, groupMap); - } else + else if (groupMap instanceof List) + ((List)groupMap).add(value.toString()); + + else log.warn("Can NOT add element: {} to group: {}, because group is of type: {}", - key, group, groupMap.getClass().getName()); + key, groupDefinition.getName(), groupMap.getClass().getName()); } else { log.trace("Add root object ... "); @@ -161,5 +176,4 @@ public abstract class AbstractGUIFormBuilderConfiguration implements IGUIBuilder } } - } -- cgit v1.2.3