142 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.ui.light;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.utils.io.JSONConverter;
|
|
|
17 |
|
|
|
18 |
import net.minidev.json.JSONObject;
|
|
|
19 |
|
|
|
20 |
public class LightUIFileUpload extends LightUserControl {
|
|
|
21 |
private static final String SEND_FILE_URL_JSON_KEY = "send-file-url";
|
|
|
22 |
|
|
|
23 |
private String sendFileUrl;
|
|
|
24 |
|
|
|
25 |
public LightUIFileUpload(final JSONObject json) {
|
|
|
26 |
super(json);
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
public LightUIFileUpload(final LightUIFileUpload file) {
|
|
|
30 |
super(file);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public LightUIFileUpload(final String id, final String sendFileUrl) {
|
|
|
34 |
super(id);
|
|
|
35 |
this.setType(LightUIElement.TYPE_FILE_UPLOAD);
|
|
|
36 |
|
|
|
37 |
this.sendFileUrl = sendFileUrl;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
@Override
|
|
|
41 |
public JSONToLightUIConvertor getConvertor() {
|
|
|
42 |
return new JSONToLightUIConvertor() {
|
|
|
43 |
@Override
|
|
|
44 |
public LightUIElement convert(final JSONObject json) {
|
|
|
45 |
return new LightUIFileUpload(json);
|
|
|
46 |
}
|
|
|
47 |
};
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
@Override
|
|
|
51 |
public LightUIElement clone() {
|
|
|
52 |
return new LightUIFileUpload(this);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
@Override
|
|
|
56 |
protected void copy(LightUIElement element) {
|
|
|
57 |
super.copy(element);
|
|
|
58 |
if (!(element instanceof LightUIFileUpload)) {
|
|
|
59 |
throw new InvalidClassException(this.getClassName(), element.getClassName(), element.getId());
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
final LightUIFileUpload files = (LightUIFileUpload) element;
|
|
|
63 |
this.sendFileUrl = files.sendFileUrl;
|
|
|
64 |
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
public void fromJSON(final JSONObject json) {
|
|
|
69 |
super.fromJSON(json);
|
|
|
70 |
|
|
|
71 |
this.sendFileUrl = JSONConverter.getParameterFromJSON(json, SEND_FILE_URL_JSON_KEY, String.class);
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
@Override
|
|
|
75 |
public JSONObject toJSON() {
|
|
|
76 |
final JSONObject json = super.toJSON();
|
|
|
77 |
json.put(SEND_FILE_URL_JSON_KEY, this.sendFileUrl);
|
|
|
78 |
return json;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
@Override
|
|
|
82 |
public void _setValueFromContext(final Object value) {
|
|
|
83 |
this.setValue((String) value);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
@Override
|
|
|
87 |
public Object getValueForContext() {
|
|
|
88 |
return this.getValue();
|
|
|
89 |
}
|
|
|
90 |
}
|