Example usage for com.google.gwt.user.client Window alert

List of usage examples for com.google.gwt.user.client Window alert

Introduction

In this page you can find the example usage for com.google.gwt.user.client Window alert.

Prototype

public static void alert(String msg) 

Source Link

Usage

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

/**
 * Add stock to FlexTable. Executed when the user clicks the addStockButton
 * or presses enter in the newSymbolTextBox.
 *//*from w ww  .  jav a 2  s .  co m*/
private void addStock() {
    final String symbol = newSymbolTextBox.getText().toUpperCase().trim();
    newSymbolTextBox.setFocus(true);

    if (!symbol.matches("^[0-9A-Z\\.]{1,10}$")) {
        Window.alert("'" + symbol + "' is not a valid symbol.");
        newSymbolTextBox.selectAll();
        return;
    }

    newSymbolTextBox.setText("");

    if (stocks.contains(symbol))
        return;

    // Add the stock to the table
    int row = stocksFlexTable.getRowCount();
    stocks.add(symbol);
    stocksFlexTable.setText(row, 0, symbol);
    stocksFlexTable.setWidget(row, 2, new Label());
    stocksFlexTable.getCellFormatter().addStyleName(row, 1, "watchListNumericColumn");
    stocksFlexTable.getCellFormatter().addStyleName(row, 2, "watchListNumericColumn");
    stocksFlexTable.getCellFormatter().addStyleName(row, 3, "watchListRemoveColumn");

    // Add a button to remove this stock from the table.
    Button removeStockButton = new Button("x");
    removeStockButton.addStyleDependentName("remove");

    removeStockButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            int removedIndex = stocks.indexOf(symbol);
            stocks.remove(removedIndex);
            stocksFlexTable.removeRow(removedIndex + 1);
        }
    });
    stocksFlexTable.setWidget(row, 3, removeStockButton);

    // Get the stock price
    refreshWatchList();
}

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

License:Apache License

public void onModuleLoad() {
    // Make a new button that does something when you click it.
    Button b = new Button("Jump!", new ClickHandler() {
        public void onClick(ClickEvent event) {
            Window.alert("How high?");
        }/*  ww w  .  ja v  a 2 s.c om*/
    });

    // Add it to the root panel.
    RootPanel.get().add(b);
}

From source file:com.google.gwt.examples.cell.EditableCellExample.java

License:Apache License

/**
 * Show the list of favorites.//from   ww w .  j  a va  2  s.  c o  m
 */
private void showCurrentFavorites() {
    if (favorites.size() > 0) {
        String text = "You favorite contacts are ";
        boolean first = true;
        for (Contact contact : favorites) {
            if (!first) {
                text += ", ";
            } else {
                first = false;
            }
            text += contact.name;
        }
        Window.alert(text);
    } else {
        Window.alert("You have not selected any favorites.");
    }
}

From source file:com.google.gwt.examples.cellview.CellListExample.java

License:Apache License

public void onModuleLoad() {
    // Create a cell to render each value.
    TextCell textCell = new TextCell();

    // Create a CellList that uses the cell.
    CellList<String> cellList = new CellList<String>(textCell);
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a selection model to handle user selection.
    final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();
    cellList.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            String selected = selectionModel.getSelectedObject();
            if (selected != null) {
                Window.alert("You selected: " + selected);
            }//from w  w w  .  ja  va  2 s .  c  o  m
        }
    });

    // Set the total row count. This isn't strictly necessary, but it affects
    // paging calculations, so its good habit to keep the row count up to date.
    cellList.setRowCount(DAYS.size(), true);

    // Push the data into the widget.
    cellList.setRowData(0, DAYS);

    // Add it to the root panel.
    RootPanel.get().add(cellList);
}

From source file:com.google.gwt.examples.cellview.CellListValueUpdaterExample.java

License:Apache License

