<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Eclipse wizards with jface databinding in Deltacloud Tools (1)
</h3>
<span style="margin-bottom: 10px;">
modified by <a href="http://community.jboss.org/people/adietish">Andre Dietisheim</a> in <i>JBoss Tools</i> - <a href="http://community.jboss.org/docs/DOC-15964">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><h1>Less code</h1><p>If you use jface databinding to code your swt views in Eclipse you'll get spared from writing listeners and updating code by hand. JFace databinding offers very nice abstractions and automatisms that offer funcitonalities for the vast majority of the tasks where you have to listen for user input and update a view accordingly.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h1>Premise</h1><p>If you implement a complex and highly dynamic UI in Eclipse you'll have to code many listener that wait for user actions. Those listeners mostly do nothing spectacular but update widgets and models in reaction to user inputs. You end up with a lot of repetitive boilerplate code. UI frameworks in the non-java land (ex.<a class="jive-link-external-small" href="http://qt.nokia.com/products/"> Trolltechs QT</a>) always had approaches that were far more elegant than what we usually did in Swing and SWT.</p><p>Fortunately those so called binding approaches made it into <a class="jive-link-external-small" href="http://jgoodies.com/">Swing</a> and <a class="jive-link-external-small" href="http://wiki.eclipse.org/index.php/JFace_Data_Binding">Eclipse</a>. Eclipse offers nowadays a very mature (developed since 2006) framework that spares you from boilerplate and leads to far more concise and a less verbose implementations: Jface Databinding!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h1>Usecase</h1><p>In Deltacloud tools, we had to implement a wizard page that allows a user to create a connection to a Deltacloud server:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The user has to supply a name, an url and the credentials for it.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-15964-66-10644/wizardpage.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-15964-66-10644/450-337/wizardpage.png </span></a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Sounds pretty simple at first sight. Looking closer at it you'll discover few buttons and labels, that shall get updated upon user inputs. We need to inform the user in a intuitive way and mark form fields by error decorations. The wizard page shall also show a global  error message that reflects the errors in a human readable manner.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-15964-66-10645/wizardpage-decorations.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-15964-66-10645/450-337/wizardpage-decorations.png </span></a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h1 style="color: #333333; font-weight: bold; padding-top: 10px; padding-right: 0pt; padding-bottom: 4px; padding-left: 0pt; font-size: 18pt; margin: 0pt;"><span style="font-weight: normal; font-size: 13px;"> </span></h1><p style="padding: 0pt; margin: 0pt;">We choose to use jface databinding and not to stick to the traditional, tedious approach. I'll discuss our implementation in a simplified way. You may have a look at the complete implementation at <a class="jive-link-external-small" href="http://anonsvn.jboss.org/repos/jbosstools/trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java">CloudConnectionPage.java</a><span> </span></p><h1></h1><h1>Let us get to the (little) code</h1><h2>The user must provide a name for the connection</h2><p>We stick to a fairly simple use case and discuss all steps that we have to take: The user musn't leave the name blank, he has to name the connection.</p><p>The picture above shows the various ways we implement to inform the user. As long as no name is provided:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><ul><li>We decorate the name filed with an error icon</li><li>We provide a meaningful error message in the title area of our page</li><li>We disable the finish-button</li></ul><h1><strong> </strong></h1><h2></h2><h2>Let us start with a text widget</h2><p>To start, we need a text field that will allow the user to enter the name. The classic approach would be to create a SWT text wiget and attach a ModifyLlistener to it. We would implement this listener by validating the user input. Jface databinding spares us from writing this listener:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre>Text nameText <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">new</span> Text<span style="color: #666666">(</span>parent<span style="color: #666666">,</span> SWT<span style="color: #666666">.</span><span style="color: #7D9029">BORDER</span> <span style="color: #666666">|</span> SWT<span style="color: #666666">.</span><span style="color: #7D9029">SINGLE</span><span style="color: #666666">);<br/></span>IObservableValue observableText <span style="color: #666666">=</span> WidgetProperties<span style="color: #666666">.</span><span style="color: #7D9029">text</span><span style="color: #666666">(</span>SWT<span style="color: #666666">.</span><span style="color: #7D9029">Modify</span><span style="color: #666666">).</span><span style="color: #7D9029">observe</span><span style="color: #666666">(</span>nameText<span style="color: #666666">);</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>JFace databinding operates on <strong>Observables</strong>. Observables provide a standardized observer pattern used across jface databinding. No matter what you observe, a widget, a bean, etc. you always listen to changes that occour in a jface observable.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-15964-66-10646/observables.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-15964-66-10646/450-363/observables.png </span></a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><br/>The code shown above attaches a ModifyListener to the text field and wraps it in an <strong>Observable</strong>. We still have no validation. We'll get to this in a few steps.</p><h2></h2><h2>We need a model to store the name</h2><p style="padding: 0pt; margin: 0pt;">Jface databinding is a framework that is built upon the principle of model-view-controller (<strong>MVC</strong>).  It connects a view to a model and transfers the user inputs to the model. It of course also operates the other way round and updates the view if new values are set to the model.</p><p>We'll now create a simple bean that holds the name of our connection:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre><span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">CloudConnectionModel</span> <span style="color: #008000; font-weight: bold">extends</span> ObservablePojo <span style="color: #666666">{</span> <br/><br/>     <span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">static</span> <span style="color: #008000; font-weight: bold">final</span> String PROPERTY_NAME <span style="color: #666666">=</span> <span style="color: #BA2121">"name"</span><span style="color: #666666">;</span> <br/><br/>     <span style="color: #008000; font-weight: bold">private</span> String name<span style="color: #666666">;</span> <br/><br/>     <span style="color: #008000; font-weight: bold">public</span> <span style="color: #0000FF">CloudConnectionModel</span><span style="color: #666666">(</span>String name<span style="color: #666666">)</span> <span style="color: #666666">{<br/></span>          <span style="color: #008000; font-weight: bold">this</span><span style="color: #666666">.</span><span style="color: #7D9029">name</span> <span style="color: #666666">=</span> name<span style="color: #666666">;</span>     <span style="color: #666666"><br/>     }</span>     <br/>     <span style="color: #008000; font-weight: bold"><br/>     public</span> String <span style="color: #0000FF">getName</span><span style="color: #666666">()</span> <span style="color: #666666">{<br/></span>          <span style="color: #008000; font-weight: bold">return</span> name<span style="color: #666666">;</span>     <span style="color: #666666"><br/>     }</span> <br/>     <span style="color: #008000; font-weight: bold"><br/>     public</span> <span style="color: #B00040">void</span> <span style="color: #0000FF">setName</span><span style="color: #666666">(</span>String name<span style="color: #666666">)</span> <span style="color: #666666">{<br/>     </span>       getPropertyChangeSupport<span style="color: #666666">().</span><span style="color: #7D9029"><br/>               firePropertyChange</span><span style="color: #666666">(</span>PROPERTY_NAME<span style="color: #666666">,</span> <span style="color: #008000; font-weight: bold">this</span><span style="color: #666666">.</span><span style="color: #7D9029">name</span><span style="color: #666666">,</span> <span style="color: #008000; font-weight: bold">this</span><span style="color: #666666">.</span><span style="color: #7D9029">name</span> <span style="color: #666666">=</span> name<span style="color: #666666">);</span>     <br/>     <span style="color: #666666">}<br/></span><span style="color: #666666">}</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Our model is a simple bean and provides getters and setter for the name property. It uses PropertyChangeSupport to inform observers about changes to the name of our connection. PropertyChangeSupport, an observer pattern shipped with the jdk, allows us to get informed of changes. Since jface uses <strong>Observables</strong>, we have to wrap our name property to conform to the <strong>Observable</strong> interface:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre>IObservableValue observableName <span style="color: #666666">=</span> <br/>    BeanProperties<span style="color: #666666">.</span><span style="color: #7D9029">value</span><span style="color: #666666">(</span>CloudConnectionModel<span style="color: #666666">.</span><span style="color: #7D9029">class</span><span style="color: #666666">,</span> CloudConnectionModel<span style="color: #666666">.</span><span style="color: #7D9029">PROPERTY_NAME</span><span style="color: #666666">)</span><br/>     <span style="color: #666666">.</span><span style="color: #7D9029">observe</span><span style="color: #666666">(</span>connectionModel<span style="color: #666666">),</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2></h2><h2>Databinding, transfer the user input to our model!</h2><p>Now that we have observables on both ends (model and widget), we can tell databinding to connect both ends. JFace databinding will then propagate user inputs to our model. It will also transfer changes in the model to the widget. A so called <strong>Binding </strong>may be created on behalf of the <strong>DataBindingContext:</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre>DataBindingContext dbc <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">new</span> DataBindingContext<span style="color: #666666">();</span><br/><br/>dbc<span style="color: #666666">.</span><span style="color: #7D9029">bindValue</span><span style="color: #666666">(</span><br/>     WidgetProperties<span style="color: #666666">.</span><span style="color: #7D9029">text</span><span style="color: #666666">(</span>SWT<span style="color: #666666">.</span><span style="color: #7D9029">Modify</span><span style="color: #666666">).</span><span style="color: #7D9029">observe</span><span style="color: #666666">(</span>nameText<span style="color: #666666">),</span><br/>     BeanProperties<span style="color: #666666">.</span><span style="color: #7D9029">value</span><span style="color: #666666">(</span>CloudConnectionModel<span style="color: #666666">.</span><span style="color: #7D9029">class</span><span style="color: #666666">,</span> CloudConnectionModel<span style="color: #666666">.</span><span style="color: #7D9029">PROPERTY_NAME</span><span style="color: #666666">)<br/>          .</span><span style="color: #7D9029">observe</span><span style="color: #666666">(</span>connectionModel<span style="color: #666666">));</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2>But hey, refuse invalid names</h2><p>We now told databinding to transfer the user input to our model. What we still miss is the ability to constrain user inputs.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-15964-66-10647/convert-validate.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-15964-66-10647/450-189/convert-validate.png </span></a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Jface databinding offers the ability to convert and validate values while they are transferred from one end to the other. We can tell databinding to validate the name before it sets the user input to the model. Databinding uses <strong>IValidator</strong> instances for that sake:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre><span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">MandatoryStringValidator</span> <span style="color: #008000; font-weight: bold">implements</span> IValidator <span style="color: #666666">{</span><br/>     <span style="color: #008000; font-weight: bold"><br/>     private</span> String errorMessage<span style="color: #666666">;</span><br/>     <span style="color: #008000; font-weight: bold"><br/>     public</span> <span style="color: #0000FF">MandatoryStringValidator</span><span style="color: #666666">(</span>String errorMessage<span style="color: #666666">)</span> <span style="color: #666666">{</span>          <br/>          <span style="color: #008000; font-weight: bold">this</span><span style="color: #666666">.</span><span style="color: #7D9029">errorMessage</span> <span style="color: #666666">=</span> errorMessage<span style="color: #666666">;</span>     <br/>     <span style="color: #666666">}</span><br/>     <span style="color: #408080; font-style: italic"><br/>     /**</span><span style="color: #408080; font-style: italic">      <br/>     * </span><span style="color: #408080; font-style: italic">      <br/>     * validates the given string. Validation passes only if the given value is</span><span style="color: #408080; font-style: italic">      <br/>     * not <tt>null</tt> and it's length's larger than 0</span><span style="color: #408080; font-style: italic">      <br/>     * </span><span style="color: #408080; font-style: italic">      <br/>     */</span>     <br/>     <span style="color: #008000; font-weight: bold">public</span> IStatus <span style="color: #0000FF">validate</span><span style="color: #666666">(</span>Object value<span style="color: #666666">)</span> <span style="color: #666666">{</span><br/>          <span style="color: #008000; font-weight: bold">if</span> <span style="color: #666666">(!((</span>value <span style="color: #008000; font-weight: bold">instanceof</span> String<span style="color: #666666">)</span> <span style="color: #666666">&&</span> <span style="color: #666666">((</span>String<span style="color: #666666">)</span> value<span style="color: #666666">).</span><span style="color: #7D9029">length</span><span style="color: #666666">()</span> <span style="color: #666666">></span> <span style="color: #666666">0))</span> <span style="color: #666666">{<br/></span>               <span style="color: #008000; font-weight: bold">return</span> ValidationStatus<span style="color: #666666">.</span><span style="color: #7D9029">error</span><span style="color: #666666">(</span>errorMessage<span style="color: #666666">);</span><br/>          <span style="color: #666666">}</span><br/>          <span style="color: #008000; font-weight: bold">return</span> ValidationStatus<span style="color: #666666">.</span><span style="color: #7D9029">ok</span><span style="color: #666666">();</span>     <br/>     <span style="color: #666666">}<br/></span><span style="color: #666666">}</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The validator shown above validates ok if the user provides any name. It fails if no name is set to the text widget.</p><p>To instruct jface databinding to use our validator, we have to wire it into a so called <strong>UpdateValueStrategy</strong>.  As we saw above, databinding transfers values both ways:  from the view to the model and from the model to the view. A binding therefore has 2 update strategies. A first one that gets applied when values are transfered from the view to the model and another one that is applied when transferring from the model to the view. We only want to validate names that the user provides. We therefore keep the default (<strong>null</strong>) strategy for updates that occur in the model:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre>Binding nameTextBinding <span style="color: #666666">=</span> <br/>     dbc<span style="color: #666666">.</span><span style="color: #7D9029">bindValue</span><span style="color: #666666">(<br/></span>          WidgetProperties<span style="color: #666666">.</span><span style="color: #7D9029">text</span><span style="color: #666666">(</span>SWT<span style="color: #666666">.</span><span style="color: #7D9029">Modify</span><span style="color: #666666">).</span><span style="color: #7D9029">observe</span><span style="color: #666666">(</span>nameText<span style="color: #666666">),</span><br/>          BeanProperties<br/>               <span style="color: #666666">.</span><span style="color: #7D9029">value</span><span style="color: #666666">(</span>CloudConnectionModel<span style="color: #666666">.</span><span style="color: #7D9029">class</span><span style="color: #666666">,</span> CloudConnectionModel<span style="color: #666666">.</span><span style="color: #7D9029">PROPERTY_NAME</span><span style="color: #666666">)<br/></span>               <span style="color: #666666">.</span><span style="color: #7D9029">observe</span><span style="color: #666666">(</span>connectionModel<span style="color: #666666">),<br/></span>          <span style="color: #008000; font-weight: bold">new</span> <span style="color: #0000FF">UpdateValueStrategy</span><span style="color: #666666">().</span><span style="color: #7D9029">setBeforeSetValidator</span><span style="color: #666666">(<br/></span>               <span style="color: #008000; font-weight: bold">new</span> <span style="color: #0000FF">MandatoryStringValidator</span><span style="color: #666666">(</span><span style="color: #BA2121">"You must name the connection"</span><span style="color: #666666">)),<br/></span>          <span style="color: #008000; font-weight: bold">null</span><span style="color: #666666">);</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2>Show me the errors</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>We now may display the result of the validation. We want the text field to be decorated:</p><h3><br/>Field decoration</h3><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-15964-66-10648/name-decoration.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-15964-66-10648/300-65/name-decoration.png </span></a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre>ControlDecorationSupport<span style="color: #666666">.</span><span style="color: #7D9029">create</span><span style="color: #666666">(</span>nameTextBinding<span style="color: #666666">,</span> SWT<span style="color: #666666">.</span><span style="color: #7D9029">LEFT</span> <span style="color: #666666">|</span> SWT<span style="color: #666666">.</span><span style="color: #7D9029">TOP</span><span style="color: #666666">);</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h3>Wizard page error</h3><p>We also want to get informed in the title area of our wizard page.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-15964-66-10649/page-error.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-15964-66-10649/267-93/page-error.png </span></a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>A single call to jface databinding achieves this for you:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre>WizardPageSupport<span style="color: #666666">.</span><span style="color: #7D9029">create</span><span style="color: #666666">(</span><span style="color: #008000; font-weight: bold">this</span><span style="color: #666666">,</span> dbc<span style="color: #666666">);<br/></span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h3>Finish button enablement</h3><p>There's a single missing piece: We also want to disable the finish button as soon as validation fails:</p><div class="highlight"><p><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-15964-66-10538/enable-disable-finish.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-15964-66-10538/250-50/enable-disable-finish.png </span></a></p></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In the classic approach, one would have to implement <strong>WizardPage#isPageComplete</strong>.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre><span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">abstract</span> <span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">WizardPage</span> <span style="color: #008000; font-weight: bold">extends</span> DialogPage <span style="color: #008000; font-weight: bold">implements</span> IWizardPage <span style="color: #666666">{</span><br/>    <span style="color: #408080; font-style: italic">/**<br/></span><span style="color: #408080; font-style: italic">     * The <code>WizardPage</code> implementation of this <code>IWizard</code> method<br/></span><span style="color: #408080; font-style: italic">     * returns the value of an internal state variable set by<br/></span><span style="color: #408080; font-style: italic">     * <code>setPageComplete</code>. Subclasses may extend.<br/></span><span style="color: #408080; font-style: italic">     */<br/></span>    <span style="color: #008000; font-weight: bold">public</span> <span style="color: #B00040">boolean</span> <span style="color: #0000FF">isPageComplete</span><span style="color: #666666">()</span> <span style="color: #666666">{</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>And here's what you have to do using jface databinding:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h4>Nothing, not a single line of additional code.</h4><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>WizardPageSupport#create</strong> displays the validation messages in the title area but also connects the validation state to the page completion state.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h1>All the code you need</h1><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>To sum up, the whole databinding code looks like the following:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><div class="highlight"><pre>DataBindingContext dbc <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">new</span> DataBindingContext<span style="color: #666666">();</span> <br/>WizardPageSupport<span style="color: #666666">.</span><span style="color: #7D9029">create</span><span style="color: #666666">(</span><span style="color: #008000; font-weight: bold">this</span><span style="color: #666666">,</span> dbc<span style="color: #666666">);</span><br/><br/>Text nameText <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">new</span> Text<span style="color: #666666">(</span>parent<span style="color: #666666">,</span> SWT<span style="color: #666666">.</span><span style="color: #7D9029">BORDER</span> <span style="color: #666666">|</span> SWT<span style="color: #666666">.</span><span style="color: #7D9029">SINGLE</span><span style="color: #666666">);<br/></span>          <br/>Binding nameTextBinding <span style="color: #666666">=</span> <br/>     dbc<span style="color: #666666">.</span><span style="color: #7D9029">bindValue</span><span style="color: #666666">(</span><br/>          WidgetProperties<span style="color: #666666">.</span><span style="color: #7D9029">text</span><span style="color: #666666">(</span>SWT<span style="color: #666666">.</span><span style="color: #7D9029">Modify</span><span style="color: #666666">).</span><span style="color: #7D9029">observe</span><span style="color: #666666">(</span>nameText<span style="color: #666666">),</span><br/>          BeanProperties<br/>               <span style="color: #666666">.</span><span style="color: #7D9029">value</span><span style="color: #666666">(</span>CloudConnectionModel<span style="color: #666666">.</span><span style="color: #7D9029">class</span><span style="color: #666666">,</span> CloudConnectionModel<span style="color: #666666">.</span><span style="color: #7D9029">PROPERTY_NAME</span><span style="color: #666666">)</span><br/>               <span style="color: #666666">.</span><span style="color: #7D9029">observe</span><span style="color: #666666">(</span>connectionModel<span style="color: #666666">),</span><br/>          <span style="color: #008000; font-weight: bold">new</span> <span style="color: #0000FF">UpdateValueStrategy</span><span style="color: #666666">().</span><span style="color: #7D9029">setBeforeSetValidator</span><span style="color: #666666">(<br/></span>               <span style="color: #008000; font-weight: bold">new</span> <span style="color: #0000FF">MandatoryStringValidator</span><span style="color: #666666">(</span><span style="color: #BA2121">"You must name the connection"</span><span style="color: #666666">)),<br/></span>          <span style="color: #008000; font-weight: bold">null<br/></span>     <span style="color: #666666">);<br/></span>ControlDecorationSupport<span style="color: #666666">.</span><span style="color: #7D9029">create</span><span style="color: #666666">(</span>nameTextBinding<span style="color: #666666">,</span> SWT<span style="color: #666666">.</span><span style="color: #7D9029">LEFT</span> <span style="color: #666666">|</span> SWT<span style="color: #666666">.</span><span style="color: #7D9029">TOP</span><span style="color: #666666">);</span></pre></div><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h1>Conclusion</h1><p>JFace databinding brings a fresh breath into UI programming compared to what was state of the art when swing was introduced. It lessens boilerplate considerably and brings well adapted paradigms to what's needed when building UIs with java. Your code gets more concise, maintainable and your work gets more effective.</p><p>JFace databinding exists for 5 years now and a large userbase made it stable and mature over the years. There's really no reason not to use it. You wont regret it.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-15964">going to Community</a></p>
        <p style="margin: 0;">Create a new document in JBoss Tools at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2128">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>