bug 2821 : Changes to ADL to implement the 'PrototypeFor classes carry default values for forms' solution.

status 2821: resolved FIXED
This commit is contained in:
sb 2009-04-28 13:34:14 +00:00
parent d2b026f8b9
commit 148624c084
3 changed files with 170 additions and 37 deletions

View file

@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes
$Author: sb $
$Revision: 1.34 $
$Date: 2009-04-27 15:19:51 $
$Revision: 1.35 $
$Date: 2009-04-28 13:34:14 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -70,7 +70,7 @@
//
// Automatically generated abstract super class for controllers for the
// <xsl:value-of select="/adl:application/@name"/> application; generated using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.34 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.35 $', 10)"/>
//
// <xsl:value-of select="/adl:application/@revision"/>
//
@ -180,7 +180,7 @@
//
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.34 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.35 $', 10)"/>
//
// This file is automatically generated; DO NOT EDIT IT.
//
@ -890,9 +890,18 @@
public void <xsl:value-of select="@name"/>( )
{
AssertUserCanRead();
<xsl:value-of select="ancestor::adl:entity/@name"/> record = null;
<xsl:value-of select="concat( 'PrototypeFor', ancestor::adl:entity/@name)"/> record =
new <xsl:value-of select="concat( 'PrototypeFor', ancestor::adl:entity/@name)"/>();
<xsl:value-of select="concat( 'this.', @name)"/>( record);
ISession hibernator = GetDBSession();
TypedPropertyBag = new {
<xsl:call-template name="formmenus">
<xsl:with-param name="form" select="."/>
</xsl:call-template>
instance = record };
RenderViewWithFailover("<xsl:value-of select="concat( @name, '.vm')"/>", "<xsl:value-of select="concat( @name, '.auto.vm')"/>");
}
<xsl:variable name="form" select="."/>

View file

