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