Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java @ 1292:bdc270ea6195
Edited item attributes are saved and send to the server on accept.
flys-client/trunk@2898 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 05 Oct 2011 16:29:14 +0000 |
parents | 1d04f35b2cc0 |
children |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java Wed Oct 05 09:26:13 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java Wed Oct 05 16:29:14 2011 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.client.client.ui.chart; import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.layout.VLayout; @@ -12,18 +13,26 @@ import com.smartgwt.client.widgets.form.fields.SpinnerItem; import com.smartgwt.client.widgets.form.fields.ColorPickerItem; import com.smartgwt.client.widgets.form.fields.ComboBoxItem; +import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.events.ItemChangedEvent; +import com.smartgwt.client.widgets.form.events.ItemChangedHandler; import com.smartgwt.client.types.Alignment; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.CollectionItemAttribute; import de.intevation.flys.client.shared.model.Style; import de.intevation.flys.client.shared.model.StyleSetting; +import de.intevation.flys.client.shared.model.FacetRecord; + +import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; +import de.intevation.flys.client.client.services.CollectionItemAttributeService; import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.Config; /** * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> @@ -44,16 +53,24 @@ /** The attributes */ protected CollectionItemAttribute attributes; + /** The selected facet. */ + protected FacetRecord facet; + /** Main layout */ protected VLayout layout; + /** The service used to set collection item attributes. */ + protected CollectionItemAttributeServiceAsync itemAttributeService = + GWT.create(CollectionItemAttributeService.class); public StyleEditorWindow ( Collection collection, - CollectionItemAttribute attributes) + CollectionItemAttribute attributes, + FacetRecord facet) { this.collection = collection; this.attributes = attributes; + this.facet = facet; this.layout = new VLayout(); init(); @@ -82,7 +99,7 @@ cancel.addClickHandler(this); accept.addClickHandler(new ClickHandler() { public void onClick(ClickEvent e) { - + saveStyle(); } }); @@ -90,7 +107,7 @@ buttons.addMember(cancel); buttons.setAlign(Alignment.RIGHT); - layout.addMember(createPropertyGrid("LongitudinalSectionW"));; + layout.addMember(createPropertyGrid());; layout.addMember(buttons); addItem(layout); } @@ -107,14 +124,20 @@ } - protected VLayout createPropertyGrid(String stylename) { - //TODO use the style-(theme-)name from response to get the correct - //attribute set. - + protected VLayout createPropertyGrid() { VLayout properties = new VLayout(); - // get the correct style using the name. - Style s = attributes.getStyle(0); + Style s = attributes.getStyle(facet.getTheme().getFacet()); + + TextItem name = new TextItem("name", "Name"); + name.setValue(facet.getName()); + name.setTitleStyle("color:#000; width:120px"); + name.setTitleAlign(Alignment.LEFT); + name.setDisabled(true); + name.setShowDisabled(false); + DynamicForm f = new DynamicForm(); + f.setFields(name); + properties.addMember(f); for (int i = 0; i < s.getNumSettings(); i ++) { final StyleSetting set = s.getSetting(i); @@ -170,6 +193,14 @@ f.setTitleStyle("color:#000; width:120px"); f.setTitleAlign(Alignment.LEFT); df.setFields(f); + df.addItemChangedHandler(new ItemChangedHandler() { + public void onItemChanged(ItemChangedEvent e) { + String name = e.getItem().getName(); + String newValue = e.getNewValue().toString(); + GWT.log("changed: " + name); + setNewValue(name, newValue); + } + }); return df; } @@ -188,7 +219,10 @@ } String hex = "#"; for (int i = 0; i < values.length; i++) { - hex += Integer.toHexString(values[i]); + if (values[i] < 16) { + hex += "0"; + } + hex += Integer.toHexString(values[i]); } return hex; } @@ -198,7 +232,6 @@ return "0, 0, 0"; } - GWT.log("sub: " + html.substring(1, 3)); int r = Integer.valueOf(html.substring(1, 3), 16); int g = Integer.valueOf(html.substring(3, 5), 16); int b = Integer.valueOf(html.substring(5, 7), 16); @@ -206,5 +239,38 @@ return r + ", " + g + ", " + b; } + protected void saveStyle () { + GWT.log("StyleEditorWindow.saveStyle()"); + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String locale = config.getLocale(); + + itemAttributeService.setCollectionItemAttribute( + this.collection, + attributes.getArtifact(), + url, + locale, + attributes, + new AsyncCallback<Void>() { + public void onFailure (Throwable caught) { + GWT.log("Could not set Collection item attributes."); + } + public void onSuccess(Void v) { + GWT.log("Successfully saved collection item attributes."); + } + }); + + + this.hide(); + } + + protected final void setNewValue(String name, String value) { + Style s = attributes.getStyle(facet.getTheme().getFacet()); + StyleSetting set = s.getSetting(name); + if(name.equals("linecolor")) { + value = htmlToRgb(value); + } + set.setDefaultValue(value); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :