Example usage for com.google.gwt.user.client.ui FormPanel wrap

List of usage examples for com.google.gwt.user.client.ui FormPanel wrap

Introduction

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

Prototype

public static FormPanel wrap(Element element, boolean createIFrame) 

Source Link

Document

Creates a FormPanel that wraps an existing <form> element.

Usage

From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java

License:Apache License

/** preserves event handlers on element to be wrapped */
public static Widget elementToWidget(Element e, String typ) {
    Widget result = null;/*from   w ww .  j  a va  2  s . co  m*/
    if (e != null) {
        int eventsSunk = DOM.getEventsSunk(e);
        EventListener el = DOM.getEventListener(e);
        if (typ == TEXT)
            result = TextBox.wrap(e);
        else if (typ == TEXT_AREA)
            result = TextArea.wrap(e);
        else if (typ == PASSWORD)
            result = PasswordTextBox.wrap(e);
        else if (typ == LABEL)
            result = Label.wrap(e);
        else if (typ == A)
            result = Anchor.wrap(e);
        else if (typ == IMAGE)
            result = Image.wrap(e);
        else if (typ == SELECT)
            result = ListBox.wrap(e);
        else if (typ == HIDDEN)
            result = Hidden.wrap(e);
        else if (typ == FILE)
            result = FileUpload.wrap(e);
        else if (typ == FORM)
            result = FormPanel.wrap(e, true);
        else if (typ == FRAME)
            result = Frame.wrap(e);
        else if (typ == SUBMIT)
            result = SubmitButton.wrap(e);
        else if (typ == BUTTON)
            result = Button.wrap(e);
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
        DOM.sinkEvents(e, eventsSunk);
        DOM.setEventListener(e, el);
    } else {
        if (typ == TEXT)
            result = new TextBox();
        else if (typ == TEXT_AREA)
            result = new TextArea();
        else if (typ == PASSWORD)
            result = new PasswordTextBox();
        else if (typ == LABEL)
            result = new Label();
        else if (typ == A)
            result = new Anchor();
        else if (typ == SELECT)
            result = new ListBox();
        else if (typ == IMAGE)
            result = new Image();
        else if (typ == HIDDEN)
            result = new Hidden();
        else if (typ == FILE)
            result = new FileUpload();
        else if (typ == FORM)
            result = new FormPanel();
        else if (typ == FRAME)
            result = new Frame();
        else if (typ == SUBMIT)
            result = new SubmitButton();
        else if (typ == BUTTON)
            result = new Button();
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
    }
    return result;
}

From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java

License:Apache License

/** preserves event handlers on element to be wrapped  */
public static Widget elementToWidget(String elementName, String typ) {
    Widget result = null;//from  w  ww. j av a2  s .  c o m
    Element e = DOM.getElementById(elementName);
    if (e != null) {
        int eventsSunk = DOM.getEventsSunk(e);
        EventListener el = DOM.getEventListener(e);
        if (typ == TEXT)
            result = TextBox.wrap(e);
        else if (typ == TEXT_AREA)
            result = TextArea.wrap(e);
        else if (typ == PASSWORD)
            result = PasswordTextBox.wrap(e);
        else if (typ == LABEL)
            result = Label.wrap(e);
        else if (typ == A)
            result = Anchor.wrap(e);
        else if (typ == SELECT)
            result = ListBox.wrap(e);
        else if (typ == IMAGE)
            result = Image.wrap(e);
        else if (typ == HIDDEN)
            result = Hidden.wrap(e);
        else if (typ == FILE)
            result = FileUpload.wrap(e);
        else if (typ == FORM)
            result = FormPanel.wrap(e, true);
        else if (typ == FRAME)
            result = Frame.wrap(e);
        else if (typ == SUBMIT)
            result = SubmitButton.wrap(e);
        else if (typ == BUTTON)
            result = Button.wrap(e);
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
        DOM.sinkEvents(e, eventsSunk);
        DOM.setEventListener(e, el);
    } else {
        if (typ == TEXT)
            result = new TextBox();
        else if (typ == TEXT_AREA)
            result = new TextArea();
        else if (typ == PASSWORD)
            result = new PasswordTextBox();
        else if (typ == LABEL)
            result = new Label();
        else if (typ == A)
            result = new Anchor();
        else if (typ == IMAGE)
            result = new Image();
        else if (typ == SELECT)
            result = new ListBox();
        else if (typ == HIDDEN)
            result = new Hidden();
        else if (typ == FILE)
            result = new FileUpload();
        else if (typ == FORM)
            result = new FormPanel();
        else if (typ == FRAME)
            result = new Frame();
        else if (typ == SUBMIT)
            result = new SubmitButton();
        else if (typ == BUTTON)
            result = new Button();
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
    }
    return result;
}

From source file:com.eucalyptus.webui.client.view.LoginViewImpl.java

License:Open Source License

private void injectLoginForm() {
    // Inject style first. After the form is wrapped, it is too late (IDs are gone)
    injectLoginFormStyle();//from ww  w.  ja  va  2 s .com
    FormPanel form = FormPanel.wrap(Document.get().getElementById(LOGINFORM_ID), false);
    form.setAction("javascript:__gwt_login()");
    loginArea.appendChild(form.getElement());
    injectLoginFormAction(this);
}

From source file:com.isotrol.impe3.pms.gui.client.widget.LoginPanel.java

License:Open Source License

/**
 * Inits this container inner components.<br/>
 *///  w ww  . j a v a  2  s.  co  m
private void initComponent() {

    LayoutContainer lc = new LayoutContainer(formSupport.getStandardLayout(false));
    lc.addStyleName(pmsStyles.loginPanel());
    lc.setAutoWidth(true);

    tfErrorMessage = new LabelField();
    tfErrorMessage.addStyleName(styles.labelInfoMessage());
    tfErrorMessage.addStyleName(styles.redMessage());
    tfErrorMessage.setVisible(false);
    lc.add(tfErrorMessage);

    add(lc);

    lcAuthenticating = new LayoutContainer(new ColumnLayout());
    lcAuthenticating.setVisible(false);
    lcAuthenticating.setStyleName(styles.marginBottom10px());
    // add "loading" icon:
    lcAuthenticating.add(new Html("<div class='loading-icon' style='float: right; margin-right: 5px;'></div>"),
            new ColumnData(165));
    // add "authenticating" label:
    Label tfAuthenticating = new Label(pmsMessages.msgAuthenticating());
    tfAuthenticating.addStyleName(styles.labelInfoMessage());
    lcAuthenticating.add(tfAuthenticating);

    add(lcAuthenticating);

    KeyPressHandler keyEnterPressHandler = new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent event) {
            if (event.getUnicodeCharCode() == KeyCodes.KEY_ENTER) {
                pmsLoginForm.submit();
            }
        }
    };

    tfUsername = (InputElement) Document.get().getElementById(USER_FIELD_ID);
    // wrap the input element in a gwt textbox to listen 'enter' key press
    TextBox tbUserName = TextBox.wrap(tfUsername);
    if (tbUserName != null) {
        tbUserName.addKeyPressHandler(keyEnterPressHandler);
    }

    tfPassword = (InputElement) Document.get().getElementById(PASSWORD_FIELD_ID);
    PasswordTextBox tbPassword = PasswordTextBox.wrap(tfPassword);
    if (tbPassword != null) {
        tbPassword.addKeyPressHandler(keyEnterPressHandler);
    }

    LabelElement userLabel = (LabelElement) Document.get().getElementById(USER_LABEL_ID);
    userLabel.setInnerText(pmsMessages.labelUsername());
    LabelElement pwdLabel = (LabelElement) Document.get().getElementById(PASSWORD_LABEL_ID);
    pwdLabel.setInnerText(pmsMessages.labelPassword());

    // Get a handle to the form and set its action. The Wraping for form must be after the input wrapings
    pmsLoginForm = FormPanel.wrap(Document.get().getElementById(FORM_ID), false);
    // form.setAction("javascript:__gwt_login()");
    // form.setAction("javascript:''");
    pmsLoginForm.addSubmitHandler(new SubmitHandler() {
        /**
         * Add login form validations (user and password are required fields)
         * @see com.google.gwt.user.client.ui.FormPanel.SubmitHandler#onSubmit(com.google.gwt.user.client.ui.FormPanel.SubmitEvent)
         */
        public void onSubmit(SubmitEvent event) {
            if (tfUsername.getValue() == null || tfUsername.getValue().equals("")) {
                tfErrorMessage.setValue(pmsMessages.msgErrorUserRequired());
                tfErrorMessage.show();
                event.cancel();
            } else if (tfPassword.getValue() == null || tfPassword.getValue().equals("")) {
                tfErrorMessage.setValue(pmsMessages.msgErrorPasswordRequired());
                tfErrorMessage.show();
                event.cancel();
            } else {
                initAuthentication();
            }
        }
    });

    // Get the submit button for text localization
    final ButtonElement submit = (ButtonElement) Document.get().getElementById(SUBMIT_BUTTON_ID);
    submit.setInnerText(messages.labelAccept());

    SelectionListener<ButtonEvent> listener = new SelectionListener<ButtonEvent>() {
        @Override
        public void componentSelected(ButtonEvent ce) {
            submit.click();
        }
    };
    Button bAccept = buttonsSupport.createAcceptButton(listener);
    addButton(bAccept);
    // Add the form to the panel
    lc.add(pmsLoginForm);
}

