OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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