View.java :  » Ajax » MyGWT » net » mygwt » ui » client » mvc » Java Open Source

Java Open Source » Ajax » MyGWT 
MyGWT » net » mygwt » ui » client » mvc » View.java
/*
 * MyGWT Widget Library
 * Copyright(c) 2007, MyGWT.
 * licensing@mygwt.net
 * 
 * http://mygwt.net/license
 */
package net.mygwt.ui.client.mvc;

/**
 * <code>Views</code> are responsible for rendering the user interface.
 */
public abstract class View {

  protected Controller controller;
  boolean initialized;

  /**
   * Creates a new view instance.
   * 
   * @param controller the parent controller
   */
  public View(Controller controller) {
    this.controller = controller;
  }

  /**
   * Returns the view's controller.
   * 
   * @return the controller
   */
  public Controller getController() {
    return controller;
  }

  /**
   * Called when a view needs to pass an event to it's controller.
   * 
   * @param event the app event
   */
  protected void fireEvent(AppEvent event) {
    Controller c = controller;
    while (c != null) {
      if (c.canHandle(event)) {
        c.handleEvent(event);
      }
      c = c.parent;
    }
  }

  /**
   * Called when a view needs to pass an event to it's controller.
   * 
   * @param eventType the event type
   */
  protected void fireEvent(int eventType) {
    fireEvent(new AppEvent(eventType));
  }

  /**
   * Process the event.
   * 
   * @param event the event to be processed
   */
  protected abstract void handleEvent(AppEvent event);

  /**
   * Called once prior to handleEvent being called. Widgets should be
   * instantiated in the init method rather than the view constructor.
   */
  protected void initialize() {

  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.