From source file:n3phele.client.view.LoginView.java

License:Open Source License

public LoginView(String homeUrl) {
    this.homeUrl = homeUrl;

    if (altMethod) {
        form = FormPanel.wrap(Document.get().getElementById(LOGINFORM_ID), true);
        form.addSubmitHandler(new SubmitHandler() {

            @Override//from   ww  w  . j a  v a  2 s.  co m
            public void onSubmit(SubmitEvent event) {
                setMessage("checking your identity and credentials.");
                N3phele.authenticate(getUsername(), getPassword(), LoginView.this);
            }
        });
    } else {
        //           // Get a handle to the form and set its action to our jsni method
        //           form = FormPanel.wrap(Document.get().getElementById(LOGINFORM_ID), false);
        //           form.setAction("javascript:__gwt_login()");
        //   
        //           // Get the submit button for text localization
        //           @SuppressWarnings("unused")
        //         ButtonElement submit = (ButtonElement) Document.get().getElementById(LOGINBUTTON_ID);
        //   
        //           // Now, inject the jsni method for handling the form submit
        //           injectLoginFunction(this);
    }

    this.decoratorPanel = new DecoratorPanel();
    VerticalPanel v = new VerticalPanel();
    this.decoratorPanel.add(v);
    Button register = new Button("<u>register</u>", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            new NewUserView(LoginView.this.homeUrl + "user").show();
        }
    });
    Button forgot = new Button("<u>forgot password</u>", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            new ForgotPasswordView(LoginView.this.homeUrl + "user/reset").show();
        }
    });
    HTML h = new HTML();
    h.setHTML(
            "<h1 style=\"text-indent:10px\">n3phele login</h1><p style=\"border-style:solid;border-width:1px;border-color:#4f81bd\"></p>");
    v.add(h);
    errmsg = new HTML();
    errmsg.setHeight("100px");
    errmsg.setWordWrap(true);
    errmsg.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    v.add(errmsg);
    register.setStyleName(N3phele.n3pheleResource.css().registerButton());
    forgot.setStyleName(N3phele.n3pheleResource.css().registerButton());
    v.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_DEFAULT);
    v.add(form);
    v.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    v.add(register);
    v.add(forgot);

    initWidget(this.decoratorPanel);

}

