# HG changeset patch # User Raimund Renkert # Date 1323937744 0 # Node ID 4df2d9a4b9b427ebb7345032208b76a997451107 # Parent 432180235caf09b009ac6385ff982d25a16bcad7 Added interfaces and container for output settings. Added settings container to collection. Extract settings from describe collection document. flys-client/trunk@3420 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Dec 13 13:24:43 2011 +0000 +++ b/flys-client/ChangeLog Thu Dec 15 08:29:04 2011 +0000 @@ -1,3 +1,24 @@ +2011-12-15 Raimund Renkert + + Added interfaces and classes for output settings. + + * src/main/java/de/intevation/flys/client/shared/model/Property.java, + src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java, + src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java, + src/main/java/de/intevation/flys/client/shared/model/StringProperty.java: + New. Interface and container for output properties. + + * src/main/java/de/intevation/flys/client/shared/model/Settings.java, + src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java: + New. Interface and container for properties. + + * src/main/java/de/intevation/flys/client/server/CollectionHelper.java: + Added methods to extract output properties. + + * src/main/java/de/intevation/flys/client/shared/model/Collection.java, + src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java: + Added getter/setter for settings. + 2011-12-13 Felix Wolfsteller * src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java: diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Tue Dec 13 13:24:43 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Thu Dec 15 08:29:04 2011 +0000 @@ -43,7 +43,18 @@ import de.intevation.flys.client.shared.model.Recommendation; import de.intevation.flys.client.shared.model.Theme; import de.intevation.flys.client.shared.model.ThemeList; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertyGroup; +import de.intevation.flys.client.shared.model.PropertySetting; +import de.intevation.flys.client.shared.model.StringProperty; +import de.intevation.flys.client.shared.model.OutputSettings; +//temporary +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.DocumentBuilder; +import org.xml.sax.InputSource; +import java.io.StringReader; /** * @author Ingo Weinzierl @@ -327,6 +338,7 @@ } List recommended = parseRecommendations(description); + Map outSettings = parseSettings(description); Map collectionItems = new HashMap(); @@ -464,6 +476,107 @@ /** + * Parse Settings elements. + * + * @param description The collection description. + * + * @return Map containing the settings. + */ + protected static Map parseSettings(Document description) { + //TODO Extract settings from output elements. + logger.info("parseSettings"); + Map list = new HashMap(); + + return list; + } + + + /** + * + */ + protected static Settings parseSettings(String outName, Element settings) { + logger.info("parseSettings(String,Element)"); + OutputSettings set = new OutputSettings(outName); + // get the categories + NodeList catNodes = settings.getChildNodes(); + for (int i = 0; i < catNodes.getLength(); i++) { + Element catNode = (Element)catNodes.item(i); + + // The category name + String category = catNode.getTagName(); + + // list of properties or groups (groups have child nodes). + NodeList list = catNode.getChildNodes(); + + // iterate through all properties or groups. + ArrayList props = new ArrayList (); + for (int j = 0; j < list.getLength(); j++) { + Property p; + Element e = (Element)list.item(j); + if (e.hasChildNodes() && + e.getFirstChild().getNodeType() != Node.TEXT_NODE) { + p = parseSettingsGroup(e); + } + else { + p = parseSetting(e); + } + props.add(p); + } + set.setSettings(category, props); + } + return set; + } + + + /** + * + */ + protected static Property parseSettingsGroup(Element group) { + PropertyGroup p = new PropertyGroup(); + p.setName(group.getTagName()); + + NodeList list = group.getChildNodes(); + ArrayList props = new ArrayList(); + for (int i = 0; i < list.getLength(); i++) { + props.add(parseSetting((Element)list.item(i))); + } + p.setProperties(props); + return p; + } + + + /** + * + */ + protected static Property parseSetting(Element property){ + NamedNodeMap attrMap = property.getAttributes(); + int attrNum = attrMap != null ? attrMap.getLength() : 0; + + Node type = attrMap.getNamedItem("type"); + String t = type.getNodeValue(); + PropertySetting ps = new PropertySetting(); + + if(t.equals("string")) { + ps = new StringProperty(); + } + ps.setName(property.getTagName()); + ps.setValue(property.getTextContent()); + + for (int i = 0; i < attrNum; i++) { + Node attr = attrMap.item(i); + + String name = attr.getNodeName(); + String value = attr.getNodeValue(); + if(name.equals("type")) { + continue; + } + ps.setAttribute(name, value); + } + return ps; + } + + + /** * This method extracts the CollectionItem from node with its output * modes. The output modes are parsed using the parseOutputModes() method. * diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java Tue Dec 13 13:24:43 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java Thu Dec 15 08:29:04 2011 +0000 @@ -38,6 +38,8 @@ public ThemeList getThemeList(String outName); + public Settings getSettings(String outName); + /** Sets mapping outputname to ThemeList. */ public void setThemeLists(Map map); diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java Tue Dec 13 13:24:43 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java Thu Dec 15 08:29:04 2011 +0000 @@ -39,6 +39,10 @@ */ protected Map themeLists; + /** + * Settings by outputmode name. + */ + protected Map settings; /** * Constructor without arguments is necessary for GWT. @@ -54,6 +58,7 @@ this.items = new ArrayList(); this.themeLists = new HashMap(); this.recommendations = new ArrayList(); + this.settings = new HashMap(); } @@ -86,6 +91,19 @@ } + public DefaultCollection( + String uuid, + long ttl, + String name, + List recommendations, + Map themeLists, + Map settings) + { + this(uuid, ttl, name, recommendations); + this.themeLists = themeLists; + this.settings = settings; + } + /** * Creates a new DefaultCollection with uuid and name. * @@ -193,6 +211,28 @@ } + /** + * Returns Settings for given output name. + */ + public Settings getSettings(String outName) { + if (settings != null) { + return settings.get(outName); + } + + return null; + } + + + public void setSettings(Map settings) { + this.settings = settings; + } + + + public void addSettings(String outname, Settings settings) { + this.settings.put(outname, settings); + } + + /** Set the outputname to themelist map. */ public void setThemeLists(Map map) { this.themeLists = map; diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java Thu Dec 15 08:29:04 2011 +0000 @@ -0,0 +1,56 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; + +/** + * @author Raimund Renkert + */ +public class OutputSettings implements Settings { + + /** The output name. */ + protected String name; + + /** The categories and settings container. */ + protected HashMap > categories; + + + + public OutputSettings() { + this.categories = new HashMap >(); + } + + + public OutputSettings(String name) { + this.name = name; + this.categories = new HashMap >(); + } + + + public void setName(String name) { + this.name = name; + } + + + public String getName() { + return this.name; + } + + + public void setSettings(String category, List settings) { + this.categories.put(category, settings); + } + + + public List getSettings(String category) { + return categories.get(category); + } + + + public List getCategories() { + ArrayList list = new ArrayList(categories.keySet()); + return list; + } +} diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/shared/model/Property.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Property.java Thu Dec 15 08:29:04 2011 +0000 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.List; + +import com.smartgwt.client.widgets.form.DynamicForm; + +/** + * This interface describes a Property of an output mode. + * + * @author Raimund Renkert + */ +public interface Property extends Serializable { + + String getName(); + + void setName(String name); + + DynamicForm generateUI(); + +} diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java Thu Dec 15 08:29:04 2011 +0000 @@ -0,0 +1,47 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +/** + * @author Raimund Renkert + */ +public class PropertyGroup implements Property { + + /** The group name */ + protected String name; + + protected List properties; + + public PropertyGroup() { + + } + + public PropertyGroup(String name) { + this.name = name; + } + + public PropertyGroup(String name, List properties) { + this.name = name; + this.properties = properties; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public List getProperties() { + return this.properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + + public void generateUI() { + return; + } +} diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java Thu Dec 15 08:29:04 2011 +0000 @@ -0,0 +1,91 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.ArrayList; + +import com.smartgwt.client.widgets.form.DynamicForm; + +import de.intevation.flys.client.client.ui.PropertyEditor; + +/** + * @author Raimund Renkert + */ +public class PropertySetting implements Property { + + /**The settings name.*/ + protected String name; + + /** The default value.*/ + protected String value; + + /** Additional attributes.*/ + protected HashMap attributes; + + /** The editor dialog. */ + protected PropertyEditor editor; + + /** + * Create a new StyleSetting for theme attribution. + */ + public PropertySetting() { + this.attributes = new HashMap(); + } + + + /** + * Create a new PropertySet. + * @param name The attribute name. + * @param value The current value. + */ + public PropertySetting( + String name, + String value) + { + this.name = name; + this.value = value; + this.attributes = new HashMap(); + } + + public void setName(String name) { + this.name = name; + } + + public void setValue(String value) { + this.value = value; + } + + public void setAttribute(String key, String Value) { + attributes.put(key, value); + } + + public String getName() { + return this.name; + } + + public String getValue() { + return this.value; + } + + public String getAttribute(String key) { + return attributes.get(key); + } + + public ArrayList getAttributeList() { + return new ArrayList(attributes.keySet()); + } + + public DynamicForm generateUI() { + return new DynamicForm(); + } + + public void setEditor(PropertyEditor editor) { + this.editor = editor; + } + + public PropertyEditor getEditor() { + return this.editor; + } +} + +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/shared/model/Settings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Settings.java Thu Dec 15 08:29:04 2011 +0000 @@ -0,0 +1,25 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.List; + +/** + * This interface describes an output settings of an artifact. + * + * @author Raimund Renkert + */ +public interface Settings extends Serializable { + + /** The output name */ + String getName(); + + /** */ + List getCategories(); + + /** */ + void setSettings(String category, List settings); + + /** */ + List getSettings(String category); + +} diff -r 432180235caf -r 4df2d9a4b9b4 flys-client/src/main/java/de/intevation/flys/client/shared/model/StringProperty.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/StringProperty.java Thu Dec 15 08:29:04 2011 +0000 @@ -0,0 +1,22 @@ +package de.intevation.flys.client.shared.model; + +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.types.Alignment; + +/** + * @author Raimund Renkert + */ +public class StringProperty extends PropertySetting { + + public DynamicForm generateUI() { + DynamicForm form = new DynamicForm(); + + TextItem item = new TextItem (); + item.setTitle(editor.getI18NString(name)); + item.setTitleAlign(Alignment.LEFT); + + form.setFields(item); + return form; + } +}