Mercurial > hg > STI-GWT
comparison src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java @ 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 | 20eb7596d466 |
children | 5db587ba4b0f fc9061488e75 |
comparison
equal
deleted
inserted
replaced
42:fe6778a2fada | 43:fad6fb60a2db |
---|---|
49 * The sti core component | 49 * The sti core component |
50 */ | 50 */ |
51 private StiCore core; | 51 private StiCore core; |
52 | 52 |
53 /** | 53 /** |
54 * The index of the dataset | |
55 */ | |
56 private int index; | |
57 | |
58 /** | |
54 * The dataset of this dynamic table | 59 * The dataset of this dynamic table |
55 */ | 60 */ |
56 private DataSet dataSet; | 61 private DataSet dataSet; |
57 | |
58 /** | |
59 * The index of the dataset | |
60 */ | |
61 private int index; | |
62 | 62 |
63 /** | 63 /** |
64 * 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) | 65 * (smaller than "dataSet" if showSelected) |
66 */ | 66 */ |
67 private ArrayList<DataObject> actualObjectSet; | 67 private ArrayList<DataObject> actualObjectSet; |
68 | 68 |
69 /** | 69 /** |
70 * Provider that hands the data to the table | |
71 */ | |
72 private ListDataProvider<DataObject> dataProvider; | |
73 | |
74 /** | |
75 * CellTable which displays the data | |
76 */ | |
77 private CellTable<DataObject> elementsTable; | |
78 | |
79 /** | |
70 * The dataobjects, which are presented at the actual page | 80 * The dataobjects, which are presented at the actual page |
71 */ | 81 */ |
72 //private DataObject[][] displayedObjects; | 82 //private DataObject[][] displayedObjects; |
73 | 83 |
74 /** | 84 /** |
75 * The grid for the page links | |
76 */ | |
77 private Grid pages; | |
78 | |
79 /** | |
80 * The number-of-results label | 85 * The number-of-results label |
81 */ | 86 */ |
82 private Label results; | 87 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 | 88 |
94 /** | 89 /** |
95 * The image for show selected elements | 90 * The image for show selected elements |
96 */ | 91 */ |
97 private Image showSelected; | 92 private Image showSelected; |
113 | 108 |
114 /** | 109 /** |
115 * RPC Interface for writing the KML file | 110 * RPC Interface for writing the KML file |
116 */ | 111 */ |
117 private ExportWriterInterfaceAsync exportWriter; | 112 private ExportWriterInterfaceAsync exportWriter; |
118 | |
119 /** | |
120 * CellTable which will replace the elements-Grid | |
121 */ | |
122 private CellTable<DataObject> elementsTable; | |
123 | 113 |
124 /** | 114 /** |
125 * Constructor for initialization of the dynamic table | 115 * Constructor for initialization of the dynamic table |
126 * | 116 * |
127 * @param core object to allow interaction with all javascript components | 117 * @param core object to allow interaction with all javascript components |
137 this.addStyleName("center"); | 127 this.addStyleName("center"); |
138 | 128 |
139 this.index = id; | 129 this.index = id; |
140 this.core = stiCore; | 130 this.core = stiCore; |
141 this.dataSet = core.getDataSets().get(index); | 131 this.dataSet = core.getDataSets().get(index); |
132 this.actualObjectSet = new ArrayList<DataObject>(); | |
142 setActualObjectSet(); | 133 setActualObjectSet(); |
143 | |
144 previous = new Image( "images/prev.png" ); | |
145 previous.setStyleName("arrow"); | |
146 next = new Image( "images/next.png" ); | |
147 next.setStyleName("arrow"); | |
148 | |
149 pages = new Grid(0,0); | |
150 organizePages(); | |
151 | |
152 previous.addClickHandler(new ClickHandler() { | |
153 public void onClick(ClickEvent event) { | |
154 organizePages(); | |
155 checkHide(); | |
156 fillTable(); | |
157 } | |
158 }); | |
159 previous.setVisible(false); | |
160 next.addClickHandler(new ClickHandler() { | |
161 public void onClick(ClickEvent event) { | |
162 organizePages(); | |
163 checkHide(); | |
164 fillTable(); | |
165 } | |
166 }); | |
167 | 134 |
168 showAll = new Image("images/viewAll"+(core.getColorId(index))+".png"); | 135 showAll = new Image("images/viewAll"+(core.getColorId(index))+".png"); |
169 showAll.setTitle(textConstants.showAll()); | 136 showAll.setTitle(textConstants.showAll()); |
170 showSelected = new Image("images/viewSelected"+(core.getColorId(index))+".png"); | 137 showSelected = new Image("images/viewSelected"+(core.getColorId(index))+".png"); |
171 showSelected.setTitle(textConstants.showSelected()); | 138 showSelected.setTitle(textConstants.showSelected()); |
177 if( viewAll != 1 ){ | 144 if( viewAll != 1 ){ |
178 showSelected.removeStyleName("selectedView"); | 145 showSelected.removeStyleName("selectedView"); |
179 showAll.addStyleName("selectedView"); | 146 showAll.addStyleName("selectedView"); |
180 viewAll = 1; | 147 viewAll = 1; |
181 setActualObjectSet(); | 148 setActualObjectSet(); |
182 organizePages(); | |
183 checkHide(); | |
184 fillTable(); | |
185 } | 149 } |
186 } | 150 } |
187 }); | 151 }); |
188 showSelected.addClickHandler(new ClickHandler() { | 152 showSelected.addClickHandler(new ClickHandler() { |
189 public void onClick(ClickEvent event) { | 153 public void onClick(ClickEvent event) { |
190 if( viewAll != -1 ){ | 154 if( viewAll != -1 ){ |
191 viewAll = -1; | 155 viewAll = -1; |
192 if( setActualObjectSet() ){ | 156 if( setActualObjectSet() ){ |
193 showAll.removeStyleName("selectedView"); | 157 showAll.removeStyleName("selectedView"); |
194 showSelected.addStyleName("selectedView"); | 158 showSelected.addStyleName("selectedView"); |
195 organizePages(); | |
196 checkHide(); | |
197 fillTable(); | |
198 } | 159 } |
199 else { | 160 else { |
200 viewAll = 1; | 161 viewAll = 1; |
201 } | 162 } |
202 } | 163 } |
250 //�berfuhrt werden | 211 //�berfuhrt werden |
251 showSelected.removeStyleName("selectedView"); | 212 showSelected.removeStyleName("selectedView"); |
252 showAll.addStyleName("selectedView"); | 213 showAll.addStyleName("selectedView"); |
253 viewAll = 1; | 214 viewAll = 1; |
254 setActualObjectSet(); | 215 setActualObjectSet(); |
255 organizePages(); | |
256 checkHide(); | |
257 fillTable(); | |
258 | 216 |
259 refine.setWidget(0, 1, search); | 217 refine.setWidget(0, 1, search); |
260 } | 218 } |
261 }); | 219 }); |
262 | 220 |
263 this.results = new Label(); | 221 this.results = new Label(); |
264 this.results.setStyleName("resultsLabel"); | 222 this.results.setStyleName("resultsLabel"); |
265 | 223 |
266 Label page = new Label(textConstants.page()+":"); | 224 Label page = new Label(textConstants.page()+":"); |
267 page.setStyleName("pageLabel"); | 225 page.setStyleName("pageLabel"); |
268 | |
269 Grid footer = new Grid(1,1); | |
270 /* | |
271 footer.setWidget(0, 0, page ); | |
272 footer.setWidget(0, 1, pages ); | |
273 footer.setWidget(0, 2, previous); | |
274 footer.setWidget(0, 3, next); | |
275 footer.addStyleName("center"); | |
276 */ | |
277 | |
278 | 226 |
279 //This anchor will hold the URL of the export-file | 227 //This anchor will hold the URL of the export-file |
280 //for download from the ExportServlet | 228 //for download from the ExportServlet |
281 aDownloadKML = new Anchor("download KML"); | 229 aDownloadKML = new Anchor("download KML"); |
282 aDownloadKML.setVisible(false); | 230 aDownloadKML.setVisible(false); |
310 func.setWidget(0, 0, aDownloadKML); | 258 func.setWidget(0, 0, aDownloadKML); |
311 func.setWidget(0, 1, export); | 259 func.setWidget(0, 1, export); |
312 func.setWidget(0, 2, delete); | 260 func.setWidget(0, 2, delete); |
313 func.addStyleName("center"); | 261 func.addStyleName("center"); |
314 | 262 |
315 Grid tableControls = new Grid(1,5); | |
316 tableControls.setWidget(0,0,showOptions); | |
317 tableControls.setWidget(0,1,refine); | |
318 tableControls.setWidget(0,2,this.results); | |
319 tableControls.setWidget(0,3,footer); | |
320 tableControls.setWidget(0,4,func); | |
321 tableControls.setStyleName("tableControls"); | |
322 | |
323 this.setWidget(0, 0, tableControls); | |
324 | |
325 tableControls.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); | |
326 | |
327 this.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); | |
328 this.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER); | |
329 this.getCellFormatter().setWidth(1, 0, "100%"); | |
330 | |
331 this.elementsTable = new CellTable<DataObject>(); | 263 this.elementsTable = new CellTable<DataObject>(); |
332 | 264 |
333 ListDataProvider<DataObject> dataProvider = new ListDataProvider<DataObject>(); | 265 dataProvider = new ListDataProvider<DataObject>(); |
334 dataProvider.addDataDisplay(this.elementsTable); | 266 dataProvider.addDataDisplay(this.elementsTable); |
335 | 267 |
336 TextColumn<DataObject> nameColumn = new TextColumn<DataObject>() { | 268 TextColumn<DataObject> nameColumn = new TextColumn<DataObject>() { |
337 @Override | 269 @Override |
338 public String getValue(DataObject object) { | 270 public String getValue(DataObject object) { |
343 | 275 |
344 this.elementsTable.addColumn(nameColumn); | 276 this.elementsTable.addColumn(nameColumn); |
345 | 277 |
346 SimplePager pager = new SimplePager(); | 278 SimplePager pager = new SimplePager(); |
347 pager.setDisplay(this.elementsTable); | 279 pager.setDisplay(this.elementsTable); |
348 footer.setWidget(0, 0, pager); | |
349 | 280 |
350 dataProvider.setList(this.actualObjectSet); | 281 dataProvider.setList(this.actualObjectSet); |
351 | 282 |
352 this.setWidget(1, 0, this.elementsTable); | 283 this.setWidget(1, 0, this.elementsTable); |
284 | |
285 Grid tableControls = new Grid(1,5); | |
286 tableControls.setWidget(0,0,showOptions); | |
287 tableControls.setWidget(0,1,refine); | |
288 tableControls.setWidget(0,2,this.results); | |
289 tableControls.setWidget(0,3,pager); | |
290 tableControls.setWidget(0,4,func); | |
291 tableControls.setStyleName("tableControls"); | |
292 | |
293 this.setWidget(0, 0, tableControls); | |
294 | |
295 tableControls.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); | |
296 | |
297 this.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); | |
298 this.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER); | |
299 this.getCellFormatter().setWidth(1, 0, "100%"); | |
353 } | 300 } |
354 | 301 |
355 /** | 302 /** |
356 * Sets the actual object set; depends on the showAll and showSelected selection | 303 * Sets the actual object set; depends on the showAll and showSelected selection |
357 * | 304 * |
358 * @return boolean value, if there are selected objects | 305 * @return boolean value, if there are selected objects |
359 */ | 306 */ |
360 private boolean setActualObjectSet(){ | 307 private boolean setActualObjectSet(){ |
308 | |
309 boolean dataSetWasEmpty = false; | |
310 | |
361 if( viewAll == -1 ){ | 311 if( viewAll == -1 ){ |
362 ArrayList<DataObject> objects = new ArrayList<DataObject>(); | 312 |
313 this.actualObjectSet.clear(); | |
314 | |
363 for( int i=0; i<this.dataSet.getObjects().length(); i++){ | 315 for( int i=0; i<this.dataSet.getObjects().length(); i++){ |
364 DataObject object = this.dataSet.getObjects().get(i); | 316 DataObject object = this.dataSet.getObjects().get(i); |
365 if( object.isSelected() ){ | 317 if( object.isSelected() ){ |
366 objects.add(object); | 318 this.actualObjectSet.add(object); |
367 } | 319 } |
368 } | 320 } |
369 if( objects.size() > 0 ){ | 321 if( this.actualObjectSet.size() == 0 ){ |
370 //TODO: Wenn die derzeitige Auswahl _keine_ Elemente | 322 //TODO: Wenn die derzeitige Auswahl _keine_ Elemente |
371 //enth�lt, werden _alle_ angezeigt. Ist das sinnvoll? | 323 //enth�lt, werden _alle_ angezeigt. Ist das sinnvoll? |
372 actualObjectSet = objects; | 324 dataSetWasEmpty = true; |
373 } | 325 this.viewAll = 1; |
374 else { | 326 } |
375 return false; | 327 } |
376 } | 328 if( this.viewAll == 1 ){ |
377 } | 329 this.actualObjectSet.clear(); |
378 else if( viewAll == 1 ){ | |
379 actualObjectSet = new ArrayList<DataObject>(); | |
380 for( int i=0; i<this.dataSet.getObjects().length(); i++){ | 330 for( int i=0; i<this.dataSet.getObjects().length(); i++){ |
381 actualObjectSet.add(this.dataSet.getObjects().get(i)); | 331 this.actualObjectSet.add(this.dataSet.getObjects().get(i)); |
382 } | 332 } |
383 } | 333 } |
384 | 334 |
385 return true; | 335 //if the dataProvider already exists, refresh the |
386 } | 336 //displayed data |
387 | 337 if (this.dataProvider != null) { |
388 /** | 338 this.dataProvider.refresh(); |
389 * Organizes the visible links in the pages grid | 339 |
390 */ | 340 this.elementsTable.setRowCount(this.actualObjectSet.size()); |
391 private void organizePages(){ | 341 } |
392 /* | 342 |
393 ArrayList<Label> pageLabels = new ArrayList<Label>(); | 343 if (dataSetWasEmpty) |
394 for( int i=1; i<this.chunkCount+1; i++ ){ | 344 return false; |
395 final Label page = new Label(""+i); | 345 else |
396 page.addClickHandler(new ClickHandler() { | 346 return true; |
397 public void onClick(ClickEvent event) { | |
398 selectedChunk = Integer.parseInt(page.getText())-1; | |
399 checkHide(); | |
400 fillTable(); | |
401 updateView(false); | |
402 organizePages(); | |
403 } | |
404 }); | |
405 pageLabels.add(page); | |
406 } | |
407 int max = 10; | |
408 if( this.chunkCount<10 ){ | |
409 max = this.chunkCount; | |
410 } | |
411 pages.resize(1,max); | |
412 int start = selectedChunk - 4; | |
413 int rest = max - 5; | |
414 if( start < 0 ){ | |
415 rest += (-1)*start; | |
416 start = 0; | |
417 } | |
418 int end = selectedChunk + rest; | |
419 if( end > this.chunkCount - 1 ){ | |
420 start -= end - this.chunkCount + 1; | |
421 end = this.chunkCount - 1; | |
422 } | |
423 if( start < 0 ){ | |
424 start = 0; | |
425 } | |
426 int j=0; | |
427 for( int i=start; i<end+1; i++ ){ | |
428 Label page = (Label) pageLabels.get(i); | |
429 if( selectedChunk == Integer.parseInt(page.getText())-1 ){ | |
430 page.setStyleName("selectedPage"); | |
431 } | |
432 else { | |
433 page.setStyleName("page"); | |
434 } | |
435 pages.setWidget(0,j,page); | |
436 j++; | |
437 } | |
438 */ | |
439 } | |
440 | |
441 /** | |
442 * Fills the table cells with content. It depends on the actual chosen chunk (page) and the objects in the actual object set. | |
443 */ | |
444 private void fillTable(){ | |
445 /* | |
446 this.elements.resize(0,0); | |
447 this.elements.resize(this.maxRows, this.maxCols); | |
448 this.displayedObjects = new DataObject[this.maxRows][this.maxCols]; | |
449 this.setWidget(1, 0, this.elements); | |
450 int start = this.selectedChunk * ( this.maxCols * this.maxRows ); | |
451 int end = start + ( this.maxCols * this.maxRows ); | |
452 if( end > this.actualObjectSet.size() ){ | |
453 end = this.actualObjectSet.size(); | |
454 } | |
455 this.results.setText("Results "+(start+1)+" - "+end+" of "+this.actualObjectSet.size()); | |
456 | |
457 int row = 0, col = 0; | |
458 for( int i=start; i<end; i++){ | |
459 DataObject object = (DataObject) this.actualObjectSet.get(i); | |
460 String oName = object.getName(); | |
461 if( oName.length() > 60 ){ | |
462 oName = oName.substring(0, 57); | |
463 oName += "..."; | |
464 } | |
465 Label name = new Label(oName); | |
466 Label place = new Label(object.getPlace()); | |
467 Label time = new Label(object.getTimeString()); | |
468 final Grid infoGrid = new Grid(3,1); | |
469 infoGrid.setWidget(0, 0, name); | |
470 infoGrid.setWidget(1, 0, place); | |
471 infoGrid.setWidget(2, 0, time); | |
472 if( !object.getDescription().equals("") ){ | |
473 infoGrid.resize(4,1); | |
474 HTML description = new HTML(object.getDescription()); | |
475 description.addStyleName("description"); | |
476 infoGrid.setWidget(3, 0, description); | |
477 } | |
478 infoGrid.addStyleName("unselectedCellInner"); | |
479 name.addStyleName("nameLabel"); | |
480 place.addStyleName("dataLabel"); | |
481 time.addStyleName("dataLabel"); | |
482 HTML text = new HTML(); | |
483 text.setHTML(infoGrid.toString()); | |
484 final int r = row; | |
485 final int c = col % this.maxCols; | |
486 this.displayedObjects[r][c] = object; | |
487 text.addMouseOverHandler(new MouseOverHandler(){ | |
488 public void onMouseOver(MouseOverEvent event) { | |
489 core.undoHover(); | |
490 displayedObjects[r][c].setHover(true); | |
491 updateCell(r,c); | |
492 core.updateTimeAndMap(); | |
493 } | |
494 }); | |
495 text.addMouseOutHandler(new MouseOutHandler(){ | |
496 public void onMouseOut(MouseOutEvent event) { | |
497 displayedObjects[r][c].setHover(false); | |
498 updateCell(r,c); | |
499 core.updateTimeAndMap(); | |
500 } | |
501 }); | |
502 text.addClickHandler(new ClickHandler(){ | |
503 public void onClick(ClickEvent event) { | |
504 if( displayedObjects[r][c].getPercentage() == 1 ){ | |
505 displayedObjects[r][c].setPercentage(0); | |
506 } | |
507 else { | |
508 displayedObjects[r][c].setPercentage(1); | |
509 } | |
510 updateCell(r,c); | |
511 core.updateTimeAndMap(); | |
512 } | |
513 }); | |
514 this.elements.setWidget(r,c,text); | |
515 this.elements.getCellFormatter().getElement(r,c).setClassName("unselectedCellOuter"); | |
516 updateCell(r,c); | |
517 col++; | |
518 if( col % this.maxCols == 0 ){ | |
519 row++; | |
520 } | |
521 } | |
522 */ | |
523 } | 347 } |
524 | 348 |
525 /** | 349 /** |
526 * Creates a (preliminary) KML file from the data in the current data set | 350 * Creates a (preliminary) KML file from the data in the current data set |
527 */ | 351 */ |
603 currentDataObject.setPercentage(1); | 427 currentDataObject.setPercentage(1); |
604 else | 428 else |
605 currentDataObject.setPercentage(0); | 429 currentDataObject.setPercentage(0); |
606 } | 430 } |
607 | 431 |
608 //TODO: das gibt es nun mehrfach im Code, sollte also in eine Funktion | |
609 //�berfuhrt werden | |
610 viewAll = -1; | |
611 setActualObjectSet(); | 432 setActualObjectSet(); |
612 showAll.removeStyleName("selectedView"); | |
613 showSelected.addStyleName("selectedView"); | |
614 organizePages(); | |
615 checkHide(); | |
616 fillTable(); | |
617 } | |
618 | |
619 /** | |
620 * Checks, if the previous or next button has to be hidden | |
621 */ | |
622 private void checkHide(){ | |
623 /* | |
624 if( this.selectedChunk == 0 ){ | |
625 previous.setVisible(false); | |
626 } | |
627 else { | |
628 previous.setVisible(true); | |
629 } | |
630 if( this.selectedChunk+1 >= this.chunkCount ){ | |
631 next.setVisible(false); | |
632 } | |
633 else { | |
634 next.setVisible(true); | |
635 } | |
636 */ | |
637 } | |
638 | |
639 /** | |
640 * Updates a cell at the position (row,col). Depends on the selection status of the corresponding dataobject. | |
641 * | |
642 * @param row the row of the cell | |
643 * @param col the col of the cell | |
644 */ | |
645 private void updateCell( int row, int col ){ | |
646 /* | |
647 boolean selected = this.displayedObjects[row][col].isSelected(); | |
648 double percentage = (new Double(this.displayedObjects[row][col].getPercentage()).doubleValue()); | |
649 String borderColor = StiCore.getBorderColor(this.index,selected); | |
650 String cellColor = StiCore.getCellColor(this.index,percentage); | |
651 | |
652 this.elements.getCellFormatter().getElement(row, col).getStyle().setBorderColor(borderColor); | |
653 this.elements.getCellFormatter().getElement(row, col).getStyle().setBackgroundColor(cellColor); | |
654 */ | |
655 } | 433 } |
656 | 434 |
657 /** | 435 /** |
658 * Updates all cells of the actual page | 436 * Updates all cells of the actual page |
659 * | 437 * |