List of usage examples for com.google.gwt.gen2.table.event.client ColumnSortHandler ColumnSortHandler
ColumnSortHandler
From source file:com.google.gwt.gen2.demo.scrolltable.client.option.log.LogOption.java
License:Apache License
@Override protected Widget onInitialize() { layout = new FlexTable(); // Create the log area logLabel = new HTML(); logLabel.setHeight("200px"); DOM.setStyleAttribute(logLabel.getElement(), "font", "8pt/10pt courier"); ScrollPanel scrollPanel = new ScrollPanel(logLabel); scrollPanel.setPixelSize(500, 200);//from www.ja v a2 s. c o m DOM.setStyleAttribute(scrollPanel.getElement(), "border", "1px solid black"); layout.setWidget(0, 0, scrollPanel); layout.getFlexCellFormatter().setColSpan(0, 0, 2); // Add a clear button Button clearButton = new Button("Clear Log", new ClickHandler() { public void onClick(ClickEvent event) { logLabel.setHTML(""); lineCount = 0; } }); layout.setWidget(1, 0, clearButton); layout.getFlexCellFormatter().setColSpan(1, 0, 2); // Add labels for highlighting final Label highlightedCellLabel = new Label("Highlighted cell:"); final Label highlightedRowLabel = new Label("Highlighted row:"); final Label unhighlightedCellLabel = new Label("Last unhighlighted cell:"); final Label unhighlightedRowLabel = new Label("Last unhighlighted row:"); layout.setWidget(2, 0, highlightedCellLabel); layout.setWidget(3, 0, highlightedRowLabel); layout.setWidget(2, 1, unhighlightedRowLabel); layout.setWidget(3, 1, unhighlightedCellLabel); // Add all of the listeners FixedWidthGrid dataTable = ScrollTableDemo.get().getDataTable(); dataTable.addTableListener(new TableListener() { public void onCellClicked(SourcesTableEvents sender, int row, int cell) { addLogEntry("cell clicked: (" + row + "," + cell + ")", "#ff00ff"); } }); dataTable.addColumnSortHandler(new ColumnSortHandler() { public void onColumnSorted(ColumnSortEvent event) { ColumnSortList sortList = event.getColumnSortList(); int column = -1; boolean ascending = true; if (sortList != null) { column = sortList.getPrimaryColumn(); ascending = sortList.isPrimaryAscending(); } if (ascending) { addLogEntry("sorted column: " + column + " (ascending)", "black"); } else { addLogEntry("sorted column: " + column, "black"); } } }); dataTable.addCellHighlightHandler(new CellHighlightHandler() { public void onCellHighlight(CellHighlightEvent event) { Cell cell = event.getValue(); highlightedCellLabel .setText("Highlighted cell: (" + cell.getRowIndex() + "," + cell.getCellIndex() + ")"); } }); dataTable.addCellUnhighlightHandler(new CellUnhighlightHandler() { public void onCellUnhighlight(CellUnhighlightEvent event) { Cell cell = event.getValue(); unhighlightedCellLabel.setText( "Last unhighlighted cell: (" + cell.getRowIndex() + "," + cell.getCellIndex() + ")"); } }); dataTable.addRowHighlightHandler(new RowHighlightHandler() { public void onRowHighlight(RowHighlightEvent event) { Row cell = event.getValue(); highlightedRowLabel.setText("Highlighted row: (" + cell.getRowIndex() + ")"); } }); dataTable.addRowUnhighlightHandler(new RowUnhighlightHandler() { public void onRowUnhighlight(RowUnhighlightEvent event) { Row cell = event.getValue(); unhighlightedRowLabel.setText("Last unhighlighted row: (" + cell.getRowIndex() + ")"); } }); dataTable.addRowSelectionHandler(new RowSelectionHandler() { public void onRowSelection(RowSelectionEvent event) { // Show the previously selected rows Set<Row> deselectedRows = event.getDeselectedRows(); String previous = "Previously selected rows: "; for (Row row : event.getOldValue()) { if (deselectedRows.contains(row)) { previous += "-"; } previous += row.getRowIndex() + ", "; } addLogEntry(previous, "green"); // Show the currently selected rows Set<Row> selectedRows = event.getSelectedRows(); String current = "Currently selected rows: "; for (Row row : event.getNewValue()) { if (selectedRows.contains(row)) { current += "+"; } current += row.getRowIndex() + ", "; } addLogEntry(current, "green"); } }); // Paging specific options if (PagingScrollTableDemo.get() != null) { PagingScrollTable<Student> pagingScrollTable = PagingScrollTableDemo.get().getPagingScrollTable(); if (pagingScrollTable != null) { pagingScrollTable.addPageChangeHandler(new PageChangeHandler() { public void onPageChange(PageChangeEvent event) { pageLoadDuration = new Duration(); } }); pagingScrollTable.addPageLoadHandler(new PageLoadHandler() { public void onPageLoad(PageLoadEvent event) { // Convert to 1 based index int page = event.getPage() + 1; int duration = -1; if (pageLoadDuration != null) { duration = pageLoadDuration.elapsedMillis(); pageLoadDuration = null; } String text = "Page " + page + " loaded in " + duration + "ms"; addLogEntry(text, "black"); } }); } } return layout; }
From source file:org.gwtaf.widgets.search.SearchResultScrollTable.java
License:Apache License
private void setValue(List<SearchResult> results, boolean saveFullResult) { // store the full results if necessary. if (saveFullResult) { fullResults = new DynamicSearchResults(); fullResults.setResults(results); }/* w ww . j a v a 2s .co m*/ // nothing to do if there are no results. if (results == null) { return; } // figure out how many columns we'll need int neededColumns = results.size() == 0 ? 0 : results.get(0).getDataValues().length; // make a new data grid this.dataGrid = createDataGrid(results.size(), neededColumns); dataGrid.setCellSpacing(0); // pass on the cell selection handler dataGrid.addCellClickHandler(clickHandler); // pass on the handler dataGrid.addRowSelectionHandler(rowSelectionHandler); // add handler for sorting dataGrid.addColumnSortHandler(new ColumnSortHandler() { public void onColumnSorted(ColumnSortEvent event) { lastSortedColumn = event.getColumnSortList().getPrimaryColumn(); lastSortDirection = event.getColumnSortList().isPrimaryAscending(); markOdd(); } }); int dataGridIndex = 0; // set the values into the list for (int i = 0; i < results.size(); i++) { // if not null if (results.get(i) != null) { setSingleResult(results.get(i), dataGridIndex); dataGridIndex++; } } /** * Creating a new header table. Cannot re-use the old one due to * scrolltable not supporting remove. (one parent widget constraint) */ FixedWidthFlexTable newHeaderTable = new FixedWidthFlexTable(); for (int i = 0; i < headerTable.getColumnCount(); i++) { newHeaderTable.setHTML(0, i, headerTable.getHTML(0, i)); } // replace the scrolltable ScrollTable newTable = new ScrollTable(dataGrid, newHeaderTable); newTable.setSortPolicy(SortPolicy.SINGLE_CELL); newTable.setResizePolicy(ScrollTable.ResizePolicy.FILL_WIDTH); this.scrollTable = newTable; mainPanel.clear(); mainPanel.setWidget(0, 0, newTable); }