Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java @ 2540:e75b15818435
Added a style chooser to the style editor to provide predefined styles and
implemented a service to request theme styles.
flys-client/trunk@4471 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 23 May 2012 08:59:49 +0000 |
parents | 8f36d4b5890c |
children | d632a6526ad9 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java Tue May 22 13:30:10 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java Wed May 23 08:59:49 2012 +0000 @@ -1,7 +1,10 @@ package de.intevation.flys.client.client.ui; import java.util.Arrays; +import java.util.Map; import java.util.LinkedHashMap; +import java.util.Set; +import java.util.Iterator; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -9,6 +12,7 @@ import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.Button; @@ -23,6 +27,9 @@ 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.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; + import com.smartgwt.client.types.Alignment; import de.intevation.flys.client.shared.model.Collection; @@ -34,6 +41,9 @@ import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; import de.intevation.flys.client.client.services.CollectionItemAttributeService; +import de.intevation.flys.client.client.services.ThemeListingServiceAsync; +import de.intevation.flys.client.client.services.ThemeListingService; + import de.intevation.flys.client.client.ui.ThemePanel; import de.intevation.flys.client.client.FLYSConstants; @@ -64,10 +74,22 @@ /** Main layout. */ protected VLayout layout; + protected VLayout properties; + protected Canvas container; + + protected Map<String, Style> styleGroups; + + protected Style current; + + protected SelectItem styleChooser; + /** The service used to set collection item attributes. */ protected CollectionItemAttributeServiceAsync itemAttributeService = GWT.create(CollectionItemAttributeService.class); + /** The service used to request a list of themes. */ + protected ThemeListingServiceAsync themeListingService = + GWT.create(ThemeListingService.class); /** * Setup editor dialog. @@ -84,7 +106,38 @@ this.attributes = attributes; this.facet = facet; this.layout = new VLayout(); + this.properties = new VLayout(); + this.container = new Canvas(); + this.styleChooser = new SelectItem("style", "Style"); + styleChooser.setTitleStyle("color:#000;"); + styleChooser.setTitleAlign(Alignment.LEFT); + styleChooser.setValue("aktuell"); + styleChooser.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent ce) { + String value = ce.getValue().toString(); + Style s = null; + if (value.equals("aktuell")) { + s = current; + } + else if (styleGroups.containsKey(value)) { + s = styleGroups.get(value); + } + + if (s != null) { + setNewStyle(s); + properties.removeMember(container); + container = createPropertyGrid(s); + properties.addMember(container); + } + } + }); + + DynamicForm f = new DynamicForm(); + f.setFields(styleChooser); + f.setColWidths("40%", "60%"); + + layout.addMember(f); init(); initPanels(); } @@ -101,6 +154,41 @@ layout.setWidth100(); layout.setHeight100(); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + Theme theme = facet.getTheme(); + Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); + String name = style.getName(); + this.current = style; + + themeListingService.list( + locale, + name, + new AsyncCallback<Map<String, Style> >() { + public void onFailure(Throwable caught) { + GWT.log("No listloaded."); + } + public void onSuccess(Map<String, Style> list) { + GWT.log("Successfully loaded list."); + + styleGroups = list; + Set keys = list.keySet(); + LinkedHashMap<String, String> valueMap = + new LinkedHashMap<String, String>(); + valueMap.put("aktuell", "Aktuell"); + Iterator i = keys.iterator(); + while (i.hasNext()) { + String s = i.next().toString(); + Style tmp = styleGroups.get(s); + tmp.setFacet(facet.getTheme().getFacet()); + tmp.setIndex(0); + valueMap.put(s, s); + } + styleChooser.setValueMap(valueMap); + } + }); } @@ -123,9 +211,12 @@ buttons.setAlign(Alignment.CENTER); buttons.setHeight(30); - VLayout propGrid = createPropertyGrid(); + Theme theme = facet.getTheme(); + Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); - layout.addMember(propGrid); + container = createPropertyGrid(style); + properties.addMember(container); + layout.addMember(properties); layout.addMember(buttons); addItem(layout); setWidth(400); @@ -155,11 +246,8 @@ * This method creates the property grid for available styling attributes. * @return The layout containing the UI elements. */ - protected VLayout createPropertyGrid() { - VLayout properties = new VLayout(); - - Theme theme = facet.getTheme(); - Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); + protected VLayout createPropertyGrid(Style style) { + VLayout vl = new VLayout(); StaticTextItem name = new StaticTextItem("name", "Name"); name.setValue(facet.getName()); @@ -167,15 +255,17 @@ name.setTitleAlign(Alignment.LEFT); name.setDisabled(true); name.setShowDisabled(false); + DynamicForm form = new DynamicForm(); form.setFields(name); form.setColWidths("40%", "60%"); - properties.addMember(form); + + vl.addMember(form); if (style == null) { - SC.warn("No style for " + theme.getFacet() + " found."); - return properties; + SC.warn("No style found."); + return vl; } // Done via array to keep the order. @@ -212,7 +302,7 @@ set.getName(), set.getType(), set.getDefaultValue()); - properties.addMember(property); + vl.addMember(property); } // Add settings not in whitelist above. @@ -227,10 +317,10 @@ set.getName(), set.getType(), set.getDefaultValue()); - properties.addMember(property); + vl.addMember(property); } - return properties; + return vl; } @@ -495,5 +585,13 @@ } set.setDefaultValue(value); } + + + protected final void setNewStyle(Style style) { + Theme t = facet.getTheme(); + Style s = attributes.getStyle(t.getFacet(), t.getIndex()); + attributes.removeStyle(s.getName()); + attributes.appendStyle(style); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :