<?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>Radek's Tech Blog &#187; java</title>
	<atom:link href="http://urbas.tk/index.php/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://urbas.tk</link>
	<description>Radoslaw H. Urbas homepage / blog</description>
	<lastBuildDate>Tue, 01 Jun 2010 20:31:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>JFace Binding</title>
		<link>http://urbas.tk/index.php/2008/07/22/jface-binding/</link>
		<comments>http://urbas.tk/index.php/2008/07/22/jface-binding/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 23:55:52 +0000</pubDate>
		<dc:creator>Radoslaw Urbas</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jface]]></category>
		<category><![CDATA[swt]]></category>

		<guid isPermaLink="false">http://urbas.tk/?p=38</guid>
		<description><![CDATA[Recently I have started using JFace Binding. Unfortunately there are not many resources available on the web with non-trivial examples. Let present example of master-detail view: a drop-down list and two text fields which display some details regarding option chosen from the list. POJO Category. It contains two fields: name and description which will be [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have started using JFace Binding. Unfortunately there are not many resources available on the web with non-trivial examples.</p>
<p>Let present example of master-detail view: a drop-down list and two text fields which display some details regarding option chosen from the list.</p>
<p>POJO Category. It contains two fields: name and description which will be displayed as details of the object chosen from the drop-down list:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.beans.PropertyChangeListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Domain object representing category
*
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Category <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>5542167952605551865L<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> description<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Default constructor
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> Category<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Do nothing</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Constructor
*
* @param name
*            name of a category
* @param description
*            description of a category
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> Category<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name, <span style="color: #003399;">String</span> description<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> name<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">description</span> <span style="color: #339933;">=</span> description<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @return the name
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> name<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param name the name to set
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> name<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @return the description
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getDescription<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> description<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param description the description to set
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDescription<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> description<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">description</span> <span style="color: #339933;">=</span> description<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Class of model that will be used to bind the data to the view:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Model for displaying categories
*
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CategoriesModel <span style="color: #000000; font-weight: bold;">extends</span> AbstractModelObject <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Category<span style="color: #339933;">&gt;</span> categories<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> IDataManager dataManager<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> Category category<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* The constructor
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> CategoriesModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dataManager</span> <span style="color: #339933;">=</span> <span style="color: #003399;">Activator</span>.<span style="color: #006633;">getDataManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">categories</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dataManager</span>.<span style="color: #006633;">getAllCategories</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @return the category
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> Category getCategory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">category</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param category
*            the category to set
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setCategory<span style="color: #009900;">&#40;</span>Category category<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">category</span> <span style="color: #339933;">=</span> category<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @return the categories
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Category<span style="color: #339933;">&gt;</span> getCategories<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> categories<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param categories the categories to set
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setCategories<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Category<span style="color: #339933;">&gt;</span> categories<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">categories</span> <span style="color: #339933;">=</span> categories<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Class of view (in this case it is Eclipse View containing managed form):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.databinding.DataBindingContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.databinding.UpdateValueStrategy</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.databinding.beans.BeansObservables</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.databinding.observable.Realm</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.databinding.observable.list.WritableList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.databinding.observable.map.IObservableMap</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.databinding.observable.value.IObservableValue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jface.databinding.swt.SWTObservables</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jface.databinding.viewers.ObservableListContentProvider</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jface.databinding.viewers.ViewersObservables</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jface.viewers.ComboViewer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.SWT</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.layout.GridData</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.layout.GridLayout</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Composite</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Text</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.ui.forms.ManagedForm</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.ui.forms.widgets.FormToolkit</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.ui.forms.widgets.ScrolledForm</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.ui.part.ViewPart</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Allows to view list of categories and their details
*
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CategoryView <span style="color: #000000; font-weight: bold;">extends</span> ViewPart <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>CategoryView.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> FORM_TITLE <span style="color: #339933;">=</span> Messages
.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;category.view.form.title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> FormToolkit formToolkit<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> CategoriesModel model<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> Text nameText<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> Text descriptionText<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> ComboViewer categoriesComboViewer<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> DataBindingContext dbc<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* {@inheritDoc}
*/</span>
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> createPartControl<span style="color: #009900;">&#40;</span><span style="color: #003399;">Composite</span> parent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
model <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CategoriesModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ManagedForm mForm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ManagedForm<span style="color: #009900;">&#40;</span>parent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ScrolledForm scrolledForm <span style="color: #339933;">=</span> mForm.<span style="color: #006633;">getForm</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
FormToolkit formToolkit <span style="color: #339933;">=</span> mForm.<span style="color: #006633;">getToolkit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Composite</span> formBody <span style="color: #339933;">=</span> scrolledForm.<span style="color: #006633;">getBody</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
formToolkit.<span style="color: #006633;">decorateFormHeading</span><span style="color: #009900;">&#40;</span>scrolledForm.<span style="color: #006633;">getForm</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
scrolledForm.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>FORM_TITLE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
formBody.<span style="color: #006633;">setLayout</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">GridLayout</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
categoriesComboViewer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ComboViewer<span style="color: #009900;">&#40;</span>formBody, SWT.<span style="color: #006633;">DROP_DOWN</span>
<span style="color: #339933;">|</span> SWT.<span style="color: #006633;">READ_ONLY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
GridData comboGridData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GridData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
comboGridData.<span style="color: #006633;">horizontalSpan</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
comboGridData.<span style="color: #006633;">horizontalAlignment</span> <span style="color: #339933;">=</span> GridData.<span style="color: #006633;">FILL</span><span style="color: #339933;">;</span>
categoriesComboViewer.<span style="color: #006633;">getCombo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setLayoutData</span><span style="color: #009900;">&#40;</span>comboGridData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
nameText <span style="color: #339933;">=</span> formToolkit.<span style="color: #006633;">createText</span><span style="color: #009900;">&#40;</span>formBody, <span style="color: #0000ff;">&quot;&quot;</span>, SWT.<span style="color: #006633;">NONE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
GridData nameGridData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GridData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
nameGridData.<span style="color: #006633;">horizontalSpan</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
nameGridData.<span style="color: #006633;">horizontalAlignment</span> <span style="color: #339933;">=</span> GridData.<span style="color: #006633;">FILL</span><span style="color: #339933;">;</span>
nameText.<span style="color: #006633;">setLayoutData</span><span style="color: #009900;">&#40;</span>nameGridData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
descriptionText <span style="color: #339933;">=</span> formToolkit.<span style="color: #006633;">createText</span><span style="color: #009900;">&#40;</span>formBody, <span style="color: #0000ff;">&quot;&quot;</span>, SWT.<span style="color: #006633;">MULTI</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
GridData textGridData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GridData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
textGridData.<span style="color: #006633;">horizontalSpan</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
textGridData.<span style="color: #006633;">horizontalAlignment</span> <span style="color: #339933;">=</span> GridData.<span style="color: #006633;">FILL</span><span style="color: #339933;">;</span>
textGridData.<span style="color: #006633;">heightHint</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
descriptionText.<span style="color: #006633;">setLayoutData</span><span style="color: #009900;">&#40;</span>textGridData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
formToolkit.<span style="color: #006633;">paintBordersFor</span><span style="color: #009900;">&#40;</span>formBody<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bindData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* {@inheritDoc}
*/</span>
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setFocus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Do nothing</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* This method binds the value from UI layer to the model object
*/</span>
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> bindData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
dbc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DataBindingContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Seting content provider for combo viewer</span>
ObservableListContentProvider categoryViewerContentProvider <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObservableListContentProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
categoriesComboViewer.<span style="color: #006633;">setContentProvider</span><span style="color: #009900;">&#40;</span>categoryViewerContentProvider<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
IObservableMap<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> attributeMaps <span style="color: #339933;">=</span> BeansObservables.<span style="color: #006633;">observeMaps</span><span style="color: #009900;">&#40;</span>
categoryViewerContentProvider.<span style="color: #006633;">getKnownElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
Category.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;name&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
categoriesComboViewer.<span style="color: #006633;">setLabelProvider</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ObservableMapLabelProvider<span style="color: #009900;">&#40;</span>
attributeMaps<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
categoriesComboViewer.<span style="color: #006633;">setInput</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> WritableList<span style="color: #009900;">&#40;</span>model.<span style="color: #006633;">getCategories</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
Category.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Observing changes in selection in combo viewer</span>
IObservableValue selection <span style="color: #339933;">=</span> ViewersObservables
.<span style="color: #006633;">observeSingleSelection</span><span style="color: #009900;">&#40;</span>categoriesComboViewer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Observing the properties of the current selection</span>
IObservableValue detailNameObservable <span style="color: #339933;">=</span> BeansObservables
.<span style="color: #006633;">observeDetailValue</span><span style="color: #009900;">&#40;</span>Realm.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, selection, <span style="color: #0000ff;">&quot;name&quot;</span>,
<span style="color: #003399;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
IObservableValue detailDescriptionObservable <span style="color: #339933;">=</span> BeansObservables
.<span style="color: #006633;">observeDetailValue</span><span style="color: #009900;">&#40;</span>Realm.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, selection,
<span style="color: #0000ff;">&quot;description&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Binding the Text widgets to the name and description details</span>
<span style="color: #666666; font-style: italic;">// (selection's properties).</span>
dbc.<span style="color: #006633;">bindValue</span><span style="color: #009900;">&#40;</span>SWTObservables.<span style="color: #006633;">observeText</span><span style="color: #009900;">&#40;</span>nameText, SWT.<span style="color: #006633;">None</span><span style="color: #009900;">&#41;</span>,
detailNameObservable, <span style="color: #000000; font-weight: bold;">new</span> UpdateValueStrategy<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span>,
UpdateValueStrategy.<span style="color: #006633;">POLICY_NEVER</span><span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
dbc.<span style="color: #006633;">bindValue</span><span style="color: #009900;">&#40;</span>SWTObservables.<span style="color: #006633;">observeText</span><span style="color: #009900;">&#40;</span>descriptionText, SWT.<span style="color: #006633;">None</span><span style="color: #009900;">&#41;</span>,
detailDescriptionObservable, <span style="color: #000000; font-weight: bold;">new</span> UpdateValueStrategy<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span>,
UpdateValueStrategy.<span style="color: #006633;">POLICY_NEVER</span><span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* {@inheritDoc}
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> dispose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>formToolkit <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
formToolkit.<span style="color: #006633;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>AbstractModelObject which provides methods required by JFace Binding (it&#8217;s not checked on compilation level):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.beans.PropertyChangeListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.beans.PropertyChangeSupport</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Provides minimal JavaBeans support for model objects
*
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractModelObject <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">PropertyChangeSupport</span> propertyChangeSupport <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">PropertyChangeSupport</span><span style="color: #009900;">&#40;</span>
<span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param listener
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addPropertyChangeListener<span style="color: #009900;">&#40;</span><span style="color: #003399;">PropertyChangeListener</span> listener<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
propertyChangeSupport.<span style="color: #006633;">addPropertyChangeListener</span><span style="color: #009900;">&#40;</span>listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param propertyName
* @param listener
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addPropertyChangeListener<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> propertyName,
<span style="color: #003399;">PropertyChangeListener</span> listener<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
propertyChangeSupport.<span style="color: #006633;">addPropertyChangeListener</span><span style="color: #009900;">&#40;</span>propertyName, listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param listener
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removePropertyChangeListener<span style="color: #009900;">&#40;</span><span style="color: #003399;">PropertyChangeListener</span> listener<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
propertyChangeSupport.<span style="color: #006633;">removePropertyChangeListener</span><span style="color: #009900;">&#40;</span>listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param propertyName
* @param listener
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removePropertyChangeListener<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> propertyName,
<span style="color: #003399;">PropertyChangeListener</span> listener<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
propertyChangeSupport.<span style="color: #006633;">removePropertyChangeListener</span><span style="color: #009900;">&#40;</span>propertyName,
listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
*
* @param propertyName
* @param oldValue
* @param newValue
*/</span>
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> firePropertyChange<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> propertyName, <span style="color: #003399;">Object</span> oldValue,
<span style="color: #003399;">Object</span> newValue<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
propertyChangeSupport.<span style="color: #006633;">firePropertyChange</span><span style="color: #009900;">&#40;</span>propertyName, oldValue,
newValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://urbas.tk/index.php/2008/07/22/jface-binding/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Netbeans 6.0 Mobility &#8211; FileBrowser</title>
		<link>http://urbas.tk/index.php/2007/12/17/netbeans-60-mobility-filebrowser/</link>
		<comments>http://urbas.tk/index.php/2007/12/17/netbeans-60-mobility-filebrowser/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 21:55:00 +0000</pubDate>
		<dc:creator>Radoslaw Urbas</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jme]]></category>
		<category><![CDATA[jsr 75]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://urbas.tk/?p=16</guid>
		<description><![CDATA[Netbeans 6.0 gives really nice support for developing Java Micro Edition applications. It provides some useful classes which are not part of standard JME profiles. One of them is class: org.netbeans.microedition.lcdui.pda.FileBrowser. It provides file browser for mobile phone implementing JSR-75. It looks fine but there is a bug in it. Method getSelectedFileURL() returns incorrect value, [...]]]></description>
			<content:encoded><![CDATA[<p>Netbeans 6.0 gives really nice support for developing Java Micro Edition applications. It provides some useful classes which are not part of standard JME profiles.<br />
One of them is class: <span style="font-size: 100%"><span style="font-family: courier new; font-weight: bold">org.netbeans.microedition.lcdui.pda.FileBrowser</span>.<span style="font-weight: bold"> </span></span><br />
It provides file browser for mobile phone implementing JSR-75. It looks fine but there is a bug in it. Method <span style="font-weight: bold; font-family: courier new; font-size: 100%">getSelectedFileURL()</span> returns incorrect value, e.g.: <span style="font-family: courier new; font-size: 100%"><span style="font-weight: bold">file:///E:/myfolder<span style="color: #ff0000">//myfile.mp3 </span></span></span>instead of <span style="font-family: courier new; font-size: 100%"><span style="font-weight: bold">file:///E:/myfolder<span style="color: #ff0000">/myfile.mp3</span></span></span><br />
Removing manually last extra slash fixes the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://urbas.tk/index.php/2007/12/17/netbeans-60-mobility-filebrowser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spring remoting quickstart</title>
		<link>http://urbas.tk/index.php/2007/09/25/spring-remoting-quickstart/</link>
		<comments>http://urbas.tk/index.php/2007/09/25/spring-remoting-quickstart/#comments</comments>
		<pubDate>Tue, 25 Sep 2007 08:17:00 +0000</pubDate>
		<dc:creator>Radoslaw Urbas</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[remoting]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://urbas.tk/?p=14</guid>
		<description><![CDATA[I have spent a lot of time on configuring Spring remoting properly (mostly because of problems with DTD). To expose business logic via for example XFire Web Services we have to define context and listeners in web.xml, example: &#60;?xml version=&#8221;1.0&#8243; encoding=&#8221;ISO-8859-1&#8243;?&#62; &#60;!DOCTYPE web-app PUBLIC &#8220;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&#8221; &#8220;http://java.sun.com/dtd/web-app_2_3.dtd&#8221;&#62; &#60;web-app&#62; &#60;context-param&#62; &#60;param-name&#62;contextConfigLocation&#60;/param-name&#62; &#60;param-value&#62;/WEB-INF/applicationContext.xml&#60;/param-value&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I have spent a lot of time on configuring Spring remoting properly (mostly because of problems with DTD).<br />
To expose business logic via for example XFire Web Services we have to define context and listeners in web.xml, example:</p>
<p><span style="font-size: 85%"><span style="font-family: courier new">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;ISO-8859-1&#8243;?&gt;<br />
</span><span style="color: #ff0000; font-family: courier new">&lt;!DOCTYPE web-app<br />
PUBLIC &#8220;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&#8221;</span><br />
<span style="font-family: courier new"><span style="color: #ff0000">&#8220;http://java.sun.com/dtd/web-app_2_3.dtd&#8221;&gt;</span><br />
</span><span style="font-family: courier new">&lt;web-app&gt;<br />
</span><span style="font-family: courier new">&lt;context-param&gt;<br />
</span><span style="color: #ff0000; font-family: courier new">&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;</span><br />
<span style="color: #ff0000; font-family: courier new">        &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;<br />
</span><span style="font-family: courier new"><span style="color: #ff0000">&lt;/context-param&gt;</span><br />
</span><span style="font-family: courier new">&lt;context-param&gt;<br />
</span><span style="font-family: courier new">&lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;</span><br />
<span style="font-family: courier new">        &lt;param-value&gt;/WEB-INF/log4j.properties&lt;/param-value&gt;<br />
</span><span style="font-family: courier new">&lt;/context-param&gt;<br />
</span><span style="font-family: courier new">&lt;listener&gt;<br />
</span><span style="font-family: courier new">&lt;listener-class&gt;</span><br />
<span style="font-family: courier new">            org.springframework.web.util.Log4jConfigListener</span><br />
<span style="font-family: courier new">        &lt;/listener-class&gt;<br />
</span><span style="color: #ff0000; font-family: courier new"><span style="color: #000000">&lt;/listener&gt;</span><br />
&lt;listener&gt;<br />
&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;</span><br />
<span style="color: #ff0000; font-family: courier new">&lt;/listener&gt;</span><br />
<span style="font-family: courier new">&lt;servlet&gt;</span><br />
<span style="font-family: courier new">&lt;servlet-name&gt;XFireServlet&lt;/servlet-name&gt;</span><br />
<span style="font-family: courier new">&lt;servlet-class&gt;org.codehaus.xfire.spring.XFireSpringServlet&lt;/servlet-class&gt;</span><br />
<span style="font-family: courier new">&lt;/servlet&gt;</span><br />
<span style="font-family: courier new">&lt;servlet-mapping&gt;</span><br />
<span style="font-family: courier new">&lt;servlet-name&gt;XFireServlet&lt;/servlet-name&gt;</span><br />
<span style="font-family: courier new">&lt;url-pattern&gt;/servlet/XFireServlet/*&lt;/url-pattern&gt;</span><br />
<span style="font-family: courier new">&lt;/servlet-mapping&gt;</span><br />
<span style="font-family: courier new"><span style="color: #ff0000">&lt;servlet-mapping&gt;</span></span><br />
<span style="color: #ff0000; font-family: courier new">&lt;servlet-name&gt;XFireServlet&lt;/servlet-name&gt;</span><br />
<span style="color: #ff0000; font-family: courier new">&lt;url-pattern&gt;/services/*&lt;/url-pattern&gt;</span><br />
<span style="color: #ff0000; font-family: courier new">&lt;/servlet-mapping&gt;</span><br />
<span style="font-family: courier new">&lt;/web-app&gt;</span><br />
</span><br />
Configuration of beans that are going to be exposed via WS is stored in separate file, in this case in applicationContext.xml. Example of  the content of the file:</p>
<p><span style="font-size: 85%"><span style="font-family: courier new">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
</span><span style="color: #ff0000; font-family: courier new">&lt;!DOCTYPE beans PUBLIC &#8220;-//SPRING//DTD BEAN//EN&#8221; &#8220;http://www.springframework.org/dtd/spring-beans-2.0.dtd&#8221;&gt;</span><br />
<span style="font-family: courier new">&lt;beans&gt;</span><br />
<span style="font-family: courier new">&lt;bean class=&#8221;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&#8221;&gt;</span><br />
<span style="font-family: courier new">        &lt;property name=&#8221;urlMap&#8221;&gt;</span><br />
<span style="font-family: courier new">&lt;map&gt;<br />
</span><span style="color: #ff0000; font-family: courier new">&lt;entry key=&#8221;/WorkflowRegister&#8221;&gt;</span><br />
<span style="color: #ff0000; font-family: courier new">                    &lt;ref bean=&#8221;workflowRegister&#8221;/&gt;</span><br />
<span style="font-family: courier new"><span style="color: #ff0000">                &lt;/entry&gt;</span><br />
</span><span style="font-family: courier new">            &lt;/map&gt;<br />
</span><span style="font-family: courier new">&lt;/property&gt;<br />
</span><span style="font-family: courier new">&lt;/bean&gt;</span><br />
<span style="color: #ff0000; font-family: courier new">&lt;bean id=&#8221;workflowRegister&#8221; <span style="color: #000000">class=&#8221;org.codehaus.xfire.spring.remoting.XFireExporter&#8221;&gt;</span></span><br />
<span style="font-family: courier new">&lt;property name=&#8221;serviceFactory&#8221;&gt;</span><br />
<span style="font-family: courier new">            &lt;ref bean=&#8221;xfire.serviceFactory&#8221;/&gt;</span><br />
<span style="font-family: courier new">        &lt;/property&gt;</span><br />
<span style="font-family: courier new">&lt;property name=&#8221;xfire&#8221;&gt;</span><br />
<span style="font-family: courier new">            &lt;ref bean=&#8221;xfire&#8221;/&gt;</span><br />
<span style="font-family: courier new">        &lt;/property&gt;</span><br />
<span style="font-family: courier new"><span style="color: #ff0000">&lt;property name=&#8221;serviceBean&#8221;&gt;</span></span><br />
<span style="color: #ff0000; font-family: courier new">            &lt;ref bean=&#8221;worklfowRegisterBean&#8221;/&gt;</span><br />
<span style="color: #ff0000; font-family: courier new">        &lt;/property&gt;</span><br />
<span style="color: #000000; font-family: courier new">&lt;property name=&#8221;serviceClass&#8221;&gt;</span><br />
<span style="color: #000000; font-family: courier new">            &lt;value&gt;pl.edu.agh.gemini.adds.core.IWorkflowRegister&lt;/value&gt;</span><br />
<span style="color: #000000; font-family: courier new">        &lt;/property&gt;</span><br />
<span style="font-family: courier new">&lt;/bean&gt;</span><br />
<span style="font-family: courier new"><span style="color: #ff0000">&lt;bean id=&#8221;worklfowRegisterBean&#8221; class=&#8221;pl.edu.agh.gemini.adds.core.WorkflowRegister&#8221; factory-method=&#8221;getInstance&#8221; /&gt;</span></span><br />
<span style="font-family: courier new">&lt;import resource=&#8221;classpath:org/codehaus/xfire/spring/xfire.xml&#8221;/&gt; </span><br />
<span style="font-family: courier new">&lt;/beans&gt;</span><br />
</span><br />
As you can see defining new WS which is based on already implemented bean requires just few lines of XML. Business logic is totally separated from the way of exposing it. No changes are required in logic to expose it as Web Service! Also changing transport layer from XFire to e.g. Burlap/Hessian/RMI is just a matter of configuration in those two files.</p>
<p>Dependencies for Spring remoting (part of Maven pom.xml):<br />
<span style="font-size: 85%"><span style="font-family: courier new"><br />
&lt;dependencies&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;pl.edu.agh.gemini.adss&lt;/groupId&gt;<br />
&lt;artifactId&gt;adsscore&lt;/artifactId&gt;<br />
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;pl.edu.agh.gemini.adss&lt;/groupId&gt;<br />
&lt;artifactId&gt;adsscoreapi&lt;/artifactId&gt;<br />
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;org.springframework&lt;/groupId&gt;<br />
&lt;artifactId&gt;spring-remoting&lt;/artifactId&gt;<br />
&lt;version&gt;2.0.6&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;org.codehaus.xfire&lt;/groupId&gt;<br />
&lt;artifactId&gt;xfire-jaxb2&lt;/artifactId&gt;<br />
&lt;version&gt;1.2-RC&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;org.codehaus.xfire&lt;/groupId&gt;<br />
&lt;artifactId&gt;xfire-spring&lt;/artifactId&gt;<br />
&lt;version&gt;1.2-RC&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;org.codehaus.xfire&lt;/groupId&gt;<br />
&lt;artifactId&gt;xfire-java5&lt;/artifactId&gt;<br />
&lt;version&gt;1.2-RC&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;/dependencies&gt;</span></span></p>
<p>Application can be simply deployed as war file in servlet container (e.g. Tomcat), no J2EE application server is required.</p>
<p>Have fun with Spring remoting!</p>
]]></content:encoded>
			<wfw:commentRss>http://urbas.tk/index.php/2007/09/25/spring-remoting-quickstart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Injecting EJB 3.0 beans into Struts 2.0</title>
		<link>http://urbas.tk/index.php/2007/05/04/injecting-ejb-30-beans-into-struts-20/</link>
		<comments>http://urbas.tk/index.php/2007/05/04/injecting-ejb-30-beans-into-struts-20/#comments</comments>
		<pubDate>Thu, 03 May 2007 23:49:00 +0000</pubDate>
		<dc:creator>Radoslaw Urbas</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[inversion of control]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://urbas.tk/?p=10</guid>
		<description><![CDATA[EJB 3.0 provides easy bean injection. While developing web layer in Struts 2.0 you can use similar mechanism as well. Struts 2.0 is using Spring libraries for implementing Inversion of Control design pattern. EJB 3.0 is based on using Java 1.5 annotations. It simplifies deployment process. Let define example Session Bean. @Stateless(mappedName=&#8221;ejb/EmployeeManager&#8221;) public class EmployeeManagerSB [...]]]></description>
			<content:encoded><![CDATA[<p>EJB 3.0 provides easy bean injection. While developing web layer in Struts 2.0 you can use similar mechanism as well. Struts 2.0 is using Spring libraries for implementing Inversion of Control design pattern.</p>
<p>EJB 3.0 is based on using Java 1.5 annotations. It simplifies deployment process.</p>
<p>Let define example Session Bean.</p>
<p><span style="font-size: 85%"><span style="font-family: courier new"><span style="color: #ff0000">@Stateless(mappedName=&#8221;ejb/EmployeeManager&#8221;)</span><br />
</span><span style="font-family: courier new">public class EmployeeManagerSB implements <span style="color: #ff0000">IEmployeeManager</span> {</span></span></p>
<p><span style="font-family: courier new">public Long createAccount(String loginName) {<br />
</span><span style="font-family: courier new">// Implementation of creating an account&#8230;<br />
</span><span style="font-family: courier new">}</span></p>
<p>}</p>
<p>It implements interface:</p>
<p><span style="font-size: 85%"><span style="font-family: courier new">@Remote<br />
</span><span style="font-family: courier new">@Local</span></span><br />
<span style="font-size: 85%"><span style="font-family: courier new">public interface <span style="color: #ff0000">IEmployeeManager</span> {</span></span></p>
<p><span style="font-family: courier new">Long createAccount(String loginName);<br />
</span><span style="font-family: courier new"><br />
}</span></p>
<p>To use EmployeeManager session bean in Struts 2.0 reference to this object has to be retrieved.</p>
<p>Let define Struts action class which will use EmployeeManager session bean.</p>
<p><span style="font-size: 85%"><span style="font-family: courier new">@Validation()<br />
</span><span style="font-family: courier new">public class NewEmployeeAction extends ActionSupport {</span></span></p>
<p><span style="color: #ff0000; font-family: courier new">private IEmployeeManager employeeManager;<br />
</span><span style="font-family: courier new">private String loginName;<br />
</span><span style="font-family: courier new">private long id;<br />
</span><span style="font-family: courier new">private String redirectURL;</span></p>
<p><span style="font-family: courier new">public String execute() throws Exception {</span><span style="font-family: courier new"><br />
Long id = <span style="color: #ff0000">this.employeeManager.createAccount(this.loginName);<br />
</span></span><span style="font-family: courier new">this.setId(id.longValue());<br />
</span><span style="font-family: courier new">return SUCCESS;<br />
</span><span style="font-family: courier new">}</span><span style="font-family: courier new"></span></p>
<p>public IEmployeeManager getEmployeeManager() {<br />
<span style="font-family: courier new">return employeeManager;<br />
</span><span style="font-family: courier new">}</span></p>
<p><span style="color: #ff0000; font-family: courier new">public void setEmployeeanager(IEmployeeManager employeeManager) {<br />
</span><span style="color: #ff0000; font-family: courier new">this.employeeManager = employeeManager;<br />
</span><span style="color: #ff0000; font-family: courier new">}</span></p>
<p><span style="font-family: courier new">public String getLoginName() {<br />
</span><span style="font-family: courier new">return loginName;<br />
</span><span style="font-family: courier new">}</span></p>
<p><span style="font-family: courier new">@RequiredStringValidator(message = &#8220;Please enter a login name&#8221;, trim = true)<br />
</span><span style="font-family: courier new">public void setLoginName(String loginName) {<br />
</span><span style="font-family: courier new">this.loginName = loginName;<br />
</span><span style="font-family: courier new">}</span></p>
<p><span style="font-family: courier new">public long getId() {<br />
</span><span style="font-family: courier new">return id;<br />
</span><span style="font-family: courier new">}</span></p>
<p><span style="font-family: courier new">public String getRedirectURL() {<br />
</span><span style="font-family: courier new">return redirectURL;<br />
</span><span style="font-family: courier new">}</span></p>
<p><span style="font-family: courier new">public void setRedirectURL(String redirectURL) {<br />
</span><span style="font-family: courier new">this.redirectURL = redirectURL;<br />
</span><span style="font-family: courier new">}</span></p>
<p><span style="font-family: courier new">}</span></p>
<p>Framework is taking care of injecting proper object while creating this action object. In Struts 2.0 the only thing that has to be done to do this is defining it in applicationContext.xml configuration file.</p>
<p><span style="font-size: 85%"><span style="font-family: courier new">&lt;jee:jndi-lookup <span style="color: #ff0000">id=&#8221;employeeManager&#8221; name=&#8221;ejb/EmployeeManager</span>&#8220;&gt;</span></span></p>
<p><span style="font-family: courier new">&lt;bean id=&#8221;newEmployeeAction&#8221; class=&#8221;pl.edu.agh.sius2007.jspynet.struts.NewEmployeeAction&#8221;&gt;</span><br />
<span style="color: #ff0000; font-family: courier new">&lt;property name=&#8221;employeeManager&#8221; ref=&#8221;employeeManager&#8221;&gt;</span><br />
<span style="font-family: courier new">&lt;/bean&gt;</span></p>
<p>The only configuration in Struts is defining two beans.</p>
<ul>
<li>employeeManager which will be retrieved from JNDI;</li>
<li>newEmployeeAction which is Struts action.</li>
</ul>
<p>employeeManager bean will be retrieved automatically and injected into newEmployeeAction.</p>
]]></content:encoded>
			<wfw:commentRss>http://urbas.tk/index.php/2007/05/04/injecting-ejb-30-beans-into-struts-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
