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

mplates.1.2.source-code.GWTPojo.ftl Maven / Gradle / Ivy

<#include "license.ftl">
<@license/>
<#assign object = doc.object>
package ${object.@package}.gwt.model;

<#list doc["/object/attributes/enum[@scope='global']"] as enum>
import ${object.@package}.gwt.model.enums.${enum.@class};

import java.util.Date;
import java.util.HashMap;

import redora.client.EnumDisplay;
import redora.client.Persistable;

import ${object.@package}.gwt.constants.Constants;
import ${object.@package}.gwt.model.fields.${object.@name}Fields;

import com.google.gwt.view.client.ProvidesKey;

/**
<#if object.description[0]??>
* ${object.description}

 * @author Redora (www.redora.net)
*/
public class ${object.@name} implements Persistable {

    public Long id;
    @Override
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Date creationDate;
    public Date getCreationDate() {
        assertList();
        return this.creationDate;
    }
    public Date updateDate;
    public Date getUpdateDate() {
        assertList();
        return this.updateDate;
    }
<#list doc["/object/attributes/enum[@scope='local']"] as att>
    <#if att.description[0]??>
    /** ${att.description} */
    
    public enum ${att.@class} implements EnumDisplay {
        <#list att.element as value>
            <#if value.@description[0]??>
        /** ${value.@description} */
            
        ${value.@name}(
            ((Constants)com.google.gwt.core.client.GWT.create(Constants.class)).${object.@name?uncap_first}_${att.@fieldName}_${value.@name}_table()
            , ((Constants)com.google.gwt.core.client.GWT.create(Constants.class)).${object.@name?uncap_first}_${att.@fieldName}_${value.@name}_form())<#if value_has_next>,<#else>;
        

        String displayForm;
        String displayTable;

        ${att.@class}(String table, String form) {
            displayTable = table;
            displayForm = form;
        }

        @Override
        public String displayForm() {
            return displayForm;
        }

        @Override
        public String displayTable() {
            return displayTable;
        }

        /** @return Null, or the result of valueOf() */
        public static ${att.@class} valueOfNullSafe(String value) {
            if (value != null && value.length() > 0)
                return valueOf(value);
            return null; 
        }
    }


<#list object.formScope?children as att>
    <#if att?node_type == "element">
        <#if att?node_name == "date" || att?node_name == "datetime">
    public Date ${att.@fieldName};
        <#else>
    public ${att.@className} ${att.@fieldName};
        

    


    public final HashMap dirty = new HashMap();
    public boolean isNew = true;
    public redora.client.Persistable.Scope fetchScope;
    @Override
    public redora.client.Persistable.Scope scope() {
        return fetchScope;
    }

    /**
    * The generated finder methods are added to this enum. Also the GWT client has
    * the same DefaultFinder, ordered in exactly the same manner. Therefor it is
    * possible to use the enum's ordinal position:
    * 
    * int ord = GwtClientObject.DefaultFinder.FindAll.ordinal();
    * if (ClientObjectSQL.DefaultFinder.values()[ord].name().equals("FindAll") {
    *    System.out.print("Hello World");
    * }
    * 
    */
    public enum DefaultFinder {
        FindAll
<#list doc["//attributes/*/finder"] as finder> //TODO add json filter
        , ${finder.@name?cap_first}

<#list doc["//queries/*/finder"] as finder>
    <#if finder?parent.@javadoc[0]??>
        /** ${finder?parent.@javadoc} */
    
        , ${finder.@name?cap_first}

    }

@Deprecated
    public ${object.@name}() {
<#list doc["/object/attributes/*[@default]"] as att>
    <#if att?node_name == "boolean">
        set${att.@fieldName?cap_first}(Boolean.${att.@default?upper_case});
    <#elseif att?node_name == "string">
        set${att.@fieldName?cap_first}("${att.@default}");
    <#elseif att?node_name == "integer" || att?node_name == "long" || att?node_name == "double">
        set${att.@fieldName?cap_first}(${att.@className}.valueOf(${att.@default}));
    <#elseif att?node_name == "enum">
        set${att.@fieldName?cap_first}(${att.@className}.${att.@default});
    <#else>
        error - undefined default ${att?node_name}
    

        fetchScope = redora.client.Persistable.Scope.Form;
        isNew = true;
    }

    /**
    * Initializes a new (isNew = true) ${object.@name} and default values are set for:
<#list doc["/object/attributes/*[@default]"] as att> * ${att.@fieldName} - ${att.@default};
*/ public ${object.@name}(redora.client.Persistable.Scope scope) { this.fetchScope = scope; <#list doc["/object/attributes/*[@default]"] as att> <#if att?node_name == "boolean"> set${att.@fieldName?cap_first}(Boolean.${att.@default?upper_case}); <#elseif att?node_name == "string"> set${att.@fieldName?cap_first}("${att.@default}"); <#elseif att?node_name == "integer" || att?node_name == "long" || att?node_name == "double"> set${att.@fieldName?cap_first}(${att.@className}.valueOf(${att.@default})); <#elseif att?node_name == "enum"> set${att.@fieldName?cap_first}(${att.@className}.${att.@default}); <#else> error - undefined default ${att?node_name} isNew = true; } <#list object.formScope?children as att> <#if att.description[0]??> /** ${att.description} */ <#if att?node_type == "element" && att?node_name != "object"> public void set${att.@fieldName?cap_first}(<#if att?node_name == "date" || att?node_name == "datetime">Date<#else>${att.@className} ${att.@fieldName}){ if ((${att.@fieldName} == null ? this.${att.@fieldName} != null : !${att.@fieldName}.equals(this.${att.@fieldName})) && !dirty.containsKey(${object.@name}Fields.${att.@fieldName})) { dirty.put(${object.@name}Fields.${att.@fieldName}, this.${att.@fieldName}); } this.${att.@fieldName} = ${att.@fieldName}; } <#if att.description[0]??> /** ${att.description} **/ public ${att.@className} get${att.@fieldName?cap_first}() { <#if att.@list != "true"> assertList(); return ${att.@fieldName}; } /** * {@inheritDoc} */ public HashMap dirty() { return dirty; } @Override /** Checks primarily on Id, if there is no Id, it will try hashCode. */ public boolean equals(Object that) { if (this == that) { return true; } if (!(that instanceof ${object.@name})) { return false; } ${object.@name} t = (${object.@name})that; if (id != null && id.equals(t.id)) { return true; } return id == null && t.id == null && hashCode() == t.hashCode(); } @Override public String toListString() { StringBuilder s = new StringBuilder(); <#if object.listScope[0]??> <#list object.listScope?children as att> <#if att?node_name != "object"> s.append(this.get${att.@fieldName?cap_first}()).append(" "); return s.toString().trim(); } /** * The key provider that provides the unique ID of a ${object.@name}. */ public static final ProvidesKey<${object.@name}> KEY_PROVIDER = new ProvidesKey<${object.@name}>() { public Object getKey(${object.@name} item) { return item == null ? null : item.getId(); } }; void assertList() { assert fetchScope != Persistable.Scope.List : "Not available when fetched as Scope.List. Fetch the object with Table or Form scope instead."; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy