comparison src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java @ 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 1e95995ddbb2
children fad6fb60a2db
comparison
equal deleted inserted replaced
39:ba7d401c2750 40:20eb7596d466
1 package econnect.wp3_3.client.widgets.table; 1 package econnect.wp3_3.client.widgets.table;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 4 import java.util.List;
5
6 import com.google.gwt.user.cellview.client.CellTable;
7 import com.google.gwt.user.cellview.client.SimplePager;
8 import com.google.gwt.user.cellview.client.TextColumn;
5 import com.google.gwt.user.client.rpc.AsyncCallback; 9 import com.google.gwt.user.client.rpc.AsyncCallback;
6 import com.google.gwt.user.client.ui.Anchor; 10 import com.google.gwt.user.client.ui.Anchor;
7 import com.google.gwt.user.client.ui.Button; 11 import com.google.gwt.user.client.ui.Button;
8 import com.google.gwt.user.client.ui.FormPanel; 12 import com.google.gwt.user.client.ui.FormPanel;
9 import com.google.gwt.user.client.ui.Grid; 13 import com.google.gwt.user.client.ui.Grid;
11 import com.google.gwt.user.client.ui.Image; 15 import com.google.gwt.user.client.ui.Image;
12 import com.google.gwt.user.client.ui.Label; 16 import com.google.gwt.user.client.ui.Label;
13 import com.google.gwt.user.client.ui.HTML; 17 import com.google.gwt.user.client.ui.HTML;
14 import com.google.gwt.user.client.ui.HasHorizontalAlignment; 18 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
15 import com.google.gwt.user.client.ui.TextBox; 19 import com.google.gwt.user.client.ui.TextBox;
20 import com.google.gwt.view.client.ListDataProvider;
16 import com.google.gwt.core.client.GWT; 21 import com.google.gwt.core.client.GWT;
17 import com.google.gwt.event.dom.client.ClickHandler; 22 import com.google.gwt.event.dom.client.ClickHandler;
18 import com.google.gwt.event.dom.client.ClickEvent; 23 import com.google.gwt.event.dom.client.ClickEvent;
19 import com.google.gwt.event.dom.client.MouseOutEvent; 24 import com.google.gwt.event.dom.client.MouseOutEvent;
20 import com.google.gwt.event.dom.client.MouseOverEvent; 25 import com.google.gwt.event.dom.client.MouseOverEvent;
34 * Implementation of a dynamic table for one dataset 39 * Implementation of a dynamic table for one dataset
35 */ 40 */
36 public class DynamicStiTable extends Grid { 41 public class DynamicStiTable extends Grid {
37 42
38 /** 43 /**
39 * The maximum number of columns of the table
40 */
41 private int maxCols = 4;
42
43 /**
44 * The maximum number of rows of the table 44 * The maximum number of rows of the table
45 */ 45 */
46 private int maxRows = 10; 46 private int maxRows = 10;
47 47
48 /** 48 /**
59 * The index of the dataset 59 * The index of the dataset
60 */ 60 */
61 private int index; 61 private int index;
62 62
63 /** 63 /**
64 * The dataobjects, which are presented at the actual page
65 */
66 private DataObject[][] displayedObjects;
67
68 /**
69 * The visual representations of the actual displayed objects
70 */
71 private Grid elements;
72
73 /**
74 * The number of chunks (pages) for the table
75 */
76 private int chunkCount;
77
78 /**
79 * The actual selected chunk (page)
80 */
81 private int selectedChunk = 0;
82
83 /**
84 * The grid for the page links
85 */
86 private Grid pages;
87
88 /**
89 * The number-of-results label
90 */
91 private Label results;
92
93 /**
94 * The image for the previous page
95 */
96 private Image previous;
97
98 /**
99 * The image for the next page
100 */
101 private Image next;
102
103 /**
104 * The image for show selected elements
105 */
106 private Image showSelected;
107
108 /**
109 * The image for show all elements
110 */
111 private Image showAll;
112
113 /**
114 * This value tells the view status: 1 for showAll, -1 for showSelected, 0 otherwise
115 */
116 private int viewAll = 1;
117
118 /**
119 * ArrayList that holds all elements that can be shown 64 * ArrayList that holds all elements that can be shown
65 * (smaller than "dataSet" if showSelected)
120 */ 66 */
121 private ArrayList<DataObject> actualObjectSet; 67 private ArrayList<DataObject> actualObjectSet;
68
69 /**
70 * The dataobjects, which are presented at the actual page
71 */
72 //private DataObject[][] displayedObjects;
73
74 /**
75 * The grid for the page links
76 */
77 private Grid pages;
78
79 /**
80 * The number-of-results label
81 */
82 private Label results;
83
84 /**
85 * The image for the previous page
86 */
87 private Image previous;
88
89 /**
90 * The image for the next page
91 */
92 private Image next;
93
94 /**
95 * The image for show selected elements
96 */
97 private Image showSelected;
98
99 /**
100 * The image for show all elements
101 */
102 private Image showAll;
103
104 /**
105 * This value tells the view status: 1 for showAll, -1 for showSelected, 0 otherwise
106 */
107 private int viewAll = 1;
122 108
123 /** 109 /**
124 * Anchor that holds the URL for the KML download 110 * Anchor that holds the URL for the KML download
125 */ 111 */
126 private Anchor aDownloadKML; 112 private Anchor aDownloadKML;
128 /** 114 /**
129 * RPC Interface for writing the KML file 115 * RPC Interface for writing the KML file
130 */ 116 */
131 private ExportWriterInterfaceAsync exportWriter; 117 private ExportWriterInterfaceAsync exportWriter;
132 118
119 /**
120 * CellTable which will replace the elements-Grid
121 */
122 private CellTable<DataObject> elementsTable;
123
133 /** 124 /**
134 * Constructor for initialization of the dynamic table 125 * Constructor for initialization of the dynamic table
135 * 126 *
136 * @param core object to allow interaction with all javascript components 127 * @param core object to allow interaction with all javascript components
137 * @param id id of the dataset 128 * @param id id of the dataset
140 131
141 final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class); 132 final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class);
142 final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class); 133 final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class);
143 134
144 this.resize(2,1); 135 this.resize(2,1);
145 this.elements = new Grid();
146 this.addStyleName("dataTable"); 136 this.addStyleName("dataTable");
147 this.addStyleName("center"); 137 this.addStyleName("center");
148 138
149 this.index = id; 139 this.index = id;
150 this.core = stiCore; 140 this.core = stiCore;
151 this.dataSet = core.getDataSets().get(index); 141 this.dataSet = core.getDataSets().get(index);
152 setActualObjectSet(); 142 setActualObjectSet();
153 143
159 pages = new Grid(0,0); 149 pages = new Grid(0,0);
160 organizePages(); 150 organizePages();
161 151
162 previous.addClickHandler(new ClickHandler() { 152 previous.addClickHandler(new ClickHandler() {
163 public void onClick(ClickEvent event) { 153 public void onClick(ClickEvent event) {
164 selectedChunk--;
165 organizePages(); 154 organizePages();
166 checkHide(); 155 checkHide();
167 fillTable(); 156 fillTable();
168 } 157 }
169 }); 158 });
170 previous.setVisible(false); 159 previous.setVisible(false);
171 next.addClickHandler(new ClickHandler() { 160 next.addClickHandler(new ClickHandler() {
172 public void onClick(ClickEvent event) { 161 public void onClick(ClickEvent event) {
173 selectedChunk++;
174 organizePages(); 162 organizePages();
175 checkHide(); 163 checkHide();
176 fillTable(); 164 fillTable();
177 } 165 }
178 }); 166 });
179 if( chunkCount == 1 ){
180 next.setVisible(false);
181 }
182 167
183 showAll = new Image("images/viewAll"+(core.getColorId(index))+".png"); 168 showAll = new Image("images/viewAll"+(core.getColorId(index))+".png");
184 showAll.setTitle(textConstants.showAll()); 169 showAll.setTitle(textConstants.showAll());
185 showSelected = new Image("images/viewSelected"+(core.getColorId(index))+".png"); 170 showSelected = new Image("images/viewSelected"+(core.getColorId(index))+".png");
186 showSelected.setTitle(textConstants.showSelected()); 171 showSelected.setTitle(textConstants.showSelected());
260 public void onClick(ClickEvent event) { 245 public void onClick(ClickEvent event) {
261 textualSearch.setEnabled(true); 246 textualSearch.setEnabled(true);
262 core.reset(); 247 core.reset();
263 248
264 //TODO: das gibt es nun mehrfach im Code, sollte also in eine Funktion 249 //TODO: das gibt es nun mehrfach im Code, sollte also in eine Funktion
265 //Ÿberfuhrt werden 250 //�berfuhrt werden
266 showSelected.removeStyleName("selectedView"); 251 showSelected.removeStyleName("selectedView");
267 showAll.addStyleName("selectedView"); 252 showAll.addStyleName("selectedView");
268 viewAll = 1; 253 viewAll = 1;
269 setActualObjectSet(); 254 setActualObjectSet();
270 organizePages(); 255 organizePages();
279 this.results.setStyleName("resultsLabel"); 264 this.results.setStyleName("resultsLabel");
280 265
281 Label page = new Label(textConstants.page()+":"); 266 Label page = new Label(textConstants.page()+":");
282 page.setStyleName("pageLabel"); 267 page.setStyleName("pageLabel");
283 268
284 Grid footer = new Grid(1,4); 269 Grid footer = new Grid(1,1);
270 /*
285 footer.setWidget(0, 0, page ); 271 footer.setWidget(0, 0, page );
286 footer.setWidget(0, 1, pages ); 272 footer.setWidget(0, 1, pages );
287 footer.setWidget(0, 2, previous); 273 footer.setWidget(0, 2, previous);
288 footer.setWidget(0, 3, next); 274 footer.setWidget(0, 3, next);
289 footer.addStyleName("center"); 275 footer.addStyleName("center");
276 */
290 277
291 278
292 //This anchor will hold the URL of the export-file 279 //This anchor will hold the URL of the export-file
293 //for download from the ExportServlet 280 //for download from the ExportServlet
294 aDownloadKML = new Anchor("download KML"); 281 aDownloadKML = new Anchor("download KML");
338 tableControls.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); 325 tableControls.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
339 326
340 this.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); 327 this.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
341 this.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER); 328 this.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
342 this.getCellFormatter().setWidth(1, 0, "100%"); 329 this.getCellFormatter().setWidth(1, 0, "100%");
343 330
344 fillTable(); 331 this.elementsTable = new CellTable<DataObject>();
345 332
333 ListDataProvider<DataObject> dataProvider = new ListDataProvider<DataObject>();
334 dataProvider.addDataDisplay(this.elementsTable);
335
336 TextColumn<DataObject> nameColumn = new TextColumn<DataObject>() {
337 @Override
338 public String getValue(DataObject object) {
339 return object.getName();
340 }
341
342 };
343
344 this.elementsTable.addColumn(nameColumn);
345
346 SimplePager pager = new SimplePager();
347 pager.setDisplay(this.elementsTable);
348 footer.setWidget(0, 0, pager);
349
350 dataProvider.setList(this.actualObjectSet);
351
352 this.setWidget(1, 0, this.elementsTable);
346 } 353 }
347 354
348 /** 355 /**
349 * Sets the actual object set; depends on the showAll and showSelected selection 356 * Sets the actual object set; depends on the showAll and showSelected selection
350 * 357 *
359 objects.add(object); 366 objects.add(object);
360 } 367 }
361 } 368 }
362 if( objects.size() > 0 ){ 369 if( objects.size() > 0 ){
363 //TODO: Wenn die derzeitige Auswahl _keine_ Elemente 370 //TODO: Wenn die derzeitige Auswahl _keine_ Elemente
364 //enthŠlt, werden _alle_ angezeigt. Ist das sinnvoll? 371 //enth�lt, werden _alle_ angezeigt. Ist das sinnvoll?
365 actualObjectSet = objects; 372 actualObjectSet = objects;
366 } 373 }
367 else { 374 else {
368 return false; 375 return false;
369 } 376 }
372 actualObjectSet = new ArrayList<DataObject>(); 379 actualObjectSet = new ArrayList<DataObject>();
373 for( int i=0; i<this.dataSet.getObjects().length(); i++){ 380 for( int i=0; i<this.dataSet.getObjects().length(); i++){
374 actualObjectSet.add(this.dataSet.getObjects().get(i)); 381 actualObjectSet.add(this.dataSet.getObjects().get(i));
375 } 382 }
376 } 383 }
377 this.chunkCount = actualObjectSet.size() / ( maxCols * maxRows ); 384
378 if( actualObjectSet.size() % ( maxCols * maxRows ) != 0 ){
379 this.chunkCount++;
380 }
381 return true; 385 return true;
382 } 386 }
383 387
384 /** 388 /**
385 * Organizes the visible links in the pages grid 389 * Organizes the visible links in the pages grid
386 */ 390 */
387 private void organizePages(){ 391 private void organizePages(){
392 /*
388 ArrayList<Label> pageLabels = new ArrayList<Label>(); 393 ArrayList<Label> pageLabels = new ArrayList<Label>();
389 for( int i=1; i<this.chunkCount+1; i++ ){ 394 for( int i=1; i<this.chunkCount+1; i++ ){
390 final Label page = new Label(""+i); 395 final Label page = new Label(""+i);
391 page.addClickHandler(new ClickHandler() { 396 page.addClickHandler(new ClickHandler() {
392 public void onClick(ClickEvent event) { 397 public void onClick(ClickEvent event) {
428 page.setStyleName("page"); 433 page.setStyleName("page");
429 } 434 }
430 pages.setWidget(0,j,page); 435 pages.setWidget(0,j,page);
431 j++; 436 j++;
432 } 437 }
438 */
433 } 439 }
434 440
435 /** 441 /**
436 * Fills the table cells with content. It depends on the actual chosen chunk (page) and the objects in the actual object set. 442 * Fills the table cells with content. It depends on the actual chosen chunk (page) and the objects in the actual object set.
437 */ 443 */
438 private void fillTable(){ 444 private void fillTable(){
445 /*
439 this.elements.resize(0,0); 446 this.elements.resize(0,0);
440 this.elements.resize(this.maxRows, this.maxCols); 447 this.elements.resize(this.maxRows, this.maxCols);
441 this.displayedObjects = new DataObject[this.maxRows][this.maxCols]; 448 this.displayedObjects = new DataObject[this.maxRows][this.maxCols];
442 this.setWidget(1, 0, this.elements); 449 this.setWidget(1, 0, this.elements);
443 int start = this.selectedChunk * ( this.maxCols * this.maxRows ); 450 int start = this.selectedChunk * ( this.maxCols * this.maxRows );
444 int end = start + ( this.maxCols * this.maxRows ); 451 int end = start + ( this.maxCols * this.maxRows );
445 if( end > this.actualObjectSet.size() ){ 452 if( end > this.actualObjectSet.size() ){
446 end = this.actualObjectSet.size(); 453 end = this.actualObjectSet.size();
447 } 454 }
448 this.results.setText("Results "+(start+1)+" - "+end+" of "+this.actualObjectSet.size()); 455 this.results.setText("Results "+(start+1)+" - "+end+" of "+this.actualObjectSet.size());
456
449 int row = 0, col = 0; 457 int row = 0, col = 0;
450 for( int i=start; i<end; i++){ 458 for( int i=start; i<end; i++){
451 DataObject object = (DataObject) this.actualObjectSet.get(i); 459 DataObject object = (DataObject) this.actualObjectSet.get(i);
452 String oName = object.getName(); 460 String oName = object.getName();
453 if( oName.length() > 60 ){ 461 if( oName.length() > 60 ){
509 col++; 517 col++;
510 if( col % this.maxCols == 0 ){ 518 if( col % this.maxCols == 0 ){
511 row++; 519 row++;
512 } 520 }
513 } 521 }
522 */
514 } 523 }
515 524
516 /** 525 /**
517 * Creates a (preliminary) KML file from the data in the current data set 526 * Creates a (preliminary) KML file from the data in the current data set
518 */ 527 */
595 else 604 else
596 currentDataObject.setPercentage(0); 605 currentDataObject.setPercentage(0);
597 } 606 }
598 607
599 //TODO: das gibt es nun mehrfach im Code, sollte also in eine Funktion 608 //TODO: das gibt es nun mehrfach im Code, sollte also in eine Funktion
600 //Ÿberfuhrt werden 609 //�berfuhrt werden
601 viewAll = -1; 610 viewAll = -1;
602 setActualObjectSet(); 611 setActualObjectSet();
603 showAll.removeStyleName("selectedView"); 612 showAll.removeStyleName("selectedView");
604 showSelected.addStyleName("selectedView"); 613 showSelected.addStyleName("selectedView");
605 organizePages(); 614 organizePages();
609 618
610 /** 619 /**
611 * Checks, if the previous or next button has to be hidden 620 * Checks, if the previous or next button has to be hidden
612 */ 621 */
613 private void checkHide(){ 622 private void checkHide(){
623 /*
614 if( this.selectedChunk == 0 ){ 624 if( this.selectedChunk == 0 ){
615 previous.setVisible(false); 625 previous.setVisible(false);
616 } 626 }
617 else { 627 else {
618 previous.setVisible(true); 628 previous.setVisible(true);
621 next.setVisible(false); 631 next.setVisible(false);
622 } 632 }
623 else { 633 else {
624 next.setVisible(true); 634 next.setVisible(true);
625 } 635 }
636 */
626 } 637 }
627 638
628 /** 639 /**
629 * Updates a cell at the position (row,col). Depends on the selection status of the corresponding dataobject. 640 * Updates a cell at the position (row,col). Depends on the selection status of the corresponding dataobject.
630 * 641 *
631 * @param row the row of the cell 642 * @param row the row of the cell
632 * @param col the col of the cell 643 * @param col the col of the cell
633 */ 644 */
634 private void updateCell( int row, int col ){ 645 private void updateCell( int row, int col ){
646 /*
635 boolean selected = this.displayedObjects[row][col].isSelected(); 647 boolean selected = this.displayedObjects[row][col].isSelected();
636 double percentage = (new Double(this.displayedObjects[row][col].getPercentage()).doubleValue()); 648 double percentage = (new Double(this.displayedObjects[row][col].getPercentage()).doubleValue());
637 String borderColor = StiCore.getBorderColor(this.index,selected); 649 String borderColor = StiCore.getBorderColor(this.index,selected);
638 String cellColor = StiCore.getCellColor(this.index,percentage); 650 String cellColor = StiCore.getCellColor(this.index,percentage);
651
639 this.elements.getCellFormatter().getElement(row, col).getStyle().setBorderColor(borderColor); 652 this.elements.getCellFormatter().getElement(row, col).getStyle().setBorderColor(borderColor);
640 this.elements.getCellFormatter().getElement(row, col).getStyle().setBackgroundColor(cellColor); 653 this.elements.getCellFormatter().getElement(row, col).getStyle().setBackgroundColor(cellColor);
654 */
641 } 655 }
642 656
643 /** 657 /**
644 * Updates all cells of the actual page 658 * Updates all cells of the actual page
645 * 659 *
648 public void updateView(boolean hover){ 662 public void updateView(boolean hover){
649 if( !hover && this.viewAll == -1 ){ 663 if( !hover && this.viewAll == -1 ){
650 showSelected.removeStyleName("selectedView"); 664 showSelected.removeStyleName("selectedView");
651 this.viewAll = 0; 665 this.viewAll = 0;
652 } 666 }
667 /*
653 for( int i=0; i<this.displayedObjects.length; i++ ){ 668 for( int i=0; i<this.displayedObjects.length; i++ ){
654 for( int j=0; j<this.displayedObjects[i].length; j++ ){ 669 for( int j=0; j<this.displayedObjects[i].length; j++ ){
655 if( this.displayedObjects[i][j] != null && this.displayedObjects[i][j].getStatus() ){ 670 if( this.displayedObjects[i][j] != null && this.displayedObjects[i][j].getStatus() ){
656 updateCell(i,j); 671 updateCell(i,j);
657 } 672 }
658 } 673 }
659 } 674 }
675 */
660 } 676 }
661 677
662 public String getTermIdentifier() { 678 public String getTermIdentifier() {
663 return this.dataSet.getTermIdentifier(); 679 return this.dataSet.getTermIdentifier();
664 } 680 }