001 package org.gwtbootstrap3.extras.typeahead.client.events;
002
003 /*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2013 - 2014 GwtBootstrap3
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024 import com.google.gwt.event.shared.GwtEvent;
025 import com.google.gwt.user.client.Event;
026 import org.gwtbootstrap3.extras.typeahead.client.ui.Typeahead;
027
028 /**
029 * Triggered when the dropdown menu of the typeahead is closed.
030 *
031 * @author Florian Kremser <florian.kremser@sage.com>
032 */
033 public class TypeaheadClosedEvent<T> extends GwtEvent<TypeaheadClosedHandler<T>> {
034
035 public static <T> void fire(final Typeahead<T> source, final Event nativeEvent) {
036 TypeaheadClosedEvent<T> event = new TypeaheadClosedEvent<T>(source, nativeEvent);
037 source.fireEvent(event);
038 }
039
040 private static final Type<TypeaheadClosedHandler<?>> TYPE = new Type<TypeaheadClosedHandler<?>>();
041
042 private final Typeahead<T> typeahead;
043 private final Event nativeEvent;
044
045 public static Type<TypeaheadClosedHandler<?>> getType() {
046 return TYPE;
047 }
048
049 private TypeaheadClosedEvent(final Typeahead<T> typeahead, final Event nativeEvent) {
050 this.typeahead = typeahead;
051 this.nativeEvent = nativeEvent;
052 }
053
054 public Typeahead<T> getTypeahead() {
055 return typeahead;
056 }
057
058 public Event getNativeEvent() {
059 return nativeEvent;
060 }
061
062 @SuppressWarnings({"unchecked"})
063 @Override
064 public Type<TypeaheadClosedHandler<T>> getAssociatedType() {
065 return (Type) TYPE;
066 }
067
068 @Override
069 protected void dispatch(final TypeaheadClosedHandler<T> handler) {
070 handler.onClosed(this);
071 }
072 }