# HG changeset patch # User Sebastian Kruse # Date 1358170646 -3600 # Node ID caca95f925ccac806de179ba2f65fa75c40aaef3 # Parent 02cdf454d94b42b0bc122f1aeed5981d87d327e2 Add switchable "views" to the CellTable (sets of Columns) diff -r 02cdf454d94b -r caca95f925cc src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java --- 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 elementsTable; /** + * This class is used for the Lists of Columns that + * represent the different "views" of the CellTable + */ + class ColumnAndName { + public Column column; + public String name; + + public ColumnAndName(Column column, String name) { + this.column = column; + this.name = name; + } + } + + /** + * "Views" of columns of the celltable + */ + private ArrayList> 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(); setActualObjectSet(); + this.columns = new ArrayList>(); + + //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(); elementsTable.getElement().getStyle().setWidth(100, Unit.PCT); - dataProvider = new ListDataProvider(); dataProvider.addDataDisplay(this.elementsTable); + + ArrayList nameplaceColumnList = new ArrayList(); TextColumn nameColumn = new TextColumn() { @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 placeColumn = new TextColumn() { @Override @@ -297,7 +337,11 @@ } }; placeColumn.setSortable(true); - this.elementsTable.addColumn(placeColumn, "Place"); + nameplaceColumnList.add(new ColumnAndName(placeColumn, "Place")); + + columns.add(nameplaceColumnList); + + ArrayList descriptionColumnList = new ArrayList(); 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 columnSortHandler = new ListHandler(dataProvider.getList()); + ArrayList descriptionDataColumnList = new ArrayList(); + 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() { 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();