changeset 68:8b58d9bc0bb6 trimmed_data

add functionality for additional tabular data from the description field (work in progress)
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Thu, 03 Jan 2013 18:43:28 +0100
parents 5b049141a26e
children ea856995abac
files src/econnect/wp3_3/client/core/DataObject.java src/econnect/wp3_3/client/core/DataSet.java src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java war/scripts/sti/DataObject.js war/scripts/sti/DataSet.js war/scripts/sti/STICore.js
diffstat 6 files changed, 111 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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);
+	}-*/;
 }
--- 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;
+	}-*/;
+
 }
--- 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<DataObject> columnSortHandler = new ListHandler<econnect.wp3_3.client.core.DataObject>(dataProvider.getList());
+	    
+	    JsArrayString descriptionDataColumns = this.dataSet.getDescriptionDataColumns();
+	    for (int i = 0; i < descriptionDataColumns.length(); i++) {
+	    	final String columnName = descriptionDataColumns.get(i);
+	    	
+		    TextColumn<DataObject> column = new TextColumn<DataObject>() {
+		        @Override
+		        public String getValue(DataObject object) {
+		          return object.getDescriptionData(columnName);
+		        }
+		    };
+
+		    column.setSortable(true);
+		    
+		    columnSortHandler.setComparator(column,
+		    		new Comparator<econnect.wp3_3.client.core.DataObject>() {
+		    			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<econnect.wp3_3.client.core.DataObject>() {
 	    			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<econnect.wp3_3.client.core.DataObject>() {
 	    			public int compare(econnect.wp3_3.client.core.DataObject o1, econnect.wp3_3.client.core.DataObject o2) {
--- 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 "";
     }
     
 };
--- 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 = {
--- 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 + ".");