Mercurial > hg > STI-GWT
changeset 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 | 02cdf454d94b |
children | d69066d16e45 |
files | src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java |
diffstat | 1 files changed, 92 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java Fri Jan 11 13:05:40 2013 +0100 +++ b/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java Mon Jan 14 14:37:26 2013 +0100 @@ -92,6 +92,31 @@ private CellTable<DataObject> elementsTable; /** + * This class is used for the Lists of Columns that + * represent the different "views" of the CellTable + */ + class ColumnAndName { + public Column<DataObject,?> column; + public String name; + + public ColumnAndName(Column<DataObject,?> column, String name) { + this.column = column; + this.name = name; + } + } + + /** + * "Views" of columns of the celltable + */ + private ArrayList<ArrayList<ColumnAndName>> columns; + + /** + * Thie index of the "View" that is currently visible + * (translates to an index of the columns ArrayList) + */ + private int currentlyVisibleView; + + /** * The dataobjects, which are presented at the actual page */ //private DataObject[][] displayedObjects; @@ -125,7 +150,7 @@ * RPC Interface for writing the KML file */ private ExportWriterInterfaceAsync exportWriter; - + /** * Constructor for initialization of the dynamic table * @@ -147,6 +172,19 @@ this.actualObjectSet = new ArrayList<DataObject>(); setActualObjectSet(); + this.columns = new ArrayList<ArrayList<ColumnAndName>>(); + + //should be Name + Place + currentlyVisibleView = 0; + + Image switchTableLayout = new Image(constants.playEnabled()); + switchTableLayout.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + //switch the layout of the table + switchTableLayout(); + } + }); + showAll = new Image("images/viewAll"+(core.getColorId(index))+".png"); showAll.setTitle(textConstants.showAll()); showSelected = new Image("images/viewSelected"+(core.getColorId(index))+".png"); @@ -188,10 +226,11 @@ } }); - Grid showOptions = new Grid(1,3); - showOptions.setWidget(0,0,showAll); - showOptions.setWidget(0,1,showSelected); - showOptions.setWidget(0,2,storeSelected); + Grid showOptions = new Grid(1,4); + showOptions.setWidget(0,0,switchTableLayout); + showOptions.setWidget(0,1,showAll); + showOptions.setWidget(0,2,showSelected); + showOptions.setWidget(0,3,storeSelected); final TextBox textualSearch = new TextBox(); final Button search = new Button("go"); @@ -277,9 +316,10 @@ this.elementsTable = new CellTable<DataObject>(); elementsTable.getElement().getStyle().setWidth(100, Unit.PCT); - dataProvider = new ListDataProvider<DataObject>(); dataProvider.addDataDisplay(this.elementsTable); + + ArrayList<ColumnAndName> nameplaceColumnList = new ArrayList<ColumnAndName>(); TextColumn<DataObject> nameColumn = new TextColumn<DataObject>() { @Override @@ -287,8 +327,8 @@ return object.getName(); } }; - nameColumn.setSortable(true); - this.elementsTable.addColumn(nameColumn, "Name"); + nameColumn.setSortable(true); + nameplaceColumnList.add(new ColumnAndName(nameColumn, "Name")); TextColumn<DataObject> placeColumn = new TextColumn<DataObject>() { @Override @@ -297,7 +337,11 @@ } }; placeColumn.setSortable(true); - this.elementsTable.addColumn(placeColumn, "Place"); + nameplaceColumnList.add(new ColumnAndName(placeColumn, "Place")); + + columns.add(nameplaceColumnList); + + ArrayList<ColumnAndName> descriptionColumnList = new ArrayList<ColumnAndName>(); SafeHtmlCell descriptionCell = new SafeHtmlCell(); @@ -310,7 +354,9 @@ } }; descriptionColumn.setSortable(true); - this.elementsTable.addColumn(descriptionColumn, "Description"); + descriptionColumnList.add(new ColumnAndName(descriptionColumn, "Description")); + + columns.add(descriptionColumnList); SimplePager pager = new SimplePager(); pager.setDisplay(this.elementsTable); @@ -321,6 +367,8 @@ //TODO: remove redundant code, make this more abstract ListHandler<DataObject> columnSortHandler = new ListHandler<econnect.wp3_3.client.core.DataObject>(dataProvider.getList()); + ArrayList<ColumnAndName> descriptionDataColumnList = new ArrayList<ColumnAndName>(); + JsArrayString descriptionDataColumns = this.dataSet.getDescriptionDataColumns(); for (int i = 0; i < descriptionDataColumns.length(); i++) { final String columnName = descriptionDataColumns.get(i); @@ -351,9 +399,11 @@ } }); - this.elementsTable.addColumn(column, columnName); + descriptionDataColumnList.add(new ColumnAndName(column, columnName)); } + columns.add(descriptionDataColumnList); + columnSortHandler.setComparator(nameColumn, new Comparator<econnect.wp3_3.client.core.DataObject>() { public int compare(econnect.wp3_3.client.core.DataObject o1, econnect.wp3_3.client.core.DataObject o2) { @@ -400,9 +450,9 @@ } }); - this.elementsTable.setColumnWidth(nameColumn, "33%"); - this.elementsTable.setColumnWidth(placeColumn, "33%"); - this.elementsTable.setColumnWidth(descriptionColumn, "33%"); + //this variable is set to 0 at the top + //so it (should) show name + place column + switchTableLayout(currentlyVisibleView); //This handler adds the hover-functionality to the table, //basically highlighting of rows (and in the map/timeplot) @@ -651,6 +701,34 @@ this.elementsTable.getRowElement(i).getStyle().setBackgroundColor(cellColor); } } + + /** + * Switches between the different "kinds" of table layouts + * This function will cycle through the available layouts + */ + public void switchTableLayout() { + this.currentlyVisibleView++; + + if (this.currentlyVisibleView >= this.columns.size()) + currentlyVisibleView = 0; + + switchTableLayout(this.currentlyVisibleView); + } + + /** + * Switches to a certain "kind" of table layout + * @layputType hover if there was a hover selection which caused to trigger this function + */ + public void switchTableLayout(int layputType) { + + while (this.elementsTable.getColumnCount() > 0 ) { + this.elementsTable.removeColumn(0); + } + + for ( ColumnAndName column : this.columns.get(layputType)) { + this.elementsTable.addColumn(column.column, column.name); + } + } public String getTermIdentifier() { return this.dataSet.getTermIdentifier();