Login dialog (Ext GWT) : Dialog « GWT « Java






Login dialog (Ext GWT)

Login dialog (Ext GWT)
 
/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

package com.google.gwt.sample.hello.client;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Status;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.RootPanel;

public class Hello implements EntryPoint {
  public void onModuleLoad() {
   // RootPanel.get().add(new ReorderingTreeGridExample());
    LoginDialog d = new LoginDialog();
    d.show();
  }
}
class LoginDialog extends Dialog {

  protected TextField<String> userName;
  protected TextField<String> password;
  protected Button reset;
  protected Button login;
  protected Status status;

  public LoginDialog() {
    FormLayout layout = new FormLayout();
    layout.setLabelWidth(90);
    layout.setDefaultWidth(155);
    setLayout(layout);
    
    setButtonAlign(HorizontalAlignment.LEFT);
    setButtons("");
    setIcon(IconHelper.createStyle("user"));
    setHeading("GXT Mail Demo Login");
    setModal(true);
    setBodyBorder(true);
    setBodyStyle("padding: 8px;background: none");
    setWidth(300);
    setResizable(false);

    KeyListener keyListener = new KeyListener() {
      public void componentKeyUp(ComponentEvent event) {
        validate();
      }

    };

    userName = new TextField<String>();
    userName.setMinLength(4);
    userName.setFieldLabel("Username");
    userName.addKeyListener(keyListener);
    add(userName);

    password = new TextField<String>();
    password.setMinLength(4);
    password.setPassword(true);
    password.setFieldLabel("Password");
    password.addKeyListener(keyListener);
    add(password);

    setFocusWidget(userName);

  }

  @Override
  protected void createButtons() {
    super.createButtons();
    status = new Status();
    status.setBusy("please wait...");
    status.hide();
    status.setAutoWidth(true);
    getButtonBar().add(status);
    
    getButtonBar().add(new FillToolItem());
    
    reset = new Button("Reset");
    reset.addSelectionListener(new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        userName.reset();
        password.reset();
        validate();
        userName.focus();
      }

    });

    login = new Button("Login");
    login.disable();
    login.addSelectionListener(new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        onSubmit();
      }
    });

    addButton(reset);
    addButton(login);

    
  }

  protected void onSubmit() {
    status.show();
    getButtonBar().disable();
    Timer t = new Timer() {

      @Override
      public void run() {
        LoginDialog.this.hide();
      }

    };
    t.schedule(2000);
  }

  protected boolean hasValue(TextField<String> field) {
    return field.getValue() != null && field.getValue().length() > 0;
  }

  protected void validate() {
    login.setEnabled(hasValue(userName) && hasValue(password)
        && password.getValue().length() > 3);
  }

}

   
  








Ext-GWT.zip( 4,297 k)

Related examples in the same category

1.Create Custom Dialog
2.Add label to a window (Smart GWT)Add label to a window (Smart GWT)
3.Add Footer to a window (Smart GWT)Add Footer to a window (Smart GWT)
4.Adding controls to window header (Smart GWT)Adding controls to window header (Smart GWT)
5.Minimizing a window (Smart GWT)Minimizing a window (Smart GWT)
6.Modal window with controls (Smart GWT)Modal window with controls (Smart GWT)
7.Mormal window vs auto-resizing window (Smart GWT)Mormal window vs auto-resizing window (Smart GWT)
8.Draggable window (Smart GWT)Draggable window (Smart GWT)
9.Put complex control onto a dialog (Smart GWT)Put complex control onto a dialog (Smart GWT)
10.Confirmation dialog (Smart GWT)Confirmation dialog (Smart GWT)
11.Expandable dialog with expandable panel (Smart GWT)Expandable dialog with expandable panel (Smart GWT)
12.A custom form control implemented as a picker (Smart GWT)A custom form control implemented as a picker (Smart GWT)
13.Adding accordion panel to a window (Ext GWT)Adding accordion panel to a window (Ext GWT)
14.Alert MessageBox (Ext GWT)Alert MessageBox (Ext GWT)
15.Confirmation MessageBox (Ext GWT)Confirmation MessageBox (Ext GWT)
16.Prompt MessageBox (Ext GWT)Prompt MessageBox (Ext GWT)
17.Adding callback listener to MessageBox (Ext GWT)Adding callback listener to MessageBox (Ext GWT)
18.Multi-line prompt MessageBox (Ext GWT)Multi-line prompt MessageBox (Ext GWT)
19.Configure the MessageBox (Ext GWT)Configure the MessageBox (Ext GWT)
20.Progress Bar dialog box (Ext GWT)Progress Bar dialog box (Ext GWT)
21.Timer based dialog box (Ext GWT)Timer based dialog box (Ext GWT)
22.Put TabPanel to Window to create a dialog (Ext GWT)Put TabPanel to Window to create a dialog (Ext GWT)
23.Simple dialog with text area and two buttons (Ext GWT)Simple dialog with text area and two buttons (Ext GWT)
24.Dialog with layout (Ext GWT)Dialog with layout (Ext GWT)
25.Create a popup window with Window class (Ext GWT)Create a popup window with Window class (Ext GWT)