Dépôt officiel du code source de l'ERP OpenConcerto
Rev 132 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.ui.light;
import org.openconcerto.utils.io.JSONConverter;
import java.util.HashMap;
import net.minidev.json.JSONObject;
public class JSONToLightUIConvertorManager {
HashMap<String, JSONToLightUIConvertor> map = new HashMap<>();
private static final JSONToLightUIConvertorManager instance = new JSONToLightUIConvertorManager();
public static JSONToLightUIConvertorManager getInstance() {
return instance;
}
public void put(final String className, final JSONToLightUIConvertor convertor) {
this.map.put(className, convertor);
}
public LightUIElement createUIElementFromJSON(final JSONObject jsonElement) {
final Integer type = (Integer) JSONConverter.getParameterFromJSON(jsonElement, "type", Integer.class, null);
switch (type) {
case LightUIElement.TYPE_LABEL: {
final LightUILabel l = new LightUILabel();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_TEXT_FIELD: {
final LightUITextField l = new LightUITextField();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_DATE: {
final LightUIDate l = new LightUIDate();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_COMBOBOX: {
final LightUIComboBox l = new LightUIComboBox();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_TABLE: {
final LightUITable l = new LightUITable();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_CHECKBOX: {
final LightUICheckBox l = new LightUICheckBox();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_TABBED_UI: {
final LightUITabbed l = new LightUITabbed();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_COMBOBOX_ELEMENT: {
// TODO : WTF
throw new IllegalAccessError("WTF");
}
case LightUIElement.TYPE_PANEL: {
final LightUIPanel l = new LightUIPanel();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_TREE: {
// TODO : TYPE_TREE
throw new IllegalAccessError("TODO");
}
case LightUIElement.TYPE_TEXT: {
final LightUIText l = new LightUIText(jsonElement);
return l;
}
case LightUIElement.TYPE_LIST: {
final LightUIList l = new LightUIList(jsonElement);
return l;
}
case LightUIElement.TYPE_DROPDOWN_BUTTON: {
final LightUIDropDownButton l = new LightUIDropDownButton(jsonElement);
return l;
}
case LightUIElement.TYPE_FRAME: {
final LightUIFrame l = new LightUIFrame();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_IMAGE: {
final LightUIImage l = new LightUIImage(jsonElement);
return l;
}
case LightUIElement.TYPE_FILE_UPLOAD_WITH_SELECTION: {
final LightUIFileUpload l = new LightUIFileUpload();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_PANEL_LINE: {
final LightUILine l = new LightUILine();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_TAB_ELEMENT: {
final LightUITab l = new LightUITab(jsonElement);
return l;
}
case LightUIElement.TYPE_SLIDER: {
final LightUISlider l = new LightUISlider();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_PICTURE_UPLOAD: {
final LightUIPictureUpload l = new LightUIPictureUpload();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_BUTTON: {
final LightUIButton l = new LightUIButton();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_BUTTON_WITH_CONTEXT: {
final LightUIButtonWithContext l = new LightUIButtonWithContext(jsonElement);
return l;
}
case LightUIElement.TYPE_BUTTON_CANCEL: {
final LightUIButton button = new LightUIButton();
button.fromJSON(jsonElement);
return button;
}
case LightUIElement.TYPE_BUTTON_UNMANAGED: {
final LightUIButtonUnmanaged l = new LightUIButtonUnmanaged();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_BUTTON_WITH_SELECTION_CONTEXT: {
final LightUIButtonWithSelectionContext l = new LightUIButtonWithSelectionContext(jsonElement);
return l;
}
case LightUIElement.TYPE_BUTTON_LINK: {
final LightUIButtonLink l = new LightUIButtonLink();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_RAW_HTML: {
final LightUIRawHMTL l = new LightUIRawHMTL(jsonElement);
return l;
}
case LightUIElement.TYPE_TEXT_AREA: {
final LightUITextArea l = new LightUITextArea(jsonElement);
return l;
}
case LightUIElement.TYPE_FILE_UPLOAD: {
final LightUIFileUpload l = new LightUIFileUpload();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_LIST_ROW: {
final LightUIListRow l = new LightUIListRow(jsonElement);
return l;
}
case LightUIElement.TYPE_BADGE: {
final LightUIBadge l = new LightUIBadge(jsonElement);
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_AUTOCOMPLETE_COMBOBOX: {
final LightUIAutoCompleteComboBox l = new LightUIAutoCompleteComboBox();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_COLOR_PICKER: {
final LightUIColorPicker l = new LightUIColorPicker(jsonElement);
return l;
}
case LightUIElement.TYPE_HOUR_EDITOR: {
final LightUIHourEditor l = new LightUIHourEditor(jsonElement);
return l;
}
case LightUIElement.TYPE_RADIO_BUTTONS: {
final LightUIRadioButtons l = new LightUIRadioButtons();
l.fromJSON(jsonElement);
return l;
}
case LightUIElement.TYPE_PASSWORD_FIELD: {
final LightUIPasswordField l = new LightUIPasswordField();
l.fromJSON(jsonElement);
return l;
}
}
throw new IllegalArgumentException("unsupported type " + type);
}
}