All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.tool.codegen.bean.InputUI Maven / Gradle / Ivy

package panda.tool.codegen.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import panda.lang.Strings;

/**
 * 

* Java class for InputUI complex type. *

* The following schema fragment specifies the expected content contained within this class. * *

 * <complexType name="InputUI">
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="field" type="{panda.tool.codegen}InputField" maxOccurs="unbounded" minOccurs="0"/>
 *         <element name="param" type="{panda.tool.codegen}Param" maxOccurs="unbounded" minOccurs="0"/>
 *         <element name="header" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="1" minOccurs="0"/>
 *         <element name="footer" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="1" minOccurs="0"/>
 *       </sequence>
 *       <attribute name="generate" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       <attribute name="safeInclude" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       <attribute name="focus" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       <attribute name="theme" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       <attribute name="formId" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       <attribute name="template" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       <attribute name="extend" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 *     </restriction>
 *   </complexContent>
 * </complexType>
 * 
*/ @XmlAccessorType(XmlAccessType.NONE) @XmlType(name = "InputUI") public class InputUI implements Comparable { @XmlElement(name = "field") private List fieldList; @XmlElement(name = "param") private List paramList; @XmlElement private String header; @XmlElement private String footer; @XmlAttribute private Boolean generate; @XmlAttribute private Boolean focus = true; @XmlAttribute private String safeInclude; @XmlAttribute private String theme; @XmlAttribute private String formId; @XmlAttribute private String template; @XmlAttribute private String extend; @XmlAttribute(required = true) private String name; /** * Constructor */ public InputUI() { } /** * Constructor - copy properties from source * * @param iui source input ui */ public InputUI(InputUI iui) { this.generate = iui.generate; this.focus = iui.focus; this.theme = iui.theme; this.safeInclude = iui.safeInclude; this.formId = iui.formId; this.template = iui.template; this.extend = iui.extend; this.name = iui.name; fieldList = new ArrayList(); for (InputField ifd : iui.getFieldList()) { fieldList.add(new InputField(ifd)); } paramList = new ArrayList(); for (Param p : iui.getParamList()) { paramList.add(new Param(p)); } this.header = iui.header; this.footer = iui.footer; } /** * extend inputui * * @param src source inputui * @param parent extend inputui * @return inputui */ public static InputUI extend(InputUI src, InputUI parent) { // System.out.println("extend input " + src.getName() + " from " + parent.getName()); InputUI me = new InputUI(parent); if (src.generate != null) { me.generate = src.generate; } if (src.focus != null) { me.focus = src.focus; } if (src.safeInclude != null) { me.safeInclude = src.safeInclude; } if (src.theme != null) { me.theme = src.theme; } if (src.formId != null) { me.formId = src.formId; } if (src.template != null) { me.template = src.template; } if (src.name != null) { me.name = src.name; } if (src.header != null) { me.header = src.header; } if (src.footer != null) { me.footer = src.footer; } List mifList = me.getFieldList(); List sifList = src.getFieldList(); for (InputField sif : sifList) { boolean add = false; for (int i = 0; i < mifList.size(); i++) { InputField mif = mifList.get(i); if (mif.getName().equals(sif.getName())) { mifList.set(i, InputField.extend(sif, mif)); add = true; break; } } if (!add) { mifList.add(new InputField(sif)); } } List mpList = me.getParamList(); List spList = src.getParamList(); for (Param sp : spList) { boolean add = false; for (int i = 0; i < mpList.size(); i++) { Param mp = mpList.get(i); if (mp.getName().equals(sp.getName())) { mp.setValue(sp.getValue()); add = true; break; } } if (!add) { mpList.add(new Param(sp)); } } return me; } /** * @return the ordered field list which InputField.display is not false */ public Set getDisplayFieldList() { Set set = new TreeSet(); List list = getFieldList(); for (int i = 0; i < list.size(); i++) { InputField f = list.get(i); if (f.getOrder() == null) { f.setOrder((i + 1) * 100); } if (!Boolean.FALSE.equals(f.getDisplay())) { set.add(f); } } return set; } // // public Set getOrderedFieldList() { // Set set = new TreeSet(); // List list = getFieldList(); // for (int i = 0; i < list.size(); i++) { // InputField f = list.get(i); // // if (f.getOrder() == null) { // f.setOrder((i + 1) * 100); // } // // set.add(f); // } // return set; // } public List getRequiredValidateFieldList() { List set = new ArrayList(); for (InputField f : getDisplayFieldList()) { if (Boolean.TRUE.equals(f.getRequired()) && Boolean.TRUE.equals(f.getRequiredvalidate())) { set.add(f); } } return set; } public String getRequiredValidateFields() { boolean allEmpty = true; for (InputField f : getRequiredValidateFieldList()) { String r = Strings.defaultString(f.getRequiredrefer()); if (Strings.isNotEmpty(r)) { allEmpty = false; } } if (allEmpty) { StringBuilder sb = new StringBuilder(); sb.append("fields: [ "); for (InputField f : getRequiredValidateFieldList()) { sb.append('\'').append(f.getName()).append("', "); } sb.setLength(sb.length() - 2); sb.append(" ]"); return sb.toString(); } else { StringBuilder sb = new StringBuilder(); sb.append("refers: { "); for (InputField f : getRequiredValidateFieldList()) { sb.append('\'').append(f.getName()).append("': '").append(Strings.defaultString(f.getRequiredrefer())).append("', "); } sb.setLength(sb.length() - 2); sb.append(" }"); return sb.toString(); } } public InputField getFieldByName(String name) { for (InputField f : getFieldList()) { if (f.getName().equals(name)) { return f; } } return null; } /** * @return the fieldList */ public List getFieldList() { if (fieldList == null) { fieldList = new ArrayList(); } return this.fieldList; } /** * @return the paramList */ public List getParamList() { if (paramList == null) { paramList = new ArrayList(); } return this.paramList; } private Map params; /** * @return the params map */ public Map getParams() { if (params == null) { params = new HashMap(); for (Param p : getParamList()) { params.put(p.getName(), p.getValue()); } } return params; } /** * @return the generate */ public Boolean getGenerate() { return generate; } /** * @param generate the generate to set */ public void setGenerate(Boolean generate) { this.generate = generate; } /** * @return the focus */ public Boolean getFocus() { return focus; } /** * @param focus the focus to set */ public void setFocus(Boolean focus) { this.focus = focus; } /** * @return the theme */ public String getTheme() { return theme; } /** * @param theme the theme to set */ public void setTheme(String theme) { this.theme = theme; } /** * @return the safeInclude */ public String getSafeInclude() { return safeInclude; } /** * @param safeInclude the safeInclude to set */ public void setSafeInclude(String safeInclude) { this.safeInclude = safeInclude; } /** * @return the formId */ public String getFormId() { return formId; } /** * @param formId the formId to set */ public void setFormId(String formId) { this.formId = formId; } /** * @return the template */ public String getTemplate() { return template; } /** * @param template the template to set */ public void setTemplate(String template) { this.template = template; } /** * @return the extend */ public String getExtend() { return extend; } public String[] getExtends() { return Strings.split(extend, ", "); } /** * @param extend the extend to set */ public void setExtend(String extend) { this.extend = extend; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the header */ public String getHeader() { return header; } /** * @param header the header to set */ public void setHeader(String header) { this.header = header; } /** * @return tpublic */ public String getFooter() { return footer; } /** * @param footer the footer to set */ public void setFooter(String footer) { this.footer = footer; } /** * @param o compare target * @return -1/0/1 */ public int compareTo(InputUI o) { if (this == o) { return 0; } int i = this.name.compareTo(o.name); return i == 0 ? this.hashCode() - o.hashCode() : i; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy