001package gwt.material.design.addins.client.fileuploader.base;
002
003/*
004 * #%L
005 * GwtMaterial
006 * %%
007 * Copyright (C) 2015 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
023import com.google.gwt.event.shared.HandlerRegistration;
024import com.google.gwt.event.shared.HasHandlers;
025import gwt.material.design.addins.client.dnd.events.DragEndEvent;
026import gwt.material.design.addins.client.dnd.events.DragStartEvent;
027import gwt.material.design.addins.client.fileuploader.events.*;
028
029public interface HasFileUpload<T> extends HasHandlers {
030
031    /**
032     * The user dropped something onto the dropzone
033     * @param handler
034     */
035    HandlerRegistration addDropHandler(DropEvent.DropHandler handler);
036
037    void fireDropEvent();
038
039    /**
040     * The user started to drag anywhere
041     * @param handler
042     */
043    HandlerRegistration addDragStartHandler(DragStartEvent.DragStartHandler handler);
044
045    void fireDragStartEvent();
046
047    /**
048     * Dragging has ended
049     * @param handler
050     */
051    HandlerRegistration addDragEndHandler(DragEndEvent.DragEndHandler handler);
052
053    void fireDragEndEvent();
054
055    /**
056     * The user dragged a file onto the Dropzone
057     * @param handler
058     */
059    HandlerRegistration addDragEnterHandler(DragEnterEvent.DragEnterHandler handler);
060
061    void fireDragEnterEvent();
062
063    /**
064     * The user is dragging a file over the Dropzone
065     * @param handler
066     */
067    HandlerRegistration addDragOverHandler(DragOverEvent.DragOverHandler handler);
068
069    void fireDragOverEvent();
070
071    /**
072     * The user is dragging a file over the Dropzone
073     * @param handler
074     */
075    HandlerRegistration addDragLeaveHandler(DragLeaveEvent.DragLeaveHandler handler);
076
077    void fireDragLeaveEvent();
078
079    /**
080     * When a file is added to the list
081     * @param handler
082     */
083    HandlerRegistration addAddedFileHandler(AddedFileEvent.AddedFileHandler<T> handler);
084
085    void fireAddedFileEvent(String fileName, String lastModified, String size, String type);
086
087    /**
088     * Called whenever a file is removed from the list. You can listen to this and delete the file from your server if you want to.
089     * @param handler
090     */
091    HandlerRegistration addRemovedFileHandler(RemovedFileEvent.RemovedFileHandler<T> handler);
092
093    void fireRemovedFileEvent(String fileName, String lastModified, String size, String type);
094
095    /**
096     * An error occured. Receives the errorMessage as second parameter and if the error was due to the XMLHttpRequest the xhr object as third.
097     * @param handler
098     */
099    HandlerRegistration addErrorHandler(ErrorEvent.ErrorHandler<T> handler);
100
101    void fireErrorEvent(String fileName, String lastModified, String size, String type, String responseCode, String responseMessage, String responseBody);
102    /**
103     * An unauthorized error occured. Probably because of session expiration.
104     * Receives the errorMessage as second parameter and if the error was due to
105     * the XMLHttpRequest the xhr object as third.
106     *
107     * @param handler
108     */
109    HandlerRegistration addUnauthorizedHandler(UnauthorizedEvent.UnauthorizedHandler<T> handler);
110
111    void fireUnauthorizedEvent(String fileName, String lastModified, String size, String type, String responseCode, String responseMessage, String responseBody);
112
113    /**
114     * Called with the total uploadProgress (0-100). This event can be used to show the overall upload progress of all files.
115     * @param handler
116     * @return
117     */
118    HandlerRegistration addTotalUploadProgressHandler(TotalUploadProgressEvent.TotalUploadProgressHandler handler);
119
120    void fireTotalUploadProgressEvent(double progress);
121
122    /**
123     * Called just before each file is sent. Gets the xhr object and the formData objects as second and third parameters, so you can modify them (for example to add a CSRF token) or add additional data.
124     * @param handler
125     */
126    HandlerRegistration addSendingHandler(SendingEvent.SendingHandler<T> handler);
127
128    void fireSendingEvent(String fileName, String lastModified, String size, String type, String responseCode, String responseMessage);
129
130    /**
131     * The file has been uploaded successfully. Gets the server response as second argument. (This event was called finished previously)
132     * @param handler
133     */
134    HandlerRegistration addSuccessHandler(SuccessEvent.SuccessHandler<T> handler);
135
136    void fireSuccessEvent(String fileName, String lastModified, String size, String type, String responseCode, String responseMessage, String responseBody);
137
138    /**
139     * Called when the upload was either successful or erroneous.
140     * @param handler
141     */
142    HandlerRegistration addCompleteHandler(CompleteEvent.CompleteHandler<T> handler);
143
144    void fireCompleteEvent(String fileName, String lastModified, String size, String type, String responseCode, String responseMessage, String responseBody);
145
146    /**
147     * Called when a file upload gets canceled.
148     * @param handler
149     */
150    HandlerRegistration addCancelHandler(CanceledEvent.CanceledHandler<T> handler);
151
152    void fireCancelEvent(String fileName, String lastModified, String size, String type);
153
154    /**
155     * Called when the number of files accepted reaches the maxFiles limit.
156     * @param handler
157     */
158    HandlerRegistration addMaxFilesReachHandler(MaxFilesReachedEvent.MaxFilesReachedHandler<T> handler);
159
160    void fireMaxFilesReachEvent(String fileName, String lastModified, String size, String type);
161
162    /**
163     * Called for each file that has been rejected because the number of files exceeds the maxFiles limit.
164     * @param handler
165     */
166    HandlerRegistration addMaxFilesExceededHandler(MaxFilesExceededEvent.MaxFilesExceededHandler<T> handler);
167
168    void fireMaxFilesExceededEvent(String fileName, String lastModified, String size, String type);
169}