Example usage for com.google.gwt.user.client.ui Grid clearCell

List of usage examples for com.google.gwt.user.client.ui Grid clearCell

Introduction

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

Prototype

@Override
public boolean clearCell(int row, int column) 

Source Link

Document

Replaces the contents of the specified cell with a single space.

Usage

From source file:edu.ucsb.eucalyptus.admin.client.EucalyptusWebInterface.java

License:Open Source License

public void displayUserRecordPage(Panel parent, UserInfoWeb userToEdit) {
    final String oldPassword;
    final boolean admin;
    final boolean newUser;
    final boolean showSkipConfirmed;
    boolean isAdminChecked = false; // not admin by default
    boolean skipConfirmationChecked = previousSkipConfirmation;

    if (loggedInUser != null && (loggedInUser.isAdministrator() != null && loggedInUser.isAdministrator())) {
        admin = true;/*from w w  w  . j  a va 2  s .c o  m*/
    } else {
        admin = false;
    }
    if (userToEdit == null) {
        newUser = true;
        showSkipConfirmed = true;
        userToEdit = new UserInfoWeb();
        oldPassword = "";
        if (admin) {
            label_box.setText("Please, fill out the form to add a user");
        } else {
            label_box.setText(signup_greeting); // Please, fill out the form:
        }
    } else {
        newUser = false;
        oldPassword = userToEdit.getPassword();
        isAdminChecked = userToEdit.isAdministrator() != null && userToEdit.isAdministrator();
        showSkipConfirmed = userToEdit.isConfirmed() == null || !userToEdit.isConfirmed();
        skipConfirmationChecked = userToEdit.isConfirmed() != null && userToEdit.isConfirmed();

        String status;
        if (userToEdit.isApproved() == null || !userToEdit.isApproved()) {
            status = "unapproved";
        } else if (userToEdit.isEnabled() == null || !userToEdit.isEnabled()) {
            status = "disabled";
        } else if (userToEdit.isConfirmed() == null || !userToEdit.isConfirmed()) {
            status = "unconfirmed";
        } else {
            status = "active";
        }
        if (userToEdit.isAdministrator() != null && userToEdit.isAdministrator()) {
            status += " & admin";
        }
        label_box.setText("Editing information for user '" + userToEdit.getUserName() + "' (" + status + ")");
    }
    label_box.setStyleName("euca-greeting-normal");

    int rowsMandatory = 5;
    if (admin) {
        rowsMandatory++; // for admin checkbox
        if (showSkipConfirmed) {
            rowsMandatory++; // for skip confirmation checkbox
        }
    }
    final Grid g1 = new Grid(rowsMandatory, 3);
    g1.getColumnFormatter().setWidth(0, "180");
    g1.getColumnFormatter().setWidth(1, "180");
    g1.getColumnFormatter().setWidth(2, "180");
    int i = 0;

    final Label label_mandatory = new Label("Mandatory fields:");
    label_mandatory.setStyleName("euca-section-header");

    final int userName_row = i;
    g1.setWidget(i, 0, new Label("Username:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox userName_box = new TextBox();
    userName_box.setText(userToEdit.getUserName());
    userName_box.setWidth("180");
    if (!newUser) {
        userName_box.setEnabled(false);
    }
    g1.setWidget(i++, 1, userName_box);

    // optional row
    final CheckBox userIsAdmin = new CheckBox("Administrator");
    userIsAdmin.setChecked(isAdminChecked);
    userIsAdmin.setStyleName("euca-remember-text");
    if (admin) {
        g1.setWidget(i++, 1, userIsAdmin);
    }

    final int password1_row = i;
    g1.setWidget(i, 0, new Label("Password:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox cleartextPassword1_box = new PasswordTextBox();
    cleartextPassword1_box.setText(userToEdit.getPassword());
    cleartextPassword1_box.setWidth("180");
    if ((!admin && !newUser)
            || (userToEdit.isAdministrator() != null && userToEdit.isAdministrator().booleanValue())) {
        cleartextPassword1_box.setEnabled(false);
    }
    g1.setWidget(i++, 1, cleartextPassword1_box);

    final int password2_row = i;
    g1.setWidget(i, 0, new Label("Password, again:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox cleartextPassword2_box = new PasswordTextBox();
    cleartextPassword2_box.setText(userToEdit.getPassword());
    cleartextPassword2_box.setWidth("180");
    if ((!admin && !newUser)
            || (userToEdit.isAdministrator() != null && userToEdit.isAdministrator().booleanValue())) {
        cleartextPassword2_box.setEnabled(false);
    }
    g1.setWidget(i++, 1, cleartextPassword2_box);

    final int realName_row = i;
    g1.setWidget(i, 0, new Label("Full Name:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox realName_box = new TextBox();
    realName_box.setText(userToEdit.getRealName());
    realName_box.setWidth("180");
    g1.setWidget(i++, 1, realName_box);

    final int emailAddress_row = i;
    g1.setWidget(i, 0, new Label("Email address:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox emailAddress_box = new TextBox();
    emailAddress_box.setText(userToEdit.getEmail());
    emailAddress_box.setWidth("180");
    g1.setWidget(i++, 1, emailAddress_box);

    // optional row
    final CheckBox skipConfirmation = new CheckBox("Skip email confirmation");
    skipConfirmation.setChecked(skipConfirmationChecked);
    skipConfirmation.setStyleName("euca-remember-text");
    if (admin && showSkipConfirmed) {
        g1.setWidget(i++, 1, skipConfirmation);
    }

    /* these widgets are allocated, but not necessarily used */
    final Grid g2 = new Grid();
    final Label label_optional = new Label("Optional fields:");
    label_optional.setStyleName("euca-section-header");
    final TextBox telephoneNumber_box = new TextBox();
    final TextBox projectPIName_box = new TextBox();
    final TextBox affiliation_box = new TextBox();
    final TextArea projectDescription_box = new TextArea();

    int extra_fields = 0;
    if (request_telephone) {
        extra_fields++;
    }
    if (request_project_leader) {
        extra_fields++;
    }
    if (request_affiliation) {
        extra_fields++;
    }
    if (request_project_description) {
        extra_fields++;
    }

    if (extra_fields > 0) {
        g2.resize(extra_fields, 2);
        g2.getColumnFormatter().setWidth(0, "180");
        g2.getColumnFormatter().setWidth(1, "360");
        i = 0;

        if (request_telephone) {
            g2.setWidget(i, 0, new Label("Telephone Number:"));
            g2.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
            telephoneNumber_box.setWidth("180");
            telephoneNumber_box.setText(userToEdit.getTelephoneNumber());
            g2.setWidget(i++, 1, telephoneNumber_box);
        }

        if (request_project_leader) {
            g2.setWidget(i, 0, new Label("Project Leader:"));
            g2.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
            projectPIName_box.setText(userToEdit.getProjectPIName());
            projectPIName_box.setWidth("180");
            g2.setWidget(i++, 1, projectPIName_box);
        }

        if (request_affiliation) {
            g2.setWidget(i, 0, new Label("Affiliation:"));
            g2.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
            affiliation_box.setText(userToEdit.getAffiliation());
            affiliation_box.setWidth("360");
            g2.setWidget(i++, 1, affiliation_box);
        }

        if (request_project_description) {
            g2.setWidget(i, 0, new Label("Project Description:"));
            g2.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
            projectDescription_box.setText(userToEdit.getProjectDescription());
            projectDescription_box.setWidth("360");
            projectDescription_box.setHeight("50");
            g2.setWidget(i++, 1, projectDescription_box);
        }
    }

    ClickListener SignupButtonListener = new ClickListener() {
        public void onClick(Widget sender) {
            boolean formOk = true;

            for (int j = 0; j < 4; j++) {
                g1.clearCell(j, 2); /* clear previous right-hand-side annotations */
            }

            // perform checks
            if (userName_box.getText().length() < 1) {
                Label l = new Label("Username is empty!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(userName_row, 2, l);
                formOk = false;
            } else {
                // do this in the else-clause so the empty username doesn't match here
                if (cleartextPassword1_box.getText().toLowerCase()
                        .matches(".*" + userName_box.getText().toLowerCase() + ".*")) {
                    Label l = new Label("Password may not contain the username!");
                    l.setStyleName("euca-error-hint");
                    g1.setWidget(password1_row, 2, l);
                    formOk = false;
                }
            }

            if (userName_box.getText().matches(".*[^\\w\\-\\.@]+.*")) {
                Label l = new Label("Invalid characters in the username!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(userName_row, 2, l);
                formOk = false;
            }

            if (userName_box.getText().length() > 30) {
                Label l = new Label("Username is too long, sorry!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(userName_row, 2, l);
                formOk = false;
            }

            if (cleartextPassword1_box.getText().length() < minPasswordLength) {
                Label l = new Label("Password must be at least " + minPasswordLength + " characters long!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(password1_row, 2, l);
                formOk = false;
            }
            if (!cleartextPassword1_box.getText().equals(cleartextPassword2_box.getText())) {
                Label l = new Label("Passwords do not match!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(password2_row, 2, l);
                formOk = false;
            }
            if (realName_box.getText().equalsIgnoreCase(cleartextPassword1_box.getText())
                    || userName_box.getText().equalsIgnoreCase(cleartextPassword1_box.getText())) {
                Label l = new Label("Password may not be your name or username!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(password1_row, 2, l);
                formOk = false;
            }

            if (realName_box.getText().length() < 1) {
                Label l = new Label("Name is empty!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(realName_row, 2, l);
                formOk = false;
            }
            if (emailAddress_box.getText().length() < 1) {
                Label l = new Label("Email address is empty!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(emailAddress_row, 2, l);
                formOk = false;
            }

            if (formOk) {
                label_box.setText("Checking with the server...");
                label_box.setStyleName("euca-greeting-pending");
                String enteredPassword = cleartextPassword1_box.getText();
                String encryptedPassword = GWTUtils.md5(enteredPassword);
                if (enteredPassword.equals(oldPassword)) {
                    encryptedPassword = enteredPassword; // it was not changed in the edit
                }
                final UserInfoWeb userToSave = new UserInfoWeb(userName_box.getText(), realName_box.getText(),
                        emailAddress_box.getText(), encryptedPassword);
                if (admin) {
                    userToSave.setAdministrator(userIsAdmin.isChecked());
                    if (showSkipConfirmed) {
                        previousSkipConfirmation = skipConfirmation.isChecked(); // remember value for the future
                        userToSave.setConfirmed(previousSkipConfirmation);
                    }
                }
                if (telephoneNumber_box.getText().length() > 0) {
                    userToSave.setTelephoneNumber(telephoneNumber_box.getText());
                }
                if (affiliation_box.getText().length() > 0) {
                    userToSave.setAffiliation(affiliation_box.getText());
                }
                if (projectDescription_box.getText().length() > 0) {
                    userToSave.setProjectDescription(projectDescription_box.getText());
                }
                if (projectPIName_box.getText().length() > 0) {
                    userToSave.setProjectPIName(projectPIName_box.getText());
                }
                if (newUser) {
                    EucalyptusWebBackend.App.getInstance().addUserRecord(
                            sessionId, /* will be null if anonymous user signs up */
                            userToSave, new AsyncCallback() {
                                public void onSuccess(Object result) {
                                    displayDialog("Thank you!", (String) result);
                                }

                                public void onFailure(Throwable caught) {
                                    String m = caught.getMessage();
                                    if (m.equals("User already exists")) {
                                        g1.setWidget(userName_row, 2, new Label("Username is taken!"));
                                        label_box.setText("Please, fix the error and resubmit:");
                                        label_box.setStyleName("euca-greeting-warning");
                                    } else {
                                        displayErrorPage(m);
                                    }
                                }
                            });
                } else {
                    EucalyptusWebBackend.App.getInstance().updateUserRecord(sessionId, userToSave,
                            new AsyncCallback() {
                                public void onSuccess(Object result) {
                                    if (loggedInUser.getUserName().equals(userToSave.getUserName())) {
                                        loggedInUser.setRealName(userToSave.getRealName());
                                        loggedInUser.setEmail(userToSave.getEmail());
                                        loggedInUser.setPassword(userToSave.getPassword());
                                        loggedInUser.setTelephoneNumber(userToSave.getTelephoneNumber());
                                        loggedInUser.setAffiliation(userToSave.getAffiliation());
                                        loggedInUser.setProjectDescription(userToSave.getProjectDescription());
                                        loggedInUser.setProjectPIName(userToSave.getProjectPIName());
                                        displayDialog("", (String) result);

                                    } else { // admin updating a user
                                        displayBarAndTabs("");
                                        statusMessage.setText((String) result);
                                    }
                                }

                                public void onFailure(Throwable caught) {
                                    String m = caught.getMessage();
                                    displayErrorPage(m);
                                }
                            });
                }
            } else {
                label_box.setText("Please, fix the errors and resubmit:");
                label_box.setStyleName("euca-greeting-warning");
            }
        }
    };

    Button submit_button;
    if (newUser) {
        if (admin) {
            submit_button = new Button("Add user", SignupButtonListener);
        } else {
            submit_button = new Button("Sign up", SignupButtonListener);
        }
    } else {
        submit_button = new Button("Update Record", SignupButtonListener);
    }

    Button cancel_button = new Button("Cancel", DefaultPageButtonListener);
    VerticalPanel mpanel = new VerticalPanel();
    mpanel.add(label_mandatory);
    mpanel.add(g1);

    VerticalPanel opanel = new VerticalPanel();
    if (extra_fields > 0) {
        opanel.add(label_optional);
        opanel.add(g2);
    }

    HorizontalPanel bpanel = new HorizontalPanel();
    bpanel.add(submit_button);
    bpanel.add(new HTML("&nbsp;&nbsp;or&nbsp;&nbsp;"));
    bpanel.add(cancel_button);

    VerticalPanel vpanel = new VerticalPanel();
    vpanel.setSpacing(15);
    vpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    vpanel.add(new HTML("<br/>"));
    if (logo != null) {
        addLogoWithText(vpanel);
        vpanel.add(new HTML("<br/>"));
    }
    ;
    vpanel.add(label_box);
    vpanel.add(mpanel);
    vpanel.add(opanel);
    vpanel.add(bpanel);

    VerticalPanel wrapper = new VerticalPanel();
    wrapper.add(vpanel);
    wrapper.setSize("100%", "100%");
    wrapper.setCellHorizontalAlignment(vpanel, VerticalPanel.ALIGN_CENTER);
    //        wrapper.setCellVerticalAlignment(vpanel, VerticalPanel.ALIGN_MIDDLE);

    parent.clear();
    parent.add(wrapper);
}

From source file:edu.ucsb.eucalyptus.admin.client.EucalyptusWebInterface.java

License:Open Source License

public void displayInitiatePasswordRecoveryPage() {
    label_box.setText("Enter the following to reset your password");
    label_box.setStyleName("euca-greeting-normal");

    final Grid g1 = new Grid(2, 3); // rows, cols
    g1.getColumnFormatter().setWidth(0, "230");
    g1.getColumnFormatter().setWidth(1, "180");
    g1.getColumnFormatter().setWidth(2, "180");
    int i = 0;// w  w w.  j  a  v  a 2 s  .c  o  m

    final int username_row = i;
    g1.setWidget(i, 0, new Label("Username:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox username_box = new TextBox();
    username_box.setWidth("180");
    g1.setWidget(i++, 1, username_box);

    final int email_row = i;
    g1.setWidget(i, 0, new Label("Email address:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox email_box = new TextBox();
    email_box.setWidth("180");
    g1.setWidget(i++, 1, email_box);

    ClickListener RecoverButtonListener = new ClickListener() {
        public void onClick(Widget sender) {
            boolean formOk = true;

            for (int j = 0; j < 2; j++) {
                g1.clearCell(j, 2); // clear previous right-hand-side annotations 
            }

            // perform checks
            if (username_box.getText().length() < 1) {
                Label l = new Label("Username is empty!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(username_row, 2, l);
                formOk = false;
            }
            if (username_box.getText().matches(".*[ \t]+.*")) {
                Label l = new Label("Username cannot have spaces, sorry!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(username_row, 2, l);
                formOk = false;
            }
            if (!email_box.getText().contains("@")) {
                Label l = new Label("Valid email is mandatory!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(email_row, 2, l);
                formOk = false;
            }

            if (formOk) {
                label_box.setText("Checking with the server...");
                label_box.setStyleName("euca-greeting-pending");

                UserInfoWeb user = new UserInfoWeb(username_box.getText(), "", // don't care about real name
                        email_box.getText(), null); // null => reset requested
                EucalyptusWebBackend.App.getInstance().recoverPassword(user, new AsyncCallback() {
                    public void onSuccess(Object result) {
                        displayDialog("Thank you!", (String) result);
                    }

                    public void onFailure(Throwable caught) {
                        String m = caught.getMessage();
                        displayErrorPage(m);
                    }
                });

            } else {
                label_box.setText("Please, fix the errors and resubmit:");
                label_box.setStyleName("euca-greeting-warning");
            }
        }
    };

    Button submit_button = new Button("Recover Password", RecoverButtonListener);
    Button cancel_button = new Button("Cancel", DefaultPageButtonListener);
    VerticalPanel mpanel = new VerticalPanel();
    mpanel.add(g1);

    HorizontalPanel bpanel = new HorizontalPanel();
    bpanel.add(submit_button);
    bpanel.add(new HTML("&nbsp;&nbsp;or&nbsp;&nbsp;"));
    bpanel.add(cancel_button);

    VerticalPanel vpanel = new VerticalPanel();
    vpanel.setSpacing(15);
    vpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    if (logo != null) {
        vpanel.add(logo);
    }
    vpanel.add(label_box);
    vpanel.add(mpanel);
    vpanel.add(bpanel);

    VerticalPanel wrapper = new VerticalPanel();
    wrapper.add(vpanel);
    wrapper.setSize("100%", "100%");
    wrapper.setCellHorizontalAlignment(vpanel, VerticalPanel.ALIGN_CENTER);
    wrapper.setCellVerticalAlignment(vpanel, VerticalPanel.ALIGN_MIDDLE);

    RootPanel.get().clear();
    RootPanel.get().add(wrapper);
}

From source file:edu.ucsb.eucalyptus.admin.client.EucalyptusWebInterface.java

License:Open Source License

public void displayCompletePasswordRecoveryPage(final String code) {
    label_box.setText("Please, choose the new password");
    label_box.setStyleName("euca-greeting-normal");

    final Grid g1 = new Grid(2, 3); // rows, cols
    g1.getColumnFormatter().setWidth(0, "230");
    g1.getColumnFormatter().setWidth(1, "180");
    g1.getColumnFormatter().setWidth(2, "180");
    int i = 0;/*from  w  ww  .ja v a2 s.com*/

    final int password1_row = i;
    g1.setWidget(i, 0, new Label("New password:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox cleartextPassword1_box = new PasswordTextBox();
    cleartextPassword1_box.setWidth("180");
    g1.setWidget(i++, 1, cleartextPassword1_box);

    final int password2_row = i;
    g1.setWidget(i, 0, new Label("The password, again:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox cleartextPassword2_box = new PasswordTextBox();
    cleartextPassword2_box.setWidth("180");
    g1.setWidget(i++, 1, cleartextPassword2_box);

    ClickListener RecoverButtonListener = new ClickListener() {
        public void onClick(Widget sender) {
            boolean formOk = true;

            for (int j = 0; j < 2; j++) {
                g1.clearCell(j, 2); // clear previous right-hand-side annotations
            }

            if (cleartextPassword1_box.getText().length() < minPasswordLength) {
                Label l = new Label("Password must be at least " + minPasswordLength + " characters long!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(password1_row, 2, l);
                formOk = false;
            }
            if (!cleartextPassword1_box.getText().equals(cleartextPassword2_box.getText())) {
                Label l = new Label("Passwords do not match!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(password2_row, 2, l);
                formOk = false;
            }

            if (formOk) {
                label_box.setText("Checking with the server...");
                label_box.setStyleName("euca-greeting-pending");

                UserInfoWeb user = new UserInfoWeb();
                user.setConfirmationCode(code);
                user.setPassword(GWTUtils.md5(cleartextPassword1_box.getText()));
                EucalyptusWebBackend.App.getInstance().recoverPassword(user, new AsyncCallback() {
                    public void onSuccess(Object result) {
                        displayDialog("Thank you!", (String) result);
                    }

                    public void onFailure(Throwable caught) {
                        String m = caught.getMessage();
                        displayErrorPage(m);
                    }
                });

            } else {
                label_box.setText("Please, fix the errors and resubmit:");
                label_box.setStyleName("euca-greeting-warning");
            }
        }
    };

    Button submit_button = new Button("Change Password", RecoverButtonListener);
    Button cancel_button = new Button("Cancel", DefaultPageButtonListener);
    VerticalPanel mpanel = new VerticalPanel();
    mpanel.add(g1);

    HorizontalPanel bpanel = new HorizontalPanel();
    bpanel.add(submit_button);
    bpanel.add(new HTML("&nbsp;&nbsp;or&nbsp;&nbsp;"));
    bpanel.add(cancel_button);

    VerticalPanel vpanel = new VerticalPanel();
    vpanel.setSpacing(15);
    vpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    if (logo != null) {
        vpanel.add(logo);
    }
    vpanel.add(label_box);
    vpanel.add(mpanel);
    vpanel.add(bpanel);

    VerticalPanel wrapper = new VerticalPanel();
    wrapper.add(vpanel);
    wrapper.setSize("100%", "100%");
    wrapper.setCellHorizontalAlignment(vpanel, VerticalPanel.ALIGN_CENTER);
    wrapper.setCellVerticalAlignment(vpanel, VerticalPanel.ALIGN_MIDDLE);

    RootPanel.get().clear();
    RootPanel.get().add(wrapper);
}

From source file:edu.ucsb.eucalyptus.admin.client.EucalyptusWebInterface.java

License:Open Source License

public void displayPasswordChangePage(boolean mustChange) {
    if (mustChange) {
        label_box.setText("You are required to change your password");
        label_box.setStyleName("euca-greeting-error");
    } else {/*w  w  w.ja  v  a 2 s.com*/
        label_box.setText("Please, change your password");
        label_box.setStyleName("euca-greeting-normal");
    }
    final Grid g1 = new Grid(3, 3);
    g1.getColumnFormatter().setWidth(0, "180");
    g1.getColumnFormatter().setWidth(1, "180");
    g1.getColumnFormatter().setWidth(2, "180");
    int i = 0;

    final int oldPassword_row = i;
    g1.setWidget(i, 0, new Label("Old password:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox oldPassword_box = new PasswordTextBox();
    oldPassword_box.setWidth("180");
    if (!mustChange) { // don't ask for old password if the change is involuntary
        g1.setWidget(i++, 1, oldPassword_box);
    }

    final int newPassword1_row = i;
    g1.setWidget(i, 0, new Label("New password:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox newCleartextPassword1_box = new PasswordTextBox();
    newCleartextPassword1_box.setWidth("180");
    g1.setWidget(i++, 1, newCleartextPassword1_box);

    final int newPassword2_row = i;
    g1.setWidget(i, 0, new Label("New password, again:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox newCleartextPassword2_box = new PasswordTextBox();
    newCleartextPassword2_box.setWidth("180");
    g1.setWidget(i++, 1, newCleartextPassword2_box);

    ClickListener ChangeButtonListener = new ClickListener() {
        public void onClick(Widget sender) {
            boolean formOk = true;

            for (int j = 0; j < 3; j++) {
                g1.clearCell(j, 2); // clear previous right-hand-side annotations
            }

            // perform checks 
            if (newCleartextPassword1_box.getText().length() < minPasswordLength) {
                Label l = new Label("Password is too short!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(newPassword1_row, 2, l);
                formOk = false;
            }
            if (!newCleartextPassword1_box.getText().equals(newCleartextPassword2_box.getText())) {
                Label l = new Label("Passwords do not match!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(newPassword2_row, 2, l);
                formOk = false;
            }

            if (formOk) {
                label_box.setText("Checking with the server...");
                label_box.setStyleName("euca-greeting-pending");

                EucalyptusWebBackend.App.getInstance().changePassword(sessionId,
                        GWTUtils.md5(oldPassword_box.getText()),
                        GWTUtils.md5(newCleartextPassword1_box.getText()), new AsyncCallback<String>() {
                            public void onSuccess(final String result) {
                                // password change succeded - pull in the new user record 
                                label_box.setText("Refreshing user data...");
                                EucalyptusWebBackend.App.getInstance().getUserRecord(sessionId, null,
                                        new AsyncCallback<List<UserInfoWeb>>() {
                                            public void onSuccess(List<UserInfoWeb> users) {
                                                loggedInUser = users.get(0);
                                                displayMessagePage((String) result);
                                            }

                                            public void onFailure(Throwable caught) {
                                                displayLoginErrorPage(caught.getMessage());
                                            }
                                        });
                            }

                            public void onFailure(Throwable caught) {
                                String m = caught.getMessage();
                                label_box.setText(m);
                                label_box.setStyleName("euca-greeting-warning");
                            }
                        });
            } else {
                label_box.setText("Please, fix the errors and try again:");
                label_box.setStyleName("euca-greeting-warning");
            }
        }
    };

    Button change_button = new Button("Change password", ChangeButtonListener);
    Button cancel_button = new Button("Cancel", DefaultPageButtonListener);

    HorizontalPanel bpanel = new HorizontalPanel();
    bpanel.add(change_button);
    if (!mustChange) {
        bpanel.add(new HTML("&nbsp;&nbsp;or&nbsp;&nbsp;"));
        bpanel.add(cancel_button);
    }

    VerticalPanel vpanel = new VerticalPanel();
    vpanel.setSpacing(15);
    vpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    if (logo != null) {
        vpanel.add(logo);
    }
    vpanel.add(label_box);
    vpanel.add(g1);
    vpanel.add(bpanel);

    VerticalPanel wrapper = new VerticalPanel();
    wrapper.add(vpanel);
    wrapper.setSize("100%", "100%");
    wrapper.setCellHorizontalAlignment(vpanel, VerticalPanel.ALIGN_CENTER);
    wrapper.setCellVerticalAlignment(vpanel, VerticalPanel.ALIGN_MIDDLE);

    RootPanel.get().clear();
    RootPanel.get().add(wrapper);
}

From source file:edu.ucsb.eucalyptus.admin.client.EucalyptusWebInterface.java

License:Open Source License

public void displayAdminEmailChangePage() {
    label_box.setText("One more thing!");
    label_box.setStyleName("euca-greeting-error");

    final Grid g1 = new Grid(2, 3);
    g1.getColumnFormatter().setWidth(0, "180");
    g1.getColumnFormatter().setWidth(1, "180");
    g1.getColumnFormatter().setWidth(2, "180");
    int i = 0;//w  w w  .  ja  va 2 s. co m

    g1.setWidget(i, 0, new Label("Email address:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox emailAddress1_box = new TextBox();
    emailAddress1_box.setWidth("180");
    g1.setWidget(i++, 1, emailAddress1_box);

    g1.setWidget(i, 0, new Label("The address, again:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox emailAddress2_box = new TextBox();
    emailAddress2_box.setWidth("180");
    g1.setWidget(i++, 1, emailAddress2_box);

    ClickListener ChangeButtonListener = new ClickListener() {
        public void onClick(Widget sender) {
            boolean formOk = true;

            for (int j = 0; j < 2; j++) {
                g1.clearCell(j, 2); /* clear previous right-hand-side annotations */
            }

            /* perform checks */
            if (emailAddress1_box.getText().length() < 3) {
                Label l = new Label("Invalid address!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(0, 2, l);
                formOk = false;
            }
            if (!emailAddress1_box.getText().equals(emailAddress2_box.getText())) {
                Label l = new Label("Addresses do not match!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(1, 2, l);
                formOk = false;
            }

            if (formOk) {
                loggedInUser.setEmail(emailAddress1_box.getText());
                label_box.setText("Checking with the server...");
                label_box.setStyleName("euca-greeting-pending");
                EucalyptusWebBackend.App.getInstance().updateUserRecord(sessionId, loggedInUser,
                        new AsyncCallback() {
                            public void onSuccess(final Object result) {
                                displayWalrusURLChangePage();
                            }

                            public void onFailure(Throwable caught) {
                                loggedInUser.setEmail(UserInfoWeb.BOGUS_ENTRY);
                                displayLoginErrorPage(caught.getMessage());
                            }
                        });
            } else {
                label_box.setText("Please, fix the errors and try again:");
                label_box.setStyleName("euca-greeting-warning");
            }
        }
    };

    Button change_button = new Button("Change address", ChangeButtonListener);
    HTML message = new HTML(admin_email_change_text);
    message.setWidth("460");

    VerticalPanel vpanel = new VerticalPanel();
    vpanel.setSpacing(15);
    //        vpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    if (logo != null) {
        vpanel.add(logo);
    }
    vpanel.add(label_box);
    vpanel.add(message);
    vpanel.add(g1);
    vpanel.add(change_button);

    VerticalPanel wrapper = new VerticalPanel();
    wrapper.add(vpanel);
    wrapper.setSize("100%", "100%");
    wrapper.setCellHorizontalAlignment(vpanel, VerticalPanel.ALIGN_CENTER); // michael commented out
    wrapper.setCellVerticalAlignment(vpanel, VerticalPanel.ALIGN_MIDDLE);

    RootPanel.get().clear();
    RootPanel.get().add(wrapper);
}

From source file:edu.ucsb.eucalyptus.admin.client.EucalyptusWebInterface.java

License:Open Source License

public void displayFirstTimeConfiguration() {
    displayStatusPage("Loading first-time configuration page...");

    VerticalPanel gpanel = new VerticalPanel();
    gpanel.setSpacing(25);/*from   w ww  .  ja v a  2s  .c o  m*/
    gpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    // password grid 

    final Grid g1 = new Grid(2, 3);
    g1.getColumnFormatter().setWidth(0, "240");
    g1.getColumnFormatter().setWidth(1, "180");
    g1.getColumnFormatter().setWidth(2, "180");
    int i = 0;

    final int newPassword1_row = i;
    g1.setWidget(i, 0, new Label("Administrator's new password:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox newCleartextPassword1_box = new PasswordTextBox();
    newCleartextPassword1_box.setFocus(true); // this box gets focus first
    newCleartextPassword1_box.setWidth("180");
    g1.setWidget(i++, 1, newCleartextPassword1_box);

    final int newPassword2_row = i;
    g1.setWidget(i, 0, new Label("The password, again:"));
    g1.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final PasswordTextBox newCleartextPassword2_box = new PasswordTextBox();
    newCleartextPassword2_box.setWidth("180");
    g1.setWidget(i++, 1, newCleartextPassword2_box);

    gpanel.add(g1);

    // email address grid

    final Grid g2 = new Grid(1, 3);
    g2.getColumnFormatter().setWidth(0, "240");
    g2.getColumnFormatter().setWidth(1, "180");
    g2.getColumnFormatter().setWidth(2, "180");
    i = 0;

    final int emailAddress_row = i;
    g2.setWidget(i, 0, new Label("Administrator's email address:"));
    g2.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox emailAddress_box = new TextBox();
    emailAddress_box.setWidth("180");
    g2.setWidget(i++, 1, emailAddress_box);

    VerticalPanel epanel = new VerticalPanel();
    epanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    epanel.setSpacing(5);
    epanel.add(g2);
    HTML emailChangeMsg = new HTML(admin_email_change_text);
    emailChangeMsg.setWidth("300");
    emailChangeMsg.setStyleName("euca-small-text");
    epanel.add(emailChangeMsg);
    gpanel.add(epanel);

    // cloud URL grid

    final Grid g3 = new Grid(1, 3);
    g3.getColumnFormatter().setWidth(0, "240");
    g3.getColumnFormatter().setWidth(1, "180");
    g3.getColumnFormatter().setWidth(2, "180");
    i = 0;

    final int cloudUrl_row = i;
    g3.setWidget(i, 0, new Label("Cloud Host:"));
    g3.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    final TextBox cloudUrl_box = new TextBox();
    cloudUrl_box.setWidth("180");
    g3.setWidget(i++, 1, cloudUrl_box);

    VerticalPanel cpanel = new VerticalPanel();
    cpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    cpanel.setSpacing(5);
    cpanel.add(g3);
    HTML cloudUrlMsg = new HTML(admin_cloud_ip_setup_text);
    cloudUrlMsg.setWidth("300");
    cloudUrlMsg.setStyleName("euca-small-text");
    cpanel.add(cloudUrlMsg);
    gpanel.add(cpanel);

    // pull in guessed cloud URL

    EucalyptusWebBackend.App.getInstance().getSystemConfig(sessionId, new AsyncCallback() {
        public void onSuccess(final Object result) {
            conf = (SystemConfigWeb) result;
            cloudUrl_box.setText(conf.getCloudHost());
        }

        public void onFailure(Throwable caught) {
        }
    });

    // user clicked submit

    Button change_button = new Button("Submit", new ClickListener() {
        public void onClick(Widget sender) {
            boolean formOk = true;

            g1.clearCell(0, 2); // clear previous right-hand-side annotations
            g1.clearCell(1, 2); // clear previous right-hand-side annotations
            g2.clearCell(0, 2); // clear previous right-hand-side annotations
            g3.clearCell(0, 2); // clear previous right-hand-side annotations

            // perform checks

            if (newCleartextPassword1_box.getText().length() < minPasswordLength) {
                Label l = new Label("Password is too short!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(newPassword1_row, 2, l);
                formOk = false;
            }
            if (!newCleartextPassword1_box.getText().equals(newCleartextPassword2_box.getText())) {
                Label l = new Label("Passwords do not match!");
                l.setStyleName("euca-error-hint");
                g1.setWidget(newPassword2_row, 2, l);
                formOk = false;
            }

            if (emailAddress_box.getText().length() < 1) {
                Label l = new Label("Email address is empty!");
                l.setStyleName("euca-error-hint");
                g2.setWidget(emailAddress_row, 2, l);
                formOk = false;
            }

            if (cloudUrl_box.getText().length() < 1) {
                Label l = new Label("Cloud URL is empty!");
                l.setStyleName("euca-error-hint");
                g3.setWidget(cloudUrl_row, 2, l);
                formOk = false;
            }

            if (!formOk) {
                label_box.setText("Please, fix the errors and try again:");
                label_box.setStyleName("euca-greeting-warning");
                return;
            }

            label_box.setText("Checking with the server...");
            label_box.setStyleName("euca-greeting-pending");

            loggedInUser.setEmail(emailAddress_box.getText());
            loggedInUser.setPassword(GWTUtils.md5(newCleartextPassword1_box.getText()));

            EucalyptusWebBackend.App.getInstance().updateUserRecord(sessionId, loggedInUser,
                    new AsyncCallback() {
                        public void onSuccess(final Object result) {
                            // password change succeded - pull in the new user record
                            label_box.setText("Refreshing user data...");
                            EucalyptusWebBackend.App.getInstance().getUserRecord(sessionId, null,
                                    new AsyncCallback() {
                                        public void onSuccess(Object result2) {
                                            loggedInUser = (UserInfoWeb) ((List) result2).get(0);

                                            // update cloud URL
                                            conf.setCloudHost(cloudUrl_box.getText());
                                            EucalyptusWebBackend.App.getInstance().setSystemConfig(sessionId,
                                                    conf, new AsyncCallback() {
                                                        public void onSuccess(final Object result) {
                                                            currentTabIndex = 3; // TODO: change this to confTabIndex when it's available
                                                            displayDefaultPage("");
                                                        }

                                                        public void onFailure(Throwable caught) {
                                                            displayErrorPage(
                                                                    "Failed to save the cloud URL (check 'Configuration' tab).");
                                                        }
                                                    });

                                        }

                                        public void onFailure(Throwable caught) {
                                            displayLoginErrorPage(caught.getMessage());
                                        }
                                    });
                        }

                        public void onFailure(Throwable caught) {
                            loggedInUser.setEmail(UserInfoWeb.BOGUS_ENTRY);
                            String m = caught.getMessage();
                            label_box.setText(m);
                            label_box.setStyleName("euca-greeting-warning");
                        }
                    });
        }
    });

    EucalyptusKeyboardListener sl = new EucalyptusKeyboardListener(change_button);
    change_button.addKeyboardListener(sl);
    newCleartextPassword1_box.addKeyboardListener(sl);
    newCleartextPassword2_box.addKeyboardListener(sl);
    emailAddress_box.addKeyboardListener(sl);
    cloudUrl_box.addKeyboardListener(sl);

    HTML message = new HTML(admin_first_time_config_text);
    message.setWidth("600");

    VerticalPanel vpanel = new VerticalPanel();
    vpanel.setSpacing(15);
    vpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    if (logo != null) {
        vpanel.add(logo);
    }
    label_box.setText("First-time Configuration");
    label_box.setStyleName("euca-greeting-normal");
    vpanel.add(label_box);
    vpanel.add(message);
    vpanel.add(gpanel);
    vpanel.add(change_button);

    VerticalPanel wrapper = new VerticalPanel();
    wrapper.add(vpanel);
    wrapper.setSize("100%", "100%");
    wrapper.setCellHorizontalAlignment(vpanel, VerticalPanel.ALIGN_CENTER);
    wrapper.setCellVerticalAlignment(vpanel, VerticalPanel.ALIGN_MIDDLE); // michael commented out

    RootPanel.get().clear();
    RootPanel.get().add(wrapper);
}