Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorial:improve_film_detail [2015/02/16 10:52]
tutorial:improve_film_detail [2020/05/08 12:05] (current)
Line 1: Line 1:
 +Adichatz generates brute Entity Editors to display detail parts of an Entity and the list of its related objects (dependencies).
 +For example the Entity Editor for a Film class is described by an XML file called '<​wrap adicode>​FilmEditorGENERATED.axml</​wrap>'​ or '<​wrap adicode>​FilmDIGENERATED.axml</​wrap>'​ (see [[http://​www.adichatz.org/​document/​FilmDI.xml|generated file]]).
 +
 +For example, open file <wrap adicode>​$projectDirectory/​resources/​xml/​model/​film/​FilmDIGENERATED.xml</​wrap>​.\\ \\
 +**Following XML elements:**
 +<sxh xml; first-line: 1; title: excerpt from '​FilmDIGENERATED.axml'​ file.>
 +<?xml version="​1.0"​ encoding="​UTF-8"​ standalone="​yes"?>​
 +<​includeTree xmlns:​xsi="​http://​www.w3.org/​2001/​XMLSchema-instance"​ coreClassName="​org.adichatz.engine.core.ASectionCore"​ entityURI="​adi://​myproject/​model.film/​FilmMM"​ xsi:​noNamespaceSchemaLocation="​http://​www.adichatz.org/​xsd/​v0.9.1/​generator/​includeTree.xsd">​
 +    <section text="#​MSG(film,​ detailContainerText)"​ id="​detailContainer">​
 +        <layout layoutConstraints="​wrap 4" columnConstraints="​[fill,​ align right]10[fill,​grow]25[align right]10[fill,​grow]"/>​
 +        <include adiResourceURI="​getToolBarURI((String) #​PARAM(TOOL_BAR_TYPE))"​ id="​detailToolbarMenu">​
 +            <​params>​
 +                <param value="#​CONTROLLER(detailContainer)"​ id="​CONTROLLER"/>​
 +                <param optional="​true"​ value="#​PARAM(TOOL_BAR_TYPE)"​ id="​TOOL_BAR_TYPE"/>​
 +            </​params>​
 +        </​include>​
 +        <​formattedText editPattern="#####"​ format="​Integer"​ property="​filmId"​ enabled="​false"​ id="​filmId"/>​
 +        <refText property="​languageByOriginalLanguageId"​ style="​SWT.BORDER | AdiSWT.FIND_BUTTON | AdiSWT.EDITOR_BUTTON | AdiSWT.DELETE_BUTTON"​ id="​languageByOriginalLanguageId">​
 +            <​convertModelToTarget>​return null==value ? ""​ : #​FV().name;</​convertModelToTarget>​
 +        </​refText>​
 +        <refText property="​languageByLanguageId"​ mandatory="​true"​ style="​SWT.BORDER | AdiSWT.FIND_BUTTON | AdiSWT.EDITOR_BUTTON"​ id="​languageByLanguageId">​
 +            <​convertModelToTarget>​return null==value ? ""​ : #​FV().name;</​convertModelToTarget>​
 +        </​refText>​
 +        <text textLimit="​255"​ property="​title"​ mandatory="​true"​ id="​title"/>​
 +        <text textLimit="​255"​ property="​description"​ id="​description"/>​
 +        <​formattedText editPattern="####"​ format="​Integer"​ property="​releaseYear"​ id="​releaseYear">​
 +            <​validators>​
 +                <​validator key="​invalidYear"​ errorMessage="#​MSG(film,​ invalid.year.value,​ #​FV())">​
 +                    <​errorWhen>​return #FV() &lt; 1900 ||  #FV() &gt; 2155;</​errorWhen>​
 +                </​validator>​
 +            </​validators>​
 +        </​formattedText>​
 +        <​checkBox property="​active"​ mandatory="​true"​ style="​SWT.CHECK"​ id="​active"/>​
 +        <​formattedText editPattern="#####"​ format="​Short"​ property="​rentalDuration"​ mandatory="​true"​ id="​rentalDuration"/>​
 +        <​formattedText editPattern="##​.##"​ format="​Double"​ property="​rentalRate"​ mandatory="​true"​ id="​rentalRate">​
 +            <​convertModelToTarget>​return null == value ? null : ((java.math.BigDecimal) value).doubleValue();</​convertModelToTarget>​
 +            <​convertTargetToModel>​return null == value ? null : new java.math.BigDecimal((Double) value);</​convertTargetToModel>​
 +        </​formattedText>​
 +        <​formattedText editPattern="#####"​ format="​Short"​ property="​length"​ id="​length"/>​
 +        <​formattedText editPattern="###​.##"​ format="​Double"​ property="​replacementCost"​ mandatory="​true"​ id="​replacementCost">​
 +            <​convertModelToTarget>​return null == value ? null : ((java.math.BigDecimal) value).doubleValue();</​convertModelToTarget>​
 +            <​convertTargetToModel>​return null == value ? null : new java.math.BigDecimal((Double) value);</​convertTargetToModel>​
 +        </​formattedText>​
 +        <ccombo property="​rating"​ id="​rating">​
 +            <​labelProvider>​
 +                <​textCode>​return ((#​MODELPACKAGE().MpaaRatingEnum) element).getValue();</​textCode>​
 +            </​labelProvider>​
 +            <​initValues>​return java.util.Arrays.asList(#​MODELPACKAGE().MpaaRatingEnum.values());</​initValues>​
 +        </​ccombo>​
 +        <text textLimit="​255"​ property="​imageUrl"​ id="​imageUrl"/>​
 +        <​dateText property="​lastUpdate"​ enabled="​false"​ style="​SWT.BORDER | SWT.TIME"​ id="​lastUpdate"/>​
 +        <​multiChoice popupToolbar="​true"​ multiChoiceType="​Array"​ values="​Trailers,​Commentaries,​Deleted Scenes,​Behind the Scenes"​ property="​specialFeatures"​ id="​specialFeatures">​
 +            <​convertTargetToModel>​return java.util.Arrays.copyOf((Object[]) value, ((Object[]) value).length,​ String[].class);</​convertTargetToModel>​
 +        </​multiChoice>​
 +    </​section>​
 +</​includeTree>​
 +</​sxh>​\\
 +**renders the following layout:**\\
 +{{ tutorial:​film_detail_generated.jpg?​550 | Film detail (brute)}}
 +\\ \\ \\
 +**Change XML elements**
 +  * Copy <wrap adicode>​FilmDIGENERATED.axml</​wrap>​ file to <wrap adicode>​FilmDI.axml</​wrap>​ which will become the reference for generated code.
 +  * Replace above XML lines with the following ones:
 +<sxh xml; first-line: 1; highlight: [15,35-38]; title: excerpt from '​FilmDI.axml'​ file (new version).>​
 +<?xml version="​1.0"​ encoding="​UTF-8"​ standalone="​yes"?>​
 +<​includeTree xmlns:​xsi="​http://​www.w3.org/​2001/​XMLSchema-instance"​ coreClassName="​org.adichatz.engine.core.ASectionCore"​ entityURI="​adi://​myproject/​model.film/​FilmMM"​ xsi:​noNamespaceSchemaLocation="​http://​www.adichatz.org/​xsd/​v0.9.1/​generator/​includeTree.xsd">​
 +    <section text="#​MSG(film,​ detailContainerText)"​ id="​detailContainer">​
 +        <layout layoutConstraints="​wrap 4" columnConstraints="​[fill,​ align right]10[fill,​grow]25[align right]10[fill,​grow]"/>​
 +        <include adiResourceURI="​getToolBarURI((String) #​PARAM(TOOL_BAR_TYPE))"​ id="​detailToolbarMenu">​
 +            <​params>​
 +                <param value="#​CONTROLLER(detailContainer)"​ id="​CONTROLLER"/>​
 +                <param optional="​true"​ value="#​PARAM(TOOL_BAR_TYPE)"​ id="​TOOL_BAR_TYPE"/>​
 +            </​params>​
 +        </​include>​
 +        <​formattedText editPattern="######"​ format="​Short"​ property="​filmId"​ enabled="​false"​ id="​filmId"/>​
 +        <text textLimit="​255"​ property="​title"​ mandatory="​true"​ id="​title"/>​
 +        <text layoutData="​span 3" textLimit="​255"​ property="​description"​ id="​description"/>​
 +        <​composite layoutData="​newline,​ grow, push, span 4" id="​bottomComposite">​
 +            <layout layoutConstraints="​wrap 2" columnConstraints="​[fill,​ grow][fill, grow]" rowConstraints="​[fill,​ grow, al top]"/>​
 +            <​imageViewer imageType="​Url"​ fitCanvas="​true"​ toolBarStyle="​AdiSWT.DELETE_BUTTON | AdiSWT.EXPANDABLE | AdiSWT.EDITABLE"​ noLabel="​true"​ layoutData="​hmax 300" property="​imageUrl"​ id="​imageUrl"/>​
 +            <​composite id="​fieldComposite">​
 +                <layout layoutConstraints="​wrap 2" columnConstraints="​[align right]10[fill,​grow]"/>​
 +                <refText property="​languageByOriginalLanguageId"​ style="​SWT.BORDER | AdiSWT.FIND_BUTTON | AdiSWT.EDITOR_BUTTON | AdiSWT.DELETE_BUTTON"​ id="​languageByOriginalLanguageId">​
 +                    <​convertModelToTarget>​return null==value ? &​quot;&​quot;​ : #​FV().name;</​convertModelToTarget>​
 +                </​refText>​
 +                <refText property="​languageByLanguageId"​ mandatory="​true"​ style="​SWT.BORDER | AdiSWT.EDITOR_BUTTON | AdiSWT.FIND_BUTTON"​ id="​languageByLanguageId">​
 +                    <​convertModelToTarget>​return null==value ? &​quot;&​quot;​ : #​FV().name;</​convertModelToTarget>​
 +                </​refText>​
 +                <ccombo property="​rating"​ id="​rating">​
 +                    <​labelProvider>​
 +                            <​textCode>​return ((#​MODELPACKAGE().MpaaRatingEnum) element).getValue();</​textCode>​
 +                    </​labelProvider>​
 +                    <​initValues>​return java.util.Arrays.asList(#​MODELPACKAGE().MpaaRatingEnum.values());</​initValues>​
 +                </​ccombo>​
 +                <​checkBox text="#​MSG(film,​active)"​ property="​active"​ noLabel="​true"​ style="​SWT.CHECK"​ id="​active"/>​
 +                <​composite id="​activeComposite">​
 +                    <layout layoutConstraints="​wrap 1, ins 0, hidemode 3" columnConstraints="​[fill,​ grow]"/>​
 +                    <pgroup text="#​MSG(film,​active)"​ id="​activeGroup"​ dirtyManagement="​false">​
 +                        <​dynamicClause listenedFieldId="​active">​
 +                            <​conditionCode>#​BEAN().isActive()</​conditionCode>​
 +                            <​postCode>#​CONTROLLER(detailContainer).reflowControllers();</​postCode>​
 +                        </​dynamicClause>​
 +                        <layout layoutConstraints="​wrap 2" columnConstraints="​[align right]10[fill,​grow]"/>​
 +                        <​formattedText editPattern="######"​ format="​Short"​ property="​rentalDuration"​ mandatory="​true"​ id="​rentalDuration"/>​
 +                        <​numericText pattern="##​.##"​ property="​rentalRate"​ mandatory="​true"​ style="​SWT.BORDER | SWT.RIGHT"​ id="​rentalRate"/>​
 +                        <​numericText pattern="###​.##"​ property="​replacementCost"​ mandatory="​true"​ style="​SWT.BORDER | SWT.RIGHT"​ id="​replacementCost"/>​
 +                    </​pgroup>​
 +                </​composite>​
 +                <​formattedText editPattern="######"​ format="​Short"​ property="​length"​ id="​length"/>​
 +                <​multiChoice popupToolbar="​true"​ multiChoiceType="​Array"​ values="​Trailers,​Commentaries,​Deleted Scenes,​Behind the Scenes"​ property="​specialFeatures"​ id="​specialFeatures">​
 +                    <​convertTargetToModel>​return java.util.Arrays.copyOf((Object[]) value, ((Object[]) value).length,​ String[].class);</​convertTargetToModel>​
 +                </​multiChoice>​
 +                <​dateText property="​lastUpdate"​ enabled="​false"​ style="​SWT.BORDER | SWT.TIME"​ id="​lastUpdate"/>​
 +            </​composite>​
 +        </​composite>​
 +    </​section>​
 +</​includeTree>​
 +</​sxh>​
 +** renders the new layout:**\\
 +{{tutorial:​film_detail.jpg?​550 | Film detail (improved)}}
 +<​html><​br clear="​all"></​html>​
 +<WRAP indic><​wrap adititle>​Remarks</​wrap>:​
 +|< 100% 10em - >|
 +^  <​html><​small></​html>​Lines 15<​html></​small></​html>:​|@#​eff5fb:​A **text controller** is replaced by an **ImageViewer controller** which displays an image for an URL.|
 +^  <​html><​small></​html>​Lines 35-38<​html></​small></​html>:​|@#​eff5fb:​show how to create a dynamic block. '​**forRentGroup**'​ pgroup is created only when field **forRent** is set to **true**.|
 +\\
 +If you are using **sakila** mysql datababase rather than **pagila** postgresql, two changes must be done:\\
 +replace lines **25-30** by following line. 
 +<​code>​
 +<ccombo values="​G,​ PG, PG-13, R, NC-17" style="​SWT.READ_ONLY | SWT.BORDER"​ property="​rating"​ id="​rating"/>​
 +</​code>​
 +replace lines **46-48** (line **41** after previous change) by following line. 
 +<​code>​
 +<​multiChoice popupToolbar="​true"​ multiChoiceType="​String"​ values="​Trailers,​Commentaries,​Deleted Scenes,​Behind the Scenes"​ property="​specialFeatures"​ id="​specialFeatures"/>​
 +</​code>​
 +//<​sub>​See page [[tutorial:​improve_film_detail_sakila|Improve Film Detail (sakila)]].</​sub>//​
 +</​WRAP>​
 +\\
 +//<​sub>​Same method can be used for [[tutorial:​improve_filmdesc_detail|FilmDescription]].
 +</​sub>//​
 +\\