From source file:org.rhq.coregui.client.LoginView.java

License:Open Source License

public void showLoginDialog() {
    if (!loginShowing) {
        UserSessionManager.logout();/*from ww  w  .ja  v  a 2s .c  o  m*/
        if (!isLoginView()) {
            redirectTo(LOGIN_VIEW);
            return;
        }
        isLoginView = true;
        loginShowing = true;
        form = new DynamicForm();
        form.setMargin(25);
        form.setAutoFocus(true);
        form.setShowErrorText(true);
        form.setErrorOrientation(FormErrorOrientation.BOTTOM);

        // NOTE: This image will either be an RHQ logo or a JON logo.
        //       but must be 80x40
        Img logoImg = new Img("header/rhq_logo_40px.png", 80, 40);

        CanvasItem logo = new CanvasItem();
        logo.setShowTitle(false);
        logo.setCanvas(logoImg);

        HeaderItem header = new HeaderItem();
        header.setValue(MSG.view_login_prompt());

        TextItem user = new TextItem("user", MSG.common_title_user());
        user.setRequired(true);
        user.setAttribute("autoComplete", "native");

        final PasswordItem password = new PasswordItem("password", MSG.common_title_password());
        password.setRequired(true);
        password.setAttribute("autoComplete", "native");

        loginButton = new SubmitItem("login", MSG.view_login_login());
        loginButton.setAlign(Alignment.CENTER);
        loginButton.setColSpan(2);

        user.addKeyPressHandler(new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {
                if ((event.getCharacterValue() != null) && (((event.getCharacterValue() == KeyCodes.KEY_ENTER))
                        || (event.getCharacterValue() == KeyCodes.KEY_TAB))) {
                    password.focusInItem(); // Work around the form not getting auto-fill values until the field is focused
                }
            }
        });

        password.addKeyPressHandler(new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {
                if ((event.getCharacterValue() != null) && (event.getCharacterValue() == KeyCodes.KEY_ENTER)) {
                    form.submit();
                }
            }
        });

        form.setFields(logo, header, new RowSpacerItem(), user, password, loginButton);

        window = new Window();
        window.setWidth(400);
        window.setHeight(275);
        window.setTitle(MSG.common_title_welcome());

        // forced focused, static size, can't close / dismiss
        window.setIsModal(true);
        window.setShowModalMask(true);
        window.setCanDragResize(false);
        window.setCanDragReposition(false);
        window.setShowCloseButton(false);
        window.setShowMinimizeButton(false);
        window.setAutoCenter(true);

        window.addItem(form);

        form.addSubmitValuesHandler(new SubmitValuesHandler() {
            public void onSubmitValues(SubmitValuesEvent submitValuesEvent) {
                if (form.validate()) {
                    setUsername(form.getValueAsString("user"));
                    setPassword(form.getValueAsString("password"));
                    fakeForm.submit();
                }
            }
        });

        // Get a handle to the form and set its action to __gwt_login() method
        fakeForm = FormPanel.wrap(Document.get().getElementById(LOGINFORM_ID), false);
        fakeForm.setVisible(true);
        fakeForm.setAction("javascript:__gwt_login()");
        // export the JSNI function
        injectLoginFunction(this);

        if (errorMessage != null) {
            form.setFieldErrors("login", MSG.view_login_noUser(), true);
            errorMessage = null; // hide it next time
        }
    }
}

From source file:org.sigmah.login.client.LoginEntryPoint.java

License:Open Source License

@Override
public void onModuleLoad() {
    panel = new LoginPanel();
    messages = GWT.create(LoginMessages.class);
    form = FormPanel.wrap(panel.getForm(), true);

    bindForm();/*from  ww w  . j a v  a  2s .c  o m*/
}