OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
    protected void copy(LightUIElement element) {
52
        super.copy(element);
53
        if (!(element instanceof LightUIFileUpload)) {
54
            throw new InvalidClassException(this.getClassName(), element.getClassName(), element.getId());
55
        }
56
        final LightUIFileUpload files = (LightUIFileUpload) element;
57
        this.sendFileUrl = files.sendFileUrl;
58
    }
59
 
60
    @Override
61
    public void fromJSON(final JSONObject json) {
62
        super.fromJSON(json);
63
 
64
        this.sendFileUrl = JSONConverter.getParameterFromJSON(json, SEND_FILE_URL_JSON_KEY, String.class);
65
    }
66
 
67
    @Override
68
    public JSONObject toJSON() {
69
        final JSONObject json = super.toJSON();
70
        json.put(SEND_FILE_URL_JSON_KEY, this.sendFileUrl);
71
        return json;
72
    }
73
 
74
    @Override
75
    public void _setValueFromContext(final Object value) {
76
        this.setValue((String) value);
77
    }
78
 
79
    @Override
80
    public Object getValueForContext() {
81
        return this.getValue();
82
    }
83
}