# HG changeset patch # User Christian Lins # Date 1354017010 -3600 # Node ID b87073a05f9d86aed4667480422ad7c3b74a4ae8 # Parent 4bd42fe098b416f7ed3bf43e6adc893c936155d4 flys-client: Patch to render combobox options as clickable links. The way of passing data arguments to the links and further to the Artifact feeding service is somewhat hacked and should be refactored (later...). diff -r 4bd42fe098b4 -r b87073a05f9d flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Tue Nov 27 10:49:57 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Tue Nov 27 12:50:10 2012 +0100 @@ -1,5 +1,12 @@ package de.intevation.flys.utils; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.artifacts.model.MapserverStyle; +import de.intevation.flys.artifacts.model.MapserverStyle.Clazz; +import de.intevation.flys.artifacts.model.MapserverStyle.Expression; +import de.intevation.flys.artifacts.model.MapserverStyle.Label; +import de.intevation.flys.artifacts.model.MapserverStyle.Style; + import java.awt.Color; import java.awt.Font; @@ -10,13 +17,6 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.flys.artifacts.model.MapserverStyle; -import de.intevation.flys.artifacts.model.MapserverStyle.Clazz; -import de.intevation.flys.artifacts.model.MapserverStyle.Expression; -import de.intevation.flys.artifacts.model.MapserverStyle.Label; -import de.intevation.flys.artifacts.model.MapserverStyle.Style; - /** * Utility to deal with themes and their representations. @@ -627,6 +627,12 @@ return createWSPLGENStyle(categories).toString(); } + /** + * Creates a style for the Mapfile template used by MapfileGenerator + * to generate floodmaps. + * @param categories + * @return + */ protected static MapserverStyle createWSPLGENStyle(NodeList categories) { MapserverStyle ms = new MapserverStyle(); diff -r 4bd42fe098b4 -r b87073a05f9d flys-artifacts/src/main/java/de/intevation/flys/wsplgen/WSPLGENCallable.java --- a/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/WSPLGENCallable.java Tue Nov 27 10:49:57 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/WSPLGENCallable.java Tue Nov 27 12:50:10 2012 +0100 @@ -1,14 +1,14 @@ package de.intevation.flys.wsplgen; +import de.intevation.artifacts.CallContext; +import de.intevation.flys.artifacts.model.map.WSPLGENJob; + import java.io.File; import java.io.IOException; import java.util.concurrent.Callable; import org.apache.log4j.Logger; -import de.intevation.artifacts.CallContext; -import de.intevation.flys.artifacts.model.map.WSPLGENJob; - /** * A Callable that is used to start and observe an external Process for WSPLGEN. @@ -63,8 +63,6 @@ protected void execute(String[] args, File dir) { logger.info("Start JobExecutor for artifact: " + dir.getName()); - String errorMsg = null; - try { synchronized (this) { process = Runtime.getRuntime().exec(args, null, dir); diff -r 4bd42fe098b4 -r b87073a05f9d flys-client/src/main/java/de/intevation/flys/client/client/ui/LinkSelection.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LinkSelection.java Tue Nov 27 10:49:57 2012 +0100 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LinkSelection.java Tue Nov 27 12:50:10 2012 +0100 @@ -36,9 +36,6 @@ /** The message class that provides i18n strings.*/ protected FLYSConstants messages = GWT.create(FLYSConstants.class); - /** The combobox.*/ - protected DynamicForm form; - /** The selected river*/ protected Data river; @@ -117,8 +114,6 @@ layout.setAlign(VerticalAlignment.TOP); layout.setHeight(25); - - form = new DynamicForm(); VLayout formLayout = new VLayout(); formLayout.setLayoutLeftMargin(60); diff -r 4bd42fe098b4 -r b87073a05f9d flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java Tue Nov 27 10:49:57 2012 +0100 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java Tue Nov 27 12:50:10 2012 +0100 @@ -49,7 +49,7 @@ moduleSelection = new ModuleSelection(); Canvas form = moduleSelection.create(data); - form.setWidth(250); + form.setWidth(400); form.setLayoutAlign(VerticalAlignment.TOP); // TODO implement event handling in the river map (here? or in LinkSelection) diff -r 4bd42fe098b4 -r b87073a05f9d flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java Tue Nov 27 10:49:57 2012 +0100 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java Tue Nov 27 12:50:10 2012 +0100 @@ -1,22 +1,28 @@ package de.intevation.flys.client.client.ui; import com.google.gwt.core.client.GWT; - import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.LinkItem; import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.SpacerItem; +import com.smartgwt.client.widgets.form.fields.events.ClickEvent; +import com.smartgwt.client.widgets.form.fields.events.ClickHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.StepForwardEvent; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.DataList; import de.intevation.flys.client.shared.model.DefaultData; import de.intevation.flys.client.shared.model.DefaultDataItem; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; @@ -36,7 +42,9 @@ protected FLYSConstants messages = GWT.create(FLYSConstants.class); /** The combobox.*/ - protected DynamicForm form; + protected DynamicForm form = new DynamicForm(); + + public static final int COMBOBOX_THRESHOLD = 20; /** @@ -50,16 +58,21 @@ */ @Override public Canvas create(DataList data) { - VLayout v = new VLayout(); - v.setMembersMargin(10); + if (data.size() > COMBOBOX_THRESHOLD) { + VLayout v = new VLayout(); + v.setMembersMargin(10); + v.addMember(createComboboxWidget(data)); + v.addMember(getNextButton()); + return v; + } + else { + return createListWidget(data); + } + } - Canvas content = createWidget(data); - Canvas button = getNextButton(); - v.addMember(content); - v.addMember(button); - - return v; + protected Canvas createWidget(DataList data) { + return create(data); } @@ -98,15 +111,83 @@ } - /** - * This method creates the content of the widget. - * - * @param data The {@link DataList} object. - * - * @return a combobox. - */ - protected Canvas createWidget(DataList data) { - GWT.log("SelectProvider - create()"); + protected Canvas createListWidget(DataList data) { + VLayout layout = new VLayout(); + layout.setAlign(VerticalAlignment.TOP); + layout.setHeight(25); + layout.setWidth("100%"); + + VLayout formLayout = new VLayout(); + formLayout.setLayoutTopMargin(20); + formLayout.setLayoutLeftMargin(50); + + ClickHandler handler = new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + LinkItem li = (LinkItem)event.getItem(); + String attr = li.getAttribute(li.getName()); + GWT.log("li.getTarget: " + attr + " " + li.getName()); + DataItem item = new DefaultDataItem( + attr, + null, + attr); + + Data d = new DefaultData( + li.getName(), + null, + null, + new DataItem [] { item }); + + Data [] odata = getData(); + Data [] ndata = new Data[odata.length+1]; + System.arraycopy(odata, 0, ndata, 0, odata.length); + ndata[odata.length] = d; + + fireStepForwardEvent(new StepForwardEvent(ndata)); + } + }; + + for (int i = 0, size = data.size(); i < size; i++) { + Data d = data.get(i); + + Label label = new Label(d.getDescription()); + label.setValign(VerticalAlignment.TOP); + label.setHeight(20); + label.setWidth(400); + + LinkedHashMap initial = new LinkedHashMap(); + ArrayList formItems = new ArrayList(); + + for (DataItem item: d.getItems()) { + initial.put(item.getLabel().replace(' ', '_'), item.getStringValue()); + GWT.log("put: " + item.getLabel().replace(' ', '_') + "=" + item.getStringValue()); + + LinkItem link = new LinkItem(d.getLabel()); + link.setLinkTitle(item.getLabel()); // i18n text of the link + link.setAttribute(d.getLabel(), item.getStringValue()); // e.g. "calculation_mode":"foo" + link.setShowTitle(false); + link.setEndRow(true); + link.setWidth("350px"); + + SpacerItem space = new SpacerItem(); + space.setWidth(15); + formItems.add(space); + formItems.add(link); + + link.addClickHandler(handler); + } + + form.setFields(formItems.toArray(new FormItem[0])); + form.setValues(initial); + + layout.addMember(label); + layout.addMember(form); + } + return layout; + } + + protected Canvas createComboboxWidget(DataList data) { + GWT.log("SelectProvider.createComboboxWidget()"); VLayout layout = new VLayout(); layout.setAlign(VerticalAlignment.TOP); @@ -114,8 +195,6 @@ LinkedHashMap initial = new LinkedHashMap(); - form = new DynamicForm(); - int size = data.size(); for (int i = 0; i < size; i++) { @@ -142,7 +221,6 @@ defaultSet = true; } - // I was here. Me 2. for (DataItem item: d.getItems()) { if (!defaultSet && first) { initial.put(d.getLabel(), item.getStringValue()); @@ -178,7 +256,7 @@ int i = 0; while (keys.hasNext()) { - String fieldname = (String) keys.next(); + String fieldname = ((String) keys.next()).replace('_', ' '); String selection = (String) values.get(fieldname); DataItem item = new DefaultDataItem(fieldname, null, selection);