@ -8,8 +8,8 @@
Transform ADL into C# entity classes
$Author: sb $
$Revision: 1.18 $
$Date: 2009-03-02 10:31:44 $
$Revision: 1.19 $
$Date: 2009-04-28 13:34:14 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -70,7 +70,7 @@
// (c)2007 Cygnet Solutions Ltd
//
// Automatically generated from application description using
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.18 $', 10)"/>
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.19 $', 10)"/>
//
// <xsl:value-of select="/adl:application/@revision"/>
//
@ -97,7 +97,7 @@
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// Automatically generated from description of group <xsl:value-of select="@name"/>
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.18 $', 10)"/>.
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.19 $', 10)"/>.
///
/// DO NOT EDIT THIS FILE!
/// &lt;/remarks&gt;
@ -123,7 +123,7 @@
// (c)2007 Cygnet Solutions Ltd
//
// Automatically generated from application description using
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.18 $', 10)"/>
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.19 $', 10)"/>
//
// <xsl:value-of select="/adl:application/@revision"/>
//
@ -149,7 +149,7 @@
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// Automatically generated from description of entity <xsl:value-of select="@name"/>
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.18 $', 10)"/>.
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.19 $', 10)"/>.
/// Note that manually maintained parts of this class may be defined in
/// a separate file called <xsl:value-of select="@name"/>.manual.cs, q.v.
///
@ -386,6 +386,25 @@
<!-- 'descendant' to catch properties inside keys as well as properties which are direct children -->
<xsl:apply-templates select="descendant::adl:property"/>
}
/// A prototype for <xsl:value-of select="@name"/> used when initialising forms for which
/// there is as yet no real record. This has only those properties of <xsl:value-of select="@name"/>
/// which have default values. Objects of this class are not known to NHibernate and are
/// never persisted to the database.
public class <xsl:value-of select="concat( 'PrototypeFor', @name)"/> {
/// Dummy IsNew property always returns true
public Boolean IsNew { get { return true; }}
/// Dummy user identifier which always returns just '[new]'
public string UserIdentifier { get { return "[new]";}}
<xsl:for-each select="adl:property">
<xsl:call-template name="prototype-property">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:for-each>
}
}
/* ---- [ cut here: next file 'junk'] ------------------------- */
@ -440,7 +459,7 @@
</xsl:when>
<xsl:when test="normalize-space( $nullable-decoration) = '?'"> = null</xsl:when>
<xsl:when test="$base-type = 'Boolean'"> = false</xsl:when>
<xsl:when test="$base-type = 'int'"> = 0</xsl:when>
<xsl:when test="$base-type = 'integer'"> = 0</xsl:when>
<xsl:when test="$csharp-type = 'Decimal'"> = 0.0M</xsl:when>
<xsl:when test="$base-type = 'real'"> = 0.0</xsl:when>
<xsl:when test="$csharp-type = 'String'">
@ -748,4 +767,93 @@
<xsl:value-of select="translate($unnormalisedname,
$notpermittedinconstantname, $permittedinconstantname)"/>
</xsl:template>
<xsl:template name="prototype-property">
<xsl:param name="property"/>
<xsl:apply-templates select="help"/>
<xsl:variable name="base-type">
<xsl:call-template name="base-type">
<xsl:with-param name="property" select="$property"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="csharp-type">
<xsl:call-template name="csharp-type">
<xsl:with-param name="property" select="$property"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="nullable-decoration">
<xsl:choose>
<xsl:when test="@required='true'"/>
<!-- when required is 'true' null is not permitted anyway; otherwise... -->
<xsl:when test="@type='message'"/>
<xsl:when test="$base-type='entity'"/>
<xsl:when test="$base-type='string'"/>
<xsl:when test="$base-type='text'"/>
<!-- entities and strings are always nullable, don't need decoration -->
<xsl:when test="$base-type='list'"/>
<xsl:when test="$base-type='link'"/>
<!-- things which are collections are not nullable -->
<xsl:otherwise>?</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="initialiser">
<xsl:choose>
<xsl:when test="@default">
<xsl:choose>
<xsl:when test="$csharp-type = 'String'">
"<xsl:value-of select="@default"/>"
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@default"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$nullable-decoration = '?'">
null
</xsl:when>
<xsl:when test="$base-type = 'Boolean'">false</xsl:when>
<xsl:when test="$base-type = 'integer'">0</xsl:when>
<xsl:when test="$csharp-type = 'Decimal'">0.0M</xsl:when>
<xsl:when test="$base-type = 'real'">0.0</xsl:when>
<xsl:when test="$base-type = 'date'">new DateTime()</xsl:when>
<xsl:when test="$csharp-type = 'String'">
<xsl:choose>
<xsl:when test="@required='true'">
""
</xsl:when>
<xsl:otherwise>
null
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
null
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
/// &lt;summary&gt;
/// Auto generated prototype property for field <xsl:value-of select="$property/@name"/>
/// &lt;/summary&gt;
<xsl:apply-templates select="adl:prompt"/>
<!-- TODO: this should get the size right if type = 'defined', but hasn't been tested -->
<xsl:if test="$base-type = 'string'">
<xsl:variable name="base-size">
<xsl:call-template name="base-size">
<xsl:with-param name="property" select="$property"/>
</xsl:call-template>
</xsl:variable>
[FieldWidth(<xsl:value-of select="$base-size"/>)]
</xsl:if>
<xsl:if test="$property/@distinct = 'user' or $property/@distinct = 'all'">[IsUserDistinct()]</xsl:if>
<xsl:if test="$property/@type = 'money'">
[Dimension( "money",Unit="<xsl:value-of select="$property/ancestor::adl:application/@currency"/>")]
</xsl:if>
public virtual <xsl:value-of select="normalize-space( $csharp-type)"/><xsl:value-of select="$nullable-decoration"/><xsl:text> </xsl:text> <xsl:value-of select="@name"/>
{
get { return <xsl:value-of select="normalize-space( $initialiser)"/>;}
}
</xsl:template>
</xsl:stylesheet>

View file

