41
41
* @param <T>
42
42
* type of transfer event, e.g.
43
43
* {@link com.vaadin.flow.server.DownloadHandler}
44
+ * @param <R>
45
+ * type of the subclass implementing this abstract class, needed for
46
+ * revealing a proper type when you chain the methods
44
47
*/
45
- public abstract class TransferProgressAwareHandler <T > implements Serializable {
48
+ public abstract class TransferProgressAwareHandler <T , R extends TransferProgressAwareHandler >
49
+ implements Serializable {
46
50
47
51
private List <TransferProgressListener > listeners ;
48
52
@@ -66,10 +70,10 @@ public abstract class TransferProgressAwareHandler<T> implements Serializable {
66
70
* </ul>
67
71
* <p>
68
72
* The calls of the given listener's methods are wrapped by the
69
- * {@link com.vaadin.flow.component.UI#access} to send UI changes defined
70
- * here when the download or upload request is being handled. Thus, no need
71
- * to call {@link com.vaadin.flow.component.UI#access} in the implementation
72
- * of the given listener. This needs
73
+ * {@link com.vaadin.flow.component.UI#access(Command) } to send UI changes
74
+ * defined here when the download or upload request is being handled. Thus,
75
+ * no need to call {@link com.vaadin.flow.component.UI#access(Command) } in
76
+ * the implementation of the given listener. This needs
73
77
* {@link com.vaadin.flow.component.page.Push} to be enabled in the
74
78
* application to properly send the UI changes to client.
75
79
*
@@ -90,21 +94,18 @@ public Registration addTransferProgressListener(
90
94
* Adds a listener to be notified when the transfer starts.
91
95
* <p>
92
96
* The call of the given callback is wrapped by the
93
- * {@link com.vaadin.flow.component.UI#access} to send UI changes defined
94
- * here when the download or upload request is being handled. Thus, no need
95
- * to call {@link com.vaadin.flow.component.UI#access} in the implementation
96
- * of the given handler. This needs
97
+ * {@link com.vaadin.flow.component.UI#access(Command) } to send UI changes
98
+ * defined here when the download or upload request is being handled. Thus,
99
+ * no need to call {@link com.vaadin.flow.component.UI#access(Command) } in
100
+ * the implementation of the given handler. This needs
97
101
* {@link com.vaadin.flow.component.page.Push} to be enabled in the
98
102
* application to properly send the UI changes to client.
99
103
*
100
104
* @param startHandler
101
105
* the handler to be called when the transfer starts
102
106
* @return this instance for method chaining
103
- * @param <R>
104
- * the type of this transfer progress aware handler
105
107
*/
106
- public <R extends TransferProgressAwareHandler <T >> R whenStart (
107
- SerializableRunnable startHandler ) {
108
+ public R whenStart (SerializableRunnable startHandler ) {
108
109
Objects .requireNonNull (startHandler , "Start handler cannot be null" );
109
110
addTransferProgressListenerInternal (new TransferProgressListener () {
110
111
@ Override
@@ -121,10 +122,10 @@ public void onStart(TransferContext context) {
121
122
* Adds a listener to be notified of transfer progress.
122
123
* <p>
123
124
* The call of the given callback is wrapped by the
124
- * {@link com.vaadin.flow.component.UI#access} to send UI changes defined
125
- * here when the download or upload request is being handled. Thus, no need
126
- * to call {@link com.vaadin.flow.component.UI#access} in the implementation
127
- * of the given handler. This needs
125
+ * {@link com.vaadin.flow.component.UI#access(Command) } to send UI changes
126
+ * defined here when the download or upload request is being handled. Thus,
127
+ * no need to call {@link com.vaadin.flow.component.UI#access(Command) } in
128
+ * the implementation of the given handler. This needs
128
129
* {@link com.vaadin.flow.component.page.Push} to be enabled in the
129
130
* application to properly send the UI changes to client.
130
131
*
@@ -133,11 +134,8 @@ public void onStart(TransferContext context) {
133
134
* @param progressIntervalInBytes
134
135
* the interval in bytes for reporting progress
135
136
* @return this instance for method chaining
136
- * @param <R>
137
- * the type of this transfer progress aware handler
138
137
*/
139
- public <R extends TransferProgressAwareHandler <T >> R onProgress (
140
- SerializableBiConsumer <Long , Long > progressHandler ,
138
+ public R onProgress (SerializableBiConsumer <Long , Long > progressHandler ,
141
139
long progressIntervalInBytes ) {
142
140
Objects .requireNonNull (progressHandler ,
143
141
"Progress handler cannot be null" );
@@ -166,21 +164,18 @@ public long progressReportInterval() {
166
164
* the second is the total number of bytes.
167
165
* <p>
168
166
* The call of the given callback is wrapped by the
169
- * {@link com.vaadin.flow.component.UI#access} to send UI changes defined
170
- * here when the download or upload request is being handled. Thus, no need
171
- * to call {@link com.vaadin.flow.component.UI#access} in the implementation
172
- * of the given handler. This needs
167
+ * {@link com.vaadin.flow.component.UI#access(Command) } to send UI changes
168
+ * defined here when the download or upload request is being handled. Thus,
169
+ * no need to call {@link com.vaadin.flow.component.UI#access(Command) } in
170
+ * the implementation of the given handler. This needs
173
171
* {@link com.vaadin.flow.component.page.Push} to be enabled in the
174
172
* application to properly send the UI changes to client.
175
173
*
176
174
* @param progressHandler
177
175
* the handler to be called with the current and total bytes
178
176
* @return this instance for method chaining
179
- * @param <R>
180
- * the type of this transfer progress aware handler
181
177
*/
182
- public <R extends TransferProgressAwareHandler <T >> R onProgress (
183
- SerializableBiConsumer <Long , Long > progressHandler ) {
178
+ public R onProgress (SerializableBiConsumer <Long , Long > progressHandler ) {
184
179
return onProgress (progressHandler ,
185
180
TransferProgressListener .DEFAULT_PROGRESS_REPORT_INTERVAL_IN_BYTES );
186
181
}
@@ -191,20 +186,18 @@ public <R extends TransferProgressAwareHandler<T>> R onProgress(
191
186
* whether the transfer was completed successfully (true) or not (false).
192
187
* <p>
193
188
* The call of the given callback is wrapped by the
194
- * {@link com.vaadin.flow.component.UI#access} to send UI changes defined
195
- * here when the download or upload request is being handled. Thus, no need
196
- * to call {@link com.vaadin.flow.component.UI#access} in the implementation
197
- * of the given handler. This needs
189
+ * {@link com.vaadin.flow.component.UI#access(Command) } to send UI changes
190
+ * defined here when the download or upload request is being handled. Thus,
191
+ * no need to call {@link com.vaadin.flow.component.UI#access(Command) } in
192
+ * the implementation of the given handler. This needs
198
193
* {@link com.vaadin.flow.component.page.Push} to be enabled in the
199
194
* application to properly send the UI changes to client.
200
195
*
201
196
* @param completeOrTerminateHandler
202
197
* the handler to be called when the transfer is completed
203
198
* @return this instance for method chaining
204
- * @param <R>
205
- * the type of this transfer progress aware handler
206
199
*/
207
- public < R extends TransferProgressAwareHandler < T >> R whenComplete (
200
+ public R whenComplete (
208
201
SerializableConsumer <Boolean > completeOrTerminateHandler ) {
209
202
Objects .requireNonNull (completeOrTerminateHandler ,
210
203
"Complete or terminate handler cannot be null" );
0 commit comments