Example usage for com.google.gwt.gen2.table.event.client RowUnhighlightHandler RowUnhighlightHandler

List of usage examples for com.google.gwt.gen2.table.event.client RowUnhighlightHandler RowUnhighlightHandler

Introduction

In this page you can find the example usage for com.google.gwt.gen2.table.event.client RowUnhighlightHandler RowUnhighlightHandler.

Prototype

RowUnhighlightHandler

Source Link

Usage

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);//w ww . java  2 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;
}