Mercurial > dive4elements > river
changeset 1439:4df2d9a4b9b4
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
line wrap: on
line diff
--- 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 <raimund.renkert@intevation.de> + + 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 <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> @@ -327,6 +338,7 @@ } List<Recommendation> recommended = parseRecommendations(description); + Map<String, Settings> outSettings = parseSettings(description); Map<String, CollectionItem> collectionItems = new HashMap<String, CollectionItem>(); @@ -464,6 +476,107 @@ /** + * Parse Settings elements. + * + * @param description The collection description. + * + * @return Map containing the settings. + */ + protected static Map<String, Settings> parseSettings(Document description) { + //TODO Extract settings from output elements. + logger.info("parseSettings"); + Map<String, Settings> list = new HashMap<String, Settings>(); + + 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<Property> props = new ArrayList<Property> (); + 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<Property> props = new ArrayList<Property>(); + 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 <i>node</i> with its output * modes. The output modes are parsed using the parseOutputModes() method. *
--- 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<String, ThemeList> map);
--- 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<String, ThemeList> themeLists; + /** + * Settings by outputmode name. + */ + protected Map<String, Settings> settings; /** * Constructor without arguments is necessary for GWT. @@ -54,6 +58,7 @@ this.items = new ArrayList<CollectionItem>(); this.themeLists = new HashMap<String, ThemeList>(); this.recommendations = new ArrayList<Recommendation>(); + this.settings = new HashMap<String, Settings>(); } @@ -86,6 +91,19 @@ } + public DefaultCollection( + String uuid, + long ttl, + String name, + List<Recommendation> recommendations, + Map<String, ThemeList> themeLists, + Map<String, Settings> 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<String, Settings> 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<String, ThemeList> map) { this.themeLists = map;
--- /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 <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class OutputSettings implements Settings { + + /** The output name. */ + protected String name; + + /** The categories and settings container. */ + protected HashMap<String, List<Property> > categories; + + + + public OutputSettings() { + this.categories = new HashMap<String, List<Property> >(); + } + + + public OutputSettings(String name) { + this.name = name; + this.categories = new HashMap<String, List<Property> >(); + } + + + public void setName(String name) { + this.name = name; + } + + + public String getName() { + return this.name; + } + + + public void setSettings(String category, List<Property> settings) { + this.categories.put(category, settings); + } + + + public List<Property> getSettings(String category) { + return categories.get(category); + } + + + public List getCategories() { + ArrayList<String> list = new ArrayList<String>(categories.keySet()); + return list; + } +}
--- /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 <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface Property extends Serializable { + + String getName(); + + void setName(String name); + + DynamicForm generateUI(); + +}
--- /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 <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class PropertyGroup implements Property { + + /** The group name */ + protected String name; + + protected List<Property> properties; + + public PropertyGroup() { + + } + + public PropertyGroup(String name) { + this.name = name; + } + + public PropertyGroup(String name, List<Property> properties) { + this.name = name; + this.properties = properties; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public List<Property> getProperties() { + return this.properties; + } + + public void setProperties(List<Property> properties) { + this.properties = properties; + } + + public void generateUI() { + return; + } +}
--- /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 <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class PropertySetting implements Property { + + /**The settings name.*/ + protected String name; + + /** The default value.*/ + protected String value; + + /** Additional attributes.*/ + protected HashMap<String, String> attributes; + + /** The editor dialog. */ + protected PropertyEditor editor; + + /** + * Create a new StyleSetting for theme attribution. + */ + public PropertySetting() { + this.attributes = new HashMap<String, String>(); + } + + + /** + * 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<String, String>(); + } + + 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<String> getAttributeList() { + return new ArrayList<String>(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 :
--- /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 <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface Settings extends Serializable { + + /** The output name */ + String getName(); + + /** */ + List<String> getCategories(); + + /** */ + void setSettings(String category, List<Property> settings); + + /** */ + List<Property> getSettings(String category); + +}
--- /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 <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +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; + } +}