001/* 002 * Copyright 2012 GWT-Bootstrap 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.github.gwtbootstrap.client.ui.event; 017 018import com.google.gwt.dom.client.NativeEvent; 019import com.google.gwt.event.shared.GwtEvent; 020 021/** 022 * Represents an event that is fired immediately when a widget's 023 * <code>show()</code> method is called. 024 * 025 * @since 2.0.4.0 026 * 027 * @author Dominik Mayer 028 * 029 * @see ShownEvent 030 * @see HideEvent 031 * @see HiddenEvent 032 * 033 */ 034public class ShowEvent extends GwtEvent<ShowHandler> { 035 036 private static final Type<ShowHandler> TYPE = new Type<ShowHandler>(); 037 private final NativeEvent nativeEvent; 038 039 public static Type<ShowHandler> getType() { 040 return TYPE; 041 } 042 043 public ShowEvent() { 044 this(null); 045 } 046 047 public ShowEvent(NativeEvent nativeEvent) { 048 this.nativeEvent = nativeEvent; 049 } 050 051 @Override 052 public final Type<ShowHandler> getAssociatedType() { 053 return TYPE; 054 } 055 056 @Override 057 protected void dispatch(ShowHandler handler) { 058 handler.onShow(this); 059 } 060 061 /** 062 * Prevents the browser from taking its default action for the given event. 063 */ 064 public final void preventDefault() { 065 066 if(nativeEvent == null) return; 067 068 nativeEvent.preventDefault(); 069 } 070 071 /** 072 * Stops the event from being propagated to parent elements. 073 */ 074 public final void stopPropagation() { 075 076 if(nativeEvent == null) return; 077 078 nativeEvent.stopPropagation(); 079 } 080 081}