changeset 43:fad6fb60a2db CellTable

refining of data in CellTable
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Fri, 07 Dec 2012 16:04:27 +0100
parents fe6778a2fada
children 5db587ba4b0f fc9061488e75
files src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java
diffstat 1 files changed, 61 insertions(+), 283 deletions(-) [+]
line wrap: on
line diff
--- a/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java	Fri Dec 07 16:01:51 2012 +0100
+++ b/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java	Fri Dec 07 16:04:27 2012 +0100
@@ -51,45 +51,40 @@
 	private StiCore core;
 
 	/**
+     * The index of the dataset
+    */
+	private int index;
+	
+	/**
      * The dataset of this dynamic table 
     */
 	private DataSet dataSet;
 	
 	/**
-     * The index of the dataset 
-    */
-	private int index;
-	
-	/**
      * ArrayList that holds all elements that can be shown 
      * (smaller than "dataSet" if showSelected)
     */	
 	private ArrayList<DataObject> actualObjectSet;
 	
 	/**
+     * Provider that hands the data to the table
+    */
+	private ListDataProvider<DataObject> dataProvider;
+	
+	/**
+     * CellTable which displays the data
+    */	
+	private CellTable<DataObject> elementsTable;
+	
+	/**
      * The dataobjects, which are presented at the actual page 
     */
 	//private DataObject[][] displayedObjects;
 
 	/**
-     * The grid for the page links 
-    */
-	private Grid pages;
-
-	/**
      * The number-of-results label 
     */
 	private Label results;
-
-	/**
-     * The image for the previous page 
-    */
-	private Image previous;
-
-	/**
-     * The image for the next page 
-    */
-	private Image next;
 	
 	/**
      * The image for show selected elements 
@@ -115,11 +110,6 @@
      * RPC Interface for writing the KML file
     */	
 	private ExportWriterInterfaceAsync exportWriter;
