DataElement.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */




  20. package org.openspcoop2.web.lib.mvc;

  21. import java.io.Serializable;
  22. import java.util.ArrayList;
  23. import java.util.Arrays;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;

  27. import org.apache.commons.lang.StringEscapeUtils;
  28. import org.apache.commons.lang.StringUtils;
  29. import org.openspcoop2.utils.UtilsRuntimeException;



  30. /**
  31.  * DataElement
  32.  *
  33.  * @author Andrea Poli (apoli@link.it)
  34.  * @author Stefano Corallo (corallo@link.it)
  35.  * @author Sandra Giangrandi (sandra@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  *
  39.  */
  40. public class DataElement implements Serializable {
  41.    
  42.     /**
  43.      *
  44.      */
  45.     private static final long serialVersionUID = 1L;

  46.     public enum STATO_APERTURA_SEZIONI { APERTO, CHIUSO, DISABILITATO }
  47.    
  48.     private static Map<String, String> escapeMap = null;
  49.    
  50.     private static int DATA_ELEMENT_SIZE = 50;
  51.     private static int DATA_ELEMENT_COLS = 15;
  52.     private static int DATA_ELEMENT_ROWS = 5;
  53.     public static void initialize(DataElementParameter p){
  54.         if(p.getSize()!= null && p.getSize().intValue() > 0) {
  55.             DataElement.DATA_ELEMENT_SIZE = p.getSize();
  56.         }
  57.        
  58.         if(p.getCols()!= null && p.getCols().intValue() > 0) {
  59.             DataElement.DATA_ELEMENT_COLS = p.getCols();
  60.         }
  61.        
  62.         if(p.getRows()!= null && p.getRows().intValue() > 0) {
  63.             DataElement.DATA_ELEMENT_ROWS = p.getRows();
  64.         }
  65.     }
  66.    
  67.    
  68.     static{
  69.         DataElement.escapeMap = new HashMap<>();
  70.        
  71.         // carico le stringhe da sostituire
  72.         DataElement.escapeMap.put("&lt;BR&gt;", "<BR>");
  73.         DataElement.escapeMap.put("&lt;BR/&gt;", "<BR/>");
  74.         DataElement.escapeMap.put("&lt;/BR&gt;", "</BR>");
  75.         DataElement.escapeMap.put("&lt;br&gt;", "<br>");
  76.         DataElement.escapeMap.put("&lt;br/&gt;", "<br/>");
  77.         DataElement.escapeMap.put("&lt;/br&gt;", "</br>");
  78.     }

  79.     String label, labelRight, labelLink, value, type, name, onChange, selected;
  80.     String [] values = null, names = null;
  81.     String [] labels = null;
  82.     int size, cols, rows, id;
  83.     boolean affiancato; // serve a gestire il successivo elemento se disegnarlo accanto o in verticale (default)
  84.     boolean labelAffiancata=true; // indica se la label e poi l'elemento sono disegnati uno accanto all'altro in orizzontale (default) oppure in verticale (default per le text-area)
  85.     String idToRemove;
  86.     boolean required=false;
  87.     boolean bold=false;
  88.     boolean postBack=false;
  89.     boolean abilitaFiltroOpzioniSelect=true;
  90.    
  91.     String note = null;
  92.     String styleClass = null;
  93.     String labelStyleClass = null;
  94.     DataElementInfo info = null;
  95.    
  96.     String [] selezionati = null; // serve per gestire i valori selezionati in una multiselect
  97.    
  98.     private String style = null;
  99.     private String width = null;
  100.    
  101.     private Integer minValue = null, maxValue= null;
  102.    
  103.     private List<DataElementImage> image = null;
  104.    
  105.     private String icon, url,toolTip, target, onClick = null;
  106.    
  107.     private boolean showAjaxStatus = true;
  108.    
  109.     private Map<String, String> dataAttributes = null;
  110.    
  111.     private String customJsFunction = null;

  112.     private List<String> statusValues = null, statusToolTips = null, statusTypes = null;
  113.    
  114.     private DataElementPassword password = null;
  115.    
  116.     private boolean visualizzaLinkApriNuovaFinestra = false;
  117.    
  118.     private STATO_APERTURA_SEZIONI statoSottosezione = STATO_APERTURA_SEZIONI.CHIUSO;
  119.    
  120.     private String valoreDefault = null;
  121.    
  122.     private Dialog dialog = null;
  123.    
  124.     private DataElementConfirm confirm = null;
  125.    
  126.     private boolean contextMenu = false;
  127.    
  128.     private String copyToClipboard = null;
  129.    
  130.     private boolean refresh = false;
  131.    
  132.     public String getIdToRemove() {
  133.         return this.idToRemove;
  134.     }

  135.     public void setIdToRemove(String idToRemove) {
  136.         this.idToRemove = idToRemove;
  137.     }

  138.     public DataElement() {
  139.         //int id = -1;
  140.         this.label = "";
  141.         this.value = "";
  142.         this.type = "text";
  143.         this.url = "";
  144.         this.target = "";
  145.         this.onClick = "";
  146.         this.name = "";
  147.         this.onChange = "";
  148.         this.selected = "";
  149.         this.toolTip ="";
  150.         this.icon = "";
  151.         this.image = new ArrayList<>();
  152.         this.size = DataElement.DATA_ELEMENT_SIZE;
  153.         this.cols = DataElement.DATA_ELEMENT_COLS;
  154.         this.rows = DataElement.DATA_ELEMENT_ROWS;
  155.         this.affiancato = false;
  156.         this.labelAffiancata = true;
  157.         this.note = "";
  158.         this.styleClass = Costanti.INPUT_LONG_CSS_CLASS;
  159.         this.labelStyleClass = null;
  160.         this.labelRight = null;
  161.         this.labelLink = null;
  162.         this.dataAttributes = new HashMap<>();
  163.         this.contextMenu = false;
  164.         this.copyToClipboard = null;
  165.         this.refresh = false;
  166.     }

  167.     public void setId(int i) {
  168.         this.id = i;
  169.     }
  170.     public int getId() {
  171.         return this.id;
  172.     }

  173.     public void setLabel(String s) {
  174.         this.label = s;
  175.     }
  176.     public String getOriginalLabel() {
  177.         return DataElement.getEscapedValue(DataElement.checkNull(this.label));
  178.     }
  179.     public String getLabel() {
  180.         return this.getLabel(true);
  181.     }
  182.     public String getLabel(boolean elementsRequiredEnabled) {
  183.         StringBuilder bf = new StringBuilder();
  184.         if(this.bold){
  185.             bf.append("<B>");
  186.         }
  187.        
  188.         bf.append(DataElement.getEscapedValue(DataElement.checkNull(this.label)));
  189.         if(elementsRequiredEnabled && this.required){
  190.             //  bf.append(" (*)");
  191.             bf.append(" <em>*</em>");
  192.         }
  193.         if(this.bold){
  194.             bf.append("</B>");
  195.         }
  196.         return bf.toString();
  197.     }

  198.     public void setValue(String s) {
  199.         this.value = s;
  200.     }
  201.     public String getValue() {
  202.         return DataElement.checkNull(this.value);
  203.     }
  204.    
  205.     public String getValuesNoEdit(String mode) {
  206.         StringBuilder sb = new StringBuilder();
  207.        
  208.         for (int i = 0; i < this.values.length; i++) {
  209.             String val = this.values[i];
  210.             String label = this.labels[i];
  211.            
  212.             if(sb.length() >0)
  213.                 sb.append(", ");
  214.            
  215.             sb.append(label).append(": ").append(val != null && !val.equals("") ? val : (mode.equals("view-noeditbutton") ? "&nbsp;" : "not defined"));
  216.         }
  217.        
  218.         return sb.toString();
  219.     }

  220.     public void setType(DataElementType s) {
  221.         this.setType(s.toString());
  222.     }
  223.     private void setType(String s) {
  224.         this.type = s;
  225.         /*if("hidden".equals(this.type)){
  226.             this.required = false;
  227.             this.bold = false;
  228.         }
  229.         if("text".equals(this.type)){
  230.             this.required = false;
  231.         }*/
  232.         if(DataElementType.TEXT_AREA.toString().equals(s) || DataElementType.TEXT_AREA_NO_EDIT.toString().equals(s)){
  233.             this.setLabelAffiancata(false);
  234.         }
  235.         // Carico la configurazione di default per il tipo password
  236.         if(DataElementType.CRYPT.toString().equals(s)) {
  237.             this.password = new DataElementPassword();
  238.         }
  239.         // classe css default per gli elementi TEXT
  240.         if(DataElementType.TEXT.toString().equals(s)) {
  241.             this.styleClass = Costanti.INPUT_TEXT_DEFAULT_CSS_CLASS;
  242.         }
  243.         // classe css default per gli elementi CHECKBOX
  244.         if(DataElementType.CHECKBOX.toString().equals(s)) {
  245.             this.styleClass = null;
  246.         }
  247.         // Fieldset per default non sono chiudibili dall'utente
  248.         if(DataElementType.TITLE.toString().equals(s)) {
  249.             this.statoSottosezione = STATO_APERTURA_SEZIONI.DISABILITATO;
  250.         }
  251.         // Subtitle per default non sono chiudibili dall'utente
  252.         if(DataElementType.SUBTITLE.toString().equals(s)) {
  253.             this.statoSottosezione = STATO_APERTURA_SEZIONI.DISABILITATO;
  254.         }
  255.         // classe css default per gli elementi LINK
  256.         if(DataElementType.LINK.toString().equals(s)) {
  257.             this.styleClass = null;
  258.         }
  259.         // Carico la configurazione di default per il tipo password
  260.         if(DataElementType.LOCK.toString().equals(s)) {
  261.             throw new UtilsRuntimeException("Use method setLock(String value) instead of setType(DataElementType.LOCK)");
  262.         }
  263.     }
  264.     public String getType() {
  265.         return DataElement.checkNull(this.type);
  266.     }
  267.    
  268.     public void setLock(String value, boolean readOnly, boolean visualizzaInformazioniCifrate, boolean visualizzaIconaLucchetto, String warningMessage, String decoderServletName,Parameter ... parameter) {
  269.         this.setValue(value);
  270.         this.type = DataElementType.LOCK.toString();
  271.         this.password = new DataElementPassword();
  272.         this.password.setLockReadOnly(readOnly);
  273.         this.password.setLockVisualizzaInformazioniCifrate(visualizzaInformazioniCifrate);
  274.         this.password.setLockWarningMessage(warningMessage);
  275.         this.password.setLockVisualizzaIconaLucchetto(visualizzaIconaLucchetto);
  276.         this.setUrl(decoderServletName, parameter);
  277.     }
  278.    
  279.     public void forceLockVisualizzazioneInputUtente(boolean isWrapped, boolean visualizzaInformazioniCifrate) {
  280.         if(this.password!=null) {
  281.             if(isWrapped) {
  282.                 this.password.setLockForzaVisualizzazioneInputUtente(false);
  283.                 this.password.setLockVisualizzaInformazioniCifrate(visualizzaInformazioniCifrate);
  284.                 this.password.setLockUtilizzaInputPassword(false);
  285.             }
  286.             else {
  287.                 this.password.setLockForzaVisualizzazioneInputUtente(true);
  288.                 this.password.setLockVisualizzaInformazioniCifrate(false);
  289.                 this.password.setLockUtilizzaInputPassword(false);
  290.             }
  291.         }
  292.     }
  293.    
  294.     public boolean isRequired() {
  295.         return this.required;
  296.     }

  297.     public void setRequired(boolean required) {
  298.         this.required = required;
  299.         /*if(!"hidden".equals(this.type)){
  300.             this.bold = required;
  301.             if(!"text".equals(this.type)){
  302.                 this.required = required;
  303.             }
  304.         }*/
  305.     }

  306.     public void setUrl(String s) {
  307.         this.url = s;
  308.     }
  309.     public void setUrl(String servletName,Parameter ... parameter) {
  310.         this.url = _getUrlValue(servletName, parameter);
  311.     }

  312.     public static String _getUrlValue(String servletName, Parameter... parameter) {
  313.         StringBuilder sb = new StringBuilder();
  314.         sb.append(servletName);
  315.         if(parameter!=null && parameter.length>0){
  316.             if(sb.indexOf("?") > 0)
  317.                 sb.append("&");
  318.             else
  319.                 sb.append("?");
  320.            
  321.             for (int i = 0; i < parameter.length; i++) {
  322.                 if(i>0){
  323.                     sb.append("&");
  324.                 }
  325.                 sb.append(parameter[i].toString());
  326.             }
  327.         }
  328.        
  329.         String urValue = sb.toString();
  330.         return urValue;
  331.     }
  332.    
  333.     public void addParameter(Parameter ... parameter) {
  334.         this.url = _getUrlValue(this.url, parameter);
  335.     }
  336.    
  337.     public String getUrl() {
  338.         return DataElement.checkNull(this.url);
  339.     }
  340.    
  341.     public void setTarget(TargetType s) {
  342.         this.target = s != null ? s.toString() : null;
  343.     }
  344.     public String getTarget() {
  345.         return DataElement.checkNull(this.target);
  346.     }

  347.     public void setName(String s) {
  348.         this.name = s;
  349.     }
  350.     public String getName() {
  351.         return DataElement.checkNull(this.name);
  352.     }

  353.     public void setOnClick(String s) {
  354.         this.onClick = s;
  355.     }
  356.     public String getOnClick() {
  357.         return DataElement.checkNull(this.onClick);
  358.     }

  359.     @Deprecated
  360.     public void setOnChange(String s) {
  361.         this.onChange = s;
  362.     }
  363.     public void setOnChangeAlternativePostBack(String s) {
  364.         this.onChange = s;
  365.     }
  366.     public String getOnChange() {
  367.         return DataElement.checkNull(this.onChange);
  368.     }

  369.     public void setSelected(String s) {
  370.         this.selected = s;
  371.     }
  372.     public void setSelectedAsNull() {
  373.         this.selected = null;
  374.     }
  375.     public void setSelected(boolean isFlag) {
  376.         if(isFlag)
  377.             this.selected = Costanti.CHECK_BOX_ENABLED;
  378.         else
  379.             this.selected = Costanti.CHECK_BOX_DISABLED;
  380.     }
  381.     public void setSelected(CheckboxStatusType status) {
  382.         this.selected = status.toString();
  383.     }
  384.     public String getSelected() {
  385.         return DataElement.checkNull(this.selected);
  386.     }

  387.     public void setSize(int i) {
  388.         this.size = i;
  389.     }
  390.     public int getSize() {
  391.         return this.size;
  392.     }

  393.     public void setCols(int i) {
  394.         this.cols = i;
  395.     }
  396.     public int getCols() {
  397.         return this.cols;
  398.     }

  399.     public void setRows(int i) {
  400.         this.rows = i;
  401.     }
  402.     public int getRows() {
  403.         return this.rows;
  404.     }

  405.     public void setAffiancato(boolean b) {
  406.         this.affiancato = b;
  407.     }
  408.     public boolean getAffiancato() {
  409.         return this.affiancato;
  410.     }

  411.     public void setValues(String [] s) {
  412.         this.values = s;
  413.     }
  414.     public void setValues(List<String> s) {
  415.         if(s==null || s.isEmpty()){
  416.             return;
  417.         }
  418.         this.setValues(s.toArray(new String[1]));
  419.     }
  420.     public String[] getValues() {
  421.         return this.values;
  422.     }

  423.     public void setLabels(String [] s) {
  424.         if( s != null && s.length > 0){
  425.             this.labels = new String[ s.length];
  426.             for (int i = 0; i < s.length; i++) {
  427.                 this.labels[i] = DataElement.getEscapedValue( s[i]);
  428.             }
  429.         }else {
  430.             this.labels = s;
  431.         }
  432.     }
  433.     public void setLabels(List<String> s) {
  434.         if(s==null || s.size()<=0){
  435.             return;
  436.         }
  437.         this.setLabels(s.toArray(new String[1]));
  438.     }
  439.     public String[] getLabels() {
  440.         return this.labels;
  441.     }
  442.    
  443.     public static String checkNull(String toCheck)
  444.     {
  445.         return (toCheck==null ? "" : toCheck);
  446.     }

  447.     public String getToolTip() {
  448.         return DataElement.checkNull(this.toolTip);
  449.     }
  450.     /**
  451.      * Il tooltip da visualizzare quando si passa con il mouse
  452.      * su di un link, se il tooltip non e' impostato e il valore del campo value
  453.      * e' &gt; size allora il link viene troncato e viene
  454.      * impostato come tooltip il valore originale di value
  455.      * @param toolTip
  456.      */
  457.     public void setToolTip(String toolTip) {
  458.         this.toolTip = toolTip;
  459.     }
  460.     public boolean isBold() {
  461.         return this.bold;
  462.     }

  463.     public void setBold(boolean bold) {
  464.         this.bold = bold;
  465.     }
  466.    
  467.     public boolean isLabelAffiancata() {
  468.         return this.labelAffiancata;
  469.     }

  470.     public void setLabelAffiancata(boolean labelAffiancata) {
  471.         this.labelAffiancata = labelAffiancata;
  472.     }
  473.    
  474.     public boolean isPostBack() {
  475.         return this.postBack;
  476.     }
  477.     public void setPostBack(boolean postBack) {
  478.         this.setPostBack(postBack, true);
  479.     }
  480.     public void setPostBack(boolean postBack,boolean setElementName) {
  481.         this.setPostBack(postBack, setElementName, false);
  482.     }
  483.     public void setPostBack_viaPOST(boolean postBack) {
  484.         this.setPostBack(postBack, true, true); // obbligatorio il nome
  485.     }
  486.     private void setPostBack(boolean postBack,boolean setElementName, boolean viaPOST) {
  487.         this.postBack = postBack;
  488.         if (this.postBack) {
  489.             if(setElementName){
  490.                 if(this.name==null || "".equals(this.name)){
  491.                     throw new RuntimeException("Per poter impostare il nome dell'element che scaturira' il postBack deve prima essere indicato tramite il metodo setName");
  492.                 }
  493.                 String prefix = "";
  494.                 if(viaPOST) {
  495.                     prefix=Costanti.POSTBACK_VIA_POST_FUNCTION_PREFIX;
  496.                 }
  497.                 prefix+=Costanti.POSTBACK_FUNCTION_WITH_PARAMETER_START;
  498.                 this.setOnClick(prefix+this.name+Costanti.POSTBACK_FUNCTION_WITH_PARAMETER_END);
  499.                 this.setOnChange(prefix+this.name+Costanti.POSTBACK_FUNCTION_WITH_PARAMETER_END);
  500.             }
  501.             else{
  502.                 this.setOnClick(Costanti.POSTBACK_FUNCTION);
  503.                 this.setOnChange(Costanti.POSTBACK_FUNCTION);
  504.             }
  505.         }
  506.         else{
  507.             this.setOnClick(null);
  508.             this.setOnChange(null);
  509.         }
  510.     }
  511.    
  512.     public static String getEscapedValue(String value){
  513.         String escaped = StringEscapeUtils.escapeHtml(StringEscapeUtils.unescapeHtml(DataElement.checkNull(value)));
  514.        
  515.         // ripristino evenutali caratteri html
  516.         for (String key : DataElement.escapeMap.keySet()) {
  517.             if(escaped.contains(key)){
  518.                 escaped = escaped.replaceAll(key, DataElement.escapeMap.get(key));
  519.             }
  520.         }
  521.        
  522.         return escaped;
  523.     }

  524.     public String getNote() {
  525.         return DataElement.checkNull(this.note);
  526.     }

  527.     public void setNote(String note) {
  528.         this.note = note;
  529.     }

  530.     public String getStyleClass() {
  531.         return DataElement.checkNull(this.styleClass);
  532.     }

  533.     public void setStyleClass(String styleClass) {
  534.         this.styleClass = styleClass;
  535.     }
  536.    
  537.     public void setSelezionati(String [] s) {
  538.             this.selezionati = s;
  539.     }
  540.    
  541.     public void setSelezionati(List<String> s) {
  542.         if(s==null || s.size()<=0){
  543.             return;
  544.         }
  545.         this.setSelezionati(s.toArray(new String[1]));
  546.     }
  547.     public String[] getSelezionati() {
  548.         return this.selezionati;
  549.     }
  550.    
  551.     public String getSelezionatiAsString() {
  552.         if(this.selezionati ==null || this.selezionati.length <=0){
  553.             return "";
  554.         }
  555.        
  556.         StringBuilder sb = new StringBuilder();
  557.         for (int i = 0; i < this.selezionati.length; i++) {
  558.             if(sb.length() > 0)
  559.                 sb.append(", ");
  560.            
  561.             sb.append(DataElement.checkNull(this.selezionati[i]));
  562.         }
  563.        
  564.         return sb.toString();
  565.     }
  566.    
  567.     public boolean isSelected(String value) {
  568.         if(this.selezionati ==null || this.selezionati.length <=0){
  569.             return false;
  570.         }
  571.        
  572.         for (int i = 0; i < this.selezionati.length; i++) {
  573.             if(value.equals(DataElement.checkNull(this.selezionati[i])))
  574.                 return true;
  575.         }
  576.        
  577.         return false;
  578.     }

  579.     public Integer getMinValue() {
  580.         return this.minValue;
  581.     }

  582.     public void setMinValue(Integer minValue) {
  583.         this.minValue = minValue;
  584.     }

  585.     public Integer getMaxValue() {
  586.         return this.maxValue;
  587.     }

  588.     public void setMaxValue(Integer maxValue) {
  589.         this.maxValue = maxValue;
  590.     }

  591.     public String getStyle() {
  592.         String width = this.getWidth();
  593.        
  594.         if(StringUtils.isNotEmpty(this.style)) {
  595.             if(width != null)
  596.                 return DataElement.checkNull(this.style) + " " + width;
  597.         } else {
  598.             if(width != null)
  599.                 return width;
  600.         }
  601.            
  602.         return DataElement.checkNull(this.style);
  603.     }

  604.     public void setStyle(String style) {
  605.         this.style = style;
  606.     }

  607.     public String getWidth() {
  608.         if(StringUtils.isNotEmpty(this.width)) {
  609.             return " width: " + this.width + ";";
  610.         } else
  611.             return null;
  612.     }
  613.    
  614.     public void allineaTdAlCentro() {
  615.         String styleAllinaCentro = "text-align : center;";
  616.         this.setStyle(styleAllinaCentro);
  617.     }

  618.     /**
  619.      * Imposta la larghezza dell'elemento
  620.      * Nota: Indicare solo il valore, il nome proprieta': "width" viene generato automaticamente.
  621.      * Valori ammessi (Decrizione):
  622.      *
  623.      * auto (Default value. The browser calculates the width)
  624.      * length   (Defines the width in px, cm, etc.)
  625.      * %    (Defines the width in percent of the containing block)
  626.      * initial  (Sets this property to its default value.)
  627.      * inherit  (Inherits this property from its parent element.)
  628.      *
  629.      * @param width
  630.      */
  631.     public void setWidth(String width) {
  632.         this.width = width;
  633.     }
  634.    
  635.     public void setWidthPx(int width) {
  636.         this.setWidth(width + "px");
  637.     }
  638.     public void setWidthCm(int width) {
  639.         this.setWidth(width + "cm");
  640.     }
  641.     public void setWidthAuto() {
  642.         this.setWidth("auto");
  643.     }
  644.     public void setWidthPercentuale(int width) {
  645.         this.setWidth(width + "%");
  646.     }

  647.     public String getLabelStyleClass() {
  648.         return DataElement.checkNull(this.labelStyleClass);
  649.     }

  650.     public void setLabelStyleClass(String labelStyleClass) {
  651.         this.labelStyleClass = labelStyleClass;
  652.     }
  653.    
  654.     public String getLabelRight() {
  655.         return DataElement.checkNull(this.labelRight);
  656.     }

  657.     public void setLabelRight(String labelRight) {
  658.         this.labelRight = labelRight;
  659.     }
  660.    
  661.     public String getLabelLink() {
  662.         return DataElement.checkNull(this.labelLink);
  663.     }

  664.     public void setLabelLink(String labelLink) {
  665.         this.labelLink = labelLink;
  666.     }

  667.     public String getIcon() {
  668.         return DataElement.checkNull(this.icon);
  669.     }

  670.     public void setIcon(String icon) {
  671.         this.icon = icon;
  672.     }
  673.    
  674.     public void setIcon(String icon,String tooltip, String url, TargetType target) {
  675.         this.image.clear();
  676.         DataElementImage newImage = new DataElementImage();
  677.         newImage.setImage(icon);
  678.         newImage.setTarget(target);
  679.         newImage.setUrl(url);
  680.         newImage.setToolTip(tooltip);
  681.         this.image.add(newImage);
  682.     }
  683.    
  684.     @Deprecated
  685.     public void setImage(List<DataElementImage> image) {
  686.         this.image = image;
  687.     }
  688.    
  689.     public List<DataElementImage> getImage() {
  690.         return this.image;
  691.     }
  692.    
  693.     public void setImage(DataElementImage icon) {
  694.         this.image.clear();
  695.         this.image.add(icon);
  696.     }

  697.     public void addImage(String icon) {
  698.         DataElementImage newImage = new DataElementImage();
  699.         newImage.setImage(icon);
  700.         this.image.add(newImage);
  701.     }
  702.    
  703.     public void addImage(DataElementImage icon) {
  704.         this.image.add(icon);
  705.     }

  706.     public Map<String, String> getDataAttributes() {
  707.         return this.dataAttributes;
  708.     }
  709.    
  710.     @Deprecated
  711.     public void setDataAttributes(Map<String, String> dataAttributes) {
  712.         this.dataAttributes = dataAttributes;
  713.     }
  714.    
  715.     public String getDataAttributesAsString() {
  716.         StringBuilder sb = new StringBuilder();
  717.        
  718.         if(!this.dataAttributes.isEmpty()) {
  719.             for (String key : this.dataAttributes.keySet()) {
  720.                 if(!key.equals("colors"))
  721.                     sb.append("data-").append(key).append("=\"").append(this.dataAttributes.get(key)).append("\"");
  722.             }
  723.         }
  724.        
  725.         return sb.toString();
  726.     }
  727.     public void enableTags() {
  728.         this.getDataAttributes().put("role", "tagsinput");
  729.     }
  730.    
  731.     public void enableTags(boolean multicolor) {
  732.         this.getDataAttributes().put("role", "tagsinput");
  733.         this.getDataAttributes().put("colors", "true");
  734.     }

  735.     public void reloadMinValue(boolean reload) {
  736.         if(reload) {
  737.             this.setCustomJsFunction(null);
  738.         } else {
  739.             this.setCustomJsFunction(Costanti.CUSTOM_JS_FUNCTION_INPUT_NUMBER_VALIDATION);
  740.         }
  741.     }
  742.    
  743.     public String getCustomJsFunction() {
  744.         return DataElement.checkNull(this.customJsFunction);
  745.     }

  746.     public void setCustomJsFunction(String customJsFunction) {
  747.         this.customJsFunction = customJsFunction;
  748.     }
  749.    
  750.     public void setNames(String [] s) {
  751.         this.names = s;
  752.     }
  753.     public void setNames(List<String> s) {
  754.         if(s==null || s.size()<=0){
  755.             return;
  756.         }
  757.         this.setNames(s.toArray(new String[1]));
  758.     }
  759.     public String[] getNames() {
  760.         return this.names;
  761.     }
  762.    
  763.     public void setInfo(DataElementInfo info) {
  764.         this.info = info;
  765.     }

  766.     public void setInfo(String titolo, String info) {
  767.         this.info = new DataElementInfo(titolo);
  768.         this.info.setHeaderBody(info);
  769.     }
  770.    
  771.     public DataElementInfo getInfo() {
  772.         return this.info;
  773.     }
  774.    
  775.     @Deprecated
  776.     public void setStatusValues(List<String> v) {
  777.         this.statusValues = v;
  778.     }
  779.    
  780.     @Deprecated
  781.     public void setStatusValues(String[] v) {
  782.         if(v == null || v.length <= 0) {
  783.             this.statusValues = null;
  784.         }else {
  785.             this.statusValues = Arrays.asList(v);
  786.         }
  787.     }
  788.    
  789.     private void addStatusValue(String v) {
  790.         if(this.statusValues==null) {
  791.             this.statusValues = new ArrayList<>();
  792.         }
  793.         this.statusValues.add(v);
  794.     }
  795.     public void setStatusValue(String v) {
  796.         // con il set viene usato un solo valore
  797.         this.statusValues = new ArrayList<>();
  798.         this.statusValues.add(v);
  799.     }
  800.     public String[] getStatusValues() {
  801.         if(this.statusValues==null || this.statusValues.size()<=0){
  802.             return null;
  803.         }
  804.         return this.statusValues.toArray(new String[1]);
  805.     }
  806.     public List<String> getStatusValuesAsList() {
  807.         return this.statusValues;
  808.     }
  809.    
  810.    
  811.     private void addStatusToolTip(String v) {
  812.         if(this.statusToolTips==null) {
  813.             this.statusToolTips = new ArrayList<>();
  814.         }
  815.         this.statusToolTips.add(v);
  816.     }
  817.     public void setStatusToolTip(String v) {
  818.         // con il set viene usato un solo valore
  819.         this.statusToolTips = new ArrayList<>();
  820.         this.statusToolTips.add(v);
  821.     }
  822.     public String[] getStatusToolTips() {
  823.         if(this.statusToolTips==null || this.statusToolTips.size()<=0){
  824.             return null;
  825.         }
  826.         return this.statusToolTips.toArray(new String[1]);
  827.     }
  828.     public List<String> getStatusToolTipsAsList() {
  829.         return this.statusToolTips;
  830.     }
  831.    
  832.     @Deprecated
  833.     public void setStatusToolTips(List<String> v) {
  834.         this.statusToolTips = v;
  835.     }
  836.     @Deprecated
  837.     public void setStatusToolTips(String[] v) {
  838.         if(v == null || v.length <= 0) {
  839.             this.statusToolTips = null;
  840.         }
  841.         else {
  842.             this.statusToolTips = Arrays.asList(v);
  843.         }
  844.     }
  845.    

  846.     private void addStatusType(String v) {
  847.         if(this.statusTypes==null) {
  848.             this.statusTypes = new ArrayList<>();
  849.         }
  850.         this.statusTypes.add(v);
  851.     }
  852.     private void addStatusType(CheckboxStatusType v) {
  853.         if(v!=null) {
  854.             this.addStatusType(v.toString());
  855.         }
  856.     }
  857.     public void setStatusType(String v) {
  858.         // con il set viene usato un solo valore
  859.         this.statusTypes = new ArrayList<>();
  860.         this.statusTypes.add(v);
  861.     }
  862.     public void setStatusType(CheckboxStatusType v) {
  863.         if(v!=null) {
  864.             this.setStatusType(v.toString());
  865.         }
  866.     }
  867.     public String[] getStatusTypes() {
  868.         if(this.statusTypes==null || this.statusTypes.size()<=0){
  869.             return null;
  870.         }
  871.         return this.statusTypes.toArray(new String[1]);
  872.     }
  873.     public List<String> getStatusTypesAsList() {
  874.         return this.statusTypes;
  875.     }
  876.     @Deprecated
  877.     public void setStatusTypes(List<String> v) {
  878.         this.statusTypes = v;
  879.     }
  880.     @Deprecated
  881.     public void setStatusTypes(String[] v) {
  882.         if(v == null || v.length <= 0) {
  883.             this.statusTypes = null;
  884.         }
  885.         else {
  886.             this.statusTypes = Arrays.asList(v);
  887.         }
  888.     }

  889.     public void addStatus(String value, CheckboxStatusType type) {
  890.         this.addStatus(null, value, type);
  891.     }
  892.     public void addStatus(String tooltip, String value, CheckboxStatusType type) {
  893.         this.addStatusToolTip(tooltip);
  894.         this.addStatusValue(value);
  895.         this.addStatusType(type);
  896.     }
  897.     public void addStatus(String value, String type) {
  898.         this.addStatus(null, value, type);
  899.     }
  900.     public void addStatus(String tooltip, String value, String type) {
  901.         this.addStatusToolTip(tooltip);
  902.         this.addStatusValue(value);
  903.         this.addStatusType(type);
  904.     }
  905.    
  906.     public void setDisabilitaAjaxStatus() {
  907.         this.showAjaxStatus = false;
  908.     }

  909.     public boolean isShowAjaxStatus() {
  910.         return this.showAjaxStatus;
  911.     }

  912.     public void setShowAjaxStatus(boolean showAjaxStatus) {
  913.         this.showAjaxStatus = showAjaxStatus;
  914.     }
  915.    
  916.     public void spostaLinkADestra() {
  917.         this.setStyle("margin-left: auto;");
  918.     }

  919.     public DataElementPassword getPassword() {
  920.         return this.password;
  921.     }

  922.     public void setPassword(DataElementPassword password) {
  923.         this.password = password;
  924.     }

  925.     public boolean isAbilitaFiltroOpzioniSelect() {
  926.         return this.abilitaFiltroOpzioniSelect;
  927.     }
  928.    
  929.     public void disabilitaFiltroOpzioniSelect() {
  930.         this.setAbilitaFiltroOpzioniSelect(false);
  931.     }

  932.     public void setAbilitaFiltroOpzioniSelect(boolean abilitaFiltroOpzioniSelect) {
  933.         this.abilitaFiltroOpzioniSelect = abilitaFiltroOpzioniSelect;
  934.     }

  935.     public boolean isVisualizzaLinkApriNuovaFinestra() {
  936.         return this.visualizzaLinkApriNuovaFinestra;
  937.     }

  938.     public void setVisualizzaLinkApriNuovaFinestra(boolean visualizzaLinkApriNuovaFinestra) {
  939.         this.visualizzaLinkApriNuovaFinestra = visualizzaLinkApriNuovaFinestra;
  940.     }
  941.    
  942.     public Dialog getDialog() {
  943.         return this.dialog;
  944.     }

  945.     public void setDialog(Dialog dialog) {
  946.         this.dialog = dialog;
  947.     }
  948.    
  949.     public void setValoreBold() {
  950.         this.setStyleClass(Costanti.INPUT_TEXT_BOLD_CSS_CLASS);
  951.     }
  952.    
  953.     public void setValoreBoldRed() {
  954.         this.setStyleClass(Costanti.INPUT_TEXT_BOLD_RED_CSS_CLASS);
  955.     }

  956.     public boolean isVisualizzaSezioneAperta() {
  957.         return STATO_APERTURA_SEZIONI.APERTO.equals(this.statoSottosezione);
  958.     }

  959.     public void setStatoAperturaSezioni(STATO_APERTURA_SEZIONI stato) {
  960.         this.statoSottosezione = stato;
  961.     }
  962.    
  963.     public STATO_APERTURA_SEZIONI getStatoSottosezione() {
  964.         return this.statoSottosezione;
  965.     }

  966.     public String getValoreDefault() {
  967.         return this.valoreDefault;
  968.     }

  969.     public void setValoreDefault(String valoreDefault) {
  970.         this.valoreDefault = valoreDefault;
  971.     }

  972.     public void setValoreDefaultCheckbox(boolean valoreDefault) {
  973.         this.valoreDefault = ServletUtils.boolToCheckBoxStatus(valoreDefault);
  974.     }
  975.    
  976.     public boolean getValoreDefaultCheckbox() {
  977.         return this.valoreDefault != null ? ServletUtils.isCheckBoxEnabled(this.valoreDefault) : false;
  978.     }
  979.    
  980.     public void setValoreDefaultSelect(String valoreDefault) {
  981.         this.valoreDefault = valoreDefault;
  982.     }
  983.    
  984.     public void setValoreDefaultMultiSelect(String[] valoriDefault) {
  985.         if(valoriDefault !=null  && valoriDefault.length  > 0){
  986.             StringBuilder sb = new StringBuilder();
  987.             for (int i = 0; i < valoriDefault.length; i++) {
  988.                 if(sb.length() > 0)
  989.                     sb.append(", ");
  990.                
  991.                 sb.append(DataElement.checkNull(valoriDefault[i]));
  992.             }
  993.            
  994.             this.valoreDefault = sb.toString();
  995.         }
  996.     }
  997.    
  998.     public boolean isElementoDaControllarePerCheckDefaultNelleForm() {
  999.         if(!DataElementType.HIDDEN.toString().equals(this.getType())
  1000.                 && !DataElementType.SUBTITLE.toString().equals(this.getType())
  1001.                 && !DataElementType.TITLE.toString().equals(this.getType())
  1002.                 && !DataElementType.LINK.toString().equals(this.getType())
  1003.                 && !DataElementType.FILE.toString().equals(this.getType())
  1004.                 && !DataElementType.MULTI_FILE.toString().equals(this.getType())
  1005.                 && !DataElementType.CRYPT.toString().equals(this.getType())
  1006.                 && !DataElementType.NOTE.toString().equals(this.getType())
  1007.                 && !DataElementType.IMAGE.toString().equals(this.getType())
  1008.                 && !DataElementType.BUTTON.toString().equals(this.getType())) {
  1009.             return true;
  1010.         }
  1011.        
  1012.         return false;
  1013.     }
  1014.    
  1015.     public void addInfoAuditDataCreazione(String tooltip, String value) {
  1016.         this.addStatus(tooltip, value, Costanti.ICON_SCHEDULE);
  1017.     }
  1018.     public void addInfoAuditDataAggiornamento(String tooltip, String value) {
  1019.         this.addStatus(tooltip, value, Costanti.ICON_UPDATE);
  1020.     }
  1021.     public void addInfoAuditUtente(String tooltip, String value) {
  1022.         this.addStatus(tooltip, value, Costanti.ICON_PERSON);
  1023.     }
  1024.    
  1025.     public DataElementConfirm getConfirm() {
  1026.         return this.confirm;
  1027.     }

  1028.     public void setConfirm(DataElementConfirm confirm) {
  1029.         this.confirm = confirm;
  1030.     }
  1031.    
  1032.     public void setConfirm(String titolo, String messaggio, String testoBottoneAzione) {
  1033.         this.confirm = new DataElementConfirm();
  1034.         this.confirm.setTitolo(titolo);
  1035.         this.confirm.setBody(messaggio);
  1036.         this.confirm.setAzione(testoBottoneAzione);
  1037.     }

  1038.     public boolean isContextMenu() {
  1039.         return this.contextMenu;
  1040.     }

  1041.     public void setContextMenu(boolean contextMenu) {
  1042.         this.contextMenu = contextMenu;
  1043.     }
  1044.    
  1045.     public void setCopyToClipboard(String copyToClipboard) {
  1046.         this.copyToClipboard = copyToClipboard;
  1047.     }
  1048.    
  1049.     public String getCopyToClipboard() {
  1050.         return this.copyToClipboard;
  1051.     }
  1052.    
  1053.     public void abilitaRefresh() {
  1054.         this.setRefresh(true);
  1055.     }

  1056.     public void setRefresh(boolean refresh) {
  1057.         this.refresh = refresh;
  1058.     }
  1059.    
  1060.     public boolean isRefresh() {
  1061.         return this.refresh;
  1062.     }
  1063. }