Example usage for com.google.gwt.user.client.ui Label setText

List of usage examples for com.google.gwt.user.client.ui Label setText

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Label setText.

Prototype

public void setText(String text) 

Source Link

Document

Sets the label's content to the given text.

Usage

From source file:com.google.developers.gdgfirenze.gwt.client.GwtDemoApp.java

License:Apache License

/**
 * This is the entry point method./*from   www .  j  a v a  2 s . co m*/
 */
public void onModuleLoad() {
    final Button sendButton = new Button("Send");
    final TextBox nameField = new TextBox();
    nameField.setText("GWT User");
    final Label errorLabel = new Label();

    // We can add style names to widgets
    sendButton.addStyleName("sendButton");

    // Add the nameField and sendButton to the RootPanel
    // Use RootPanel.get() to get the entire body element
    RootPanel.get("nameFieldContainer").add(nameField);
    RootPanel.get("sendButtonContainer").add(sendButton);
    RootPanel.get("errorLabelContainer").add(errorLabel);

    // Focus the cursor on the name field when the app loads
    nameField.setFocus(true);
    nameField.selectAll();

    // Create the popup dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Remote Procedure Call");
    dialogBox.setAnimationEnabled(true);
    final Button closeButton = new Button("Close");
    // We can set the id of a widget by accessing its Element
    closeButton.getElement().setId("closeButton");
    final Label textToServerLabel = new Label();
    final HTML serverResponseLabel = new HTML();
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.addStyleName("dialogVPanel");
    dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
    dialogVPanel.add(textToServerLabel);
    dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
    dialogVPanel.add(serverResponseLabel);
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    dialogVPanel.add(closeButton);
    dialogBox.setWidget(dialogVPanel);

    // Add a handler to close the DialogBox
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            sendButton.setEnabled(true);
            sendButton.setFocus(true);
        }
    });

    /**
     * The Class MyHandler.
     * 
     * Create a handler for the sendButton and nameField
     */
    class MyHandler implements ClickHandler, KeyUpHandler {
        /**
         * Fired when the user clicks on the sendButton.
         */
        public void onClick(ClickEvent event) {
            sendNameToServer();
        }

        /**
         * Fired when the user types in the nameField.
         */
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                sendNameToServer();
            }
        }

        /**
         * Send the name from the nameField to the server and wait for a response.
         */
        private void sendNameToServer() {
            // First, we validate the input.
            errorLabel.setText("");
            String textToServer = nameField.getText();
            if (!FieldVerifier.isValidName(textToServer)) {
                errorLabel.setText("Please enter at least four characters");
                return;
            }

            // Then, we send the input to the server.
            sendButton.setEnabled(false);
            textToServerLabel.setText(textToServer);
            serverResponseLabel.setText("");
            greetingService.greetServer(textToServer, new AsyncCallback<String>() {
                public void onFailure(Throwable caught) {
                    // Show the RPC error message to the user
                    dialogBox.setText("Remote Procedure Call - Failure");
                    serverResponseLabel.addStyleName("serverResponseLabelError");
                    serverResponseLabel.setHTML(SERVER_ERROR);
                    dialogBox.center();
                    closeButton.setFocus(true);
                }

                public void onSuccess(String result) {
                    dialogBox.setText("Remote Procedure Call");
                    serverResponseLabel.removeStyleName("serverResponseLabelError");
                    serverResponseLabel.setHTML(result);
                    dialogBox.center();
                    closeButton.setFocus(true);
                }
            });
        }
    }

    // Add a handler to send the name to the server
    MyHandler handler = new MyHandler();
    sendButton.addClickHandler(handler);
    nameField.addKeyUpHandler(handler);
}

From source file:com.google.gwt.demos.spinner.client.SpinnerDemoPanel.java

License:Apache License

public SpinnerDemoPanel() {
    FlexTable table = new FlexTable();
    table.setHTML(1, 0, "Value spinner:");
    // Create a value spinner with initial value=0 that allows values between
    // -1000 and 1000
    final ValueSpinner simpleSpinner = new ValueSpinner(0, -1000, 1000);
    table.setWidget(1, 1, simpleSpinner);
    final CheckBox enableSpinner = new CheckBox("Enable/disable");
    enableSpinner.setChecked(simpleSpinner.isEnabled());
    enableSpinner.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            simpleSpinner.setEnabled(enableSpinner.isChecked());
        }/*from   w w w.  j a  va2  s. com*/
    });
    table.setWidget(1, 2, enableSpinner);

    // Create a value spinner that displays the value as a formatted date
    final ValueSpinner dateSpinner = new ValueSpinner(new Date().getTime()) {
        protected String formatValue(long value) {
            return DateTimeFormat.getLongDateFormat().format(new Date(value));
        }

        protected long parseValue(String value) {
            return DateTimeFormat.getLongDateFormat().parse(value).getTime();
        }
    };
    // Min step = milliseconds per day
    dateSpinner.getSpinner().setMinStep(86400000);
    dateSpinner.setStylePrimaryName("dateSpinner");
    table.setHTML(2, 0, "Date spinner:");
    table.setWidget(2, 1, dateSpinner);
    final CheckBox enableDateSpinner = new CheckBox("Enable/disable");
    enableDateSpinner.setChecked(dateSpinner.isEnabled());
    enableDateSpinner.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dateSpinner.setEnabled(enableDateSpinner.isChecked());
        }
    });
    table.setWidget(2, 2, enableDateSpinner);

    // A TimePicker using AM/PM 12h format
    final TimePicker timePicker = new TimePicker(false);
    table.setHTML(3, 0, "Time picker:");
    table.setWidget(3, 1, timePicker);
    final CheckBox enableTimePicker = new CheckBox("Enable/disable");
    enableTimePicker.setChecked(timePicker.isEnabled());
    enableTimePicker.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            timePicker.setEnabled(enableTimePicker.isChecked());
        }
    });
    table.setWidget(3, 2, enableTimePicker);

    // Creating a date time picker with AM/PM 12h TimePicker
    final DateTimePicker dateTimePicker = new DateTimePicker(false);
    dateTimePicker.setWidth("200px");
    // Create a label to display the selected date
    final Label dateLabel = new Label();
    Button getDate = new Button("Show date");
    getDate.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            // Display the selected date/time using DateTimeFormat
            dateLabel.setText(DateTimeFormat.getMediumDateTimeFormat().format(dateTimePicker.getDate()));
        }
    });
    dateLabel.setStyleName("sandbox-Date");
    table.setHTML(4, 0, "Date time picker:");
    table.setWidget(4, 1, dateTimePicker);
    table.setWidget(5, 0, getDate);
    table.setWidget(5, 1, dateLabel);
    final CheckBox enableDateTimePicker = new CheckBox("Enable/disable");
    enableDateTimePicker.setChecked(dateTimePicker.isEnabled());
    enableDateTimePicker.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dateTimePicker.setEnabled(enableDateTimePicker.isChecked());
        }
    });
    table.setWidget(4, 2, enableDateTimePicker);

    final VolumeSlider volumeSlider = new VolumeSlider(0, -100, 100);
    volumeSlider.setWidth("250px");
    table.setHTML(7, 0, "Volume slider:");
    table.setWidget(7, 1, volumeSlider);
    final CheckBox enableVolumeSlider = new CheckBox("Enable/disable");
    enableVolumeSlider.setChecked(volumeSlider.isEnabled());
    enableVolumeSlider.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            volumeSlider.setEnabled(enableVolumeSlider.isChecked());
        }
    });
    table.setWidget(7, 2, enableVolumeSlider);

    final TimePicker customTimePicker = new TimePicker(new Date(), null, DateTimeFormat.getFormat("HH"),
            DateTimeFormat.getFormat("mm"), null);
    table.setHTML(8, 0, "Another time picker (24h):");
    table.setWidget(8, 1, customTimePicker);
    final CheckBox enable = new CheckBox("Enable/disable");
    enable.setChecked(customTimePicker.isEnabled());
    enable.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            customTimePicker.setEnabled(enable.isChecked());
        }
    });
    table.setWidget(8, 2, enable);
    initWidget(table);
}

From source file:com.google.gwt.example.stockwatcher.client.StockWatcher.java

/**
 * Update a single row in the stock table.
 *
 * @param price Stock data for a single row.
 *//*from   www .  j  a  va  2s .  c  o m*/

private void updateTable(StockPrice price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);
}

From source file:com.google.gwt.examples.DatePickerExample.java

License:Apache License

public void onModuleLoad() {
    // Create a date picker
    DatePicker datePicker = new DatePicker();
    final Label text = new Label();

    // Set the value in the text box when the user selects a date
    datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
        public void onValueChange(ValueChangeEvent<Date> event) {
            Date date = event.getValue();
            String dateString = DateTimeFormat.getMediumDateFormat().format(date);
            text.setText(dateString);
        }//from w  w w .j  a  va 2 s. co m
    });

    // Set the default value
    datePicker.setValue(new Date(), true);

    // Add the widgets to the page
    RootPanel.get().add(text);
    RootPanel.get().add(datePicker);
}

From source file:com.google.gwt.examples.IncrementalCommandExample.java

License:Apache License

public void onModuleLoad() {
    final Label label = new Label();

    DeferredCommand.addCommand(new IncrementalCommand() {
        private int index = 0;

        protected static final int COUNT = 10;

        public boolean execute() {
            label.setText("IncrementalCommand - index " + Integer.toString(index));

            return ++index < COUNT;
        }/*from  www.ja va2s  .c  om*/
    });
}

From source file:com.google.gwt.gdata.sample.hellogdata.client.AccountsAuthSubAuthenticationDemo.java

License:Apache License

/**
 * Display the AuthSub authentication statuses in a
 * tabular fashion with the help of a GWT FlexTable widget.
 * We initialize an array containing the name, scope, icon
 * and url for each of the supported GData systems.
 * For each system a table row is added displaying the name,
 * page, link and icon, in addition to the AuthSub status
 * and a hyperlink for logging in or logging, as appropriate.
 * The User class contains the getStatus method which is used
 * to retrieve the authentication status for the current user
 * and for a given system (scope).//  ww  w .  j a va  2s . c  o m
 */
private void showAuthSubStatus() {
    String[][] systems = new String[][] {
            new String[] { "Google Analytics", "https://www.google.com/analytics/feeds/", "gdata-analytics.png",
                    "http://code.google.com/apis/analytics/" },
            new String[] { "Google Base", "http://www.google.com/base/feeds/", "gdata-base.png",
                    "http://code.google.com/apis/base/" },
            new String[] { "Google Blogger", "http://www.blogger.com/feeds/", "gdata-blogger.png",
                    "http://code.google.com/apis/blogger/" },
            new String[] { "Google Calendar", "http://www.google.com/calendar/feeds/", "gdata-calendar.png",
                    "http://code.google.com/apis/calendar/" },
            new String[] { "Google Contacts", "http://www.google.com/m8/feeds/", "gdata-contacts.png",
                    "http://code.google.com/apis/contacts/" },
            new String[] { "Google Finance", "http://finance.google.com/finance/feeds/", "gdata-finance.png",
                    "http://code.google.com/apis/finance/" },
            new String[] { "Google Maps", "http://maps.google.com/maps/feeds/", "gdata-maps.png",
                    "http://code.google.com/apis/maps/documentation/mapsdata/" },
            new String[] { "Google Sidewiki", "http://www.google.com/sidewiki/feeds/", "gdata-sidewiki.png",
                    "http://code.google.com/apis/sidewiki/" } };
    for (int i = 0; i < systems.length; i++) {
        String[] sys = systems[i];
        final String scope = sys[1];
        mainPanel.insertRow(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        Image icon = new Image(sys[2]);
        mainPanel.setWidget(i, 0, icon);
        Label name = new HTML("<a href=\"" + sys[3] + "\">" + sys[0] + "</a>");
        mainPanel.setWidget(i, 1, name);
        Label statusLabel = new Label();
        Anchor actionLink = new Anchor();
        AuthSubStatus status = User.getStatus(scope);
        if (status == AuthSubStatus.LOGGED_IN) {
            statusLabel.setText("Logged in");
            actionLink.setText("Log out");
            actionLink.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    User.logout(scope);
                    refreshDemo();
                }
            });
        } else if (status == AuthSubStatus.LOGGED_OUT) {
            statusLabel.setText("Logged out");
            actionLink.setText("Log in");
            actionLink.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    User.login(scope);
                }
            });
        }
        mainPanel.setWidget(i, 2, statusLabel);
        mainPanel.setWidget(i, 3, actionLink);
    }
}

From source file:com.google.gwt.gdata.sample.hellogdata.client.GDataPackagesDemo.java

License:Apache License

/**
 * Display the GData package statuses in a
 * tabular fashion with the help of a GWT FlexTable widget.
 * We initialize an array containing the name, icon
 * and url for each of the supported GData packages.
 * For each package a table row is added displaying the name,
 * page, link and icon, in addition to the load status.
 * The GData class contains the isLoaded method which is used
 * to retrieve the load status for a given package.
 *///from  w  w  w . jav a 2 s  . com
