Listener is a way to add code to generated UI classes by specifying it in the xml File. For example, open file $projectDirectory/resources/xml/include/detail/FilmDI.xml with XML editor.
Change element:

		<text textLimit="255" mandatory="true" property="title" id="title"/>
by
		<text textLimit="255" mandatory="true" property="title" id="title">
		    <listeners>
		        <listener listenerTypes="MODIFY_TEXT">
		             <code>//Use red if title length &gt;=40, otherwise use blue color
import org.eclipse.swt.SWT;
if (40 &lt; #CONTROL(title).getText().length())
    #CONTROL(title).setForeground(#COLOR(SWT.COLOR_RED));
else
    #CONTROL(title).setForeground(#COLOR(SWT.COLOR_BLUE));</code>
		         </listener>      
		     </listeners>      
		</text>

Open a new editor for the detail of a film, if the description field is longer than 40 letters, then the foreground color pass to Red otherwise the foreground color is Blue. Be sure that the editor was not already open for the Film, otherwise the editor use the old version without the listener.

tutorial/create_listener.txt · Last modified: 2015/10/05 17:52 (external edit)