public void ajouterElement(JSONArray parametres, final int x, final int y, final String type) { final FormulaireController gc = FormulaireController.getInstance(); FormulaireBoard cb = gc.getCheckerBoard(); Widget element = null; TextBox label = new TextBox(); label.addStyleName("inputLabel"); JSONValue paramAsJSONValue; if (type.equals("text") || type.equals("date") || type.equals("time") || type.equals("chiffre")) paramAsJSONValue = parametres.get(0); else { JSONValue parametresValue = parametres.get(0); JSONObject parametresObject = parametresValue.isObject(); if (parametresObject.get("nom").isString().stringValue().equals("titre")) paramAsJSONValue = parametres.get(0); else paramAsJSONValue = parametres.get(1); } JSONObject paramAsJSONObject = paramAsJSONValue.isObject(); label.setText(paramAsJSONObject.get("valeur").isString().stringValue()); TextBox choix = null; final DroppableElement cellule = (DroppableElement) cb.getCell(x, y); cellule.type = type; Element elem = new Element(new Position(y, x), "deplace"); elem.getElement().setClassName(elem.getType() + "Style"); Image suppression = new Image(); suppression.setUrl("images/formulaire/delete.png"); suppression.addStyleName("deleteForm"); String id = Utils.generateId(); ; // Création de l'element selon le type if (type.equals("text")) { element = new TextBox(); } if (type.equals("image")) { element = new Image("../images/formulaire/Photo.png"); } else if (type.equals("checkbox")) { CheckBox c = new CheckBox(); // Ajout de l'attribut name pour les champs checkbox et radio cellule.name = "" + CHOICE; element = c; // Ajout du label de choix pour les champs de type checkbox et radio choix = new TextBox(); choix.addStyleName("inputLabel"); choix.getElement().setAttribute("placeholder", "Choix"); } else if (type.equals("radio")) { RadioButton r = new RadioButton("Choix"); cellule.name = "" + CHOICE; element = r; choix = new TextBox(); choix.addStyleName("inputLabel"); choix.getElement().setAttribute("placeholder", "Choix"); } else if (type.equals("combobox")) { OPTION++; // Ajout de l'option pour les champs de type combobox cellule.option = "" + OPTION; element = new ListBox(); } else if (type.equals("chiffre")) { element = new HTML( "<input type='text' class='gwt-TextBox' onkeypress=\"if((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 46){ event.returnValue=false;}else if(event.keyCode == 46 && (this.value == '' || this.value.indexOf('.') != -1)){ event.returnValue =false;} \" />"); } else if (type.equals("date")) { element = new HTML("<input type='text' id='date" + id + "' class='gwt-TextBox' />"); } else { element = new HTML("<input type='text' id='time" + id + "' class='gwt-TextBox' />"); } HorizontalPanel hp = cellule.getWidgetElement(); hp.add(label); hp.add(element); cellule.choix = false; if (type.equals("checkbox") || type.equals("radio") || type.equals("combobox")) { JSONValue parametresValue = parametres.get(0); JSONObject parametresObject = parametresValue.isObject(); if (parametresObject.get("nom").isString().stringValue().equals("titre")) paramAsJSONValue = parametres.get(1); else paramAsJSONValue = parametres.get(0); paramAsJSONObject = paramAsJSONValue.isObject(); String ch[] = paramAsJSONObject.get("valeur").isString().stringValue().split("\\*_\\*"); if (type.equals("checkbox") || type.equals("radio")) { choix.setText(ch[0]); for (int i = 1; i < ch.length; i++) { DroppableElement.ajouterChoix(x + i, y, type, ch[i]); } CHOICE++; } else { for (int i = 0; i < ch.length; i++) { ((ListBox) element).addItem(ch[i], ch[i]); } } } if (choix != null) hp.add(choix); hp.add(elem); hp.add(suppression); cellule.lock(); if (type.equals("date") || type.equals("time")) FormulaireController.nativeMethod(type + id, type); // Action de la suppression suppression.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { // Vider la cellule cellule.clear(); // Si le champs est de type checkbox ou radio, il faix vider les // champs de choix également if (type.equals("checkbox") || type.equals("radio")) { final FormulaireController gc = FormulaireController.getInstance(); FormulaireBoard c = gc.getCheckerBoard(); boolean end = false; int ligne = x + 1; while (!end) { DroppableElement cellule_choix = (DroppableElement) c.getCell(ligne, y); if (cellule_choix.choix) { cellule_choix.clear(); cellule_choix.type = null; cellule_choix.choix = false; cellule_choix.name = null; cellule_choix.enable(); ligne++; } else end = true; } } // Rendre le champs capable de recevoir des elements puisqu'on // l'a vidé cellule.enable(); cellule.type = null; } }); }