<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EclipseSource Blog &#187; databinding</title>
	<atom:link href="http://eclipsesource.com/blogs/tag/databinding/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsesource.com/blogs</link>
	<description>Eclipse Equinox OSGi</description>
	<lastBuildDate>Fri, 18 May 2012 15:00:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Tip: Computing the difference of two collections</title>
		<link>http://eclipsesource.com/blogs/2009/10/23/tip-computing-the-difference-of-two-collections-made-easy/</link>
		<comments>http://eclipsesource.com/blogs/2009/10/23/tip-computing-the-difference-of-two-collections-made-easy/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 00:29:16 +0000</pubDate>
		<dc:creator>Elias Volanakis</dc:creator>
				<category><![CDATA[syndicate]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=3228</guid>
		<description><![CDATA[Sometimes you have two collections and want to know how they differ. It would also be useful to have a series of steps that transform collection &#8216;A&#8217; into collection &#8216;B&#8217; (or the reverse). private static List list1 = Arrays.asList&#40;&#34;a&#34;, &#34;b&#34;, &#34;c&#34;&#41;; private static List list2 = Arrays.asList&#40;&#34;a&#34;, &#34;c&#34;, &#34;d&#34;&#41;; &#160; // Diff of list1 vs [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you have two collections and want to know how they differ. It would also be useful to have a series of steps that transform collection &#8216;A&#8217; into collection &#8216;B&#8217; (or the reverse).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">List</span> list1 <span style="color: #339933;">=</span> <span style="color: #003399;">Arrays</span>.<span style="color: #006633;">asList</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span>, <span style="color: #0000ff;">&quot;b&quot;</span>, <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">List</span> list2 <span style="color: #339933;">=</span> <span style="color: #003399;">Arrays</span>.<span style="color: #006633;">asList</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span>, <span style="color: #0000ff;">&quot;c&quot;</span>, <span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Diff of list1 vs list2:</span>
<span style="color: #666666; font-style: italic;">//  removed 'b' at 1</span>
<span style="color: #666666; font-style: italic;">//  added 'd' at 2</span></pre></div></div>

<p>With a little help from the class <strong>Diffs</strong> (found in the <strong>org.eclipse.core.databinding.observable</strong> bundle / package), it only takes a few lines, as shown in the snippet below. Thank you, Eclipse Databinding!</p>
<p><script src="http://gist.github.com/216484.js"></script></p>
<p>If you don&#8217;t see the snippet <a href="http://eclipsesource.com/blogs/2009/10/23/tip-computing-the-difference-of-two-collections-made-easy/">click here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2009/10/23/tip-computing-the-difference-of-two-collections-made-easy/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Eclipse e4 on the web</title>
		<link>http://eclipsesource.com/blogs/2009/08/25/e4-on-the-web/</link>
		<comments>http://eclipsesource.com/blogs/2009/08/25/e4-on-the-web/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 16:38:33 +0000</pubDate>
		<dc:creator>Benjamin Muskalla</dc:creator>
				<category><![CDATA[syndicate]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[e4]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[Single Sourcing]]></category>
		<category><![CDATA[swt]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=2371</guid>
		<description><![CDATA[With e4 0.9 out in the wild, we should think again about the goals e4 tries to provide. One of them was to reduce the gap between Desktop and Web &#8211; not only speaking of reusing widgets but also to enable the platform handle multi-user scenarios. While the core e4 team concentrated on eliminating bad smells like [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://eclipsesource.com/blogs/2009/08/03/eclipse-e4-0-9-alpha-release/">e4 0.9</a> out in the wild, we should think again about the goals e4 tries to provide. One of them was to reduce the gap between Desktop and Web &#8211; not only speaking of reusing widgets but also to enable the platform handle multi-user scenarios. While the core e4 team concentrated on eliminating bad smells like singletons, the RAP team worked on better support for single sourcing applications in general. With an experimental version of RAP which includes some features not yet in the current release, we were able to run the demo out of the box including the whole underlying infrastructure like the modeled workbench &#8211; without touching the e4 code.</p>
<p><a href="http://eclipse.org/rap/demos.php"><img src="http://eclipsesource.com/blogs/wp-content/uploads/2009/08/e4_contacts.png" alt="e4 contacts Eclipse e4 on the web" title="e4_contacts" width="250" height="190" class="alignnone size-full wp-image-2862" /></a></p>
<p>If you take a look at the <a href="http://eclipse.org/rap/demos.php">RAP Demos</a> page you&#8217;ll find the e4 contacts demo running on RAP. If you want to try it out yourself or even help to contribute to this effort, take a look this <a href="http://wiki.eclipse.org/E4/RAP_Integration/Experimental">wiki page</a>. In case you&#8217;re interested what you can do with e4, be sure to participate in the <a href="http://www.eclipse.org/community/e4webinar/abstracts.php">e4 webinars</a>.This week, there will be Part 2 with topics like RAP, the Compatibility layer and the flexible resources model. Looking at the questions that came up in the last <a href="http://live.eclipse.org/node/718">RAP webinar</a> and the first part of the E4 webinar, people seem to be very interested how e4 and RAP play together. I&#8217;ll try to answer the open questions during the webinar this week. Looking forward to a great event.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2009/08/25/e4-on-the-web/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tip: Validation with a MultiValidator</title>
		<link>http://eclipsesource.com/blogs/2009/02/27/databinding-crossvalidation-with-a-multivalidator/</link>
		<comments>http://eclipsesource.com/blogs/2009/02/27/databinding-crossvalidation-with-a-multivalidator/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 12:40:27 +0000</pubDate>
		<dc:creator>Moritz Post</dc:creator>
				<category><![CDATA[syndicate]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[jface]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=321</guid>
		<description><![CDATA[In the last blog entry regarding databinding, we learned how to create a custom observable for a DateTime widget. Starting with Eclipse 3.5 there is a new approach to creating custom observables as described by Matthew Hall in the comments to that post. Which ever way you choose, we will now use the observable to [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a title="EclipseSource Blog: A Custom Observable for a Widget" href="http://eclipsesource.com/blogs/2009/02/03/databinding-a-custom-observable-for-your-widget/">last blog entry regarding databinding</a>, we learned how to create a custom observable for a <em>DateTime</em> widget. Starting with Eclipse 3.5 there is a new approach to creating custom observables as described by Matthew Hall in the comments to that post. Which ever way you choose, we will now use the observable to showcase another cool databinding feature: Crossvalidation. Crossvalidation was introduced with Eclipse 3.4 and describes the process of validating one <em>IObservable</em> based on the value or state of another <em>IObservable</em>. A classic example is the input  of a date ranges where the start of the period can not be after the end of the period.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2009/02/databinding-cross-validation.png"><img src="http://eclipsesource.com/blogs/wp-content/uploads/2009/02/databinding-cross-validation-300x91.png" alt="databinding cross validation 300x91 Tip: Validation with a MultiValidator" title="Databinding Cross Validation" width="300" height="91" class="alignnone size-medium wp-image-324" /></a></p>
<p>As we can see on the screenshot above, the status message informs us of a violated validation constrain. So, how is such  kind of crosscutting validation achieved? First of we need some kind of model, to hold the start and end value. Next we need the two DateTime widgets and the corresponding <em>DateTimeObservableValue</em>. The observables can than be tied to the bean model, holding the start and end values. In order to create a crosscutting validation for the dates, we introduce a custom <em>PeriodValidator</em> extending a <em>MultiValidator</em>, which is in fact an implementation of a <em>ValidationStatusProvider</em>.The <em>MultiValidator</em> lets us implement a <em>validate()</em> method, returning an <em>IStatus</em> corresponding to our validation results. Since we are implicitly implementing a <em>ValidationStatusProvider</em>, the state of our validation can be bound to any party interested in the validation result. Here is the implementation of the <em>PeriodValidator</em>, comparing the start and end date (ignore the shortcomings of the <em>Date</em> class):</p>
<pre class="brush: java">
public class PeriodValidator extends MultiValidator {

private final IObservableValue start;
private final IObservableValue end;

public PeriodValidator(final IObservableValue start, final IObservableValue end) {
this.start = start;
this.end = end;
}

@Override
protected IStatus validate() {
Date startDate = (Date) this.start.getValue();
Date endDate = (Date) this.end.getValue();
IStatus status = ValidationStatus.ok();

if ((this.start != null) &amp;&amp; (this.end != null)) {
     if (startDate.after(endDate)) {
          status = ValidationStatus.error(”The start date has to be before the end date.”);
     }
}
return status;
}
}
</pre>
<p>As we can see, there is not much magic going on in the <em>PeriodValidator</em>. Lets have a look at the broader context, in which this <em>MultiValidator</em> is applied. The following code demonstrates the overall setup of the databinding. Note how the validation status (wrapped in an <em>IObservableValue</em>) is obtained from the <em>PeriodValidator</em> and bound to the status <em>Text</em> widget.</p>
<pre class="brush: java">
private void createDatabinding() {

DateTimeObservableValue startObservable = new DateTimeObservableValue(this.dateTimeStart);
DateTimeObservableValue endObservable = new DateTimeObservableValue(this.dateTimeEnd);
DataBindingContext context = new DataBindingContext();

// bind start and end
UpdateValueStrategy modelToTarget = new UpdateValueStrategy(
UpdateValueStrategy.POLICY_UPDATE);
UpdateValueStrategy targetToModel = new UpdateValueStrategy(
UpdateValueStrategy.POLICY_UPDATE);
context.bindValue(
     startObservable,
     BeansObservables.observeValue(this.period,Period.PROP_START), targetToModel, modelToTarget);

context.bindValue(endObservable,
     BeansObservables.observeValue(this.period, Period.PROP_END), targetToModel, modelToTarget);

// bind status
PeriodValidator periodValidator = new PeriodValidator(startObservable, endObservable);
modelToTarget = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
modelToTarget.setConverter(new Converter(IStatus.class, String.class) {

public Object convert(final Object arg) {

if (arg instanceof IStatus) {
     IStatus status = (IStatus) arg;
     return status.getMessage();
}

return null;
}
});

targetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
context.bindValue(
     SWTObservables.observeText(this.status),
     periodValidator.getValidationStatus(), targetToModel, modelToTarget);
}
</pre>
<p>The validation status of the period validator is updated everytime any of the DateTime widgets is changed. In turn the validation message is updated to reflect the validation state.</p>
<p>You can download the the entire project containing the sample snippets <a href="http://eclipsesource.com/blogs/wp-content/uploads/2009/02/orgeclipsesourcedatabindingmultivalidation.zip">here</a>.</p>
<p>Also note that you will need to adjust the elements on the classpath. See the .project file for the required libs.</p>
<p>I hope you found these hints valuable and am looking forward to your comments and suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2009/02/27/databinding-crossvalidation-with-a-multivalidator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Databinding: A Custom Observable for a Widget</title>
		<link>http://eclipsesource.com/blogs/2009/02/03/databinding-a-custom-observable-for-your-widget/</link>
		<comments>http://eclipsesource.com/blogs/2009/02/03/databinding-a-custom-observable-for-your-widget/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 15:41:20 +0000</pubDate>
		<dc:creator>Moritz Post</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[jface]]></category>
		<category><![CDATA[observable]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=289</guid>
		<description><![CDATA[The introduction of the databinding framework in Eclipse 3.3 is with no doubt one of the most useful tools in the hands of the form developer. The ability to transform and validate user input in such a flexible and reusable way is a great enhancement. But where there is light, there is shadow. Sometimes there [...]]]></description>
			<content:encoded><![CDATA[<p>The introduction of the <a href="http://wiki.eclipse.org/index.php/JFace_Data_Binding">databinding framework</a> in Eclipse 3.3 is with no doubt one of the most useful tools in the hands of the form developer. The ability to transform and validate user input in such a flexible and reusable way is a great enhancement. But where there is light, there is shadow. Sometimes there is just no <em>IObservable </em>available for your target or model object. This blog entry will demonstrate how easy it can be to create a custom <em>IObservable </em>for a DateTime widget.</p>
<p>The <em>DateTime </em>widget represents one value: a <em>java.util.Date</em>. This <em>Date </em>object is the one we want to get and set on the target (target being the UI widget). Therefore we wrap the <em>DateTime </em>in an <em>IObservableValue </em>by extending the <em>AbstractObservableValue</em> class. Essentially an <em>IObservable*</em> offers methods to get and set data, to determine the type of data and to register listeners to be notified of changes. The following code demonstrates a skeleton implementation of an <em>IObservableValue</em>.</p>
<pre class="brush: java">
public class DateTimeObservableValue extends AbstractObservableValue {

  private final DateTime dateTime;
  Listener listener = new Listener() { ... };

  public DateTimeObservableValue(final DateTime dateTime) {
    this.dateTime = dateTime;
    this.dateTime.addSelectionListener(this.listener);
  }

  @Override
  protected Object doGetValue() {
    // the utility method creates a Date from the DateTime
    return dateTimeToDate();
  }

  @Override
    protected void doSetValue(final Object value) {
      if (value instanceof Date) {
        // the utility method sets the date on the DateTime
        dateToDateTime((Date) value);
      }
  }

  @Override
    public Object getValueType() {
    return Date.class;
  }

  @Override
    public synchronized void dispose() {
    this.dateTime.removeSelectionListener(this.listener);
    super.dispose();
  }
}
</pre>
<p>The implementation details are not very special. The <em>getValueType() </em>method has to return the type represented by this <em>IObservableValue</em> (which is the type <em>Date</em>). The do methods set and get the <em>Date </em>value. Since the observable has to propagate changes in the <em>DateTime</em> widget as soon as they ocurre, we attach a listener on the <em>DateTime </em>widget to inform any registered <em>IValueChangeListener </em>of the event. The listener implementation looks like the following:</p>
<pre class="brush: java">
Listener listener = new Listener() {

  @Override
  public void handleEvent(final Event event) {
    Date newValue = dateTimeToDate();

    if (!newValue.equals(DateTimeObservableValue.this.oldValue)) {
      fireValueChange(Diffs.createValueDiff(DateTimeObservableValue.this.oldValue, newValue));
      DateTimeObservableValue.this.oldValue = newValue;
    }
  }
};
</pre>
<p>In the <em>DateTime</em> listener we inform any interested <em>IValueChangeListener</em> of our <em>DateTimeObservableValue</em>. In order to avoid unnecessary propagation of update events in the databinding context, we compare the last set <em>Date</em> in the <em>IObservableValue</em> with the new value. Next we create a <em>ValueDiff</em> from our new date value and fire the the value change event. The advantage of listening to the changes in the DateTime widget, is that we are able to fire events which are either invoked by the user changing the DateTime widget or by programmatic changes of the <em>IObservableValue</em>s wrapped <em>Date</em>.</p>
<p>You can download the full listing of the observable class here: <a href='http://eclipsesource.com/blogs/2009/02/03/databinding-a-custom-observable-for-your-widget/datetimeobservablevalue/' rel='attachment wp-att-332'>DateTimeObservableValue.zip</a></p>
<p>As we can see, it is quite easy to write a custom observable for any kind of widget or datastructure, represented by a single value&#8230;  So, how do you embed your data in custom observables? Any obstacles you had to overcome? Problems you faced? Share them with us. <img src='http://eclipsesource.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Databinding: A Custom Observable for a Widget" class='wp-smiley' title="Databinding: A Custom Observable for a Widget" /> </p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2009/02/03/databinding-a-custom-observable-for-your-widget/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

