All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gwt.event.logical.shared.CloseEvent Maven / Gradle / Ivy

There is a newer version: 2.12.1
Show newest version
/*
 * Copyright 2008 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.event.logical.shared;

import com.google.gwt.event.shared.GwtEvent;

/**
 * Represents a close event.
 * 
 * @param  the type being closed
 */
public class CloseEvent extends GwtEvent> {

  /**
   * Handler type.
   */
  private static Type> TYPE;

  /**
   * Fires a close event on all registered handlers in the handler manager. If
   * no such handlers exist, this method will do nothing.
   * 
   * @param  the target type
   * @param source the source of the handlers
   * @param target the target
   */
  public static  void fire(HasCloseHandlers source, T target) {
    fire(source, target, false);
  }

  /**
   * Fires a close event on all registered handlers in the handler manager.
   * 
   * @param  the target type
   * @param source the source of the handlers
   * @param target the target
   * @param autoClosed was the target closed automatically
   */
  public static  void fire(HasCloseHandlers source, T target,
      boolean autoClosed) {
    if (TYPE != null) {
      CloseEvent event = new CloseEvent(target, autoClosed);
      source.fireEvent(event);
    }
  }

  /**
   * Gets the type associated with this event.
   * 
   * @return returns the handler type
   */
  public static Type> getType() {
    return TYPE != null ? TYPE : (TYPE = new Type>());
  }

  private final T target;

  private final boolean autoClosed;

  /**
   * Creates a new close event.
   * 
   * @param target the target
   * @param autoClosed whether it is auto closed
   */
  protected CloseEvent(T target, boolean autoClosed) {
    this.autoClosed = autoClosed;
    this.target = target;
  }

  // The instance knows its of type T, but the TYPE
  // field itself does not, so we have to do an unsafe cast here.
  @SuppressWarnings("unchecked")
  @Override
  public final Type> getAssociatedType() {
    return (Type) TYPE;
  }

  /**
   * Gets the target.
   * 
   * @return the target
   */
  public T getTarget() {
    return target;
  }

  /**
   * Was the target automatically closed?
   * 
   * @return auto closed
   */
  public boolean isAutoClosed() {
    return autoClosed;
  }

  @Override
  protected void dispatch(CloseHandler handler) {
    handler.onClose(this);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy