OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
132 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
132 ilm 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 java.util.HashMap;
19
 
20
import net.minidev.json.JSONObject;
21
 
22
public class JSONToLightUIConvertorManager {
156 ilm 23
    HashMap<String, JSONToLightUIConvertor> map = new HashMap<>();
132 ilm 24
 
25
    private static final JSONToLightUIConvertorManager instance = new JSONToLightUIConvertorManager();
26
 
27
    public static JSONToLightUIConvertorManager getInstance() {
28
        return instance;
29
    }
30
 
31
    public void put(final String className, final JSONToLightUIConvertor convertor) {
32
        this.map.put(className, convertor);
33
    }
34
 
35
    public LightUIElement createUIElementFromJSON(final JSONObject jsonElement) {
156 ilm 36
        final Integer type = (Integer) JSONConverter.getParameterFromJSON(jsonElement, "type", Integer.class, null);
37
        switch (type) {
38
        case LightUIElement.TYPE_LABEL: {
39
            final LightUILabel l = new LightUILabel();
40
            l.fromJSON(jsonElement);
41
            return l;
132 ilm 42
        }
156 ilm 43
        case LightUIElement.TYPE_TEXT_FIELD: {
44
            final LightUITextField l = new LightUITextField();
45
            l.fromJSON(jsonElement);
46
            return l;
47
 
132 ilm 48
        }
156 ilm 49
        case LightUIElement.TYPE_DATE: {
50
            final LightUIDate l = new LightUIDate();
51
            l.fromJSON(jsonElement);
52
            return l;
53
 
54
        }
55
        case LightUIElement.TYPE_COMBOBOX: {
56
            final LightUIComboBox l = new LightUIComboBox();
57
            l.fromJSON(jsonElement);
58
            return l;
59
 
60
        }
61
        case LightUIElement.TYPE_TABLE: {
62
            final LightUITable l = new LightUITable();
63
            l.fromJSON(jsonElement);
64
            return l;
65
 
66
        }
67
        case LightUIElement.TYPE_CHECKBOX: {
68
            final LightUICheckBox l = new LightUICheckBox();
69
            l.fromJSON(jsonElement);
70
            return l;
71
 
72
        }
73
        case LightUIElement.TYPE_TABBED_UI: {
74
            final LightUITabbed l = new LightUITabbed();
75
            l.fromJSON(jsonElement);
76
            return l;
77
 
78
        }
79
        case LightUIElement.TYPE_COMBOBOX_ELEMENT: {
80
            // TODO : WTF
81
            throw new IllegalAccessError("WTF");
82
        }
83
        case LightUIElement.TYPE_PANEL: {
84
            final LightUIPanel l = new LightUIPanel();
85
            l.fromJSON(jsonElement);
86
            return l;
87
 
88
        }
89
        case LightUIElement.TYPE_TREE: {
90
            // TODO : TYPE_TREE
91
            throw new IllegalAccessError("TODO");
92
 
93
        }
94
        case LightUIElement.TYPE_TEXT: {
95
            final LightUIText l = new LightUIText(jsonElement);
96
            return l;
97
 
98
        }
99
        case LightUIElement.TYPE_LIST: {
100
            final LightUIList l = new LightUIList(jsonElement);
101
            return l;
102
 
103
        }
104
        case LightUIElement.TYPE_DROPDOWN_BUTTON: {
105
            final LightUIDropDownButton l = new LightUIDropDownButton(jsonElement);
106
            return l;
107
 
108
        }
109
        case LightUIElement.TYPE_FRAME: {
110
            final LightUIFrame l = new LightUIFrame();
111
            l.fromJSON(jsonElement);
112
            return l;
113
 
114
        }
115
        case LightUIElement.TYPE_IMAGE: {
116
            final LightUIImage l = new LightUIImage(jsonElement);
117
            return l;
118
        }
119
        case LightUIElement.TYPE_FILE_UPLOAD_WITH_SELECTION: {
120
            final LightUIFileUpload l = new LightUIFileUpload();
121
            l.fromJSON(jsonElement);
122
            return l;
123
 
124
        }
125
        case LightUIElement.TYPE_PANEL_LINE: {
126
            final LightUILine l = new LightUILine();
127
            l.fromJSON(jsonElement);
128
            return l;
129
 
130
        }
131
        case LightUIElement.TYPE_TAB_ELEMENT: {
132
            final LightUITab l = new LightUITab(jsonElement);
133
            return l;
134
 
135
        }
136
        case LightUIElement.TYPE_SLIDER: {
137
            final LightUISlider l = new LightUISlider();
138
            l.fromJSON(jsonElement);
139
            return l;
140
 
141
        }
142
        case LightUIElement.TYPE_PICTURE_UPLOAD: {
143
            final LightUIPictureUpload l = new LightUIPictureUpload();
144
            l.fromJSON(jsonElement);
145
            return l;
146
 
147
        }
148
        case LightUIElement.TYPE_BUTTON: {
149
            final LightUIButton l = new LightUIButton();
150
            l.fromJSON(jsonElement);
151
            return l;
152
 
153
        }
154
        case LightUIElement.TYPE_BUTTON_WITH_CONTEXT: {
155
            final LightUIButtonWithContext l = new LightUIButtonWithContext(jsonElement);
156
            return l;
157
 
158
        }
159
        case LightUIElement.TYPE_BUTTON_CANCEL: {
160
            final LightUIButton button = new LightUIButton();
161
            button.fromJSON(jsonElement);
162
            return button;
163
        }
164
        case LightUIElement.TYPE_BUTTON_UNMANAGED: {
165
            final LightUIButtonUnmanaged l = new LightUIButtonUnmanaged();
166
            l.fromJSON(jsonElement);
167
            return l;
168
 
169
        }
170
        case LightUIElement.TYPE_BUTTON_WITH_SELECTION_CONTEXT: {
171
            final LightUIButtonWithSelectionContext l = new LightUIButtonWithSelectionContext(jsonElement);
172
            return l;
173
        }
174
        case LightUIElement.TYPE_BUTTON_LINK: {
175
            final LightUIButtonLink l = new LightUIButtonLink();
176
            l.fromJSON(jsonElement);
177
            return l;
178
 
179
        }
180
        case LightUIElement.TYPE_RAW_HTML: {
181
            final LightUIRawHMTL l = new LightUIRawHMTL(jsonElement);
182
            return l;
183
 
184
        }
185
        case LightUIElement.TYPE_TEXT_AREA: {
186
            final LightUITextArea l = new LightUITextArea(jsonElement);
187
            return l;
188
 
189
        }
190
        case LightUIElement.TYPE_FILE_UPLOAD: {
191
            final LightUIFileUpload l = new LightUIFileUpload();
192
            l.fromJSON(jsonElement);
193
            return l;
194
 
195
        }
196
        case LightUIElement.TYPE_LIST_ROW: {
197
            final LightUIListRow l = new LightUIListRow(jsonElement);
198
            return l;
199
 
200
        }
201
        case LightUIElement.TYPE_BADGE: {
202
            final LightUIBadge l = new LightUIBadge(jsonElement);
203
            l.fromJSON(jsonElement);
204
            return l;
205
 
206
        }
207
        case LightUIElement.TYPE_AUTOCOMPLETE_COMBOBOX: {
208
            final LightUIAutoCompleteComboBox l = new LightUIAutoCompleteComboBox();
209
            l.fromJSON(jsonElement);
210
            return l;
211
        }
212
        case LightUIElement.TYPE_COLOR_PICKER: {
213
            final LightUIColorPicker l = new LightUIColorPicker(jsonElement);
214
            return l;
215
 
216
        }
217
        case LightUIElement.TYPE_HOUR_EDITOR: {
218
            final LightUIHourEditor l = new LightUIHourEditor(jsonElement);
219
            return l;
220
 
221
        }
222
        case LightUIElement.TYPE_RADIO_BUTTONS: {
223
            final LightUIRadioButtons l = new LightUIRadioButtons();
224
            l.fromJSON(jsonElement);
225
            return l;
226
 
227
        }
228
        case LightUIElement.TYPE_PASSWORD_FIELD: {
229
            final LightUIPasswordField l = new LightUIPasswordField();
230
            l.fromJSON(jsonElement);
231
            return l;
232
 
233
        }
234
 
235
        }
236
        throw new IllegalArgumentException("unsupported type " + type);
132 ilm 237
    }
238
}