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.sample.loancalculator.client.LoanCalculator.java

protected void computeCredit() {
    // validate entries types (float and integer only)
    final String amountString = amountTextBox.getText().trim();
    if (!amountString.matches("[0-9]*\\.?[0-9]*")) {
        Window.alert("'" + amountString + "' is not a valid entry for amount.");
        amountTextBox.selectAll();/*from ww w.j  a  v a  2 s. c  o m*/
        amountTextBox.setFocus(true);
        return;
    }
    amount = Double.parseDouble(amountString);

    final String downPaymentString = downPaymentTextBox.getText().trim();
    if (!downPaymentString.matches("[0-9]*\\.?[0-9]*")) {
        Window.alert("'" + downPaymentString + "' is not a valid entry for down payment.");
        downPaymentTextBox.selectAll();
        downPaymentTextBox.setFocus(true);
        return;
    }
    if (downPaymentString.isEmpty()) {
        downPayment = 0.0;
    } else {
        downPayment = Double.parseDouble(downPaymentString);
    }

    final String monthString = monthTextBox.getText().trim();
    if (!monthString.matches("[1-9][0-9]*")) {
        Window.alert("'" + monthString + "' is not a valid entry for month.");
        monthTextBox.selectAll();
        monthTextBox.setFocus(true);
        return;
    }
    month = Double.parseDouble(monthString);

    final String rateString = rateTextBox.getText().trim();
    if (!rateString.matches("[0-9]+\\.?[0-9]*%?|\\.[0-9]+%?")) {
        Window.alert("'" + rateString + "' is not a valid entry for rate.");
        rateTextBox.selectAll();
        rateTextBox.setFocus(true);
        return;
    } else {
        rate = Double.parseDouble(rateString.replace("%", ""));
    }

    if (!amountString.isEmpty()) {
        computeWithAmount();
    } else {
        Window.alert("'Please enter a value for amount.");
        amountTextBox.setFocus(true);
        return;
    }
}

From source file:com.google.gwt.sample.logexample.client.ServerLoggingArea.java

License:Apache License

@UiHandler("serverSharedMethodButton")
void handleServerSharedMethodButton(ClickEvent e) {
    myService.doSomethingUsingSharedLibrary(new AsyncCallback<Void>() {

        public void onFailure(Throwable caught) {
            Window.alert("Call to my service failed");
        }// w w  w .j  a v  a2  s .c o m

        public void onSuccess(Void result) {
        }
    });
}

From source file:com.google.gwt.sample.logexample.client.ServerLoggingArea.java

License:Apache License

@UiHandler("serverMethodButton")
void handleServerMethodButton(ClickEvent e) {
    myService.doSomething(new AsyncCallback<Void>() {

        public void onFailure(Throwable caught) {
            Window.alert("Call to my service failed");
        }//from   w w w  .  j ava2s  .  c om

        public void onSuccess(Void result) {
        }
    });
}

From source file:com.google.gwt.sample.mail.client.TopPanel.java

License:Apache License

@UiHandler("signOutLink")
void onSignOutClicked(ClickEvent event) {
    Window.alert("If this were implemented, you would be signed out now.");
}

From source file:com.google.gwt.sample.Marketing.client.Marketing.java

