Deal with browser history : History « GWT « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Java » GWT » HistoryScreenshots 
Deal with browser history


package com.java2s.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.HistoryListener;

public class GWTClient implements EntryPoint,HistoryListener {
  private static final String LOGIN_STATE = "login";
  private static final String WELCOME_STATE = "welcome";

  public void onModuleLoad() {
    setupHistory();
  }
  private void setupHistory() {
    History.addHistoryListener(this);
    History.onHistoryChanged(LOGIN_STATE);
  }
  public void onHistoryChanged(String historyToken) {
    if (LOGIN_STATE.equals(historyToken)) {
      loadLoginView();
    }
    else
      if (WELCOME_STATE.equals(historyToken)) {
        loadWelcomeView();
      }
  }

  private void loadLoginView() {
    final Label loginPrompt = new Label("login");
    final Grid grid = new Grid(32);
    final Label namePrompt = new Label("name");
    final TextBox nameTextbox = new TextBox();
    final Label passwordPrompt = new Label("password");
    final PasswordTextBox passwordTextbox = new PasswordTextBox();
    final Button button = new Button("Login");

    button.addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
        History.newItem(WELCOME_STATE);
      }
    });

    loginPrompt.addStyleName("loginPrompt");
    nameTextbox.addStyleName("nameField");
    passwordTextbox.addStyleName("passwordField");

    grid.setWidget(00, namePrompt);
    grid.setWidget(01, nameTextbox);

    grid.setWidget(10, passwordPrompt);
    grid.setWidget(11, passwordTextbox);

    grid.setWidget(21, button);
    
    RootPanel.get().clear();
    RootPanel.get().add(loginPrompt);
    RootPanel.get().add(grid);
  }

  private void loadWelcomeView() {
    final Label welcomeMsg = new Label("welcome");

    welcomeMsg.addStyleName("welcomeMsg");

    RootPanel.get().clear();
    RootPanel.get().add(welcomeMsg);
    RootPanel.get().add(new Hyperlink("logoutLink",LOGIN_STATE));
  }
}


           
       
GWT-loginHistory.zip( 3 k)
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.