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 |
|
144 |
ilm |
19 |
import java.util.Collections;
|
132 |
ilm |
20 |
import java.util.HashMap;
|
|
|
21 |
import java.util.Map;
|
|
|
22 |
|
94 |
ilm |
23 |
import net.minidev.json.JSONObject;
|
|
|
24 |
|
|
|
25 |
public class LightUIButtonLink extends LightUIElement {
|
144 |
ilm |
26 |
private static final String OPEN_NEW_FRAME_KEY = "open-new-frame";
|
|
|
27 |
private static final String URL_PARAMETER_KEY = "url-parameter";
|
132 |
ilm |
28 |
|
|
|
29 |
private Boolean openNewFrame = false;
|
|
|
30 |
private Map<String, String> urlParameters = new HashMap<String, String>();
|
|
|
31 |
|
156 |
ilm |
32 |
public LightUIButtonLink() {
|
|
|
33 |
// Serialization
|
|
|
34 |
}
|
|
|
35 |
|
132 |
ilm |
36 |
public LightUIButtonLink(final String id, final String filePath, final boolean openNewFrame) {
|
|
|
37 |
super(id);
|
|
|
38 |
this.setType(LightUIElement.TYPE_BUTTON_LINK);
|
|
|
39 |
this.setValue(filePath);
|
|
|
40 |
this.setOpenNewFrame(openNewFrame);
|
|
|
41 |
}
|
|
|
42 |
|
94 |
ilm |
43 |
public LightUIButtonLink(final JSONObject json) {
|
132 |
ilm |
44 |
super(json);
|
94 |
ilm |
45 |
}
|
|
|
46 |
|
132 |
ilm |
47 |
public LightUIButtonLink(final LightUIButtonLink button) {
|
|
|
48 |
super(button);
|
94 |
ilm |
49 |
}
|
132 |
ilm |
50 |
|
156 |
ilm |
51 |
@Override
|
|
|
52 |
public void destroy() {
|
|
|
53 |
super.destroy();
|
|
|
54 |
urlParameters = null;
|
|
|
55 |
}
|
|
|
56 |
|
132 |
ilm |
57 |
public Boolean isOpenNewFrame() {
|
|
|
58 |
return this.openNewFrame;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public void setOpenNewFrame(final Boolean openNewFrame) {
|
|
|
62 |
this.openNewFrame = openNewFrame;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public void addUrlParameter(final String key, final String value) {
|
|
|
66 |
this.urlParameters.put(key, value);
|
|
|
67 |
}
|
142 |
ilm |
68 |
|
132 |
ilm |
69 |
public void removeUrlParameter(final String key) {
|
|
|
70 |
this.urlParameters.remove(key);
|
|
|
71 |
}
|
142 |
ilm |
72 |
|
132 |
ilm |
73 |
public void clearUrlParameter() {
|
|
|
74 |
this.urlParameters.clear();
|
|
|
75 |
}
|
|
|
76 |
|
144 |
ilm |
77 |
public Map<String, String> getUrlParameters() {
|
|
|
78 |
return Collections.unmodifiableMap(urlParameters);
|
132 |
ilm |
79 |
}
|
|
|
80 |
|
|
|
81 |
@Override
|
|
|
82 |
protected void copy(LightUIElement element) {
|
|
|
83 |
super.copy(element);
|
|
|
84 |
|
|
|
85 |
if (!(element instanceof LightUIButtonLink)) {
|
|
|
86 |
throw new InvalidClassException(LightUIButtonLink.class.getName(), element.getClassName(), element.getId());
|
|
|
87 |
}
|
|
|
88 |
final LightUIButtonLink button = (LightUIButtonLink) element;
|
|
|
89 |
this.openNewFrame = button.openNewFrame;
|
|
|
90 |
this.urlParameters = button.urlParameters;
|
|
|
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 |
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);
|
142 |
ilm |
110 |
this.urlParameters = CollectionUtils.castMap(JSONConverter.getParameterFromJSON(json, URL_PARAMETER_KEY, Map.class), String.class, String.class);
|
132 |
ilm |
111 |
}
|
156 |
ilm |
112 |
|
94 |
ilm |
113 |
}
|