public void onModuleLoad() {

    linkPanel.add(link1);//from   w  ww. j a  va 2  s . c o m
    linkPanel.add(link2);
    linkPanel.add(link3);
    linkPanel.add(link4);
    adminlinkPanel.add(link5);
    adminlinkPanel.add(link6);
    adminlinkPanel.setVisible(false);

    RootPanel.get("leftnav").add(linkPanel);
    RootPanel.get("leftnav").add(adminlinkPanel);

    History.addValueChangeHandler(this);

    if (History.getToken().isEmpty()) {
        History.newItem("productlist");
    } else {
        changePage(History.getToken());
    }

    addProductFlexTable.setText(0, 0, "Product ID");
    addProductFlexTable.setWidget(0, 1, pidTextBox);
    addProductFlexTable.setText(1, 0, "Model");
    addProductFlexTable.setWidget(1, 1, modelTextBox);
    addProductFlexTable.setText(2, 0, "Price");
    addProductFlexTable.setWidget(2, 1, priceTextBox);
    addProductFlexTable.setText(3, 0, "Discount");
    addProductFlexTable.setWidget(3, 1, discountTextBox);
    addProductFlexTable.setText(4, 0, "Image");
    addProductFlexTable.setWidget(4, 1, imgTextBox);
    addProductFlexTable.setWidget(5, 1, addProductButton);

    addProductFlexTable.setCellPadding(6);

    addProductFlexTable.getCellFormatter().addStyleName(0, 0, "phoneListHeader");
    addProductFlexTable.getCellFormatter().addStyleName(1, 0, "phoneListHeader");
    addProductFlexTable.getCellFormatter().addStyleName(2, 0, "phoneListHeader");
    addProductFlexTable.getCellFormatter().addStyleName(3, 0, "phoneListHeader");
    addProductFlexTable.getCellFormatter().addStyleName(4, 0, "phoneListHeader");
    addProductFlexTable.addStyleName("phoneList");

    addProductButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            insertProduct(Integer.parseInt(pidTextBox.getText()), modelTextBox.getText(),
                    Double.parseDouble(priceTextBox.getText()), Integer.parseInt(discountTextBox.getText()),
                    imgTextBox.getText());

        }
    });

    accountFlexTable.setText(0, 0, "First name");
    accountFlexTable.setWidget(0, 1, firstnameTextBox);
    accountFlexTable.setText(1, 0, "Last name");
    accountFlexTable.setWidget(1, 1, lastnameTextBox);
    accountFlexTable.setText(2, 0, "Email");
    accountFlexTable.setWidget(2, 1, emailTextBox);
    accountFlexTable.setText(3, 0, "Phone number");
    accountFlexTable.setWidget(3, 1, phonenumberTextBox);
    accountFlexTable.setText(4, 0, "Address");
    accountFlexTable.setWidget(4, 1, addressTextBox);
    accountFlexTable.setText(5, 0, "City");
    accountFlexTable.setWidget(5, 1, cityTextBox);
    accountFlexTable.setText(6, 0, "Zip Code");
    accountFlexTable.setWidget(6, 1, zipTextBox);
    accountFlexTable.setText(7, 0, "Username");
    accountFlexTable.setWidget(7, 1, newusernameTextBox);
    accountFlexTable.setText(8, 0, "Password");
    accountFlexTable.setWidget(8, 1, newpasswordTextBox);

    accountFlexTable.getCellFormatter().addStyleName(0, 0, "phoneListHeader");
    accountFlexTable.getCellFormatter().addStyleName(1, 0, "phoneListHeader");
    accountFlexTable.getCellFormatter().addStyleName(2, 0, "phoneListHeader");
    accountFlexTable.getCellFormatter().addStyleName(3, 0, "phoneListHeader");
    accountFlexTable.getCellFormatter().addStyleName(4, 0, "phoneListHeader");
    accountFlexTable.getCellFormatter().addStyleName(5, 0, "phoneListHeader");
    accountFlexTable.getCellFormatter().addStyleName(6, 0, "phoneListHeader");
    accountFlexTable.getCellFormatter().addStyleName(7, 0, "phoneListHeader");
    accountFlexTable.getCellFormatter().addStyleName(8, 0, "phoneListHeader");
    accountFlexTable.addStyleName("phoneList");

    orderFlexTable.setText(0, 0, "Cart type");
    orderFlexTable.setWidget(0, 1, carttypeTextBox);
    orderFlexTable.setText(1, 0, "Holder's name");
    orderFlexTable.setWidget(1, 1, holdernameTextBox);
    orderFlexTable.setText(2, 0, "Card number");
    orderFlexTable.setWidget(2, 1, cardnumberTextBox);
    orderFlexTable.setText(3, 0, "Expiry year");
    orderFlexTable.setWidget(3, 1, expiryyearTextBox);
    orderFlexTable.setText(4, 0, "Expiry month");
    orderFlexTable.setWidget(4, 1, expirymonthTextBox);
    orderFlexTable.setText(5, 0, "Security number");
    orderFlexTable.setWidget(5, 1, securitynumberTextBox);

    orderFlexTable.getCellFormatter().addStyleName(0, 0, "phoneListHeader");
    orderFlexTable.getCellFormatter().addStyleName(1, 0, "phoneListHeader");
    orderFlexTable.getCellFormatter().addStyleName(2, 0, "phoneListHeader");
    orderFlexTable.getCellFormatter().addStyleName(3, 0, "phoneListHeader");
    orderFlexTable.getCellFormatter().addStyleName(4, 0, "phoneListHeader");
    orderFlexTable.getCellFormatter().addStyleName(5, 0, "phoneListHeader");
    orderFlexTable.addStyleName("phoneList");

    loginTable.setText(0, 0, "username");
    loginTable.setWidget(0, 1, usernameTextBox);
    loginTable.setText(1, 0, "password");
    loginTable.setWidget(1, 1, passwordTextBox);
    loginTable.setWidget(2, 0, loginBtn);
    loginTable.setText(3, 0, "Hello: ");
    loginTable.setWidget(3, 1, loginLabel);
    loginTable.setWidget(4, 0, ViewCart);
    loginPanel.add(loginTable);

    loginTable.getCellFormatter().addStyleName(0, 0, "phoneListHeader");
    loginTable.getCellFormatter().addStyleName(1, 0, "phoneListHeader");
    loginTable.addStyleName("phoneList");

    registerButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if ((newusernameTextBox.getText().trim().equals(""))
                    || (newpasswordTextBox.getText().trim().equals(""))) {
                Window.alert("The username and password are neccesary!");
                newusernameTextBox.setFocus(true);
                newpasswordTextBox.setText("");
            } else if (emailTextBox.getText().trim().equals("")) {
                Window.alert("The email is neccesary!");
            } else {
                insertAccount();
            }
        }
    });

    editProductPanel.add(editProductFlexTable);
    editProductPanel.add(addProductFlexTable);
    editProductPanel.setVisible(false);
    mainPanel.add(editProductPanel);

    deliveredPanel.add(deliveredFlexTable);
    deliveredPanel.setVisible(false);
    mainPanel.add(deliveredPanel);

    registerPanel.add(accountFlexTable);
    registerPanel.add(registerButton);
    registerPanel.setVisible(false);
    mainPanel.add(registerPanel);

    productPanel.add(productFlexTable);
    mainPanel.add(productPanel);

    cartPanel.add(cartFlexTable);
    cartPanel.setVisible(false);
    mainPanel.add(cartPanel);

    orderPanel.add(orderFlexTable);
    orderPanel.add(orderButton);
    orderPanel.setVisible(false);
    mainPanel.add(orderPanel);

    RootPanel.get("leftnav").add(loginPanel);
    RootPanel.get("content").add(mainPanel);

    orderButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            /*if  (!cardnumberTextBox.getText().trim().matches("^[0-9]$")) {
                  Window.alert("'" + cardnumberTextBox.getText() + "' is not a valid card number.");
                  holdernameTextBox.selectAll();
                  return;
             }*/
            if (ShoppingCart.getTotalCount() == 0) {
                Window.alert("There is no item in Shopping cart");
            } else if (carttypeTextBox.getText().trim().equals("")
                    || holdernameTextBox.getText().trim().equals("")
                    || cardnumberTextBox.getText().trim().equals("")
                    || expiryyearTextBox.getText().trim().equals("")
                    || expirymonthTextBox.getText().trim().equals("")
                    || securitynumberTextBox.getText().trim().equals("")) {
                Window.alert("please fill all required fields.");
            } else {
                genID();
            }

        }
    });

    loginBtn.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if ((account.getUsername() != "Guest") && (ShoppingCart.cart != null) && (Window
                    .confirm("if you login again all the purchases will be ignored! are you sure?") == false)) {
                Window.alert("you can continue purchasing by this user : " + account.getUsername());
                usernameTextBox.setText("");
                passwordTextBox.setText("");
            } else {
                ShoppingCart.cart = null;
                ViewCart.setText("View Cart : 0 , $0");
                account.setUsername(usernameTextBox.getText());
                account.setPassword(passwordTextBox.getText());
                checkPassword();
                passwordTextBox.setText("");
            }
        }
    });

    readProductList();

}

