changeset 40:20eb7596d466 CellTable

Preparation for a switch to a CellTable. This is work in progress.
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Thu, 06 Dec 2012 18:05:39 +0100
parents ba7d401c2750
children fe6778a2fada
files src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java war/scripts/sti/DynamicTable.js
diffstat 2 files changed, 67 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java	Thu Dec 06 18:05:16 2012 +0100
+++ b/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java	Thu Dec 06 18:05:39 2012 +0100
@@ -1,7 +1,11 @@
 package econnect.wp3_3.client.widgets.table;
 
 import java.util.ArrayList;
+import java.util.List;
 
+import com.google.gwt.user.cellview.client.CellTable;
+import com.google.gwt.user.cellview.client.SimplePager;
+import com.google.gwt.user.cellview.client.TextColumn;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.Anchor;
 import com.google.gwt.user.client.ui.Button;
@@ -13,6 +17,7 @@
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.view.client.ListDataProvider;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.event.dom.client.ClickEvent;
@@ -36,11 +41,6 @@
 public class DynamicStiTable extends Grid {
 
 	/**
-     * The maximum number of columns of the table 
-    */
-	private int maxCols = 4;
-
-	/**
      * The maximum number of rows of the table 
     */
 	private int maxRows = 10;
@@ -61,24 +61,15 @@
 	private int index;
 	
 	/**
+     * ArrayList that holds all elements that can be shown 
+     * (smaller than "dataSet" if showSelected)
+    */	
+	private ArrayList<DataObject> actualObjectSet;
+	
+	/**
      * The dataobjects, which are presented at the actual page 
     */
-	private DataObject[][] displayedObjects;
-
-	/**
-     * The visual representations of the actual displayed objects 
-    */
-	private Grid elements;
-	
-	/**
-     * The number of chunks (pages) for the table 
-    */
-	private int chunkCount;
-
-	/**
-     * The actual selected chunk (page) 
-    */
-	private int selectedChunk = 0;
+	//private DataObject[][] displayedObjects;
 
 	/**
      * The grid for the page links 
@@ -116,11 +107,6 @@
 	private int viewAll = 1;
 	
 	/**
-     * ArrayList that holds all elements that can be shown 
-    */	
-	private ArrayList<DataObject> actualObjectSet;
-	
-	/**
      * Anchor that holds the URL for the KML download
     */	
 	private Anchor aDownloadKML;
@@ -131,6 +117,11 @@
 	private ExportWriterInterfaceAsync exportWriter;
 	
 	/**
+     * CellTable which will replace the elements-Grid
+    */	
+	private CellTable<DataObject> elementsTable;
+
+	/**
      * Constructor for initialization of the dynamic table
      * 
      * @param core object to allow interaction with all javascript components
@@ -142,10 +133,9 @@
 		final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class);
 		
 		this.resize(2,1);
-		this.elements = new Grid();
 		this.addStyleName("dataTable");
 		this.addStyleName("center");
-		
+			    
 		this.index = id;
 		this.core = stiCore;
 		this.dataSet = core.getDataSets().get(index);
@@ -161,7 +151,6 @@
 		
 		previous.addClickHandler(new ClickHandler() {
 			public void onClick(ClickEvent event) {
-				selectedChunk--;
 				organizePages();
 				checkHide();
 				fillTable();
@@ -170,15 +159,11 @@
 		previous.setVisible(false);
 		next.addClickHandler(new ClickHandler() {
 			public void onClick(ClickEvent event) {
-				selectedChunk++;
 				organizePages();
 				checkHide();
 				fillTable();
 			}
 		});
-		if( chunkCount == 1 ){
-			next.setVisible(false);
-		}		
 		
 		showAll =  new Image("images/viewAll"+(core.getColorId(index))+".png");
 		showAll.setTitle(textConstants.showAll());
@@ -262,7 +247,7 @@
 				core.reset();
 				
 				//TODO: das gibt es nun mehrfach im Code, sollte also in eine Funktion
-				//Ÿberfuhrt werden
+				//�berfuhrt werden
 				showSelected.removeStyleName("selectedView");
 				showAll.addStyleName("selectedView");
 				viewAll = 1;
@@ -281,12 +266,14 @@
 		Label page = new Label(textConstants.page()+":");
 		page.setStyleName("pageLabel");
 		
-		Grid footer = new Grid(1,4);
+		Grid footer = new Grid(1,1);
+		/*
 		footer.setWidget(0, 0, page );
 		footer.setWidget(0, 1, pages );
 		footer.setWidget(0, 2, previous);
 		footer.setWidget(0, 3, next);
 		footer.addStyleName("center");
+		*/
 		
 		
 		//This anchor will hold the URL of the export-file
@@ -340,9 +327,29 @@
 		this.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
 		this.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
 		this.getCellFormatter().setWidth(1, 0, "100%");
+	
+		this.elementsTable = new CellTable<DataObject>();
+
+		ListDataProvider<DataObject> dataProvider = new ListDataProvider<DataObject>();
+	    dataProvider.addDataDisplay(this.elementsTable);
 		
-		fillTable();
+	    TextColumn<DataObject> nameColumn = new TextColumn<DataObject>() {
+	        @Override
+	        public String getValue(DataObject object) {
+	          return object.getName();
+	        }
+	    
+	    };	    
 
+	    this.elementsTable.addColumn(nameColumn);
+	    
+	    SimplePager pager = new SimplePager();
+	    pager.setDisplay(this.elementsTable);
+	    footer.setWidget(0, 0, pager);
+	    
+	    dataProvider.setList(this.actualObjectSet);
+	    
+	    this.setWidget(1, 0, this.elementsTable);		
 	}
 	
     /**
@@ -361,7 +368,7 @@
 			}
 			if( objects.size() > 0 ){
 				//TODO: Wenn die derzeitige Auswahl _keine_ Elemente
-				//enthŠlt, werden _alle_ angezeigt. Ist das sinnvoll?
+				//enth�lt, werden _alle_ angezeigt. Ist das sinnvoll?
 				actualObjectSet = objects;
 			}
 			else {
@@ -374,10 +381,7 @@
 				actualObjectSet.add(this.dataSet.getObjects().get(i));	
 			}
 		}
-		this.chunkCount = actualObjectSet.size() / ( maxCols * maxRows );
-		if( actualObjectSet.size() % ( maxCols * maxRows ) != 0 ){
-			this.chunkCount++;
-		}
+
 		return true;
 	}
 	
@@ -385,6 +389,7 @@
      * Organizes the visible links in the pages grid
     */
 	private void organizePages(){
+		/*
 		ArrayList<Label> pageLabels = new ArrayList<Label>();
 		for( int i=1; i<this.chunkCount+1; i++ ){
 			final Label page = new Label(""+i);
@@ -430,12 +435,14 @@
 			pages.setWidget(0,j,page);
 			j++;
 		}
+		*/
 	}
 	
     /**
      * Fills the table cells with content. It depends on the actual chosen chunk (page) and the objects in the actual object set.
     */
