Differences

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

Link to this comparison view

tutorial:create_listener [2020/05/08 12:05] (current)
Line 1: Line 1:
 +**Listener** is a way to add code to generated UI classes by specifying it in the xml File. 
 +For example, open file <wrap adicode>​$projectDirectory/​resources/​xml/​include/​detail/​FilmDI.xml</​wrap>​ with XML editor.\\ 
 +Change element: 
 +  
 +<sxh xml; title: excerpt from '​FilmDI.axml'​ file.> 
 + <text textLimit="​255"​ mandatory="​true"​ property="​title"​ id="​title"/>​ 
 +</​sxh>​ 
 +by 
 +<sxh xml; highlight: [2-11]; title: excerpt from '​FilmDI.axml'​ file.> 
 +        <text textLimit="​255"​ property="​description"​ layoutData="​span 3" id="​description">​ 
 +            <​listeners>​ 
 +                <​listener listenerTypes="​MODIFY_TEXT | AFTER_SYNCHRONIZE">​ 
 +                    <​code>//​Use red if title length &gt; 12, otherwise use blue color 
 +import org.eclipse.swt.SWT;​ 
 +if (12 &gt; #​CONTROL().getText().length()) 
 +    #​CONTROLLER().setForeground(#​CSSCOLOR(#​adichatz-common,​ error-foreground-color));​ 
 +else 
 +    #​CONTROLLER().setForeground(#​CSSCOLOR(#​adichatz-common,​ info-foreground-color));</​code>​ 
 +                </​listener>​ 
 +            </​listeners>​ 
 +        </​text>​ 
 +</​sxh>​ 
 +  
 +  
 +Open a new editor for the detail of a film, if the description field is longer than 12 letters, then the foreground color pass to Red otherwise the foreground color is Blue. 
 +\\ 
 +<wrap adicode>​listenerTypes="​MODIFY_TEXT | AFTER_SYNCHRONIZE</​wrap>​ means that listener is launched when text change or after synchonization process.\\ 
 +Be sure that the editor was not already open for the Film, otherwise the editor use the old version without the listener.