From source file:com.google.gwt.sample.Marketing.client.Marketing.java

public void changePage(String token) {
    if (History.getToken().equals("signup")) {
        orderPanel.setVisible(false);// w  w  w .j ava2  s  . co m
        registerPanel.setVisible(true);
        cartPanel.setVisible(false);
        productPanel.setVisible(false);
        deliveredPanel.setVisible(false);
        editProductPanel.setVisible(false);
    } else if (History.getToken().equals("checkout")) {
        orderPanel.setVisible(true);
        registerPanel.setVisible(false);
        cartPanel.setVisible(false);
        productPanel.setVisible(false);
        deliveredPanel.setVisible(false);
        editProductPanel.setVisible(false);
    } else if (History.getToken().equals("viewcart")) {
        orderPanel.setVisible(false);
        registerPanel.setVisible(false);
        cartPanel.setVisible(true);
        productPanel.setVisible(false);
        deliveredPanel.setVisible(false);
        editProductPanel.setVisible(false);
        if (ShoppingCart.getTotalCount() != 0)
            updateCart();
        else
            Window.alert("There is no item in Shopping cart!");
    } else if (History.getToken().equals("delivereditems")) {
        orderPanel.setVisible(false);
        registerPanel.setVisible(false);
        cartPanel.setVisible(false);
        productPanel.setVisible(false);
        deliveredPanel.setVisible(true);
        editProductPanel.setVisible(false);
        //readDeliveredProductList();
    } else if (History.getToken().equals("editproducts")) {
        orderPanel.setVisible(false);
        registerPanel.setVisible(false);
        cartPanel.setVisible(false);
        productPanel.setVisible(false);
        deliveredPanel.setVisible(false);
        editProductPanel.setVisible(true);
        readEditProductList();
    } else {
        orderPanel.setVisible(false);
        registerPanel.setVisible(false);
        cartPanel.setVisible(false);
        productPanel.setVisible(true);
        deliveredPanel.setVisible(false);
        editProductPanel.setVisible(false);
        readProductList();
    }
}