-	
-	/**
-     * CellTable which will replace the elements-Grid
-    */	
-	private CellTable<DataObject> elementsTable;
 
 	/**
      * Constructor for initialization of the dynamic table
@@ -139,32 +129,9 @@
 		this.index = id;
 		this.core = stiCore;
 		this.dataSet = core.getDataSets().get(index);
+		this.actualObjectSet = new ArrayList<DataObject>();
 		setActualObjectSet();
 		
-		previous = new Image( "images/prev.png" );
-		previous.setStyleName("arrow");
-		next = new Image( "images/next.png" );
-		next.setStyleName("arrow");		
-
-		pages = new Grid(0,0);
-		organizePages();
-		
-		previous.addClickHandler(new ClickHandler() {
-			public void onClick(ClickEvent event) {
-				organizePages();
-				checkHide();
-				fillTable();
-			}
-		});
-		previous.setVisible(false);
-		next.addClickHandler(new ClickHandler() {
-			public void onClick(ClickEvent event) {
-				organizePages();
-				checkHide();
-				fillTable();
-			}
-		});
-		
 		showAll =  new Image("images/viewAll"+(core.getColorId(index))+".png");
 		showAll.setTitle(textConstants.showAll());
 		showSelected =  new Image("images/viewSelected"+(core.getColorId(index))+".png");
@@ -179,9 +146,6 @@
 					showAll.addStyleName("selectedView");
 					viewAll = 1;
 					setActualObjectSet();
-					organizePages();
-					checkHide();
-					fillTable();
 				}
 			}
 		});
@@ -192,9 +156,6 @@
 					if( setActualObjectSet() ){
 						showAll.removeStyleName("selectedView");
 						showSelected.addStyleName("selectedView");
-						organizePages();
-						checkHide();
-						fillTable();
 					}
 					else {
 						viewAll = 1;
@@ -252,9 +213,6 @@
 				showAll.addStyleName("selectedView");
 				viewAll = 1;
 				setActualObjectSet();
-				organizePages();
-				checkHide();
-				fillTable();
 				
 				refine.setWidget(0, 1, search);
 			}
@@ -266,16 +224,6 @@
 		Label page = new Label(textConstants.page()+":");
 		page.setStyleName("pageLabel");
 		
-		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
 		//for download from the ExportServlet
 		aDownloadKML = new Anchor("download KML");
@@ -312,25 +260,9 @@
 		func.setWidget(0, 2, delete);
 		func.addStyleName("center");
 		
-		Grid tableControls = new Grid(1,5);
-		tableControls.setWidget(0,0,showOptions);
-		tableControls.setWidget(0,1,refine);
-		tableControls.setWidget(0,2,this.results);
-		tableControls.setWidget(0,3,footer);
-		tableControls.setWidget(0,4,func);
-		tableControls.setStyleName("tableControls");
-		
-		this.setWidget(0, 0, tableControls);
-
-		tableControls.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
-
-		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 = new ListDataProvider<DataObject>();
 	    dataProvider.addDataDisplay(this.elementsTable);
 		
 	    TextColumn<DataObject> nameColumn = new TextColumn<DataObject>() {
@@ -345,11 +277,26 @@
 	    
 	    SimplePager pager = new SimplePager();
 	    pager.setDisplay(this.elementsTable);
-	    footer.setWidget(0, 0, pager);
 	    
 	    dataProvider.setList(this.actualObjectSet);
 	    
-	    this.setWidget(1, 0, this.elementsTable);		
+	    this.setWidget(1, 0, this.elementsTable);
+	    
+		Grid tableControls = new Grid(1,5);
+		tableControls.setWidget(0,0,showOptions);
+		tableControls.setWidget(0,1,refine);
+		tableControls.setWidget(0,2,this.results);
+		tableControls.setWidget(0,3,pager);
+		tableControls.setWidget(0,4,func);
+		tableControls.setStyleName("tableControls");
+		
+		this.setWidget(0, 0, tableControls);
+
+		tableControls.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
+
+		this.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
+		this.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
+		this.getCellFormatter().setWidth(1, 0, "100%");		
 	}
 	
     /**
@@ -358,168 +305,45 @@
      * @return boolean value, if there are selected objects
     */
 	private boolean setActualObjectSet(){
+		
+		boolean dataSetWasEmpty = false;
+		
 		if( viewAll == -1 ){
-			ArrayList<DataObject> objects = new ArrayList<DataObject>();
+
+			this.actualObjectSet.clear();
+			
 			for( int i=0; i<this.dataSet.getObjects().length(); i++){
 				DataObject object = this.dataSet.getObjects().get(i);
 				if( object.isSelected() ){
-					objects.add(object);
+					this.actualObjectSet.add(object);
 				}
 			}
-			if( objects.size() > 0 ){
+			if( this.actualObjectSet.size() == 0 ){
 				//TODO: Wenn die derzeitige Auswahl _keine_ Elemente
 				//enth�lt, werden _alle_ angezeigt. Ist das sinnvoll?
-				actualObjectSet = objects;
-			}
-			else {
-				return false;
-			}
-		}
-		else if( viewAll == 1 ){
-			actualObjectSet = new ArrayList<DataObject>();
-			for( int i=0; i<this.dataSet.getObjects().length(); i++){
-				actualObjectSet.add(this.dataSet.getObjects().get(i));	
+				dataSetWasEmpty = true;
+				this.viewAll = 1;
 			}
 		}
-
-		return true;
-	}
-	
-    /**
-     * 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);
-			page.addClickHandler(new ClickHandler() {
-				public void onClick(ClickEvent event) {					
-					selectedChunk = Integer.parseInt(page.getText())-1;
-					checkHide();
-					fillTable();
-					updateView(false);
-					organizePages();
-				}
-			});
-			pageLabels.add(page);
-		}	
-		int max = 10;
-		if( this.chunkCount<10 ){
-			max = this.chunkCount;
-		}
-		pages.resize(1,max);
-		int start = selectedChunk - 4;
-		int rest = max - 5;
-		if( start < 0 ){
-			rest += (-1)*start;
-			start = 0;	
-		}
-		int end = selectedChunk + rest;
-		if( end > this.chunkCount - 1 ){
-			start -= end - this.chunkCount + 1;
-			end = this.chunkCount - 1;
-		}
-		if( start < 0 ){
-			start = 0;	
-		}
-		int j=0;
-		for( int i=start; i<end+1; i++ ){
-			Label page = (Label) pageLabels.get(i);
-			if( selectedChunk == Integer.parseInt(page.getText())-1 ){
-				page.setStyleName("selectedPage");
-			}
-			else {
-				page.setStyleName("page");
-			}
-			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(){
-		/*
-		this.elements.resize(0,0);
-		this.elements.resize(this.maxRows, this.maxCols);
-		this.displayedObjects = new DataObject[this.maxRows][this.maxCols];
-		this.setWidget(1, 0, this.elements);
-		int start = this.selectedChunk * ( this.maxCols * this.maxRows );
-		int end = start + ( this.maxCols * this.maxRows );
-		if( end > this.actualObjectSet.size() ){
-			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);
-			String oName = object.getName();
-			if( oName.length() > 60 ){
-				oName = oName.substring(0, 57);
-				oName += "...";
-			}
-			Label name = new Label(oName);
-			Label place = new Label(object.getPlace());
-			Label time = new Label(object.getTimeString());
-			final Grid infoGrid = new Grid(3,1);
-			infoGrid.setWidget(0, 0, name);
-			infoGrid.setWidget(1, 0, place);
-			infoGrid.setWidget(2, 0, time);
-			if( !object.getDescription().equals("") ){
-				infoGrid.resize(4,1);
-				HTML description = new HTML(object.getDescription());
-				description.addStyleName("description");
-				infoGrid.setWidget(3, 0, description);
-			}
-			infoGrid.addStyleName("unselectedCellInner");
-			name.addStyleName("nameLabel");
-			place.addStyleName("dataLabel");
-			time.addStyleName("dataLabel");
-			HTML text = new HTML();
-			text.setHTML(infoGrid.toString());
-			final int r = row;
-			final int c = col % this.maxCols;
-			this.displayedObjects[r][c] = object;
-			text.addMouseOverHandler(new MouseOverHandler(){
-				public void onMouseOver(MouseOverEvent event) {
-					core.undoHover();
-					displayedObjects[r][c].setHover(true);
-					updateCell(r,c);
-					core.updateTimeAndMap();
-				}
-			});
-			text.addMouseOutHandler(new MouseOutHandler(){
-				public void onMouseOut(MouseOutEvent event) {
-					displayedObjects[r][c].setHover(false);
-					updateCell(r,c);
-					core.updateTimeAndMap();
-				}
-			});
-			text.addClickHandler(new ClickHandler(){
-				public void onClick(ClickEvent event) {
-					if( displayedObjects[r][c].getPercentage() == 1 ){
-						displayedObjects[r][c].setPercentage(0);
-					}
-					else {
-						displayedObjects[r][c].setPercentage(1);
-					}
-					updateCell(r,c);
-					core.updateTimeAndMap();
-				}
-			});
-			this.elements.setWidget(r,c,text);
-			this.elements.getCellFormatter().getElement(r,c).setClassName("unselectedCellOuter");
-			updateCell(r,c);			
-			col++;
-			if( col % this.maxCols == 0 ){
-				row++;
+		if( this.viewAll == 1 ){
+			this.actualObjectSet.clear();
+			for( int i=0; i<this.dataSet.getObjects().length(); i++){
+				this.actualObjectSet.add(this.dataSet.getObjects().get(i));	
 			}
 		}
-		*/
+		
+		//if the dataProvider already exists, refresh the
+		//displayed data
+		if (this.dataProvider != null) {
+			this.dataProvider.refresh();
+		
+			this.elementsTable.setRowCount(this.actualObjectSet.size());
+		}
+		
+		if (dataSetWasEmpty)
+			return false;
+		else
+			return true;
 	}
 	
     /**
@@ -605,53 +429,7 @@
 				currentDataObject.setPercentage(0);
 		}
 		
-		//TODO: das gibt es nun mehrfach im Code, sollte also in eine Funktion
-		//�berfuhrt werden
-		viewAll = -1;
 		setActualObjectSet();
-		showAll.removeStyleName("selectedView");
-		showSelected.addStyleName("selectedView");
-		organizePages();
-		checkHide();
-		fillTable();
-	}
-	
-	/**
-     * Checks, if the previous or next button has to be hidden
-    */
-	private void checkHide(){
-		/*
-		if( this.selectedChunk == 0 ){
-			previous.setVisible(false);
-		}
-		else {
-			previous.setVisible(true);
-		}
-		if( this.selectedChunk+1 >= this.chunkCount ){
-			next.setVisible(false);
-		}
-		else {
-			next.setVisible(true);
-		}
-		*/
-	}
-	
-    /**
-     * Updates a cell at the position (row,col). Depends on the selection status of the corresponding dataobject.
-     * 
-     * @param row the row of the cell
-     * @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);
-		*/
 	}
 	
     /**