Mercurial > dive4elements > river
changeset 235:d3f8d6966c20
Added location and distance tables.
flys-client/trunk@1791 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/flys-client/ChangeLog Mon May 02 10:18:56 2011 +0000 +++ b/flys-client/ChangeLog Mon May 02 14:47:12 2011 +0000 @@ -1,3 +1,24 @@ +2011-05-02 Raimund Renkert <rrenkert@intevation.de> + + * src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java: + Added location and distance tables. A selection fills the textfield with + the selected values. + + * src/main/java/de/intevation/flys/client/shared/model/DistanceInfoRecord.java: + New. + + * 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, + src/main/java/de/intevation/flys/client/client/FLYSConstants.java: + Added i18n strings for the new tables. + + * src/main/java/de/intevation/flys/client/client/FLYSImages.java: Added new + images. + + * src/main/java/de/intevation/flys/client/client/images/marker_green.png, + src/main/java/de/intevation/flys/client/client/images/marker_red.png: New. + 2011-05-02 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Mon May 02 10:18:56 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Mon May 02 14:47:12 2011 +0000 @@ -78,6 +78,14 @@ String wrongFormat(); + String description(); + + String from(); + + String to(); + + String riverside(); + String wqTitle(); String wqW();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Mon May 02 10:18:56 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Mon May 02 14:47:12 2011 +0000 @@ -33,6 +33,10 @@ unitWidth = m unitLocation = km wrongFormat = Wrong format +description = Description +from = From +to = To +riverside = Riverside wqTitle = Input for W/Q Data wqW = W at Gauge [cm]
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Mon May 02 10:18:56 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Mon May 02 14:47:12 2011 +0000 @@ -33,6 +33,10 @@ unitWidth = m unitLocation = km wrongFormat = Falsches Format +description = Beschreibung +from = von +to = bis +riverside = Flussseite wqTitle = Eingabe für W/Q Daten wqW = W am Pegel [cm]
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Mon May 02 10:18:56 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Mon May 02 14:47:12 2011 +0000 @@ -33,6 +33,10 @@ unitWidth = m unitLocation = km wrongFormat = Wrong format +description = Description +from = From +to = To +riverside = Riverside wqTitle = Input for W/Q Data wqW = W at Gauge [cm]
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSImages.java Mon May 02 10:18:56 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSImages.java Mon May 02 14:47:12 2011 +0000 @@ -19,4 +19,10 @@ @Source("images/gewkarte.png") ImageResource riverMap(); + + @Source("images/marker_red.png") + ImageResource markerRed (); + + @Source("images/marker_green.png") + ImageResource markerGreen (); }
Binary file flys-client/src/main/java/de/intevation/flys/client/client/images/marker_green.png has changed
Binary file flys-client/src/main/java/de/intevation/flys/client/client/images/marker_red.png has changed
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Mon May 02 10:18:56 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Mon May 02 14:47:12 2011 +0000 @@ -4,6 +4,7 @@ import java.util.List; import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; @@ -16,13 +17,41 @@ import com.smartgwt.client.widgets.form.fields.RadioGroupItem; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; + +import com.smartgwt.client.widgets.tab.TabSet; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.data.Record; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionAppearance; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler; +import com.smartgwt.client.widgets.grid.events.SelectionEvent; 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 de.intevation.flys.client.shared.model.DistanceInfoObject; +import de.intevation.flys.client.shared.model.DistanceInfoObjectImpl; +import de.intevation.flys.client.shared.model.DistanceInfoRecord; +import de.intevation.flys.client.shared.model.ArtifactDescription; + +import de.intevation.flys.client.server.DistanceInfoServiceImpl; +import de.intevation.flys.client.client.services.DistanceInfoService; +import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.FLYSImages; +import de.intevation.flys.client.client.Config; /** @@ -37,6 +66,12 @@ /** The message class that provides i18n strings.*/ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + /** The interface that provides the image resources. */ + private FLYSImages IMAGES = GWT.create(FLYSImages.class); + + /** The DistanceInfoService used to retrieve locations about rivers.*/ + protected DistanceInfoServiceAsync distanceInfoService = + GWT.create(DistanceInfoService.class); /** The constant name of the input field to enter locations.*/ public static final String FIELD_LOCATION = "location"; @@ -81,11 +116,31 @@ /** The values entered in the location mode.*/ protected double[] values; + /** The input panel for locations */ + protected DoubleArrayPanel locationPanel; + + /** The input panel for distances */ + protected DoubleRangePanel distancePanel; + + /** The tab set containing the location and distance table*/ + protected TabSet inputTables; + + /** The distance table. */ + protected ListGrid distanceTable; + + /** The locations table */ + protected ListGrid locationsTable; + + /** The locations table for distance input. */ + protected ListGrid locationDistanceTable; /** * Creates a new LocationDistancePanel instance. */ public LocationDistancePanel() { + distanceTable = new ListGrid(); + locationsTable = new ListGrid(); + locationDistanceTable = new ListGrid(); } @@ -107,6 +162,10 @@ Label label = new Label(MESSAGES.location_distance_state()); Canvas widget = createWidget(data); Canvas submit = getNextButton(); + createDistanceInputPanel(); + + createDistanceTable(); + createLocationTable(); widget.setHeight(50); label.setHeight(25); @@ -119,6 +178,167 @@ } + /** + * This method creates a table that contains the distance values. + */ + protected void createDistanceTable() { + distanceTable.setWidth100(); + distanceTable.setShowRecordComponents(true); + distanceTable.setShowRecordComponentsByCell(true); + distanceTable.setHeight100(); + + ListGridField addDistance = new ListGridField ("", ""); + addDistance.setType (ListGridFieldType.ICON); + addDistance.setWidth ("30"); + addDistance.addRecordClickHandler (new RecordClickHandler () { + public void onRecordClick (RecordClickEvent e) { + if (!isLocationMode ()) { + Record r = e.getRecord(); + double min = r.getAttributeAsDouble("from"); + double max = r.getAttributeAsDouble("to"); + setDistanceValues(min, max); + } + else { + double[] selected; + if (getLocationValues() != null) { + double[] val = getLocationValues(); + selected = new double[val.length + 2]; + for(int i = 0; i < val.length; i++){ + selected[i] = val[i]; + } + selected[val.length] = min; + selected[val.length + 1] = max; + } + else { + selected = new double[2]; + selected[0] = min; + selected[1] = max; + } + setLocationValues(selected); + } + } + }); + addDistance.setCellIcon (IMAGES.markerGreen ().getURL ()); + + ListGridField ddescr = new ListGridField("description", + MESSAGES.description()); + ddescr.setType(ListGridFieldType.TEXT); + ddescr.setWidth("*"); + ListGridField from = new ListGridField("from", MESSAGES.from()); + from.setType(ListGridFieldType.TEXT); + from.setWidth(75); + ListGridField to = new ListGridField("to", MESSAGES.to()); + to.setType(ListGridFieldType.TEXT); + to.setWidth(75); + ListGridField dside = new ListGridField("riverside", + MESSAGES.riverside()); + dside.setType(ListGridFieldType.TEXT); + dside.setWidth(60); + + distanceTable.setFields(addDistance, ddescr, from, to, dside); + } + + + /** + * This method creates a table that contains the location values. + */ + protected void createLocationTable() { + locationsTable.setWidth100(); + locationsTable.setShowRecordComponents(true); + locationsTable.setShowRecordComponentsByCell(true); + locationsTable.setHeight100(); + + ListGridField addLocation = new ListGridField ("", ""); + addLocation.setType (ListGridFieldType.ICON); + addLocation.setWidth ("30"); + addLocation.addRecordClickHandler (new RecordClickHandler () { + public void onRecordClick (RecordClickEvent e) { + ListGridRecord[] records = locationsTable.getSelection(); + double[] selected; + if (getLocationValues() != null) { + double[] val = getLocationValues(); + selected = new double[val.length + 1]; + for(int i = 0; i < val.length; i++){ + selected[i] = val[i]; + } + selected[val.length] = + records[0].getAttributeAsDouble("from"); + } + else { + selected = new double[1]; + selected[0] = records[0].getAttributeAsDouble("from"); + } + setLocationValues(selected); + } + }); + addLocation.setCellIcon (IMAGES.markerGreen ().getURL ()); + + ListGridField ldescr = new ListGridField("description", + MESSAGES.description()); + ldescr.setType(ListGridFieldType.TEXT); + ldescr.setWidth("*"); + ListGridField lside = new ListGridField("riverside", + MESSAGES.riverside()); + lside.setType(ListGridFieldType.TEXT); + lside.setWidth(60); + ListGridField loc = new ListGridField("from", MESSAGES.location()); + loc.setType(ListGridFieldType.TEXT); + loc.setWidth(80); + locationsTable.setFields(addLocation, ldescr, loc, lside); + } + + + /** + * This method creates a table that contains the location values. + */ + protected void createLocationTableDistance (){ + locationDistanceTable.setWidth100(); + locationDistanceTable.setShowRecordComponents(true); + locationDistanceTable.setShowRecordComponentsByCell(true); + locationDistanceTable.setHeight100(); + + ListGridField addfrom = new ListGridField ("", ""); + addfrom.setType (ListGridFieldType.ICON); + addfrom.setWidth ("30"); + addfrom.setCellIcon (IMAGES.markerGreen ().getURL ()); + + ListGridField addto2 = new ListGridField ("", ""); + addto2.setType (ListGridFieldType.ICON); + addto2.setWidth ("30"); + addto2.setCellIcon (IMAGES.markerRed ().getURL ()); + + + ListGridField ldescr = new ListGridField("description", + MESSAGES.description()); + ldescr.setType(ListGridFieldType.TEXT); + ldescr.setWidth("*"); + ListGridField lside = new ListGridField("riverside", + MESSAGES.riverside()); + lside.setType(ListGridFieldType.TEXT); + lside.setWidth(60); + ListGridField loc = new ListGridField("from", MESSAGES.location()); + loc.setType(ListGridFieldType.TEXT); + loc.setWidth(80); + locationDistanceTable.addCellClickHandler (new CellClickHandler () { + public void onCellClick (CellClickEvent e) { + if (e.getColNum() == 0) { + Record r = e.getRecord (); + double fromvalue = r.getAttributeAsDouble ("from"); + double tovalue = getTo (); + setDistanceValues (fromvalue, tovalue); + } + else if (e.getColNum() == 1) { + Record r = e.getRecord (); + double fromvalue = getFrom (); + double tovalue = r.getAttributeAsDouble ("to"); + setDistanceValues (fromvalue, tovalue); + } + } + }); + locationDistanceTable.setFields(addfrom, addto2, ldescr, loc, lside); + } + + public Canvas createOld(DataList dataList) { List<Data> items = dataList.getAll(); @@ -208,7 +428,7 @@ Canvas checkboxPanel = createRadioButtonPanel(); // the initial view will display the location input mode - Canvas locationPanel = new DoubleArrayPanel( + locationPanel = new DoubleArrayPanel( MESSAGES.unitLocation(), getLocationValues(), this); @@ -217,7 +437,23 @@ layout.addMember(checkboxPanel); layout.addMember(container); - // TODO Add a table on the right to select locations by mouse click + createDistanceInputPanel(); + container.setMembersMargin(30); + + inputTables = new TabSet(); + Tab locations = new Tab(MESSAGES.location()); + Tab distances = new Tab(MESSAGES.distance()); + + inputTables.setWidth(500); + inputTables.setHeight(350); + + locations.setPane(locationsTable); + distances.setPane(distanceTable); + + inputTables.addTab(locations); + inputTables.addTab(distances); + + container.addMember(inputTables); return layout; } @@ -374,18 +610,30 @@ if (value == null) { return; } - + createDistanceInputPanel(); if (value.equals(FIELD_LOCATION)) { - Canvas locationPanel = new DoubleArrayPanel( + locationPanel = new DoubleArrayPanel( MESSAGES.unitLocation(), getLocationValues(), this); container.removeMembers(container.getMembers()); container.addMember(locationPanel); + inputTables.removeTab(1); + inputTables.removeTab(0); + Tab t1 = new Tab (MESSAGES.location()); + createLocationTable(); + t1.setPane(locationsTable); + inputTables.addTab(t1); + createDistanceTable(); + Tab t2 = new Tab (MESSAGES.distance()); + t2.setPane(distanceTable); + inputTables.addTab(t2); + container.addMember(inputTables); + inputTables.selectTab(0); } else { - Canvas distancePanel = new DoubleRangePanel( + distancePanel = new DoubleRangePanel( MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), getFrom(), getTo(), getStep(), 250, @@ -393,6 +641,18 @@ container.removeMembers(container.getMembers()); container.addMember(distancePanel); + inputTables.removeTab(1); + inputTables.removeTab(0); + Tab t1 = new Tab(MESSAGES.location ()); + createLocationTableDistance (); + t1.setPane(locationDistanceTable); + inputTables.addTab(t1); + createDistanceTable (); + Tab t2 = new Tab(MESSAGES.distance ()); + t2.setPane(distanceTable); + inputTables.addTab(t2); + container.addMember(inputTables); + inputTables.selectTab(1); } } @@ -424,6 +684,7 @@ } + /** * Validates and stores all values entered in the location mode. * @@ -512,6 +773,65 @@ } + protected void createDistanceInputPanel() { + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String locale = config.getLocale (); + String river = ""; + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + if (dl.getState().equals("state.winfo.river")) { + for (int j = 0; j < dl.size(); j++) { + Data d = dl.get(j); + DataItem[] di = d.getItems(); + if (di != null && di.length == 1) { + river = d.getItems()[0].getStringValue(); + } + } + } + } + } + + distanceInfoService.getDistanceInfo(url, locale, river, + new AsyncCallback<DistanceInfoObject[]>() { + public void onFailure(Throwable caught) { + GWT.log("Could not recieve distance informations."); + GWT.log(caught.getMessage()); + } + + public void onSuccess(DistanceInfoObject[] di) { + int num = di != null ? di.length :0; + + if (num == 0) { + return; + } + updateDistanceInfo(di); + } + } + ); + } + + + protected void updateDistanceInfo(DistanceInfoObject[] di) { + int i = 0; + for (DistanceInfoObject dio: di) { + if (dio.getTo() != null) { + distanceTable.addData(new DistanceInfoRecord(dio)); + } + else { + locationsTable.addData(new DistanceInfoRecord(dio)); + locationDistanceTable.addData(new DistanceInfoRecord(dio)); + } + } + return; + } + + protected double getFrom() { return from; } @@ -549,6 +869,14 @@ protected void setLocationValues(double[] values) { this.values = values; + locationPanel.setValues(values); + } + + + protected void setDistanceValues (double from, double to) { + setFrom(from); + setTo(to); + distancePanel.setValues(from, to, getStep()); } } // 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/DistanceInfoRecord.java Mon May 02 14:47:12 2011 +0000 @@ -0,0 +1,92 @@ +package de.intevation.flys.client.shared.model; + +import java.util.Date; + +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.google.gwt.core.client.GWT; + + +/** + * The DistanceInfoRecord is a wrapper to put DistanceInfo objects into + * a ListGrid. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DistanceInfoRecord extends ListGridRecord { + + /** The artifact collection. */ + protected DistanceInfoObject distanceInfo; + + + /** + * The default constructor. + * + * @param info The distance info object. + */ + public DistanceInfoRecord(DistanceInfoObject info) { + this.distanceInfo = info; + + setDescription(info.getDescription()); + setFrom(info.getFrom()); + if (info.getTo() != null) + setTo(info.getTo()); + else + setTo(info.getFrom()); + setRiverside(info.getRiverside()); + } + + + /** + * Sets the creation time. + * + * @param creationTime The creation time. + */ + public void setDescription(String description) { + setAttribute("description", description); + } + + + /** + * Returns the description. + * + * @return the description. + */ + public String getDescription() { + return getAttributeAsString("description"); + } + + + public void setFrom(double from) { + setAttribute("from", from); + } + + + public double getFrom() { + return getAttributeAsDouble("from"); + } + + public void setTo(double to) { + setAttribute("to", to); + } + + + public double getTo() { + return getAttributeAsDouble("to"); + } + + + public void setRiverside(String side) { + setAttribute("riverside", side); + } + + + public String getRiverside() { + return getAttributeAsString("riverside"); + } + + + public DistanceInfoObject getDistanceInfo() { + return distanceInfo; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :