comparison src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java @ 74:caca95f925cc trimmed_data

Add switchable "views" to the CellTable (sets of Columns)
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Mon, 14 Jan 2013 14:37:26 +0100
parents a610b45d0f90
children 731a2f32978c
comparison
equal deleted inserted replaced
73:02cdf454d94b 74:caca95f925cc
90 * CellTable which displays the data 90 * CellTable which displays the data
91 */ 91 */
92 private CellTable<DataObject> elementsTable; 92 private CellTable<DataObject> elementsTable;
93 93
94 /** 94 /**
95 * This class is used for the Lists of Columns that
96 * represent the different "views" of the CellTable
97 */
98 class ColumnAndName {
99 public Column<DataObject,?> column;
100 public String name;
101
102 public ColumnAndName(Column<DataObject,?> column, String name) {
103 this.column = column;
104 this.name = name;
105 }
106 }
107
108 /**
109 * "Views" of columns of the celltable
110 */
111 private ArrayList<ArrayList<ColumnAndName>> columns;
112
113 /**
114 * Thie index of the "View" that is currently visible
115 * (translates to an index of the columns ArrayList)
116 */
117 private int currentlyVisibleView;
118
119 /**
95 * The dataobjects, which are presented at the actual page 120 * The dataobjects, which are presented at the actual page
96 */ 121 */
97 //private DataObject[][] displayedObjects; 122 //private DataObject[][] displayedObjects;
98 123
99 /** 124 /**
123 148
124 /** 149 /**
125 * RPC Interface for writing the KML file 150 * RPC Interface for writing the KML file
126 */ 151 */
127 private ExportWriterInterfaceAsync exportWriter; 152 private ExportWriterInterfaceAsync exportWriter;
128 153
129 /** 154 /**
130 * Constructor for initialization of the dynamic table 155 * Constructor for initialization of the dynamic table
131 * 156 *
132 * @param core object to allow interaction with all javascript components 157 * @param core object to allow interaction with all javascript components
133 * @param id id of the dataset 158 * @param id id of the dataset
144 this.index = id; 169 this.index = id;
145 this.core = stiCore; 170 this.core = stiCore;
146 this.dataSet = core.getDataSets().get(index); 171 this.dataSet = core.getDataSets().get(index);
147 this.actualObjectSet = new ArrayList<DataObject>(); 172 this.actualObjectSet = new ArrayList<DataObject>();
148 setActualObjectSet(); 173 setActualObjectSet();
174
175 this.columns = new ArrayList<ArrayList<ColumnAndName>>();
176
177 //should be Name + Place
178 currentlyVisibleView = 0;
179
180 Image switchTableLayout = new Image(constants.playEnabled());
181 switchTableLayout.addClickHandler(new ClickHandler() {
182 public void onClick(ClickEvent event) {
183 //switch the layout of the table
184 switchTableLayout();
185 }
186 });
149 187
150 showAll = new Image("images/viewAll"+(core.getColorId(index))+".png"); 188 showAll = new Image("images/viewAll"+(core.getColorId(index))+".png");
151 showAll.setTitle(textConstants.showAll()); 189 showAll.setTitle(textConstants.showAll());
152 showSelected = new Image("images/viewSelected"+(core.getColorId(index))+".png"); 190 showSelected = new Image("images/viewSelected"+(core.getColorId(index))+".png");
153 showSelected.setTitle(textConstants.showSelected()); 191 showSelected.setTitle(textConstants.showSelected());
186 public void onClick(ClickEvent event) { 224 public void onClick(ClickEvent event) {
187 core.storeSelected(id); 225 core.storeSelected(id);
188 } 226 }
189 }); 227 });
190 228
191 Grid showOptions = new Grid(1,3); 229 Grid showOptions = new Grid(1,4);
192 showOptions.setWidget(0,0,showAll); 230 showOptions.setWidget(0,0,switchTableLayout);
193 showOptions.setWidget(0,1,showSelected); 231 showOptions.setWidget(0,1,showAll);
194 showOptions.setWidget(0,2,storeSelected); 232 showOptions.setWidget(0,2,showSelected);
233 showOptions.setWidget(0,3,storeSelected);
195 234
196 final TextBox textualSearch = new TextBox(); 235 final TextBox textualSearch = new TextBox();
197 final Button search = new Button("go"); 236 final Button search = new Button("go");
198 final Image cancelImage = new Image(constants.cancelImage()); 237 final Image cancelImage = new Image(constants.cancelImage());
199 final Image refineImage = new Image(constants.refineImage()); 238 final Image refineImage = new Image(constants.refineImage());
275 func.setWidget(0, 2, delete); 314 func.setWidget(0, 2, delete);
276 func.addStyleName("center"); 315 func.addStyleName("center");
277 316
278 this.elementsTable = new CellTable<DataObject>(); 317 this.elementsTable = new CellTable<DataObject>();
279 elementsTable.getElement().getStyle().setWidth(100, Unit.PCT); 318 elementsTable.getElement().getStyle().setWidth(100, Unit.PCT);
280
281 dataProvider = new ListDataProvider<DataObject>(); 319 dataProvider = new ListDataProvider<DataObject>();
282 dataProvider.addDataDisplay(this.elementsTable); 320 dataProvider.addDataDisplay(this.elementsTable);
321
322 ArrayList<ColumnAndName> nameplaceColumnList = new ArrayList<ColumnAndName>();
283 323
284 TextColumn<DataObject> nameColumn = new TextColumn<DataObject>() { 324 TextColumn<DataObject> nameColumn = new TextColumn<DataObject>() {
285 @Override 325 @Override
286 public String getValue(DataObject object) { 326 public String getValue(DataObject object) {
287 return object.getName(); 327 return object.getName();
288 } 328 }
289 }; 329 };
290 nameColumn.setSortable(true); 330 nameColumn.setSortable(true);
291 this.elementsTable.addColumn(nameColumn, "Name"); 331 nameplaceColumnList.add(new ColumnAndName(nameColumn, "Name"));
292 332
293 TextColumn<DataObject> placeColumn = new TextColumn<DataObject>() { 333 TextColumn<DataObject> placeColumn = new TextColumn<DataObject>() {
294 @Override 334 @Override
295 public String getValue(DataObject object) { 335 public String getValue(DataObject object) {
296 return object.getPlace(); 336 return object.getPlace();
297 } 337 }
298 }; 338 };
299 placeColumn.setSortable(true); 339 placeColumn.setSortable(true);
300 this.elementsTable.addColumn(placeColumn, "Place"); 340 nameplaceColumnList.add(new ColumnAndName(placeColumn, "Place"));
341
342 columns.add(nameplaceColumnList);
343
344 ArrayList<ColumnAndName> descriptionColumnList = new ArrayList<ColumnAndName>();
301 345
302 SafeHtmlCell descriptionCell = new SafeHtmlCell(); 346 SafeHtmlCell descriptionCell = new SafeHtmlCell();
303 347
304 Column<DataObject, SafeHtml> descriptionColumn = new Column<DataObject, SafeHtml>(descriptionCell) { 348 Column<DataObject, SafeHtml> descriptionColumn = new Column<DataObject, SafeHtml>(descriptionCell) {
305 @Override 349 @Override
308 sb.appendHtmlConstant(object.getDescription()); 352 sb.appendHtmlConstant(object.getDescription());
309 return sb.toSafeHtml(); 353 return sb.toSafeHtml();
310 } 354 }
311 }; 355 };
312 descriptionColumn.setSortable(true); 356 descriptionColumn.setSortable(true);
313 this.elementsTable.addColumn(descriptionColumn, "Description"); 357 descriptionColumnList.add(new ColumnAndName(descriptionColumn, "Description"));
358
359 columns.add(descriptionColumnList);
314 360
315 SimplePager pager = new SimplePager(); 361 SimplePager pager = new SimplePager();
316 pager.setDisplay(this.elementsTable); 362 pager.setDisplay(this.elementsTable);
317 363
318 dataProvider.setList(this.actualObjectSet); 364 dataProvider.setList(this.actualObjectSet);
319 365
320 //The actual (at this time lexicographical) sorting routine. 366 //The actual (at this time lexicographical) sorting routine.
321 //TODO: remove redundant code, make this more abstract 367 //TODO: remove redundant code, make this more abstract
322 ListHandler<DataObject> columnSortHandler = new ListHandler<econnect.wp3_3.client.core.DataObject>(dataProvider.getList()); 368 ListHandler<DataObject> columnSortHandler = new ListHandler<econnect.wp3_3.client.core.DataObject>(dataProvider.getList());
369
370 ArrayList<ColumnAndName> descriptionDataColumnList = new ArrayList<ColumnAndName>();
323 371
324 JsArrayString descriptionDataColumns = this.dataSet.getDescriptionDataColumns(); 372 JsArrayString descriptionDataColumns = this.dataSet.getDescriptionDataColumns();
325 for (int i = 0; i < descriptionDataColumns.length(); i++) { 373 for (int i = 0; i < descriptionDataColumns.length(); i++) {
326 final String columnName = descriptionDataColumns.get(i); 374 final String columnName = descriptionDataColumns.get(i);
327 375
349 397
350 return -1; 398 return -1;
351 } 399 }
352 }); 400 });
353 401
354 this.elementsTable.addColumn(column, columnName); 402 descriptionDataColumnList.add(new ColumnAndName(column, columnName));
355 } 403 }
404
405 columns.add(descriptionDataColumnList);
356 406
357 columnSortHandler.setComparator(nameColumn, 407 columnSortHandler.setComparator(nameColumn,
358 new Comparator<econnect.wp3_3.client.core.DataObject>() { 408 new Comparator<econnect.wp3_3.client.core.DataObject>() {
359 public int compare(econnect.wp3_3.client.core.DataObject o1, econnect.wp3_3.client.core.DataObject o2) { 409 public int compare(econnect.wp3_3.client.core.DataObject o1, econnect.wp3_3.client.core.DataObject o2) {
360 if (o1 == o2) 410 if (o1 == o2)
398 public void onRangeChange(RangeChangeEvent event){ 448 public void onRangeChange(RangeChangeEvent event){
399 updateView(false); 449 updateView(false);
400 } 450 }
401 }); 451 });
402 452
403 this.elementsTable.setColumnWidth(nameColumn, "33%"); 453 //this variable is set to 0 at the top
404 this.elementsTable.setColumnWidth(placeColumn, "33%"); 454 //so it (should) show name + place column
405 this.elementsTable.setColumnWidth(descriptionColumn, "33%"); 455 switchTableLayout(currentlyVisibleView);
406 456
407 //This handler adds the hover-functionality to the table, 457 //This handler adds the hover-functionality to the table,
408 //basically highlighting of rows (and in the map/timeplot) 458 //basically highlighting of rows (and in the map/timeplot)
409 this.elementsTable.addCellPreviewHandler(new Handler<DataObject>() 459 this.elementsTable.addCellPreviewHandler(new Handler<DataObject>()
410 { 460 {
649 699
650 this.elementsTable.getRowElement(i).getStyle().setBorderColor(borderColor); 700 this.elementsTable.getRowElement(i).getStyle().setBorderColor(borderColor);
651 this.elementsTable.getRowElement(i).getStyle().setBackgroundColor(cellColor); 701 this.elementsTable.getRowElement(i).getStyle().setBackgroundColor(cellColor);
652 } 702 }
653 } 703 }
704
705 /**
706 * Switches between the different "kinds" of table layouts
707 * This function will cycle through the available layouts
708 */
709 public void switchTableLayout() {
710 this.currentlyVisibleView++;
711
712 if (this.currentlyVisibleView >= this.columns.size())
713 currentlyVisibleView = 0;
714
715 switchTableLayout(this.currentlyVisibleView);
716 }
717
718 /**
719 * Switches to a certain "kind" of table layout
720 * @layputType hover if there was a hover selection which caused to trigger this function
721 */
722 public void switchTableLayout(int layputType) {
723
724 while (this.elementsTable.getColumnCount() > 0 ) {
725 this.elementsTable.removeColumn(0);
726 }
727
728 for ( ColumnAndName column : this.columns.get(layputType)) {
729 this.elementsTable.addColumn(column.column, column.name);
730 }
731 }
654 732
655 public String getTermIdentifier() { 733 public String getTermIdentifier() {
656 return this.dataSet.getTermIdentifier(); 734 return this.dataSet.getTermIdentifier();
657 } 735 }
658 736