001package gwt.material.design.addins.client.fileuploader.events; 002 003/* 004 * #%L 005 * GwtMaterial 006 * %% 007 * Copyright (C) 2015 - 2016 GwtMaterialDesign 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 024import com.google.gwt.event.shared.EventHandler; 025import com.google.gwt.event.shared.GwtEvent; 026import gwt.material.design.addins.client.fileuploader.base.HasFileUpload; 027import gwt.material.design.addins.client.fileuploader.base.UploadResponse; 028 029public class SendingEvent<T> extends GwtEvent<SendingEvent.SendingHandler<T>> { 030 031 private static Type<SendingHandler<?>> TYPE; 032 033 public interface SendingHandler<T> extends EventHandler { 034 void onSending(SendingEvent<T> event); 035 } 036 037 public static <T> void fire(HasFileUpload<T> source, T target, UploadResponse response) { 038 if (TYPE != null) { 039 SendingEvent<T> event = new SendingEvent<T>(target, response); 040 source.fireEvent(event); 041 } 042 } 043 044 public static Type<SendingHandler<?>> getType() { 045 return TYPE != null ? TYPE : (TYPE = new Type<SendingHandler<?>>()); 046 } 047 048 private final T target; 049 private final UploadResponse response; 050 051 protected SendingEvent(T target, UploadResponse response) { 052 this.target = target; 053 this.response = response; 054 } 055 056 @Override 057 public final Type<SendingHandler<T>> getAssociatedType() { 058 return (Type) TYPE; 059 } 060 061 public T getTarget() { 062 return target; 063 } 064 065 public UploadResponse getResponse() { 066 return response; 067 } 068 069 @Override 070 protected void dispatch(SendingHandler<T> handler) { 071 handler.onSending(this); 072 } 073}