From source file:com.google.gwt.sample.Marketing.client.Marketing.java

private void insertOrder() {
    // Initialize the service proxy.
    if (marketingSvc == null) {
        marketingSvc = GWT.create(MarketingService.class);
    }//from ww  w  .  j  a  v  a 2  s  .  c  o m

    // Set up the callback object.
    AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
        public void onFailure(Throwable caught) {
            // If the stock code is in the list of delisted codes, display an error message.
            String details = caught.getMessage();
            errorMsgLabel.setText("Error: " + details);
            errorMsgLabel.setVisible(true);
        }

        public void onSuccess(Boolean result) {
            ShoppingCart.cart = null;
            account.setUsername("Guest");
            account.setPassword("");
            loginLabel.setText("Guest");
            ViewCart.setText("Cart : 0 , $0");
            carttypeTextBox.setText("");
            holdernameTextBox.setText("");
            cardnumberTextBox.setText("");
            expiryyearTextBox.setText("");
            expirymonthTextBox.setText("");
            securitynumberTextBox.setText("");
            Window.alert("Thanks for your shopping. your shopping id is " + ShoppingCart.cartid);
        }
    };

    // Make the call to the stock price service.
    order o = new order(ShoppingCart.cartid, ShoppingCart.cart, carttypeTextBox.getText(),
            holdernameTextBox.getText(), cardnumberTextBox.getText(), expiryyearTextBox.getText(),
            expirymonthTextBox.getText(), securitynumberTextBox.getText(), ShoppingCart.getTotalPrice());
    marketingSvc.insertOrder(o.getCartId(), o.getCartType(), o.getHolderName(), o.getCardNumber(),
            o.getExpiryYear(), o.getExpiryMonth(), o.getSecurityNumber(), o.getPayableAmount(), callback);
}

From source file:com.google.gwt.sample.Marketing.client.Marketing.java

