Differences

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

Link to this comparison view

tutorial:include_gmap_controller [2020/04/21 11:19]
tutorial:include_gmap_controller [2020/04/21 11:19] (current)
Line 1: Line 1:
 +Part can use rich controllers provided by Adichatz as [[controllers:​gmapcontroller|GMapController]].
  
 +Before using [[controllers:​gmapcontroller|GMapController]],​ [[https://​developers.google.com/​maps/​documentation/​javascript/​get-api-key | get GMap API key]] and store it in '​./​resources/​xml/​AdichatzRcpConfig.xml'​ file as shown below.
 +<sxh xml; first-line: 1; title: excerpt from '​AdichatzRcpConfig.xml'​ file.>
 +<?xml version="​1.0"​ encoding="​UTF-8"​ standalone="​yes"?>​
 +<​adichatzRcpConfigTree xmlns:​xsi="​http://​www.w3.org/​2001/​XMLSchema-instance"​ xsi:​noNamespaceSchemaLocation="​http://​www.adichatz.org/​xsd/​v0.9.0/​engine/​adichatzRcpConfigTree.xsd">​
 +    <​rcpConfiguration>​
 +    ...
 +        <param id="​adichatzGMapAPIKey"​ value="​YOUR_GMAP_API_KEY"/>​
 +        ...
 +    </​rcpConfiguration>​
 +</​adichatzRcpConfigTree>​
 +</​sxh>​\\
 +
 +\\
 +For example, open file <wrap adicode>​$projectDirectory/​resources/​xml/​model/​address/​AddressDIGENERATED.xml</​wrap>​.\\ \\
 +**Following XML elements:**
 +<sxh xml; first-line: 1; title: excerpt from '​AddressDIGENERATED.axml'​ file.>
 +<?xml version="​1.0"​ encoding="​UTF-8"​ standalone="​yes"?>​
 +<?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.actor/​ActorMM"​ xsi:​noNamespaceSchemaLocation="​http://​www.adichatz.org/​xsd/​v0.9.1/​generator/​includeTree.xsd">​
 +    <section text="#​MSG(actor,​ 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="​actorId"​ enabled="​false"​ id="​actorId"/>​
 +        <text textLimit="​45"​ property="​firstName"​ mandatory="​true"​ id="​firstName"/>​
 +        <text textLimit="​45"​ property="​lastName"​ mandatory="​true"​ id="​lastName"/>​
 +        <​dateText property="​lastUpdate"​ enabled="​false"​ style="​SWT.BORDER | SWT.TIME"​ id="​lastUpdate"/>​
 +    </​section>​
 +</​includeTree>​
 +</​sxh>​\\
 +**renders the following layout:**\\
 +{{ tutorial:​address_detail.png?​600 | Address detail (brute) }}
 +\\ \\ \\
 +
 +**Change XML elements**:
 +  * Copy <wrap adicode>​AddressDIGENERATED.axml</​wrap>​ file to <wrap adicode>​AddressDI.axml</​wrap>​ which will become the reference for generated code.
 +  * Replace above XML lines with the following ones:
 +<sxh xml; first-line: 1; highlight: [12-14,​16-41,​55];​ title: excerpt from '​AddressDI.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.address/​AddressMM"​ generationType="​DETAIL"​ xsi:​noNamespaceSchemaLocation="​http://​www.adichatz.org/​xsd/​v0.8.4/​generator/​includeTree.xsd">​
 +    <section text="#​MSG(actor,​ detailContainerText)"​ id="​detailContainer">​
 + <​layout layoutConstraints="​wrap 2" columnConstraints="​[fill]25[fill,​grow]"​ rowConstraints="​[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>​
 + <​listeners>​
 +     <​listener listenerTypes="​AFTER_SYNCHRONIZE | AFTER_PROPERTY_CHANGE | POST_REFRESH">​
 +         <​code>​displayGMap();</​code>​
 +     </​listener>​
 + </​listeners>​
 + <​additionalCode>​import org.adichatz.engine.widgets.GMap;​
 +import java.lang.Runnable;​
 +private boolean doit = true;
 +private void displayGMap() {
 + if (doit) {
 + doit = false;
 + GMap gmapControl = #​CONTROL(map);​
 + Address address = #BEAN();
 + if (null != address) {
 + StringBuffer addresSB = new StringBuffer();​
 + if (null != address.getAddress())
 + addresSB.append(address.getAddress()).append("​ ");
 + if (null != address.getAddress2())
 + addresSB.append(address.getAddress2()).append("​ ");
 + if (null != address.getPostalCode())
 + addresSB.append(address.getPostalCode()).append("​ ");
 + if (null != address.getCity()) {
 + addresSB.append(address.getCity().getCity()).append("​ ");
 + addresSB.append(#​BEAN().city.country.country);​
 + }
 + gmapControl.setValue(addresSB.toString().trim());​
 + } else
 + gmapControl.setValue(null);​
 + doit = true;
 + }
 +}</​additionalCode>​
 + <​composite>​
 +     <layout layoutConstraints="​wrap 2" columnConstraints="​[fill,​ align right]10[grow,​fill]"​ rowConstraints="​20[]20[][]"/>​
 +     <​formattedText editPattern="######"​ format="​Short"​ property="​addressId"​ enabled="​false"​ id="​addressId"/>​
 +     <refText property="​city"​ mandatory="​true"​ style="​SWT.BORDER | AdiSWT.FIND_BUTTON | AdiSWT.EDITOR_BUTTON"​ id="​city">​
 +             <​convertModelToTarget>​return null==value ? &​quot;&​quot;​ : #​FV().city;</​convertModelToTarget>​
 +     </​refText>​
 +     <text textLimit="​50"​ property="​address"​ mandatory="​true"​ id="​address"/>​
 +     <text textLimit="​50"​ property="​address2"​ id="​address2"/>​
 +     <text textLimit="​20"​ property="​district"​ mandatory="​true"​ id="​district"/>​
 +     <text textLimit="​10"​ property="​postalCode"​ id="​postalCode"/>​
 +     <text textLimit="​20"​ property="​phone"​ mandatory="​true"​ id="​phone"/>​
 +     <​dateText property="​lastUpdate"​ enabled="​false"​ style="​SWT.BORDER | SWT.TIME"​ id="​lastUpdate"/>​
 + </​composite>​
 + <gMap mapDataType="​ADDRESS"​ toolBarStyle="​AdiSWT.EXPANDABLE"​ zoom="​12"​ id="​map"​ delayMillisLoading="​500"/>​
 +    </​section>​
 +</​includeTree>​
 +</​sxh>​
 +** renders the new layout:**\\
 +{{tutorial:​address_detail_gmap.png?​600 | Address detail (improved)}}
 +\\
 +
 +<WRAP indic><​wrap adititle>​Remarks</​wrap>:​\\
 +Lines 12-14: Method <wrap adicode>​displayGMap</​wrap>​ is called at three moments of the life cycle of the controller:
 +  * <wrap adicode>​AFTER_SYNCHRONIZE</​wrap>:​ After received entity is injected inside UI controllers.
 +  * <wrap adicode>​AFTER_PROPERTY_CHANGE</​wrap>:​ After UI send a change to a property of the entity.
 +  * <wrap adicode>​POST_REFRESH</​wrap>:​ After changes on entity are cancelled by asking to refresh property values from Database.
 +
 +Lines 16-41: Build an address string from property values and set the string to the GMap control.
 +
 +Line 55: Set a gmap controller.
 + 
 +</​WRAP>​