# HG changeset patch # User Raimund Renkert # Date 1324557983 0 # Node ID 237e7450ae2e4416f871208f1be5d8c3e0a10a73 # Parent 6e694603cde1fede816102ef9fd08cc8fee92770 Save output settings in chart properties dialog. flys-client/trunk@3524 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6e694603cde1 -r 237e7450ae2e flys-client/ChangeLog --- a/flys-client/ChangeLog Thu Dec 22 09:28:22 2011 +0000 +++ b/flys-client/ChangeLog Thu Dec 22 12:46:23 2011 +0000 @@ -1,3 +1,17 @@ +2011-12-22 Raimund Renkert + + Save output settings. + + * src/main/java/de/intevation/flys/client/server/CollectionHelper.java: + Create the XML elements for output settings. + + * src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java: + Added handler to UI elements and call CollectionAttributeService to save the + new settings. + + * src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java: + Fixed typo. + 2011-12-22 Ingo Weinzierl * src/main/java/de/intevation/flys/client/server/CSVExportServiceImpl.java: diff -r 6e694603cde1 -r 237e7450ae2e flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java Thu Dec 22 09:28:22 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java Thu Dec 22 12:46:23 2011 +0000 @@ -3,7 +3,9 @@ import java.util.List; import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.tab.TabSet; import com.smartgwt.client.widgets.tab.Tab; @@ -24,6 +26,7 @@ import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; import com.smartgwt.client.types.Alignment; +import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.ui.OutputTab; import de.intevation.flys.client.shared.model.Property; @@ -34,8 +37,12 @@ import de.intevation.flys.client.shared.model.IntegerProperty; import de.intevation.flys.client.shared.model.StringProperty; import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.OutputSettings; +import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.client.services.CollectionAttributeService; +import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; + /** * @author Raimund Renkert */ @@ -46,12 +53,22 @@ /** The interface that provides i18n messages. */ protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + protected CollectionAttributeServiceAsync updater = + GWT.create(CollectionAttributeService.class); + /** The tab called the editor window. */ protected OutputTab tab; /** The tabset for chart properties */ protected TabSet tabs; + /** The collection */ + protected Collection collection; + + /** The output settings */ + protected OutputSettings settings; + + /** * Setup editor dialog. * @param callerTab The tab called the editor window. @@ -72,9 +89,9 @@ setCanDragResize(true); - Collection c = tab.getCollectionView().getCollection(); + collection = tab.getCollectionView().getCollection(); String outputName = tab.getOutputName(); - Settings settings = c.getSettings(outputName); + settings = (OutputSettings)collection.getSettings(outputName); if (settings == null) { return; @@ -91,7 +108,6 @@ } else if (props.get(j) instanceof PropertySetting) { PropertySetting p = (PropertySetting)props.get(j); - if (p.getAttribute("display").equals("false")) { continue; } @@ -107,7 +123,7 @@ cancel.addClickHandler(this); accept.addClickHandler(new ClickHandler() { public void onClick(ClickEvent e) { - + updateCollection(); } }); @@ -152,23 +168,19 @@ StringProperty label = (StringProperty)pg.getPropertyByName("label"); FormItem title = createStringProperty(label); - title.setValue(label.getValue()); IntegerProperty fontsize = (IntegerProperty)pg.getPropertyByName("font-size"); FormItem fs = createIntegerProperty(fontsize); - fs.setValue(fontsize.getValue()); DoubleProperty upper = (DoubleProperty)pg.getPropertyByName("upper"); final FormItem range1 = createDoubleProperty(upper); - range1.setValue(upper.getValue()); range1.setWidth(50); DoubleProperty lower = (DoubleProperty)pg.getPropertyByName("lower"); final FormItem range2 = createDoubleProperty(lower); - range2.setValue(lower.getValue()); range2.setWidth(50); BooleanProperty fixation = @@ -187,12 +199,10 @@ } }); if (fixation.getValue().equals("true")) { - fix.setValue(true); range1.enable(); range2.enable(); } else { - fix.setValue(false); range1.disable(); range2.disable(); } @@ -221,19 +231,22 @@ * */ protected DynamicForm generatePropertySetting(Property setting) { + final PropertySetting s = (PropertySetting)setting; DynamicForm form = new DynamicForm(); + FormItem item = new FormItem(); if (setting instanceof BooleanProperty) { - form.setFields(createBooleanProperty((BooleanProperty)setting)); + item = createBooleanProperty((BooleanProperty)setting); } else if (setting instanceof DoubleProperty) { - form.setFields(createDoubleProperty((DoubleProperty)setting)); + item = createDoubleProperty((DoubleProperty)setting); } else if (setting instanceof IntegerProperty) { - form.setFields(createIntegerProperty((IntegerProperty)setting)); + item = createIntegerProperty((IntegerProperty)setting); } else if (setting instanceof StringProperty) { - form.setFields(createStringProperty((StringProperty)setting)); + item = createStringProperty((StringProperty)setting); } + form.setFields(item); return form; } @@ -241,7 +254,7 @@ /** * */ - protected FormItem createStringProperty(StringProperty sp) { + protected FormItem createStringProperty(final StringProperty sp) { String name = sp.getName(); if (name.contains("-")) { name = name.replace("-", "_"); @@ -249,6 +262,19 @@ TextItem item = new TextItem(); item.setTitle(MSG.getString(name)); item.setTitleAlign(Alignment.LEFT); + item.setValue(sp.getValue()); + item.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent e) { + String val; + if (e.getValue() == null) { + val = ""; + } + else { + val = e.getValue().toString(); + } + sp.setValue(val); + } + }); return item; } @@ -256,7 +282,7 @@ /** * */ - protected FormItem createBooleanProperty(BooleanProperty bp) { + protected FormItem createBooleanProperty(final BooleanProperty bp) { String name = bp.getName(); if (name.contains("-")) { name = name.replace("-", "_"); @@ -266,6 +292,24 @@ item.setLabelAsTitle(true); item.setTitleStyle("color:#000;"); item.setTitleAlign(Alignment.LEFT); + if(bp.getValue().equals("true")) { + item.setValue(true); + } + else { + item.setValue(false); + } + item.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent e) { + String val; + if (e.getValue() == null) { + val = ""; + } + else { + val = e.getValue().toString(); + } + bp.setValue(val); + } + }); return item; } @@ -273,7 +317,7 @@ /** * */ - protected FormItem createDoubleProperty(DoubleProperty dp) { + protected FormItem createDoubleProperty(final DoubleProperty dp) { String name = dp.getName(); if (name.contains("-")) { name = name.replace("-", "_"); @@ -282,6 +326,19 @@ TextItem item = new TextItem(); item.setTitle(MSG.getString(name)); item.setTitleAlign(Alignment.LEFT); + item.setValue(dp.getValue()); + item.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent e) { + String val; + if (e.getValue() == null) { + val = ""; + } + else { + val = e.getValue().toString(); + } + dp.setValue(val); + } + }); return item; } @@ -289,7 +346,7 @@ /** * */ - protected FormItem createIntegerProperty(IntegerProperty ip) { + protected FormItem createIntegerProperty(final IntegerProperty ip) { String name = ip.getName(); if (name.contains("-")) { name = name.replace("-", "_"); @@ -298,6 +355,42 @@ TextItem item = new TextItem(); item.setTitle(MSG.getString(name)); item.setTitleAlign(Alignment.LEFT); + item.setValue(ip.getValue()); + item.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent e) { + String val; + if (e.getValue() == null) { + val = ""; + } + else { + val = e.getValue().toString(); + } + ip.setValue(val); + } + }); return item; } + + + protected void updateCollection() { + final Config config = Config.getInstance(); + final String loc = config.getLocale(); + + GWT.log("PropertiesEditor.updateCollection via RPC now"); + this.hide(); + + updater.update(collection, loc, new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Could not update collection attributes."); + SC.warn(MSG.getString(caught.getMessage())); + } + + + public void onSuccess(Collection collection) { + } + }); + + } + + } diff -r 6e694603cde1 -r 237e7450ae2e 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 Thu Dec 22 09:28:22 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Thu Dec 22 12:46:23 2011 +0000 @@ -178,6 +178,22 @@ } } + Document doc = out.getOwnerDocument(); + + ElementCreator settingscr = new ElementCreator(doc, "", ""); + + Settings settings = collection.getSettings(mode.getName()); + if (settings == null || + settings.getCategories().size() == 0) + { + logger.debug("No settings for output mode: " + mode.getName()); + return null; + } + Element s = createSettingsElement(settingscr, collection, settings); + if (s != null) { + out.appendChild(s); + } + logger.info(XMLUtils.toString(out)); return out; } @@ -285,6 +301,86 @@ /** + * + */ + protected static Element createSettingsElement( + ElementCreator cr, + Collection c, + Settings s) + { + logger.debug("CollectionHelper.createSettingsElement"); + Element settings = cr.create("settings"); + + List categories = s.getCategories(); + + for (String category: categories) { + Element cat =cr.create(category); + settings.appendChild(cat); + List props = s.getSettings(category); + for (Property p: props) { + if (p instanceof PropertyGroup) { + Element prop = createPropertyGroupElement(cr, + (PropertyGroup)p); + cat.appendChild(prop); + } + else if (p instanceof PropertySetting) { + Element prop = createPropertyElement (cr, + (PropertySetting)p); + cat.appendChild(prop); + } + } + } + return settings; + } + + + /** + * + */ + protected static Element createPropertyGroupElement( + ElementCreator cr, + PropertyGroup pg) + { + Element e = cr.create(pg.getName()); + + List list = pg.getProperties(); + for (Property p: list) { + Element pe = createPropertyElement(cr, (PropertySetting)p); + e.appendChild(pe); + } + return e; + } + + + /** + * + */ + protected static Element createPropertyElement( + ElementCreator cr, + PropertySetting p) + { + Element e = cr.create(p.getName()); + + if(p instanceof BooleanProperty) { + cr.addAttr(e, "type", "boolean", false); + } + else if(p instanceof DoubleProperty) { + cr.addAttr(e, "type", "double", false); + } + else if(p instanceof IntegerProperty) { + cr.addAttr(e, "type", "integer", false); + } + else if(p instanceof StringProperty) { + cr.addAttr(e, "type", "string", false); + } + + e.setTextContent(p.getValue()); + cr.addAttr(e, "display", p.getAttribute("display"), false); + return e; + } + + + /** * Take the DESCRIBE document of the Collections describe() * operation and extracts the information about the collection itself and * the collection items. @@ -512,7 +608,6 @@ * */ protected static Settings parseSettings(String outName, Element node) { - logger.info("parseSettings(String,Element)"); OutputSettings set = new OutputSettings(outName); NodeList elements = node.getElementsByTagName("settings"); @@ -558,7 +653,6 @@ * */ protected static Property parseSettingsGroup(Element group) { - logger.debug("parseSettingsGroup"); PropertyGroup p = new PropertyGroup(); p.setName(group.getTagName()); @@ -576,7 +670,6 @@ * */ protected static Property parseSetting(Element property){ - logger.debug("parseSetting"); NamedNodeMap attrMap = property.getAttributes(); int attrNum = attrMap != null ? attrMap.getLength() : 0; diff -r 6e694603cde1 -r 237e7450ae2e flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java Thu Dec 22 09:28:22 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java Thu Dec 22 12:46:23 2011 +0000 @@ -47,8 +47,8 @@ this.value = value; } - public void setAttribute(String key, String Value) { - attributes.put(key, value); + public void setAttribute(String k, String v) { + attributes.put(k, v); } public String getName() {