private void updateListTable(Product product) {
    Button addProductButton = new Button("Add to Shopping cart");
    Image image = new Image();
    image.setPixelSize(50, 60);// www  .ja  v  a 2  s. c om
    int row = productFlexTable.getRowCount();
    final String PIDText = Integer.toString(product.getPID());
    String modelText = product.getModel();
    String priceText = NumberFormat.getFormat("#,##0.00").format(product.getPrice());
    NumberFormat discountFormat = NumberFormat.getFormat("#,##0.00");
    String discountText = discountFormat.format(product.getDiscount());
    String discountPriceText = discountFormat.format(product.getDiscountPrice());
    image.setUrl("images/" + product.getImg());

    addProductButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            int index = Product.indexOf(PIDText);
            Product p = Product.productList[index];
            if (account.getUsername() == "Guest") {
                Window.alert("Please login before any purchase");
                usernameTextBox.setFocus(true);
            } else {
                ShoppingCart.add(new ShoppingCart(p, account.getUsername()));
                ViewCart.setText("View Cart : " + ShoppingCart.getTotalCount() + " $"
                        + NumberFormat.getFormat("#,##0.00").format(ShoppingCart.getTotalPrice()));
            }
        }
    });

    productFlexTable.setText(row, 0, PIDText);
    productFlexTable.setText(row, 1, modelText);
    productFlexTable.setText(row, 2, "$" + priceText);
    productFlexTable.setText(row, 3, "$" + discountPriceText + " (" + discountText + "%)");
    productFlexTable.setWidget(row, 4, image);
    productFlexTable.setWidget(row, 5, addProductButton);

}

From source file:com.google.gwt.sample.Marketing.client.Marketing.java

public void checkPassword() {
    // Initialize the service proxy.
    if (marketingSvc == null) {
        marketingSvc = GWT.create(MarketingService.class);
    }// w w w  . j  a  v a 2s . c o m

    // Set up the callback object.
    AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
        public void onFailure(Throwable caught) {

            String details = caught.getMessage();
            errorMsgLabel.setText("Error: " + details);
            errorMsgLabel.setVisible(true);
        }

        public void onSuccess(Boolean result) {
            if (result == true) {
                loginLabel.setText(account.getUsername());
                usernameTextBox.setText("");
                passwordTextBox.setText("");
                isAdmin();
            } else {
                Window.alert("Username or Password is not correct! Please try again.");
                loginLabel.setText("");
                passwordTextBox.setText("");
                passwordTextBox.setFocus(true);
            }
        }
    };

    marketingSvc.checkPassword(account.getPassword(), account.getUsername(), callback);
}

From source file:com.google.gwt.sample.mobilewebapp.client.App.java

License:Apache License

/**
 * Given a parent view to show itself in, start this App.
 * //from ww w . j  av  a 2s . co m
 * @param parentView where to show the app's widget
 */
public void run(HasWidgets.ForIsWidget parentView) {
    activityManager.setDisplay(shell);

    parentView.add(shell);

    ActionEvent.register(eventBus, ActionNames.ADD_TASK, new ActionEvent.Handler() {
        @Override
        public void onAction(ActionEvent event) {
            placeController.goTo(TaskPlace.getTaskCreatePlace());
        }
    });

    eventBus.addHandler(ShowTaskEvent.TYPE, new ShowTaskEvent.Handler() {
        @Override
        public void onShowTask(ShowTaskEvent event) {
            TaskProxy task = event.getTask();
            placeController.goTo(TaskPlace.createTaskEditPlace(task.getId(), task));
        }
    });

    ActionEvent.register(eventBus, ActionNames.GO_HOME, new ActionEvent.Handler() {
        @Override
        public void onAction(ActionEvent event) {
            placeController.goTo(new TaskListPlace(false));
        }
    });

    ActionEvent.register(eventBus, ActionNames.TASK_SAVED, new ActionEvent.Handler() {
        @Override
        public void onAction(ActionEvent event) {
            placeController.goTo(new TaskListPlace(true));
        }
    });

    ActionEvent.register(eventBus, ActionNames.EDITING_CANCELED, new ActionEvent.Handler() {
        @Override
        public void onAction(ActionEvent event) {
            placeController.goTo(new TaskListPlace(false));
        }
    });

    GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void onUncaughtException(Throwable e) {
            while (e instanceof UmbrellaException) {
                e = ((UmbrellaException) e).getCauses().iterator().next();
            }

            String message = e.getMessage();
            if (message == null) {
                message = e.toString();
            }
            log.log(Level.SEVERE, "Uncaught exception", e);
            Window.alert("An unexpected error occurred: " + message);
        }
    });

    // Check for authentication failures or mismatches
    reloadOnAuthenticationFailure.register(eventBus);

    initBrowserHistory(historyMapper, historyHandler, new TaskListPlace(true));
}