public void onModuleLoad() {
    // Create a cell that will interact with a value updater.
    TextInputCell inputCell = new TextInputCell();

    // Create a CellList that uses the cell.
    CellList<String> cellList = new CellList<String>(inputCell);

    // Create a value updater that will be called when the value in a cell
    // changes.//www .ja  v a2  s  .com
    ValueUpdater<String> valueUpdater = new ValueUpdater<String>() {
        public void update(String newValue) {
            Window.alert("You typed: " + newValue);
        }
    };

    // Add the value updater to the cellList.
    cellList.setValueUpdater(valueUpdater);

    // Set the total row count. This isn't strictly necessary, but it affects
    // paging calculations, so its good habit to keep the row count up to date.
    cellList.setRowCount(DAYS.size(), true);

    // Push the data into the widget.
    cellList.setRowData(0, DAYS);

    // Add it to the root panel.
    RootPanel.get().add(cellList);
}

From source file:com.google.gwt.examples.cellview.CellTableExample.java

License:Apache License

public void onModuleLoad() {
    // Create a CellTable.
    CellTable<Contact> table = new CellTable<Contact>();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a text column to show the name.
    TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
        @Override/*from   w  w  w.j a v a  2s  . c o m*/
        public String getValue(Contact object) {
            return object.name;
        }
    };
    table.addColumn(nameColumn, "Name");

    // Add a date column to show the birthday.
    DateCell dateCell = new DateCell();
    Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell) {
        @Override
        public Date getValue(Contact object) {
            return object.birthday;
        }
    };
    table.addColumn(dateColumn, "Birthday");

    // Add a text column to show the address.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
        @Override
        public String getValue(Contact object) {
            return object.address;
        }
    };
    table.addColumn(addressColumn, "Address");

    // Add a selection model to handle user selection.
    final SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
    table.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            Contact selected = selectionModel.getSelectedObject();
            if (selected != null) {
                Window.alert("You selected: " + selected.name);
            }
        }
    });

    // Set the total row count. This isn't strictly necessary, but it affects
    // paging calculations, so its good habit to keep the row count up to date.
    table.setRowCount(CONTACTS.size(), true);

    // Push the data into the widget.
    table.setRowData(0, CONTACTS);

    // Add it to the root panel.
    RootPanel.get().add(table);
}

From source file:com.google.gwt.examples.cellview.CellTableFieldUpdaterExample.java

License:Apache License

@Override
public void onModuleLoad() {
    // Create a CellTable with a key provider.
    final CellTable<Contact> table = new CellTable<Contact>(KEY_PROVIDER);

    // Add a text input column to edit the name.
    final TextInputCell nameCell = new TextInputCell();
    Column<Contact, String> nameColumn = new Column<Contact, String>(nameCell) {
        @Override/*from w ww  .  j a v  a  2 s  .  c o m*/
        public String getValue(Contact object) {
            // Return the name as the value of this column.
            return object.name;
        }
    };
    table.addColumn(nameColumn, "Name");

    // Add a field updater to be notified when the user enters a new name.
    nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() {
        @Override
        public void update(int index, Contact object, String value) {
            // Inform the user of the change.
            Window.alert("You changed the name of " + object.name + " to " + value);

            // Push the changes into the Contact. At this point, you could send an
            // asynchronous request to the server to update the database.
            object.name = value;

            // Redraw the table with the new data.
            table.redraw();
        }
    });

    // Push the data into the widget.
    table.setRowData(CONTACTS);

    // Add it to the root panel.
    RootPanel.get().add(table);
}

From source file:com.google.gwt.examples.cellview.CellTableFieldUpdaterExampleComplex.java

License:Apache License

@Override
public void onModuleLoad() {
    // Create a CellTable with a key provider.
    final CellTable<Contact> table = new CellTable<Contact>(KEY_PROVIDER);
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a text input column to edit the name.
    final TextInputCell nameCell = new TextInputCell();
    Column<Contact, String> nameColumn = new Column<Contact, String>(nameCell) {
        @Override// w  w  w.j  a  v a  2s. c o m
        public String getValue(Contact object) {
            return object.name;
        }
    };
    table.addColumn(nameColumn, "Name");

    // Add a field updater to be notified when the user enters a new name.
    nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() {
        @Override
        public void update(int index, Contact object, String value) {
            // Validate the data.
            if (value.length() < 3) {
                Window.alert("Names must be at least three characters long.");

                /*
                 * Clear the view data. The view data contains the pending change and
                 * allows the table to render with the pending value until the data is
                 * committed. If the data is committed into the object, the view data
                 * is automatically cleared out. If the data is not committed because
                 * it is invalid, you must delete.
                 */
                nameCell.clearViewData(KEY_PROVIDER.getKey(object));

                // Redraw the table.
                table.redraw();
                return;
            }

            // Inform the user of the change.
            Window.alert("You changed the name of " + object.name + " to " + value);

            // Push the changes into the Contact. At this point, you could send an
            // asynchronous request to the server to update the database.
            object.name = value;

            // Redraw the table with the new data.
            table.redraw();
        }
    });

    // Add a date column to show the birthday.
    Column<Contact, Date> dateColumn = new Column<Contact, Date>(new DatePickerCell()) {
        @Override
        public Date getValue(Contact object) {
            return object.birthday;
        }
    };
    table.addColumn(dateColumn, "Birthday");

    // Add a field updater to be notified when the user enters a new birthday.
    dateColumn.setFieldUpdater(new FieldUpdater<Contact, Date>() {
        @Override
        public void update(int index, Contact object, Date value) {
            Window.alert("You changed the birthday of " + object.name + " to "
                    + DateTimeFormat.getFormat(PredefinedFormat.DATE_LONG).format(value));

            // Push the changes into the Contact.
            object.birthday = value;

            // Redraw the table with the new data.
            table.redraw();
        }
    });
    // Add a text column to show the address.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
        @Override
        public String getValue(Contact object) {
            return object.address;
        }
    };
    table.addColumn(addressColumn, "Address");

    // Set the total row count. This isn't strictly necessary, but it affects
    // paging calculations, so its good habit to keep the row count up to date.
    table.setRowCount(CONTACTS.size(), true);

    // Push the data into the widget.
    table.setRowData(0, CONTACTS);

    // Add it to the root panel.
    RootPanel.get().add(table);
}

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

License:Apache License

public void onModuleLoad() {
    // Make a new check box, and select it by default.
    CheckBox cb = new CheckBox("Foo");
    cb.setChecked(true);/*from w  ww.j av  a  2s.  c  om*/

    // Hook up a handler to find out when it's clicked.
    cb.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            boolean checked = ((CheckBox) event.getSource()).isChecked();
            Window.alert("It is " + (checked ? "" : "not ") + "checked");
        }
    });

    // Add it to the root panel.
    RootPanel.get().add(cb);
}

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

License:Apache License

public void onModuleLoad() {
    // Create a FormPanel and point it at a service.
    final FormPanel form = new FormPanel();
    form.setAction("/myFormHandler");

    // Because we're going to add a FileUpload widget, we'll need to set the
    // form to use the POST method, and multipart MIME encoding.
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    // Create a panel to hold all of the form widgets.
    VerticalPanel panel = new VerticalPanel();
    form.setWidget(panel);//from ww  w  . j  ava  2 s  . c om

    // Create a TextBox, giving it a name so that it will be submitted.
    final TextBox tb = new TextBox();
    tb.setName("textBoxFormElement");
    panel.add(tb);

    // Create a ListBox, giving it a name and some values to be associated with
    // its options.
    ListBox lb = new ListBox();
    lb.setName("listBoxFormElement");
    lb.addItem("foo", "fooValue");
    lb.addItem("bar", "barValue");
    lb.addItem("baz", "bazValue");
    panel.add(lb);

    // Create a FileUpload widget.
    FileUpload upload = new FileUpload();
    upload.setName("uploadFormElement");
    panel.add(upload);

    // Add a 'submit' button.
    panel.add(new Button("Submit", new ClickHandler() {
        public void onClick(ClickEvent event) {
            form.submit();
        }
    }));

    // Add an event handler to the form.
    form.addSubmitHandler(new FormPanel.SubmitHandler() {
        public void onSubmit(SubmitEvent event) {
            // This event is fired just before the form is submitted. We can take
            // this opportunity to perform validation.
            if (tb.getText().length() == 0) {
                Window.alert("The text box must not be empty");
                event.cancel();
            }
        }
    });
    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
        public void onSubmitComplete(SubmitCompleteEvent event) {
            // When the form submission is successfully completed, this event is
            // fired. Assuming the service returned a response of type text/html,
            // we can get the result text here (see the FormPanel documentation for
            // further explanation).
            Window.alert(event.getResults());
        }
    });

    RootPanel.get().add(form);
}