# HG changeset patch # User Sebastian Kruse # Date 1357235008 -3600 # Node ID 8b58d9bc0bb66f9091ef4caa47794e06968c073c # Parent 5b049141a26ed96a582c59acf2a6bbc32321546c add functionality for additional tabular data from the description field (work in progress) diff -r 5b049141a26e -r 8b58d9bc0bb6 src/econnect/wp3_3/client/core/DataObject.java --- a/src/econnect/wp3_3/client/core/DataObject.java Wed Jan 02 16:52:01 2013 +0100 +++ b/src/econnect/wp3_3/client/core/DataObject.java Thu Jan 03 18:43:28 2013 +0100 @@ -161,5 +161,13 @@ public final native boolean isSelected() /*-{ return this.isSelected(); }-*/; - + + /** + * Getter for a row value in the description data table + * + * @return the row value + */ + public final native String getDescriptionData(String columnName) /*-{ + return this.getDescriptionData(columnName); + }-*/; } diff -r 5b049141a26e -r 8b58d9bc0bb6 src/econnect/wp3_3/client/core/DataSet.java --- a/src/econnect/wp3_3/client/core/DataSet.java Wed Jan 02 16:52:01 2013 +0100 +++ b/src/econnect/wp3_3/client/core/DataSet.java Thu Jan 03 18:43:28 2013 +0100 @@ -2,6 +2,7 @@ import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; +import com.google.gwt.core.client.JsArrayString; /** * Implementation of the wrapper for the DataSet class of the STI JavaScript source @@ -52,4 +53,14 @@ return this.objects; }-*/; + /** + * Getter for the Array of (additional) column names in the + * description fields + * + * @return the array of column names (Strings) + */ + public final native JsArrayString getDescriptionDataColumns() /*-{ + return this.descriptionDataColumns; + }-*/; + } diff -r 5b049141a26e -r 8b58d9bc0bb6 src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java --- a/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java Wed Jan 02 16:52:01 2013 +0100 +++ b/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java Thu Jan 03 18:43:28 2013 +0100 @@ -25,6 +25,7 @@ import com.google.gwt.view.client.Range; import com.google.gwt.view.client.RangeChangeEvent; import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.JsArrayString; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.Style.BorderStyle; import com.google.gwt.dom.client.Style.Unit; @@ -302,7 +303,7 @@ }; descriptionColumn.setSortable(true); this.elementsTable.addColumn(descriptionColumn, "Description"); - + SimplePager pager = new SimplePager(); pager.setDisplay(this.elementsTable); @@ -311,6 +312,36 @@ //The actual (at this time lexicographical) sorting routine. //TODO: remove redundant code, make this more abstract ListHandler columnSortHandler = new ListHandler(dataProvider.getList()); + + JsArrayString descriptionDataColumns = this.dataSet.getDescriptionDataColumns(); + for (int i = 0; i < descriptionDataColumns.length(); i++) { + final String columnName = descriptionDataColumns.get(i); + + TextColumn column = new TextColumn() { + @Override + public String getValue(DataObject object) { + return object.getDescriptionData(columnName); + } + }; + + column.setSortable(true); + + columnSortHandler.setComparator(column, + new Comparator() { + public int compare(econnect.wp3_3.client.core.DataObject o1, econnect.wp3_3.client.core.DataObject o2) { + if (o1 == o2) + return 0; + + if (o1 != null) + return (o2 != null) ? o1.getDescriptionData(columnName).compareTo(o2.getDescriptionData(columnName)) : 1; + + return -1; + } + }); + + this.elementsTable.addColumn(column, columnName); + } + columnSortHandler.setComparator(nameColumn, new Comparator() { public int compare(econnect.wp3_3.client.core.DataObject o1, econnect.wp3_3.client.core.DataObject o2) { @@ -323,6 +354,7 @@ return -1; } }); + columnSortHandler.setComparator(placeColumn, new Comparator() { public int compare(econnect.wp3_3.client.core.DataObject o1, econnect.wp3_3.client.core.DataObject o2) { diff -r 5b049141a26e -r 8b58d9bc0bb6 war/scripts/sti/DataObject.js --- a/war/scripts/sti/DataObject.js Wed Jan 02 16:52:01 2013 +0100 +++ b/war/scripts/sti/DataObject.js Thu Jan 03 18:43:28 2013 +0100 @@ -10,7 +10,7 @@ * * @constructor */ -DataObject = function(name, description, place, timeStamp, timeSpan, granularity, lon, lat){ +DataObject = function(name, description, place, timeStamp, timeSpan, granularity, lon, lat, descriptionData){ this.name = name; this.description = description; @@ -19,7 +19,9 @@ this.granularity = granularity; this.longitude = lon; this.latitude = lat; - + + this.descriptionData = descriptionData; + this.setPlaces(place); this.status = false; this.percentage = 0; @@ -140,6 +142,13 @@ return this.placeDetail[this.placeDetail.length-1]; } return this.placeDetail[level]; + }, + + getDescriptionData: function(columnName){ + if (this.descriptionData[columnName] != null) + return this.descriptionData[columnName]; + else + return ""; } }; diff -r 5b049141a26e -r 8b58d9bc0bb6 war/scripts/sti/DataSet.js --- a/war/scripts/sti/DataSet.js Wed Jan 02 16:52:01 2013 +0100 +++ b/war/scripts/sti/DataSet.js Thu Jan 03 18:43:28 2013 +0100 @@ -11,7 +11,16 @@ this.objects = objects; this.termIdentifier = termIdentifier; this.maxGranularity = maxGranularity; - + + //check through each object if the description field contained a table, + //and "remember" the column names for easy access later + this.descriptionDataColumns = new Array(); + for (var i = 0; i < this.objects.length; i++) { + for (var columnName in this.objects[i].descriptionData) { + if ($.inArray(columnName, this.descriptionDataColumns) == -1) + this.descriptionDataColumns.push(columnName); + } + } } DataSet.prototype = { diff -r 5b049141a26e -r 8b58d9bc0bb6 war/scripts/sti/STICore.js --- a/war/scripts/sti/STICore.js Wed Jan 02 16:52:01 2013 +0100 +++ b/war/scripts/sti/STICore.js Thu Jan 03 18:43:28 2013 +0100 @@ -340,7 +340,7 @@ for (var i = 0; i < elements.length; i++) { var placemark = elements[i]; - var name, description, place, timeData, coordinates, timeStamp, timeSpan, g; + var name, description, descriptionData, place, timeData, coordinates, timeStamp, timeSpan, g; try{ var nameElement = placemark.getElementsByTagName("name"); @@ -357,7 +357,41 @@ try{ var descriptionElement = placemark.getElementsByTagName("description"); if ( (descriptionElement != null) && (descriptionElement.length > 0) && (descriptionElement[0].childNodes.length > 0) ){ - description = descriptionElement[0].childNodes[0].nodeValue; + + description = $(descriptionElement).text(); + + //check whether the description element contains a table + //if yes, this data will be loaded as separate columns + try{ + //cleanWhitespace removes non-sense text-nodes (space, tab) + //and is an addition to jquery defined in Sti.html + var descriptionDocument = $($.parseXML(description)).cleanWhitespace(); + + descriptionData = new Object(); + + $(descriptionDocument).find("tr").each( + function() { + var isHeader = true; + var lastHeader = ""; + + $(this).find("td").each( + function() { + if (isHeader) { + lastHeader = $(this).text(); + isHeader = false; + } else { + var value = $(this).text(); + descriptionData[lastHeader] = value; + isHeader = true; + } + } + ) + } + ); + } catch(e) { + //Description is either no HTML or no table + alert(e); + } } else { description = ""; @@ -443,7 +477,7 @@ alert("No valid coordinate information for element " + i + "."); continue; } - newObjects.push(new DataObject(name, description, place, timeStamp, timeSpan, g, lonlat[0], lonlat[1])); + newObjects.push(new DataObject(name, description, place, timeStamp, timeSpan, g, lonlat[0], lonlat[1], descriptionData)); } catch(e){ alert("No valid coordinate information for element " + i + ".");