@ -15,8 +15,8 @@
Transform ADL into velocity view templates
$Author: sb $
$Revision: 1.37 $
$Date: 2009-04-27 16:29:40 $
$Revision: 1.38 $
$Date: 2009-04-28 13:34:14 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
Whitespace (or lack of it) is significant! -->
@ -124,7 +124,7 @@
Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>,
generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
</xsl:comment>
<xsl:call-template name="maybe-delete">
<xsl:with-param name="entity" select="."/>
@ -161,7 +161,7 @@
Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>,
generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
<xsl:value-of select="/adl:application/@revision"/>
</xsl:comment>
@ -244,7 +244,7 @@
Auto generated Velocity <xsl:value-of select="@name"/> form for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
Generation parameters were:
locale: <xsl:value-of select="$locale"/>
generate-site-navigation: <xsl:value-of select="$generate-site-navigation"/>
@ -259,12 +259,18 @@
</xsl:comment>
#capturefor( title)
#if ( $instance)
#if ( ! $instance.IsNew)
<xsl:value-of select="concat( 'Edit ', ' ', ancestor::adl:entity/@name)"/> $instance.UserIdentifier
#else
<xsl:call-template name="i18n-add-a-new">
<xsl:with-param name="entity-name" select="ancestor::adl:entity/@name"/>
</xsl:call-template>
#end
#else
<xsl:call-template name="i18n-add-a-new">
<xsl:with-param name="entity-name" select="ancestor::adl:entity/@name"/>
</xsl:call-template>
#end
#end
#capturefor( headextras)
<xsl:call-template name="head"/>
@ -305,12 +311,18 @@
<html>
<xsl:comment>
#if ( $instance)
#if ( ! $instance.IsNew)
#set( $title = "<xsl:value-of select="concat( 'Edit ', ' ', ancestor::adl:entity/@name)"/> $instance.UserIdentifier")
#else
#set( $title = "<xsl:call-template name="i18n-add-a-new">
<xsl:with-param name="entity-name" select="ancestor::adl:entity/@name"/>
</xsl:call-template>")
#end
#else
#set( $title = "<xsl:call-template name="i18n-add-a-new">
<xsl:with-param name="entity-name" select="ancestor::adl:entity/@name"/>
</xsl:call-template>")
#end
</xsl:comment>
<head>
<xsl:call-template name="head"/>
@ -320,7 +332,7 @@
Auto generated Velocity form for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL.
Generated using adl2views.xsl <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
Generated using adl2views.xsl <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
Generation parameters were:
locale: <xsl:value-of select="$locale"/>
generate-site-navigation: <xsl:value-of select="$generate-site-navigation"/>
@ -619,6 +631,7 @@
</xsl:variable>
<!-- don't emit a verb unless there is an instance for it to act on -->
#if( $instance)
#if( ! $instance.IsNew)
<tr>
<xsl:attribute name="class">
<xsl:value-of select="$class"/>
@ -644,6 +657,7 @@
</button>
</td>
</tr>
#end
#end
</xsl:template>
@ -765,6 +779,7 @@
<xsl:template name="shuffle-widget">
<xsl:param name="property" select="."/>
#if ( $instance)
#if ( ! $instance.IsNew)
<table class="shuffle">
<tr>
<td class="widget shuffle-all" rowspan="2">
@ -805,6 +820,7 @@
</table>
#else
<i>You must create your <xsl:value-of select="$property/ancestor::adl:entity/@name"/> record before you can add <xsl:value-of select="$property/@name"/> to it</i>
#end
#end
</xsl:template>
@ -921,7 +937,7 @@
Auto generated Velocity list for <xsl:value-of select="@name"/>,
generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
Generation parameters were:
locale: <xsl:value-of select="$locale"/>
generate-site-navigation: <xsl:value-of select="$generate-site-navigation"/>
@ -984,7 +1000,7 @@
Auto generated Velocity list for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL.
Generated using adl2listview.xsl <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
Generated using adl2listview.xsl <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
Generation parameters were:
locale: <xsl:value-of select="$locale"/>
generate-site-navigation: <xsl:value-of select="$generate-site-navigation"/>
@ -1707,7 +1723,7 @@
// &lt;![CDATA[
new Control.Slider('<xsl:value-of select="$property/@name"/>-slider','<xsl:value-of select="$property/@name"/>-track',{
onSlide:function(v){$('<xsl:value-of select="concat( 'instance_', $property/@name)"/>').value = <xsl:value-of select="$minimum"/>+ Math.floor(v*(<xsl:value-of select="$maximum - $minimum"/>))}
})
});
// ]]&gt;
</script>
</xsl:if>