-
Notifications
You must be signed in to change notification settings - Fork 62
/
IFileInput.java
376 lines (335 loc) · 9.42 KB
/
IFileInput.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/*
* Copyright 2007 Manuel Carrasco Moñino. (manolo at apache/org)
* http://code.google.com/p/gwtupload
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package gwtupload.client;
import java.util.List;
import gwtupload.client.dnd.DropZoneButtonFileInput;
import gwtupload.client.dnd.DropZoneFileInput;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.HasAllDragAndDropHandlers;
import com.google.gwt.event.dom.client.HasChangeHandlers;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import gwtupload.client.DecoratedFileUpload.FileUploadWithMouseEvents;
/**
* Interface used by Uploaders to use and configure a customized file fileUplad.
*
* Widgets implementing this interface have to render a file fileUplad tag because
* it will be added to the form which is sent to the server.
*
* This interface has thought to let the user the option to create customizable
* panels for file inputs.
*
* @author Manolo Carrasco Moñino
*
*/
public interface IFileInput extends HasChangeHandlers, IsWidget {
/**
* A HyperLinkFileInput implementing the IFileInput interface
*
*/
public class AnchorFileInput extends ButtonFileInput {
public AnchorFileInput() {
super(new Anchor());
}
}
/**
* Just a FileUpload which implements the interface IFileInput
*/
public class BrowserFileInput extends FileUploadWithMouseEvents implements
IFileInput {
@Deprecated
public Widget getWidget() {
return asWidget();
}
public IFileInput newInstance() {
return new BrowserFileInput();
}
public void setLength(int length) {
DOM.setElementAttribute(getElement(), "size", "" + length);
}
/**
* It is not possible to change the button text in a fileUplad type=file
*/
public void setText(String text) {
}
public void updateSize() {
}
}
/**
* A DecoratedFileInput implementing the IFileInput interface
*
*/
public class ButtonFileInput extends DecoratedFileUpload implements IFileInput {
protected boolean i18n = true;
public ButtonFileInput() {
this(new Button());
}
public ButtonFileInput(Widget w) {
this(w, true);
}
public ButtonFileInput(Widget w, boolean i18n) {
super(w);
this.i18n = i18n;
if (i18n) {
super.setText(Uploader.I18N_CONSTANTS.uploaderBrowse());
}
}
public IFileInput newInstance() {
Widget widget = button != null ? button : new Button(this.getText());
return new ButtonFileInput(widget, i18n);
}
public void setLength(int length) {
}
public void setText(String text) {
if (i18n) {
super.setText(text);
}
}
}
/**
* Enum for different IFileInput implementations
*/
public enum FileInputType implements HasFileInputType {
ANCHOR {
public IFileInput getInstance() {
return GWT.create(AnchorFileInput.class);
}
public FileInputType with(Widget w, boolean hasText) {
return this;
}
public FileInputType with(Widget w) {
return this;
}
public FileInputType withInput(IFileInput i) {
return this;
}
public FileInputType withZone(HasAllDragAndDropHandlers dropZone) {
return this;
}
},
BROWSER_INPUT {
public IFileInput getInstance() {
return GWT.create(BrowserFileInput.class);
}
public FileInputType with(Widget w, boolean hasText) {
return this;
}
public FileInputType with(Widget w) {
return this;
}
public FileInputType withInput(IFileInput i) {
return this;
}
public FileInputType withZone(HasAllDragAndDropHandlers dropZone) {
return this;
}
},
BUTTON {
public IFileInput getInstance() {
return GWT.create(ButtonFileInput.class);
}
public FileInputType with(Widget w, boolean hasText) {
return this;
}
public FileInputType with(Widget w) {
return this;
}
public FileInputType withInput(IFileInput i) {
return this;
}
public FileInputType withZone(HasAllDragAndDropHandlers dropZone) {
return this;
}
},
LABEL {
public IFileInput getInstance() {
return GWT.create(LabelFileInput.class);
}
public FileInputType with(Widget w, boolean hasText) {
return this;
}
public FileInputType with(Widget w) {
return this;
}
public FileInputType withInput(IFileInput i) {
return this;
}
public FileInputType withZone(HasAllDragAndDropHandlers dropZone) {
return this;
}
},
CUSTOM {
Widget widget;
boolean hasText = false;
IFileInput i = null;
private HasAllDragAndDropHandlers dropZone = null;
private boolean withDropZone = false;
public IFileInput getInstance() {
if (i == null) {
if (withDropZone) {
if (widget == null) {
i = GWT.create(DropZoneButtonFileInput.class);
} else {
i = new DropZoneButtonFileInput(widget, hasText, dropZone);
}
} else {
if (widget == null) {
i = GWT.create(ButtonFileInput.class);
} else {
i = new ButtonFileInput(widget, hasText);
}
}
}
return i.newInstance();
}
public FileInputType with(Widget widget, boolean hasText) {
i = null;
this.widget = widget;
this.hasText = hasText;
return this;
}
public FileInputType with(Widget w) {
return with(w, false);
}
public FileInputType withInput(IFileInput i) {
this.i = i;
return this;
}
public FileInputType withZone(HasAllDragAndDropHandlers dropZone) {
this.withDropZone = dropZone != null;
this.dropZone = dropZone;
return this;
}
},
DROPZONE {
private HasAllDragAndDropHandlers dropZone;
public IFileInput getInstance() {
return new DropZoneFileInput(dropZone);
}
public FileInputType with(Widget widget, boolean hasText) {
return this;
}
public FileInputType with(Widget w) {
return with(w, false);
}
public FileInputType withInput(IFileInput i) {
return this;
}
public FileInputType withZone(HasAllDragAndDropHandlers dropZone) {
this.dropZone = dropZone;
return this;
}
}
}
/**
* interface for FileInputType enum
*/
interface HasFileInputType {
IFileInput getInstance();
FileInputType with(Widget w, boolean hasText);
FileInputType with(Widget w);
FileInputType withInput(IFileInput w);
FileInputType withZone(HasAllDragAndDropHandlers dropZone);
}
/**
* A LabelFileInput implementing the IFileInput interface
*
*/
public class LabelFileInput extends ButtonFileInput {
public LabelFileInput() {
super(new Label());
addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
setText(getFilename());
}
});
}
}
/**
* Gets the filename selected by the user. This property has no mutator, as
* browser security restrictions preclude setting it.
*
* @return the widget's filename
*/
String getFilename();
/**
* Gets the filenames selected by the user.
*/
List<String> getFilenames();
/**
* Gets the name of this fileUplad element.
*
* @return fieldName
*/
String getName();
/**
* Returns the widget which will be inserted in the document.
* @deprecated use asWidget instead
*/
@Deprecated
Widget getWidget();
/**
* return whether the fileUplad is or not enabled.
*/
boolean isEnabled();
/**
* Creates a new instance of the current object type.
*
* @return a new instance
*/
IFileInput newInstance();
/**
* Enable the file fileUplad.
*/
void setEnabled(boolean b);
/**
* Set the length in characters of the fileinput which are shown.
*
* @param length
*/
void setLength(int length);
/**
* Sets the html name for this fileUplad element. It is the name of the form
* parameter sent to the server.
*
* @param fieldName
*/
void setName(String fieldName);
/**
* Set the size of the widget.
*
* @param width
* @param height
*/
void setSize(String width, String height);
/**
* Set the text for the link which opens the browse file dialog.
*
* @param text
*/
void setText(String text);
void setVisible(boolean b);
void updateSize();
void enableMultiple(boolean b);
void setAccept(String accept);
}