# HG changeset patch # User Raimund Renkert # Date 1337763589 0 # Node ID e75b158184355dd9da31316f87a562564ed3d3f9 # Parent a9cdd62aa73efcd73522b61684e0b7c3a4a6b5c4 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 diff -r a9cdd62aa73e -r e75b15818435 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue May 22 13:30:10 2012 +0000 +++ b/flys-client/ChangeLog Wed May 23 08:59:49 2012 +0000 @@ -1,3 +1,17 @@ +2012-05-23 Raimund Renkert + + * src/main/java/de/intevation/flys/client/client/services/ThemeListingService.java, + src/main/java/de/intevation/flys/client/client/services/ThemeListingServiceAsync.java, + src/main/java/de/intevation/flys/client/server/ThemeListingServiceImpl.java: + New. Service to request themes filtered by name. Response is a list of + theme groups each containing the filtered theme. + + * src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java: + Added a style chooser. The user can now choose predefined styles. + + * src/main/webapp/WEB-INF/web.xml: + Added new service. + 2012-05-22 Sascha L. Teichmann * src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java, diff -r a9cdd62aa73e -r e75b15818435 flys-client/src/main/java/de/intevation/flys/client/client/services/ThemeListingService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ThemeListingService.java Wed May 23 08:59:49 2012 +0000 @@ -0,0 +1,29 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Style; + +/** + * This interface provides a method to list themes filtered by name. + * + * @author Raimund.Renkert + */ +@RemoteServiceRelativePath("themelisting") +public interface ThemeListingService extends RemoteService { + + /** + * This method returns a list of themes filtered by name. + * + * @param locale The locale used for the request. + * + * @return a list of themes provided by the artifact server. + */ + public Map list(String locale, String name) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a9cdd62aa73e -r e75b15818435 flys-client/src/main/java/de/intevation/flys/client/client/services/ThemeListingServiceAsync.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ThemeListingServiceAsync.java Wed May 23 08:59:49 2012 +0000 @@ -0,0 +1,22 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Style; + + +/** + * This interface provides a method to list themes filterd by name. + * + * @author Raimund Renkert + */ +public interface ThemeListingServiceAsync { + + public void list( + String locale, + String name, + AsyncCallback> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a9cdd62aa73e -r e75b15818435 flys-client/src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java --- 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 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 >() { + public void onFailure(Throwable caught) { + GWT.log("No listloaded."); + } + public void onSuccess(Map list) { + GWT.log("Successfully loaded list."); + + styleGroups = list; + Set keys = list.keySet(); + LinkedHashMap valueMap = + new LinkedHashMap(); + 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 : diff -r a9cdd62aa73e -r e75b15818435 flys-client/src/main/java/de/intevation/flys/client/server/ThemeListingServiceImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ThemeListingServiceImpl.java Wed May 23 08:59:49 2012 +0000 @@ -0,0 +1,139 @@ +package de.intevation.flys.client.server; + +import java.util.Map; +import java.util.HashMap; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Style; +import de.intevation.flys.client.shared.model.StyleSetting; +import de.intevation.flys.client.client.services.ThemeListingService; + + +/** + * This interface provides a method to list themes filtered by name. + * + * @author Raimund Renkert + */ +public class ThemeListingServiceImpl +extends RemoteServiceServlet +implements ThemeListingService +{ + private static final Logger logger = + Logger.getLogger(ThemeListingServiceImpl.class); + + + private static final String XPATH_THEME_GROUPS = "/themes/themegroup"; + /** The error message key that is thrown if an error occured while reading + * the supported rivers from server.*/ + public static final String ERROR_NO_GROUPS_FOUND = "error_no_groups_found"; + + + public Map list(String locale, String name) + throws ServerException + { + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + null, + null); + + Element e = ec.create("theme"); + ec.addAttr(e, "name", name); + doc.appendChild(e); + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document res = client.callService(url, "themelisting", doc); + + NodeList themeGroups = (NodeList) XMLUtils.xpath( + res, + XPATH_THEME_GROUPS, + XPathConstants.NODESET, + null); + + if (themeGroups == null || themeGroups.getLength() == 0) { + throw new ServerException(ERROR_NO_GROUPS_FOUND); + } + + int count = themeGroups.getLength(); + + Map theStyles = new HashMap(count); + + for (int i = 0; i < count; i++) { + Element tmp = (Element)themeGroups.item(i); + + String groupName = tmp.getAttribute("name"); + NodeList theTheme = (NodeList) XMLUtils.xpath( + tmp, + "theme", + XPathConstants.NODESET, + null); + + for (int j = 0; j < theTheme.getLength(); j++) { + Element elem = (Element) theTheme.item(j); + theStyles.put(groupName, getStyle(elem)); + } + } + + return theStyles; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_GROUPS_FOUND); + } + + + protected Style getStyle (Element element) { + if (!element.getTagName().equals("theme")) { + return null; + } + + NodeList list = element.getElementsByTagName("field"); + Style style = new Style(); + + style.setName (element.getAttribute("name")); + style.setFacet (element.getAttribute("facet")); + + try { + int ndx = Integer.parseInt(element.getAttribute("index")); + style.setIndex (ndx); + } + catch(NumberFormatException nfe) { + return null; + } + + for(int i = 0; i < list.getLength(); i++) { + Element e = (Element) list.item(i); + StyleSetting set = new StyleSetting ( + e.getAttribute("name"), + e.getAttribute("default"), + e.getAttribute("display"), + e.getAttribute("hints"), + e.getAttribute("type")); + style.appendStyleSetting(set); + } + return style; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a9cdd62aa73e -r e75b15818435 flys-client/src/main/webapp/WEB-INF/web.xml --- a/flys-client/src/main/webapp/WEB-INF/web.xml Tue May 22 13:30:10 2012 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Wed May 23 08:59:49 2012 +0000 @@ -458,6 +458,16 @@ /flys/fileupload + + themelisting + de.intevation.flys.client.server.ThemeListingServiceImpl + + + + themelisting + /flys/themelisting + + FLYS.html