-	private void fillTable(){				
+	private void fillTable(){
+		/*
 		this.elements.resize(0,0);
 		this.elements.resize(this.maxRows, this.maxCols);
 		this.displayedObjects = new DataObject[this.maxRows][this.maxCols];
@@ -446,6 +453,7 @@
 			end = this.actualObjectSet.size();
 		}
 		this.results.setText("Results "+(start+1)+" - "+end+" of "+this.actualObjectSet.size());
+
 		int row = 0, col = 0;
 		for( int i=start; i<end; i++){	
 			DataObject object = (DataObject) this.actualObjectSet.get(i);
@@ -511,6 +519,7 @@
 				row++;
 			}
 		}
+		*/
 	}
 	
     /**
@@ -597,7 +606,7 @@
 		}
 		
 		//TODO: das gibt es nun mehrfach im Code, sollte also in eine Funktion
-		//Ÿberfuhrt werden
+		//�berfuhrt werden
 		viewAll = -1;
 		setActualObjectSet();
 		showAll.removeStyleName("selectedView");
@@ -611,6 +620,7 @@
      * Checks, if the previous or next button has to be hidden
     */
 	private void checkHide(){
+		/*
 		if( this.selectedChunk == 0 ){
 			previous.setVisible(false);
 		}
@@ -623,6 +633,7 @@
 		else {
 			next.setVisible(true);
 		}
+		*/
 	}
 	
     /**
@@ -632,12 +643,15 @@
      * @param col the col of the cell
     */
 	private void updateCell( int row, int col ){
+		/*
 		boolean selected = this.displayedObjects[row][col].isSelected();
 		double percentage = (new Double(this.displayedObjects[row][col].getPercentage()).doubleValue());
 		String borderColor = StiCore.getBorderColor(this.index,selected);
 		String cellColor = StiCore.getCellColor(this.index,percentage);
+		
 		this.elements.getCellFormatter().getElement(row, col).getStyle().setBorderColor(borderColor);
 		this.elements.getCellFormatter().getElement(row, col).getStyle().setBackgroundColor(cellColor);
+		*/
 	}
 	
     /**
@@ -650,6 +664,7 @@
 			showSelected.removeStyleName("selectedView");
 			this.viewAll = 0;		
 		}
+		/*
 		for( int i=0; i<this.displayedObjects.length; i++ ){
 			for( int j=0; j<this.displayedObjects[i].length; j++ ){
 				if( this.displayedObjects[i][j] != null && this.displayedObjects[i][j].getStatus() ){
@@ -657,6 +672,7 @@
 				}
 			}
 		}
+		*/
 	}
 
 	public String getTermIdentifier() {
--- a/war/scripts/sti/DynamicTable.js	Thu Dec 06 18:05:16 2012 +0100
+++ b/war/scripts/sti/DynamicTable.js	Thu Dec 06 18:05:39 2012 +0100
@@ -5,7 +5,6 @@
 
     this.core = core;
     this.dataSet = dataSet;
-    this.chunks = [];
     this.index = index;
     this.tableDiv;
     this.tableHeader;
@@ -22,6 +21,7 @@
 DynamicTable.prototype = {
 
     initialize: function(){
+    	/*
     
         this.chunks.push([]);
         for (var i = 0; i < this.dataSet.objects.length; i++) {
@@ -155,10 +155,11 @@
         table.appendChild(this.tableFooter);
         
         this.createTableBody();
-        
+        */
     },
     
     createRow: function(object, index){
+    	/*
     
         var base = this;
         
@@ -236,10 +237,12 @@
         }
         
         return dataRow;
+        */
         
     },
     
     createTableBody: function(){
+    	/*
         try {
             var selectedChunk = parseInt(this.chunkSelect.value);
             if (selectedChunk > this.chunks.length) {
@@ -261,9 +264,11 @@
             this.rows.push(row);
         }
         this.update();
+        */
     },
     
     update: function(){
+    	/*
         for (var i = 0; i < this.chunks[this.actualChunk].length; i++) {
             var object = this.chunks[this.actualChunk][i];
             var p = object.percentage;
@@ -275,6 +280,7 @@
             var b = cellColor.b + Math.round(p * (colors[this.index].bt - cellColor.b));
             this.rows[i].style.background = 'rgb(' + r + ',' + g + ',' + b + ')';
         }
+        */
     }
     
 }