Mercurial > dive4elements > river
changeset 2505:87ac5c532523
First part of the UI for fixing analysis parameter.
flys-client/trunk@4350 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/flys-client/ChangeLog Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/ChangeLog Mon May 07 13:22:43 2012 +0000 @@ -1,3 +1,39 @@ +2012-05-07 Raimund Renkert <raimund.renkert@intevation.de> + + First implementation for fixing analysis parameter. + + * src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java: + Updated services implementation. The service now returns an info + object containing the fixing overview data and html representation. + + * src/main/java/de/intevation/flys/client/shared/model/FixingsOverviewInfo.java: + New. Info object containing overview data and html representation. + + * src/main/java/de/intevation/flys/client/client/services/FixingsOverviewServiceAsync.java, + src/main/java/de/intevation/flys/client/client/services/FixingsOverviewService.java: + Updated interfaces. + + * src/main/java/de/intevation/flys/client/client/ui/fixation, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixQSelectPanel.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixEventSelect.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java: + New. Panels for fixing analysis parameter. + + * src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java: + Added new UI-Provider to factory. + + * src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl: + Modified the stylesheet to take a parameter containing a callback. + + * src/main/java/de/intevation/flys/client/client/FLYSConstants.java, + src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties: + Added i18n strings. + 2012-05-04 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Mon May 07 13:22:43 2012 +0000 @@ -321,6 +321,13 @@ String start_year(); String end_year(); + + String period(); + + String gauge_class(); + + String eventselect(); + // Elevation window String ele_window_title(); @@ -553,6 +560,8 @@ String error_invalid_date(); + String error_wrong_date(); + String bottom_edge(); String top_edge();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Mon May 07 13:22:43 2012 +0000 @@ -80,7 +80,7 @@ resultCount = Hits start_year = Start end_year = End - +period = Period # Header images flysLogo = images/flys_logo.gif bfgLogo = images/bfg_logo.gif @@ -201,6 +201,8 @@ at = AT pdf = PDF computed_dischargecurve_at_export = AT Export +gauge_class = Gauge Class +eventselect = Eventselection chart_themepanel_header_themes = Theme chart_themepanel_header_actions = Actions @@ -246,6 +248,7 @@ error_same_waterlevels_in_pair = Error - minuend and subtrahend have to differ. error_not_logged_in = You need to log in before you are allowed to start your work. error_load_parameterization = Could not load the parameterization. +error_wrong_date = Please enter valid dates. error_feed_no_data = No input data found. error_feed_from_out_of_range = The lower value is bigger than the upper value.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Mon May 07 13:22:43 2012 +0000 @@ -80,7 +80,7 @@ resultCount = Treffer start_year = Start end_year = Ende - +period = Zeitraum # Header images flysLogo = images/flys_logo.gif bfgLogo = images/bfg_logo.gif @@ -201,6 +201,8 @@ at = AT pdf = PDF computed_dischargecurve_at_export = AT Export +gauge_class = Abflussklasse +eventselect = Ereignisauswahl chart_themepanel_header_themes = Thema chart_themepanel_header_actions = Aktionen @@ -246,6 +248,7 @@ error_same_waterlevels_in_pair = Error - minuend and subtrahend m\u00fcssen sich unterscheiden. error_not_logged_in = Sie m\u00fcssen sich erst einloggen um mit der Arbeit beginnen zu k\u00f6nnen. error_load_parameterization = Fehler beim Laden der Parametrisierung. +error_wrong_date = Bitte geben Sie gültige Daten ein. error_feed_no_data = Keine Eingabedaten gefunden. error_feed_from_out_of_range = Der untere Wert liegt au\u00dferhalb des g\u00fcltigen Wertebereiches.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Mon May 07 13:22:43 2012 +0000 @@ -80,6 +80,7 @@ resultCount = Hits start_year = Start end_year = end +period = Period # Header images flysLogo = images/flys_logo.gif @@ -201,6 +202,8 @@ at = AT pdf = PDF computed_dischargecurve_at_export = AT Export +gauge_class = Gauge Class +eventselect = Eventselection chart_themepanel_header_themes = Theme chart_themepanel_header_actions = Actions @@ -246,6 +249,7 @@ error_same_waterlevels_in_pair = Error - minuend and subtrahend have to differ. error_not_logged_in = You need to log in before you are allowed to start your work. error_load_parameterization = Could not load the parameterization. +error_wrong_date = Please enter valid dates. error_feed_no_data = No input data found. error_feed_from_out_of_range = The lower value is bigger than the upper value.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewService.java Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewService.java Mon May 07 13:22:43 2012 +0000 @@ -5,14 +5,17 @@ import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo; + @RemoteServiceRelativePath("fixings-overview") public interface FixingsOverviewService extends RemoteService { - String generateOverview( - String locale, - String uuid, - boolean checkboxes, - String filter + FixingsOverviewInfo generateOverview( + String locale, + String uuid, + String filter, + boolean checkbox, + String callback ) throws ServerException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewServiceAsync.java Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewServiceAsync.java Mon May 07 13:22:43 2012 +0000 @@ -2,13 +2,16 @@ import com.google.gwt.user.client.rpc.AsyncCallback; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo; + public interface FixingsOverviewServiceAsync { void generateOverview( String locale, String uuid, - boolean checkboxes, String filter, - AsyncCallback<String> callback); + boolean checkbox, + String callbackFunction, + AsyncCallback<FixingsOverviewInfo> callback); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java Mon May 07 13:22:43 2012 +0000 @@ -2,6 +2,10 @@ import de.intevation.flys.client.shared.model.User; +import de.intevation.flys.client.client.ui.fixation.FixLocationPanel; +import de.intevation.flys.client.client.ui.fixation.FixPeriodPanel; +import de.intevation.flys.client.client.ui.fixation.FixGaugeSelectPanel; +import de.intevation.flys.client.client.ui.fixation.FixEventSelect; /** * Depending on the provider the state declared, return a UIProvider. @@ -81,6 +85,18 @@ else if (uiProvider.equals("gaugetimerange")) { return new GaugeTimeRangePanel(); } + else if (uiProvider.equals("fix.location_panel")) { + return new FixLocationPanel(); + } + else if (uiProvider.equals("fix.period_panel")) { + return new FixPeriodPanel(); + } + else if (uiProvider.equals("fix.gaugeselect_panel")) { + return new FixGaugeSelectPanel(); + } + else if (uiProvider.equals("fix.event_panel")) { + return new FixEventSelect(); + } else { return new SelectProvider(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixEventSelect.java Mon May 07 13:22:43 2012 +0000 @@ -0,0 +1,103 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.List; +import java.util.ArrayList; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; + +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.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixEventSelect +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected List<String> events; + + public FixEventSelect() { + htmlOverview = ""; + events = new ArrayList<String>(); + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Canvas title = new Label(MESSAGES.eventselect()); + title.setHeight("25px"); + + layout.addMember(title); + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + return (Data[]) data.toArray(new Data[data.size()]); + } + + + @Override + public void setValues(String cid, boolean checked) { + if (checked) { + events.add(cid); + } + else { + if (events.contains(cid)) { + events.remove(cid); + } + } + } + + + @Override + public boolean renderCheckboxes() { + return true; + } + + + public void dumpGWT(String cid) { + GWT.log("Setting values for cId: " + cid); + GWT.log("River: " + fixInfo.getRiver()); + GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); + GWT.log("Name: " + fixInfo.getEventByCId(cid).getName()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java Mon May 07 13:22:43 2012 +0000 @@ -0,0 +1,175 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.List; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import java.lang.NumberFormatException; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; + +import de.intevation.flys.client.client.FLYSConstants; + +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; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixGaugeSelectPanel +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected String first; + protected String second; + + protected SelectItem from; + protected SelectItem to; + + public FixGaugeSelectPanel() { + htmlOverview = ""; + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Label title = new Label(MESSAGES.gauge_class()); + title.setHeight(25); + + LinkedHashMap map = new LinkedHashMap(); + map.put("0", "0"); + map.put("1", "1"); + map.put("2", "2"); + map.put("3", "3"); + + from = new SelectItem(MESSAGES.from()); + to = new SelectItem(MESSAGES.to()); + + from.setShowTitle(false); + to.setShowTitle(false); + from.setValueMap(map); + from.setWidth(60); + to.setValueMap(map); + to.setWidth(60); + + DynamicForm form = new DynamicForm(); + StaticTextItem separator = new StaticTextItem("separator"); + separator.setShowTitle(false); + separator.setValue(MESSAGES.to()); + form.setNumCols(5); + form.setFields(from, separator, to); + + layout.addMember(title); + layout.addMember(form); + + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data f = getData(items, "q1"); + Data t = getData(items, "q2"); + DataItem[] fItems = f.getItems(); + DataItem[] tItems = t.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(fItems[0].getLabel()); + sb.append(" " + MESSAGES.to() + " "); + sb.append(tItems[0].getLabel()); + + Label old = new Label(sb.toString()); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveClassValues(); + if (valid) { + DataItem firstItem = new DefaultDataItem("q1", "q1", this.first); + DataItem secItem = new DefaultDataItem("q2", "q2", this.second); + data.add(new DefaultData( + "q1", + null, + null, + new DataItem[] { firstItem })); + data.add(new DefaultData( + "q2", + null, + null, + new DataItem[] { secItem })); + } + return (Data[]) data.toArray(new Data[data.size()]); + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } + + + protected boolean saveClassValues() { + String v1 = from.getValueAsString(); + String v2 = to.getValueAsString(); + try { + int v1i = Integer.valueOf(v1).intValue(); + int v2i = Integer.valueOf(v2).intValue(); + if (v1i <= v2i) { + this.first = v1; + this.second = v2; + return true; + } + } + catch(NumberFormatException nfe) { + return false; + } + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java Mon May 07 13:22:43 2012 +0000 @@ -0,0 +1,190 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.List; +import java.util.ArrayList; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.ui.DoubleRangePanel; + +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; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixLocationPanel +extends FixationPanel +implements BlurHandler +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + /** The constant name of the input field to enter locations.*/ + public static final String FIELD_VALUE_LOCATION = "location"; + + /** The constant name of the input field to enter distance.*/ + public static final String FIELD_VALUE_DISTANCE = "distance"; + + DoubleRangePanel inputPanel; + + double from; + double to; + double step; + + public FixLocationPanel() { + htmlOverview = ""; + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Canvas title = new Label(MESSAGES.distance()); + title.setHeight("25px"); + + inputPanel = new DoubleRangePanel( + MESSAGES.unitFrom(), + MESSAGES.unitTo(), + MESSAGES.unitWidth(), + 5d, + 10d, + 1d, + 240, + this); + + layout.addMember(title); + layout.addMember(inputPanel); + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data f = getData(items, "from"); + Data t = getData(items, "to"); + Data s = getData(items, "step"); + DataItem[] fItems = f.getItems(); + DataItem[] tItems = t.getItems(); + DataItem[] sItems = s.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(fItems[0].getLabel()); + sb.append(" " + MESSAGES.unitFrom() + " "); + sb.append(tItems[0].getLabel()); + sb.append(" " + MESSAGES.unitTo() + " "); + sb.append(sItems[0].getLabel()); + sb.append(" " + MESSAGES.unitWidth()); + + Label old = new Label(sb.toString()); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveRangeValues(inputPanel); + if (valid) { + String f = Double.valueOf(this.from).toString(); + String t = Double.valueOf(this.to).toString(); + String s = Double.valueOf(this.step).toString(); + DataItem fi = new DefaultDataItem("from", "from", f); + DataItem ti = new DefaultDataItem("to", "to", t); + DataItem si = new DefaultDataItem("step", "step", s); + data.add(new DefaultData("from", null, null, new DataItem[]{ fi })); + data.add(new DefaultData("to", null, null, new DataItem[]{ ti })); + data.add(new DefaultData("step", null, null, new DataItem[]{ si })); + } + // what else? + return (Data[]) data.toArray(new Data[data.size()]); + } + + + protected boolean saveRangeValues(DoubleRangePanel p) { + FormItem[] items = p.getFields(); + boolean valid = p.validateForm(); + + if(valid) { + this.from = p.getFrom(); + this.to = p.getTo(); + this.step = p.getStep(); + } + return valid; + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } + + + /** + * This method is used to validate the inserted data in the form fields. + * + * @param event The BlurEvent that gives information about the FormItem that + * has been modified and its value. + */ + public void onBlur(BlurEvent event) { + FormItem item = event.getItem(); + String field = item.getFieldName(); + + if (field == null) { + return; + } + DoubleRangePanel p = (DoubleRangePanel) event.getForm(); + } + + + public void dumpGWT(String cid) { + GWT.log("Setting values for cId: " + cid); + GWT.log("River: " + fixInfo.getRiver()); + GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); + GWT.log("Name: " + fixInfo.getEventByCId(cid).getName()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java Mon May 07 13:22:43 2012 +0000 @@ -0,0 +1,161 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.List; +import java.util.ArrayList; +import java.util.Date; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.util.SC; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.DateRangeItem; + +import de.intevation.flys.client.client.FLYSConstants; + +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; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixPeriodPanel +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + DateRangeItem inputPanel; + + long start; + long end; + + public FixPeriodPanel() { + htmlOverview = ""; + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Label title = new Label(MESSAGES.period()); + title.setHeight("25px"); + + DynamicForm form = new DynamicForm(); + inputPanel = new DateRangeItem(); + inputPanel.setToTitle(MESSAGES.to()); + inputPanel.setFromTitle(MESSAGES.from()); + inputPanel.setShowTitle(false); + form.setFields(inputPanel); + + layout.addMember(title); + layout.addMember(form); + + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data start = getData(items, "start"); + Data end = getData(items, "end"); + DataItem[] startItem = start.getItems(); + DataItem[] endItem = end.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(startItem[0].getLabel() + " - "); + sb.append(endItem[0].getLabel()); + + Label old = new Label(sb.toString()); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveDateValues(); + if(valid) { + String start = Long.valueOf(this.start).toString(); + String end = Long.valueOf(this.end).toString(); + DataItem startItem = new DefaultDataItem("start", "start", start); + DataItem endItem = new DefaultDataItem("end", "end", end); + data.add(new DefaultData( + "start", + null, + null, + new DataItem[] { startItem })); + data.add(new DefaultData( + "end", + null, + null, + new DataItem[] { endItem })); + } + + return (Data[]) data.toArray(new Data[data.size()]); + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } + + + protected boolean saveDateValues() { + Date st = inputPanel.getFromDate(); + Date en = inputPanel.getToDate(); + if (st == null || en == null) { + SC.warn(MESSAGES.error_wrong_date()); + return false; + } + + long start = st.getTime(); + long end = en.getTime(); + + if (start <= end) { + this.start = start; + this.end = end; + return true; + } + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixQSelectPanel.java Mon May 07 13:22:43 2012 +0000 @@ -0,0 +1,65 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.List; +import java.util.ArrayList; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; + +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixQSelectPanel +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + public FixQSelectPanel() { + htmlOverview = ""; + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + return new Canvas(); + } + + @Override + public Canvas createOld(DataList dataList) { + return new Canvas(); + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + return (Data[]) data.toArray(new Data[data.size()]); + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java Mon May 07 13:22:43 2012 +0000 @@ -0,0 +1,149 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.HashMap; + +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.Canvas; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.HTMLPane; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.ui.AbstractUIProvider; + +import de.intevation.flys.client.client.Config; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo; + +import de.intevation.flys.client.client.services.FixingsOverviewService; +import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync; + + +/** + * This UIProvider creates helper panel for fixation analysis without input + * elements. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public abstract class FixationPanel +extends AbstractUIProvider +{ + protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>(); + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected FixingsOverviewServiceAsync overviewService = + GWT.create(FixingsOverviewService.class); + + protected String htmlOverview; + protected FixingsOverviewInfo fixInfo; + + public FixationPanel() { + htmlOverview = ""; + } + + protected String getArtifactUuid() { + return this.artifact.getUuid(); + } + + protected void init() { + + } + + public Data[] getData() { + return null; + } + + public Canvas create(DataList list) { + VLayout layout = new VLayout(); + + Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(list); + + layout.addMember(widget); + layout.addMember(submit); + return layout; + } + + public Canvas createOld(DataList list) { + return new DynamicForm(); + } + + protected Canvas createHelper() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + final HTMLPane helper = new HTMLPane(); + + String river = artifact.getArtifactDescription().getRiver(); + + createCallback(); +/* +Filter example. +{"fixings": { "river": { "name": "Elbe"}, "range": {"from": 1, "to": 200}, "filter": {"and": { "column": {"cid": 1}, "column": {"cid": 2} } }} +*/ + String callBack = "fixationCallback(this.checked, this.name)"; + + overviewService.generateOverview( + locale, + artifact.getUuid(), + "{\"fixings\": {\"river\": {\"name\": \"" + river + "\"}}}", + renderCheckboxes(), + callBack, + new AsyncCallback<FixingsOverviewInfo>() { + public void onFailure(Throwable caught) { + GWT.log("Could not receive overview."); + SC.warn(caught.getMessage()); + } + public void onSuccess(FixingsOverviewInfo info) { + GWT.log("Successfully loaded overview."); + fixInfo = info; + htmlOverview = info.getHTML(); + GWT.log("html: " + info.getHTML()); + helper.setContents(htmlOverview); + + } + }); + + this.helperContainer.addMember(helper); + + return helper; + } + + private native void createCallback() /*-{ + $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;); + }-*/; + + private static void helperCallback(boolean checked, String name) { + String[] parts = name.split(":"); + String uuid = parts[0]; + String cid = parts[1]; + FixationPanel p = FixationPanel.getInstance(uuid); + if (p != null) { + p.setValues(cid, checked); + } + } + + private static FixationPanel getInstance(String uuid) { + for (int i = 0; i < instances.size(); i++) { + if (instances.get(uuid) != null) { + return instances.get(uuid); + } + } + return null; + } + + public abstract Canvas createWidget(DataList data); + public abstract void setValues(String cid, boolean checked); + public abstract boolean renderCheckboxes(); +}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java Mon May 07 13:22:43 2012 +0000 @@ -1,8 +1,18 @@ package de.intevation.flys.client.server; +import java.util.List; +import java.util.ArrayList; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.xpath.XPathConstants; + import com.google.gwt.user.server.rpc.RemoteServiceServlet; import de.intevation.artifacts.common.utils.XMLUtils; + import de.intevation.artifacts.common.utils.XSLTransformer; import de.intevation.artifacts.httpclient.exceptions.ConnectionException; @@ -14,13 +24,15 @@ import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo.Sector; + import java.io.IOException; import java.io.InputStream; import org.apache.log4j.Logger; -import org.w3c.dom.Document; - public class FixingsOverviewServiceImpl extends RemoteServiceServlet implements FixingsOverviewService @@ -33,53 +45,178 @@ public static final String XSL_TRANSFORM = "/WEB-INF/stylesheets/fixoverview2html.xsl"; + protected static final String XPATH_RID = "/fixings/river/@rid"; + protected static final String XPATH_RIVER = "/fixings/river/@name"; + protected static final String XPATH_RFROM = "/fixings/river/@from"; + protected static final String XPATH_RTO = "/fixings/river/@to"; + + protected static final String XPATH_EVENT = "/fixings/events/event"; + protected static final String XPATH_SECTORS = "sector"; + + protected static final String XPATH_CID = "@cid"; + protected static final String XPATH_DATE = "@date"; + protected static final String XPATH_NAME = "@name"; + protected static final String XPATH_CLS = "@class"; + protected static final String XPATH_FROM = "@from"; + protected static final String XPATH_TO = "@to"; + @Override - public String generateOverview( - String locale, + public FixingsOverviewInfo generateOverview( + String locale, String uuid, - boolean checkboxes, - String filter - ) + String filter, + boolean checkboxes, + String callback + ) throws ServerException { log.info("FixingsOverviewServiceImpl.doGet"); if (filter == null || filter.length() == 0) { log.warn("Missing 'filter' parameter."); - return ""; + return null; } Document filterDoc = XMLUtils.jsonToXML(filter); if (filterDoc == null) { log.warn("Creating filter document failed."); - return ""; + return null; } - InputStream transform = - getServletContext().getResourceAsStream(XSL_TRANSFORM); - +/* filterDoc = XMLUtils.newDocument(); + ElementCreator ec = new ElementCreator(filterDoc, null, null); + Element f = ec.create("fixings"); + Element r = ec.create("river"); + r.setAttribute("name", "Saar"); + f.appendChild(r); + filterDoc.appendChild(f); +*/ try { String url = getServletContext().getInitParameter("server-url"); HttpClient client = new HttpClientImpl(url, locale); Document resultDoc = client.callService(url, SERVICE_NAME, filterDoc); - XSLTransformer xformer = new XSLTransformer(); - xformer.addParameter("project-uuid", uuid); - xformer.addParameter( - "render-checkboxes", checkboxes ? "true()" : "false()"); - String result = xformer.transform(resultDoc, transform); - return result != null ? result : ""; + FixingsOverviewInfo i = getInfo(resultDoc, uuid, checkboxes, callback); + return i; } catch (ConnectionException ce) { log.error(ce); } - finally { - try { transform.close(); } - catch (IOException ioe) {} + return null; + } + + + protected FixingsOverviewInfo getInfo( + Document doc, + String uuid, + boolean checkboxes, + String callback + ) { + InputStream transform = + getServletContext().getResourceAsStream(XSL_TRANSFORM); + XSLTransformer xformer = new XSLTransformer(); + xformer.addParameter("project-uuid", uuid); + xformer.addParameter( + "render-checkboxes", checkboxes ? Boolean.TRUE : Boolean.FALSE); + xformer.addParameter("callback", callback); + String result = xformer.transform(doc, transform); + + try { transform.close(); } + catch (IOException ioe) {} + + int rid = -1; + double from = -1; + double to = -1; + String rid_str = XMLUtils.xpathString(doc, XPATH_RID, null); + String river = XMLUtils.xpathString(doc, XPATH_RIVER, null); + String from_str = XMLUtils.xpathString(doc, XPATH_RFROM, null); + String to_str = XMLUtils.xpathString(doc, XPATH_RTO, null); + try { + rid = Integer.valueOf(rid_str).intValue(); + from = Double.valueOf(from_str).doubleValue(); + to = Double.valueOf(to_str).doubleValue(); + } + catch(NumberFormatException nfe) { + log.warn(nfe, nfe); } - return ""; + List<FixEvent> fixEvents = getFixEvents(doc); + return new FixingsOverviewInfo( + rid, + river, + from, + to, + fixEvents, + result); + } + + + protected List<FixEvent> getFixEvents(Document doc) { + NodeList events = (NodeList) XMLUtils.xpath( + doc, + XPATH_EVENT, + XPathConstants.NODESET, + null); + + if (events == null || events.getLength() == 0) { + log.warn("No events in Overview!"); + return null; + } + + List<FixEvent> list = + new ArrayList<FixEvent>(); + for (int i = 0; i < events.getLength(); i++) { + Node n = events.item(i); + List<Sector> sectors = getSectors(n); + String cid = XMLUtils.xpathString(n, XPATH_CID, null); + log.debug("'" + cid + "'"); + String date = XMLUtils.xpathString(n, XPATH_DATE, null); + String name = XMLUtils.xpathString(n, XPATH_NAME, null); + list.add(new FixEvent( + cid, + date, + name, + sectors)); + } + return list; + } + + protected List<Sector> getSectors(Node event) { + NodeList sectors = (NodeList) XMLUtils.xpath( + event, + XPATH_SECTORS, + XPathConstants.NODESET, + null); + if (sectors == null || sectors.getLength() == 0) { + log.warn("No Sectors in Event!"); + return null; + } + + List<Sector> list = + new ArrayList<Sector>(); + for (int i = 0; i < sectors.getLength(); i++) { + Node n = sectors.item(i); + int cls = -1; + double from = -1; + double to = -1; + String cls_str = XMLUtils.xpathString(n, XPATH_CLS, null); + String from_str = XMLUtils.xpathString(n, XPATH_FROM, null); + String to_str = XMLUtils.xpathString(n, XPATH_TO, null); + try { + cls = Integer.valueOf(cls_str).intValue(); + from = Double.valueOf(from_str).doubleValue(); + to = Double.valueOf(to_str).doubleValue(); + } + catch(NumberFormatException nfe) { + log.warn(nfe, nfe); + } + list.add(new Sector( + cls, + from, + to)); + } + return list; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixingsOverviewInfo.java Mon May 07 13:22:43 2012 +0000 @@ -0,0 +1,136 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import java.util.List; +import java.util.ArrayList; + +public class FixingsOverviewInfo implements Serializable { + + protected List<FixEvent> events; + protected String river; + protected double from; + protected double to; + protected int rid; + protected String html; + + protected FixingsOverviewInfo() {} + + public FixingsOverviewInfo( + int rid, + String river, + double from, + double to, + List<FixEvent> events, + String html + ) { + this.rid = rid; + this.river = river; + this.from = from; + this.to = to; + this.events = new ArrayList<FixEvent>(events); + this.html = html; + } + + public int getRId() { + return this.rid; + } + + public String getRiver() { + return this.river; + } + + public double getFrom() { + return this.from; + } + + public double getTo() { + return this.to; + } + + public List<FixEvent> getEvents() { + return this.events; + } + + public FixEvent getEventByCId(String cid) { + for (int i = 0; i < events.size(); i++) { + if (events.get(i).getCId().equals(cid)) { + return events.get(i); + } + } + return null; + } + + public String getHTML() { + return this.html; + } + + + public static class FixEvent implements Serializable { + protected String cid; + protected String date; + protected String name; + protected List<Sector> sectors; + + protected FixEvent () {} + + public FixEvent( + String cid, + String date, + String name, + List<Sector> sectors + ) { + this.cid = cid; + this.date = date; + this.name = name; + this.sectors = new ArrayList<Sector>(sectors); + } + + public String getCId() { + return this.cid; + } + + public String getDate() { + return this.date; + } + + public String getName() { + return this.name; + } + + public List<Sector> getSectors() { + return this.sectors; + } + } + + public static class Sector implements Serializable { + protected int cls; + protected double from; + protected double to; + + protected Sector () {} + + public Sector( + int cls, + double from, + double to + ) { + this.cls = cls; + this.from = from; + this.to = to; + } + + public int getCls() { + return this.cls; + } + + public double getFrom() { + return this.from; + } + + public double getTo() { + return this.to; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl Fri May 04 18:31:03 2012 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl Mon May 07 13:22:43 2012 +0000 @@ -7,6 +7,7 @@ <xsl:param name="project-uuid">de3f3307-3429-4ff9-8f43-3fb2fcf21b27</xsl:param> <xsl:param name="render-checkboxes" select="true()"/> + <xsl:param name="callback"/> <xsl:template name="percent"> <xsl:param name="sector"/> @@ -86,10 +87,10 @@ </xsl:template> <xsl:template match="event"> - <tr> + <tr id="{@cid}"> <xsl:if test="$render-checkboxes"> <td> - <input type="checkbox" name="{$project-uuid}:{@cid}"/> + <input type="checkbox" name="{$project-uuid}:{@cid}" onclick="{$callback}"/> </td> </xsl:if> <td> @@ -107,10 +108,10 @@ style="font-size: 11pt;font-family:Arial;Verdana,sans-serif"> <colgroup> <xsl:if test="$render-checkboxes"> - <col width="1em"/> + <col width="20px"/> </xsl:if> <col width="*"/> - <col width="11em"/> + <col width="90px"/> </colgroup> <xsl:apply-templates/> </table>