OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
94 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
 
132 ilm 16
import org.openconcerto.utils.io.JSONConverter;
17
 
18
import java.util.HashMap;
19
import java.util.Map;
20
 
94 ilm 21
import net.minidev.json.JSONObject;
22
 
23
public class LightUIButtonLink extends LightUIElement {
132 ilm 24
    private final static String OPEN_NEW_FRAME_KEY = "open-new-frame";
25
    private final static String URL_PARAMETER_KEY = "url-parameter";
26
 
27
    private Boolean openNewFrame = false;
28
    private Map<String, String> urlParameters = new HashMap<String, String>();
29
 
30
    public LightUIButtonLink(final String id, final String filePath, final boolean openNewFrame) {
31
        super(id);
32
        this.setType(LightUIElement.TYPE_BUTTON_LINK);
33
        this.setValue(filePath);
34
        this.setOpenNewFrame(openNewFrame);
35
    }
36
 
94 ilm 37
    public LightUIButtonLink(final JSONObject json) {
132 ilm 38
        super(json);
94 ilm 39
    }
40
 
132 ilm 41
    public LightUIButtonLink(final LightUIButtonLink button) {
42
        super(button);
94 ilm 43
    }
132 ilm 44
 
45
    public Boolean isOpenNewFrame() {
46
        return this.openNewFrame;
47
    }
48
 
49
    public void setOpenNewFrame(final Boolean openNewFrame) {
50
        this.openNewFrame = openNewFrame;
51
    }
52
 
53
    public void addUrlParameter(final String key, final String value) {
54
        this.urlParameters.put(key, value);
55
    }
56
 
57
    public void removeUrlParameter(final String key) {
58
        this.urlParameters.remove(key);
59
    }
60
 
61
    public void clearUrlParameter() {
62
        this.urlParameters.clear();
63
    }
64
 
65
    @Override
66
    public LightUIElement clone() {
67
        return new LightUIButtonLink(this);
68
    }
69
 
70
    @Override
71
    protected void copy(LightUIElement element) {
72
        super.copy(element);
73
 
74
        if (!(element instanceof LightUIButtonLink)) {
75
            throw new InvalidClassException(LightUIButtonLink.class.getName(), element.getClassName(), element.getId());
76
        }
77
        final LightUIButtonLink button = (LightUIButtonLink) element;
78
        this.openNewFrame = button.openNewFrame;
79
        this.urlParameters = button.urlParameters;
80
    }
81
 
82
    @Override
83
    public JSONToLightUIConvertor getConvertor() {
84
        return new JSONToLightUIConvertor() {
85
            @Override
86
            public LightUIElement convert(final JSONObject json) {
87
                return new LightUIButtonLink(json);
88
            }
89
        };
90
    }
91
 
92
    @Override
93
    public JSONObject toJSON() {
94
        final JSONObject json = super.toJSON();
95
 
96
        if (this.openNewFrame) {
97
            json.put(OPEN_NEW_FRAME_KEY, true);
98
        }
99
        if (!this.urlParameters.isEmpty()) {
100
            json.put(URL_PARAMETER_KEY, this.urlParameters);
101
        }
102
 
103
        return json;
104
    }
105
 
106
    @Override
107
    public void fromJSON(JSONObject json) {
108
        super.fromJSON(json);
109
        this.openNewFrame = JSONConverter.getParameterFromJSON(json, OPEN_NEW_FRAME_KEY, Boolean.class, false);
110
        this.urlParameters = JSONConverter.getParameterFromJSON(json, URL_PARAMETER_KEY, Map.class);
111
    }
94 ilm 112
}