private void showPackageStatus() {
    String[][] systems = new String[][] {
            new String[] { "Google Analytics", "ANALYTICS", "gdata-analytics.png",
                    "http://code.google.com/apis/analytics/" },
            new String[] { "Google Base", "GBASE", "gdata-base.png", "http://code.google.com/apis/base/" },
            new String[] { "Google Blogger", "BLOGGER", "gdata-blogger.png",
                    "http://code.google.com/apis/blogger/" },
            new String[] { "Google Calendar", "CALENDAR", "gdata-calendar.png",
                    "http://code.google.com/apis/calendar/" },
            new String[] { "Google Contacts", "CONTACTS", "gdata-contacts.png",
                    "http://code.google.com/apis/contacts/" },
            new String[] { "Google Finance", "FINANCE", "gdata-finance.png",
                    "http://code.google.com/apis/finance/" },
            new String[] { "Google Maps", "MAPS", "gdata-maps.png",
                    "http://code.google.com/apis/maps/documentation/mapsdata/" },
            new String[] { "Google Sidewiki", "SIDEWIKI", "gdata-sidewiki.png",
                    "http://code.google.com/apis/sidewiki/" } };
    for (int i = 0; i < systems.length; i++) {
        String[] sys = systems[i];
        final String identifier = sys[1];
        mainPanel.insertRow(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        Image icon = new Image(sys[2]);
        mainPanel.setWidget(i, 0, icon);
        Label name = new HTML("<a href=\"" + sys[3] + "\">" + sys[0] + "</a>");
        mainPanel.setWidget(i, 1, name);
        Label statusLabel = new Label();
        Anchor actionLink = new Anchor();
        if (GData.isLoaded(GDataSystemPackage.valueOf(identifier))) {
            statusLabel.setText("Loaded");
        } else {
            statusLabel.setText("Not loaded");
            actionLink.setText("Load");
            actionLink.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    GData.loadGDataApi(GDATA_API_KEY, new Runnable() {
                        public void run() {
                            refreshDemo();
                        }
                    }, GDataSystemPackage.valueOf(identifier));
                }
            });
        }
        mainPanel.setWidget(i, 2, statusLabel);
        mainPanel.setWidget(i, 3, actionLink);
    }
}

From source file:com.google.gwt.gen2.demo.picker.client.PickerDemoPanel.java

License:Apache License

public PickerDemoPanel() {
    FlexTable table = new FlexTable();

    // A TimePicker using AM/PM 12h format
    final TimePicker timePicker = new TimePicker(false);
    table.setHTML(3, 0, "Time picker:");
    table.setWidget(3, 1, timePicker);//from w  ww .  j a  va 2 s .co  m
    final CheckBox enableTimePicker = new CheckBox("Enable/disable");
    enableTimePicker.setValue(timePicker.isEnabled());
    enableTimePicker.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent source) {
            timePicker.setEnabled(enableTimePicker.getValue());
        }
    });
    table.setWidget(3, 2, enableTimePicker);

    // Creating a date time picker with AM/PM 12h TimePicker
    final DateTimePicker dateTimePicker = new DateTimePicker(false);
    dateTimePicker.setWidth("200px");
    // Create a label to display the selected date
    final Label dateLabel = new Label();
    Button getDate = new Button("Show date");
    getDate.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent source) {
            // Display the selected date/time using DateTimeFormat
            dateLabel.setText(DateTimeFormat.getMediumDateTimeFormat().format(dateTimePicker.getDate()));
        }
    });
    dateLabel.setStyleName("sandbox-Date");
    table.setHTML(4, 0, "Date time picker:");

    table.setWidget(4, 1, dateTimePicker);
    table.setWidget(5, 0, getDate);
    table.setWidget(5, 1, dateLabel);
    final CheckBox enableDateTimePicker = new CheckBox("Enable/disable");
    enableDateTimePicker.setValue(dateTimePicker.isEnabled());
    enableDateTimePicker.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dateTimePicker.setEnabled(enableDateTimePicker.getValue());
        }
    });
    table.setWidget(4, 2, enableDateTimePicker);

    final TimePicker customTimePicker = new TimePicker(new Date(), null, DateTimeFormat.getFormat("HH"),
            DateTimeFormat.getFormat("mm"), null);
    table.setHTML(8, 0, "Another time picker (24h):");
    table.setWidget(8, 1, customTimePicker);
    final CheckBox enable = new CheckBox("Enable/disable");
    enable.setValue(customTimePicker.isEnabled());
    enable.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent sender) {
            customTimePicker.setEnabled(enable.getValue());
        }

    });
    table.setWidget(8, 2, enable);

    initWidget(table);
}

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 w  w  w  .j a  va 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;
}

From source file:com.google.gwt.maps.sample.hellomaps.client.EventDemo.java

License:Apache License

public EventDemo() {
    Panel panel = new FlowPanel();
    map = new MapWidget(LatLng.newInstance(37.4419, -122.1419), 13);
    map.setSize("500px", "300px");
    map.addControl(new SmallMapControl());
    panel.add(map);/*from www .  j  a  v  a 2 s. co m*/
    final Label message = new Label();
    panel.add(message);
    initWidget(panel);

    map.addMapMoveEndHandler(new MapMoveEndHandler() {
        public void onMoveEnd(MapMoveEndEvent event) {
            message.setText(map.getCenter().toString());
        }
    });
}