<?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>Blog @ SIB Visions &#187; API</title>
	<atom:link href="http://blog.sibvisions.com/category/dev/api/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.sibvisions.com</link>
	<description>Blog @ SIB Visions</description>
	<lastBuildDate>Mon, 30 Mar 2026 11:14:36 +0000</lastBuildDate>
		<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JVx&#039; REST interface Update for JVx 2.8</title>
		<link>https://blog.sibvisions.com/2018/10/30/jvx-rest-interface-update-for-jvx-2-8/</link>
		<comments>https://blog.sibvisions.com/2018/10/30/jvx-rest-interface-update-for-jvx-2-8/#comments</comments>
		<pubDate>Tue, 30 Oct 2018 14:23:34 +0000</pubDate>
		<dc:creator>rjahn</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">https://blog.sibvisions.com/?p=8143</guid>
		<description><![CDATA[Our generic REST interface in JVx is well documented and different examples for different technologies are available. The generic approach itself is smart but not super specific because the implementation follows the CoC paradigm. It's awesome for "REST out-of-the-box" without additional coding effort, but the flexibility is sometimes missing.
We tried to break some of this [...]]]></description>
			<content:encoded><![CDATA[<p>Our generic REST interface in JVx is well <a href="http://doc.sibvisions.com/jvx/common/util/rest">documented</a> and <a href="http://doc.sibvisions.com/jvx/home">different examples</a> for different technologies are available. The generic approach itself is smart but not super specific because the implementation follows the <a href="https://en.wikipedia.org/wiki/Convention_over_configuration">CoC</a> paradigm. It's awesome for "REST out-of-the-box" without additional coding effort, but the flexibility is sometimes missing.</p>
<p>We tried to break some of this restrictions and get more flexibility. Here is a list of new features to explain some details:</p>
<ul>
<li><strong>Fetch on demand</strong>
<p>The old implementation always returned all records from the database. It wasn't possible to implement paging or lazy loading. To solve this problem, we introduced new request parameters:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">_firstRow<br />
_maxRows</div>
</div>
<p>With _firstRow (starts from 0) you define the start record number. The _maxRows defines the amount of records for the resultset, e.g. start from 0 and return max. 20 records, start from 20 and return 20 records
</li>
<li><strong>Configure visible columns</strong>
<p>The old implementation returned the same column list for the REST call and the GUI/frontend. But sometimes the REST call should return a different list of columns because some internal columns aren't relevant or should be hidden. The new implementation got a new property in the metadata object: <strong>visibleColumnNames</strong>. If you set this property, the REST interface will return only the configure columns. The GUI won't recognize the new property because GUI controls have own visible column properties.</li>
<li><strong>Actions with Array parameters</strong>
<p>The old implementation didn't support simple Arrays like <strong>BigDecimal[]</strong> as parameter types for action calls. Only <strong>List<BigDecimal></strong> was supported. The new implementation supports Arrays but it's not possible to mix Array and List parameters. An example:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="co1">//valid</span><br />
<span class="kw1">public</span> <span class="kw3">String</span> createPerson<span class="br0">&#40;</span><span class="kw3">String</span><span class="br0">&#91;</span><span class="br0">&#93;</span> name, <span class="kw3">String</span><span class="br0">&#91;</span><span class="br0">&#93;</span> title<span class="br0">&#41;</span><br />
<span class="co1">//valid</span><br />
<span class="kw1">public</span> <span class="kw3">String</span> createPerson<span class="br0">&#40;</span>List<span class="sy0">&lt;</span>String<span class="sy0">&gt;</span> name, List<span class="sy0">&lt;</span>String<span class="sy0">&gt;</span> title<span class="br0">&#41;</span><br />
<span class="co1">//invalid</span><br />
<span class="kw1">public</span> <span class="kw3">String</span> createPerson<span class="br0">&#40;</span><span class="kw3">String</span><span class="br0">&#91;</span><span class="br0">&#93;</span> name, List<span class="sy0">&lt;</span>String<span class="sy0">&gt;</span> title<span class="br0">&#41;</span></div>
</div>
</li>
<li><strong>New admin zone</strong>
<p>We introduced a new admin zone for generic admin options. The URLs are:</p>
<div class="codesnip-container" >
<div class="html4strict codesnip" style="font-family:monospace;">http://.../services/rest/APPLICATION_NAME/_admin/ACTION_NAME<br />
http://.../services/rest/APPLICATION_NAME/_admin/ACTION_NAME/ACTION_PARAM</div>
</div>
<p>Currently, we support following actions (POST requests): changePassword, testAuthentication</p>
<p>The request needs a JSON object with username, oldpassword, newpassword or password properties.</li>
<li><strong>Configurable zones</strong>
<p>We now allow custom zones. The current default zones are:</p>
<div class="codesnip-container" >
<div class="html4strict codesnip" style="font-family:monospace;">http://.../services/rest/APPLICATION_NAME/_admin/...<br />
http://.../services/rest/APPLICATION_NAME/LIFECYCLE_CLASS/data/OBJECT_NAME/...<br />
http://.../services/rest/APPLICATION_NAME/LIFECYCLE_CLASS/action/ACTION_NAME/...<br />
http://.../services/rest/APPLICATION_NAME/LIFECYCLE_CLASS/object/OBJECT_NAME/...</div>
</div>
<p>The zone names are: <strong>_admin</strong>, <strong>data</strong>, <strong>action, object</strong><br />
It's possible to set custom names with following parameters in the deployment descriptor: <strong>zone.admin</strong>, <strong>zone.data</strong>, <strong>zone.action</strong>, <strong>zone.object</strong></li>
<li><strong>Hide object names</strong>
<p>If you want to hide the object name(s), e.g.</p>
<div class="codesnip-container" >
<div class="html4strict codesnip" style="font-family:monospace;">https://.../demoerp/services/rest/DemoERP/Customers/data/customer/</div>
</div>
<p>The URL contains the Lifecycle Name (Customers) and the object name (customer). Both are easy to understand. In this example, we return the customer list from our customers object. If you want to use different names, it's possible to change the name in the lifecycle object code, e.g.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">@Replacement<span class="br0">&#40;</span>name<span class="sy0">=</span><span class="st0">&quot;business&quot;</span><span class="br0">&#41;</span><br />
<span class="kw1">public</span> <span class="kw1">class</span> Customers <span class="kw1">extends</span> Session<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; @Replacement<span class="br0">&#40;</span>name<span class="sy0">=</span><span class="st0">&quot;clist&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> IStorage getCustomer<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>With above code, it'll be possible to request:</p>
<div class="codesnip-container" >
<div class="html4strict codesnip" style="font-family:monospace;">https://.../demoerp/services/rest/DemoERP/business/data/clist/</div>
</div>
</li>
</ul>
<p>The updated implementation is still a generic solution but it's now more flexible than before and should help you to offer new services. To use the new features, simply use our nightly <a href="https://dev.sibvisions.com/jvx.nightly/">JVx builds</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2018/10/30/jvx-rest-interface-update-for-jvx-2-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JVx Reference, the FormLayout</title>
		<link>https://blog.sibvisions.com/2017/11/15/jvx-reference-the-formlayout/</link>
		<comments>https://blog.sibvisions.com/2017/11/15/jvx-reference-the-formlayout/#comments</comments>
		<pubDate>Wed, 15 Nov 2017 09:42:23 +0000</pubDate>
		<dc:creator>rzenz</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[JVx Reference]]></category>

		<guid isPermaLink="false">https://blog.sibvisions.com/?p=7334</guid>
		<description><![CDATA[Let's talk about the FormLayout, and why the anchor system makes it much more flexible than just a simple grid.
Basics
JVx comes with 5 layouts by default:

null/none/manual
BorderLayout
FlowLayout
GridLayout
FormLayout

From these five the first four are easily explained, only the FormLayout needs some more information because it might not be as easy to grasp in the first moment than [...]]]></description>
			<content:encoded><![CDATA[<p>Let's talk about the <a href="http://forum.sibvisions.com/viewtopic.php?f=11&amp;t=167&amp;p=219">FormLayout</a>, and why the anchor system makes it much more flexible than just a simple grid.</p>
<h3 style="padding-top: 10px">Basics</h3>
<p>JVx comes with 5 layouts by default:</p>
<ul>
<li>null/none/manual</li>
<li>BorderLayout</li>
<li>FlowLayout</li>
<li>GridLayout</li>
<li>FormLayout</li>
</ul>
<p>From these five the first four are easily explained, only the FormLayout needs some more information because it might not be as easy to grasp in the first moment than the others.</p>
<p>The FormLayout uses a dependent anchor system. An Anchor in this context is a position inside the layout which is calculated from parent anchors and either the size of the component or a fixed value. So we can say there are two different types of Anchors inside the FormLayout which we are concerned about:</p>
<ul>
<li><strong>AutoSize-Anchors</strong>, its position is calculated from the component assigned to it.</li>
<li><strong>Fixed-Anchors</strong>, its position is fixed.</li>
</ul>
<p>Additionally, there are three special cases of Fixed-Anchors:</p>
<ul>
<li><strong>Border-Anchors</strong>, which surround the FormLayout at its border.</li>
<li><strong>Margin-Anchors</strong>, which are inset from the border by the defined value.</li>
<li><strong>Gap-Anchors</strong>, which are added to create a gap between components.</li>
</ul>
<p>When it comes to calculating the position of an anchor, the position of the parent anchor is determined and then the value of the current anchor is added (which is either the size of a component or a fixed value). Simplified and in pseudo-code it can expressed like this:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2"><span class="kw1">public</span> <span class="kw4">int</span> getPosition<span class="br0">&#40;</span>Anchor pAnchor<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">int</span> parentPosition <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>pAnchor.<span class="me1">getParent</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">!=</span> <span class="kw2">null</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; parentPosition <span class="sy0">=</span> getPosition<span class="br0">&#40;</span>pAnchor.<span class="me1">getParent</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>pAnchor.<span class="me1">isAutoSize</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> parentPosition <span class="sy0">+</span> pAnchor.<span class="me1">getComponent</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getWidth</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> parentPosition <span class="sy0">+</span> pAnchor.<span class="me1">getValue</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p>With this knowledge, we are nearly done with completely understanding the FormLayout.</p>
<h3 style="padding-top: 10px">Creating constraints</h3>
<p>Now, the second important part after the basics is knowing how the constraints are created. For example this:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-1.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-1.png" alt="FormLayout with one added component." width="500" style="border: 1px solid #cccccc" /></a></p>
<p>With the coordinates of 0,0, no new anchors are created but instead the component is attached to the top and left margin anchor. Two new AutoSize-Anchors (horizontally and vertically) are created and attached to the component.</p>
<p>If we now add a second component in the same row:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-2.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-2.png" alt="FormLayout with two added components." width="500" style="border: 1px solid #cccccc" /></a></p>
<p>Because we are still on row 0 the component is attached to the top margin anchor and the previous AutoSize-Anchor for this row. Then, a new Gap-Anchor will be created which is attached to the trailing AutoSize-Anchor of the previous component.</p>
<p>We can of course also add items to the right and bottom:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span><span class="sy0">-</span>1, <span class="sy0">-</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-3.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-3.png" alt="FormLayout with three added components, one in the bottom right corner." width="500" style="border: 1px solid #cccccc" /></a></p>
<p>What happens is the same as when adding a component at the coordinates 0,0, except that the reference is the lower right corner. The component is attached to the bottom and right margin anchors, with trialing AutoSize-Anchors.</p>
<p>Last but not least, we can add components which span between anchors:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span><span class="sy0">-</span>1, <span class="sy0">-</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>2, 1, <span class="sy0">-</span>2, <span class="sy0">-</span>2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-4.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-4.png" alt="FormLayout with four added components, one stretched." width="500" style="border: 1px solid #cccccc" /></a></p>
<p>Again, the same logic applies as previously, with the notable exception that new Gap-Anchors are created for all four sides. That includes variants which span over anchors:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 1, 2, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-5.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-5.png" alt="FormLayout with three added components, one of them spans multiple anchors." width="500" style="border: 1px solid #cccccc" /></a></p>
<p>The component is horizontally attached to the left Margin-Anchor and additionally to the AutoSize-Anchor of the second column. The AutoSize- and Gap-Anchor of the first column are not ignored, they are not relevant to this case.</p>
<p>At this point it is important to note that spanning and stretched components are disregarded for the preferred size calculation of the layout. So whenever you span or stretch a component, it is not taken into account when the preferred size of the layout is calculated, which can lead to unexpected results.</p>
<h3 style="padding-top: 10px">Interactive demo</h3>
<p>Sometimes, however, it might not be obvious what anchors are created and how they are used. For this we have created a simple interactive demonstration application which allows to inspect the created anchors of a layout, the <a href="https://github.com/sibvisions/jvx.formlayout-visualization">JVx FormLayout Visualization</a>.</p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-visualization.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-visualization.png" alt="FormLayout Visualization Demo" width="400" style="border: 1px solid #cccccc" /></a></p>
<p>On the left is the possibility to show and hide anchors together with the information about the currently highlighted anchor. On the right is a Lua scripting area which allows you to quickly and easily rebuild and test layouts. It utilizes the <a href="https://blog.sibvisions.com/2017/09/25/jvx-lua-proof-of-concept/">JVx-Lua bridge from a previous blog post</a> and so any changes to the code are directly applied.</p>
<h3 style="padding-top: 10px">The most simple usage: Flow-like</h3>
<p>Enough of the internals, let's talk use-cases. The most simple use-case for the FormLayout can be a container which flows its contents in a line until a certain number of items is reach, at which it breaks into a new line:</p>
<div class="tab-me-wrapper"><ul class="tab-me-tabs"><li class="active first"><a href="javascript:void(0)" rel="tab1001"><span>Java</span></a></li><li><a href="javascript:void(0)" rel="tab1135"><span>Lua (Demo Application)</span></a></li></ul><!-- .tab-me-tabs --><div class="tab-me-content-wrapper"><div class="tab-me-tab-content" id="tab1001" ><div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">layout.<span class="me1">setNewlineCount</span><span class="br0">&#40;</span>3<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p></div><div class="tab-me-tab-content" id="tab1135" style="display:none"></p>
<div class="codesnip-container" >
<div class="lua codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">layout:setNewlineCount<span class="br0">&#40;</span>3<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p></div></div></div><!-- .tabs-wrapper --></p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-flow.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-flow.png" alt="FormLayout with a flow layout" width="400" style="border: 1px solid #cccccc" /></a></p>
<p>It does not require any interaction from us except adding components. In this case, when three components have been added, the next one will be added to the next line and so on. This is quite useful when all you want to do is display components in a fixed horizontal grid.</p>
<h3 style="padding-top: 10px">The obvious usage: Grid-like</h3>
<p>The FormLayout can also be used to align components in a grid, and actually layout them in a grid-like fashion:</p>
<div class="tab-me-wrapper"><ul class="tab-me-tabs"><li class="active first"><a href="javascript:void(0)" rel="tab1747"><span>Java</span></a></li><li><a href="javascript:void(0)" rel="tab1744"><span>Lua (Demo Application)</span></a></li></ul><!-- .tab-me-tabs --><div class="tab-me-content-wrapper"><div class="tab-me-tab-content" id="tab1747" ><div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>2, 0, <span class="sy0">-</span>2, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span><span class="sy0">-</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 1, 2, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>3, 1, <span class="sy0">-</span>1, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 2, <span class="sy0">-</span>2, <span class="sy0">-</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span><span class="sy0">-</span>1, 2, <span class="sy0">-</span>1, <span class="sy0">-</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p></div><div class="tab-me-tab-content" id="tab1744" style="display:none"></p>
<div class="codesnip-container" >
<div class="lua codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>2, 0, -2, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>-1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>0, 1, 2, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>3, 1, -1, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>0, 2, -2, -1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>-1, 2, -1, -1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p></div></div></div><!-- .tabs-wrapper --></p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-grid.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-grid.png" alt="FormLayout with a grid layout" width="400" style="border: 1px solid #cccccc" /></a></p>
<p>With the main difference being that the columns and rows are sized according to the components in it and not given a fixed slice of the width of the panel.</p>
<h3 style="padding-top: 10px">The advanced usage: Anchor Configuration</h3>
<p>Additionally, the FormLayout offers the possibility to manually set the anchor positions, for example when it is necessary to give the first elements a certain size:</p>
<div class="tab-me-wrapper"><ul class="tab-me-tabs"><li class="active first"><a href="javascript:void(0)" rel="tab1005"><span>Java</span></a></li><li><a href="javascript:void(0)" rel="tab1191"><span>Lua (Demo Application)</span></a></li></ul><!-- .tab-me-tabs --><div class="tab-me-content-wrapper"><div class="tab-me-tab-content" id="tab1005" ><div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>2, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>2, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel.<span class="me1">add</span><span class="br0">&#40;</span>component, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>2, 2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">layout.<span class="me1">setAnchorConfiguration</span><span class="br0">&#40;</span><span class="st0">&quot;r0=64,r1=8,r2=128,b1=32&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p></div><div class="tab-me-tab-content" id="tab1191" style="display:none"></p>
<div class="codesnip-container" >
<div class="lua codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>2, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>0, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>1, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>2, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>0, 2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>1, 2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">panel:add<span class="br0">&#40;</span>stub<span class="br0">&#40;</span><span class="br0">&#41;</span>, layout:getConstraints<span class="br0">&#40;</span>2, 2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">layout:setAnchorConfiguration<span class="br0">&#40;</span><span class="st0">&quot;r0=64,r1=8,r2=128,b1=32&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
</div>
<p></div></div></div><!-- .tabs-wrapper --></p>
<p>Together with the ability to span components, this allows to create complex and rich layouts.</p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-anchorconfiguration.png" rel="lightbox[7334]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/11/formlayout-anchorconfiguration.png" alt="FormLayout with a set anchor configuration" width="400" style="border: 1px solid #cccccc" /></a></p>
<h3 style="padding-top: 10px">Conclusion</h3>
<p>The JVx FormLayout allows to quickly and easily create complex, good looking and working layouts which are still flexible enough for the cases when a component is swapped, removed or added. It can be used in many different circumstances and is still easy enough to use to make sure that even beginners are able to create a basic layout within seconds.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2017/11/15/jvx-reference-the-formlayout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JVx Reference, Launchers and Applications</title>
		<link>https://blog.sibvisions.com/2017/09/28/jvx-reference-launchers-and-applications/</link>
		<comments>https://blog.sibvisions.com/2017/09/28/jvx-reference-launchers-and-applications/#comments</comments>
		<pubDate>Thu, 28 Sep 2017 15:57:38 +0000</pubDate>
		<dc:creator>rzenz</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[JVx Reference]]></category>

		<guid isPermaLink="false">https://blog.sibvisions.com/?p=6661</guid>
		<description><![CDATA[Let's talk about Launchers, and how they are used to start JVx applications.
Starting an application
We've previously outlined a simple way to start a JVx application, and now we're going to look at how to do it with a launcher to benefit from everything JVx has to offer. From a technical point of view, there are [...]]]></description>
			<content:encoded><![CDATA[<p>Let's talk about Launchers, and how they are used to start JVx applications.</p>
<h3 style="padding-top: 10px">Starting an application</h3>
<p>We've previously outlined <a href="https://blog.sibvisions.com/2017/04/24/jvx-reference-application-basics/">a simple way to start a JVx application</a>, and now we're going to look at how to do it with a launcher to benefit from everything JVx has to offer. From a technical point of view, there are two prerequisites which must be fulfilled before a JVx application can run:</p>
<ol>
<li>the JVM must have started.</li>
<li>the technology specific system must have started.</li>
</ol>
<p>Then, and only then, the JVx application can run. Depending on the implementation that is used, that can be as easily as instancing the factory (Swing, JavaFX), but can also mean that a servlet server has to start (Vaadin). Because we do not wish to encumber our applications with technology specific code, we have to entrust all this to an encapsulated entity, meaning the implementations of ILauncher and IApplication.</p>
<h3 style="padding-top: 10px">Following the chain</h3>
<p>The steps for getting an application to start are as follows:</p>
<ol>
<li>The first thing that must run is obviously the JVM, without it we won't have much luck starting anything.</li>
<li>The launcher must be created and it must start the Technology.</li>
<li>The launcher than creates the application which the user is seeing.</li>
</ol>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/09/launcher.png" rel="lightbox[6661]"><img src="https://blog.sibvisions.com/wp-content/uploads/2017/09/launcher.png" alt="Launcher chain" width="400" style="border: 1px solid #cccccc" /></a></p>
<p>So we need two classes, the ILauncher implementation which knows how to start the Technology and the IApplication implementation. That we already knew, so let's try to put this into code. For simplicity reasons (and because I don't want to write a complete factory from scratch for this example) we will reuse the Swing implementation and write a new launcher and application for it.</p>
<h3 style="padding-top: 10px">Entry point</h3>
<p>The Main class that we will use as example is very straightforward:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2"><span class="kw1">public</span> <span class="kw1">class</span> Main</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">void</span> main<span class="br0">&#40;</span><span class="kw3">String</span><span class="br0">&#91;</span><span class="br0">&#93;</span> pArgs<span class="br0">&#41;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// All we have to do here is kickoff the creation of the launcher.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// The launcher will do everything that is required to start for us.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// In a real world scenario and/or application there might be more</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// setup or groundwork required, for example processing the arguments,</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// but we don't need any of that here.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">new</span> SwingLauncher<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p>All we have to do there is start the launcher itself. As the comment suggests, there might be work required for a "real" application startup. For this example, it is all we need to do. Of course <strong>we could also directly embed this little function</strong> into the launcher implementation itself, <strong>to save us one class</strong>.</p>
<h3 style="padding-top: 10px">The launcher</h3>
<p>The ILauncher implementation on the other hand contains quite some logic, but nothing not manageable:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2"><span class="kw1">public</span> <span class="kw1">class</span> SwingLauncher <span class="kw1">extends</span> SwingFrame </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">implements</span> ILauncher</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// We have to extend from SwingFrame because there is no factory</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// instantiated at that point, so we can't use UI components.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">private</span> IApplication application<span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">public</span> SwingLauncher<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">try</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">SwingUtilities</span>.<span class="me1">invokeAndWait</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">::</span>startup<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">catch</span> <span class="br0">&#40;</span><span class="kw3">InvocationTargetException</span> <span class="sy0">|</span> <span class="kw3">InterruptedException</span> e<span class="br0">&#41;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span class="me1">printStackTrace</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; @Override</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> dispose<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">try</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We must notify the application that we are being disposed.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; application.<span class="me1">notifyDestroy</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">catch</span> <span class="br0">&#40;</span><span class="kw3">SecurityException</span> e<span class="br0">&#41;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span class="me1">printStackTrace</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span>.<span class="me1">dispose</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We have to make sure that the application is exiting when</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// the frame is disposed of.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">System</span>.<span class="me1">exit</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw4">void</span> startup<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We create a new SwingFactory and it is directly registered as global</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// instance, that means it will be used by all components which are</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// created from now on.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; UIFactoryManager.<span class="me1">getFactoryInstance</span><span class="br0">&#40;</span>SwingFactory.<span class="kw1">class</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Also we set it as our factory instance.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; setFactory<span class="br0">&#40;</span>UIFactoryManager.<span class="me1">getFactory</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Because the IApplication implementation we use is based upon</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// UI components (which is advisable) we have to wrap this launcher</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// in an UILauncher.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; UILauncher uiLauncher <span class="sy0">=</span> <span class="kw1">new</span> UILauncher<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Now we create the main application.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Note that the ExampleApplication is already based upon</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// UI components.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; application <span class="sy0">=</span> <span class="kw1">new</span> ExampleApplication<span class="br0">&#40;</span>uiLauncher<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Then we add the application as content to the launcher.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; uiLauncher.<span class="me1">add</span><span class="br0">&#40;</span>application<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Perform some setup work and start everything.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; uiLauncher.<span class="me1">pack</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; uiLauncher.<span class="me1">setVisible</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We also have to notify the application itself.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; application.<span class="me1">notifyVisible</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// SNIP</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p>In short, the launcher is kicking off the Swing thread by invoking the startup method on the main Swing thread. This startup method will instantiate the factory and then create the application. From there we only need to set it visible and then our application has started.</p>
<p>The launcher extends from SwingFrame, that is required because there hasn't been a factory created yet which could be used by UI components to create themselves. If we'd try to use an UI component before creating/setting a factory, we would obviously see the constructor of the component fail with a NullPointerException.</p>
<p>The method startup() is invoked on the main Swing thread, which also happens to be the main UI thread for JVx in this application. Once we are on the main UI thread we can create the application, add it and then set everything to visible.</p>
<h3 style="padding-top: 10px">The application</h3>
<p>The IApplication implementation is quite short, because we extend com.sibvisions.rad.application.Application, an IApplication implementation created with UI components.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">
<ol>
<li class="li2">
<div class="de2"><span class="kw1">public</span> <span class="kw1">class</span> ExampleApplication <span class="kw1">extends</span> Application</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">public</span> ExampleApplication<span class="br0">&#40;</span>UILauncher pParamUILauncher<span class="br0">&#41;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span>pParamUILauncher<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; @Override</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">protected</span> IConnection createConnection<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Exception</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Not required for this example.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">null</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; @Override</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">protected</span> <span class="kw3">String</span> getApplicationName<span class="br0">&#40;</span><span class="br0">&#41;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;Example Application&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p>Because the launcher has previously started the technology and created the factory we can from here on now use UI components, which means we are already independent of the underlying technology. So the IApplication implementation can already be used with different technologies and is completely independent.</p>
<h3 style="padding-top: 10px">Notes on the launcher</h3>
<p>As you might have noticed, in our example the launcher is a (window) frame, that makes sense for nearly every desktop GUI toolkit as they all depend upon a window as main method to display their applications. But the launcher could also be simpler, for example just a call to start the GUI thread. Or it could be something completely different, for example an incoming HTTP request.</p>
<p>Also don't forget that the launcher is providing additional functionality to the application, like saving file handles, reading and writing the configuration and similar platform and toolkit dependent operations, see the <a href="https://sourceforge.net/p/jvx/code/HEAD/tree/trunk/java/swing/src/com/sibvisions/rad/ui/swing/impl/SwingApplication.java">launcher for Swing for further details</a>.</p>
<h3 style="padding-top: 10px">Conclusion</h3>
<p>This example demonstrates how a simple launcher is implemented and why it is necessary to have a launcher in the first place. Compared with the "just set the factory" method this seems like a lot of work, but the launchers used by JVx are of course a lot more complex than these examples, that is because they implement all the required functionality and also take care of a lot of boiler plate operations. It is taking care of all technology specific code and allows to keep your application free from knowing about the platform it runs on.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2017/09/28/jvx-reference-launchers-and-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JVx Reference, DataBooks</title>
		<link>https://blog.sibvisions.com/2017/05/01/jvx-reference-databooks/</link>
		<comments>https://blog.sibvisions.com/2017/05/01/jvx-reference-databooks/#comments</comments>
		<pubDate>Mon, 01 May 2017 08:51:59 +0000</pubDate>
		<dc:creator>rzenz</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[JVx Reference]]></category>

		<guid isPermaLink="false">http://blog.sibvisions.com/?p=6115</guid>
		<description><![CDATA[Let's talk about DataBooks, which allow access to data without any effort.
What is it?
DataBooks are an active model, which allow you to directly query and manipulate the data. Contrary to many other systems JVx does not map the data into objects, but instead allows you to directly access it in a table like fashion, exposing [...]]]></description>
			<content:encoded><![CDATA[<p>Let's talk about DataBooks, which allow access to data without any effort.</p>
<h3 style="padding-top: 10px">What is it?</h3>
<p>DataBooks are an active model, which allow you to directly query and manipulate the data. Contrary to many other systems JVx does not map the data into objects, but instead allows you to directly access it in a table like fashion, exposing columns, rows and values.</p>
<p>One could say that it is like a three dimensional array, with these dimensions:</p>
<ol>
<li>DataPages</li>
<li>DataRows</li>
<li>Columns/Values</li>
</ol>
<p>With DataPages containing DataRows, which itself contain the values and everything is referencing the RowDefinition, which outlines how a row looks like.</p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/01/databook.png" rel="lightbox[6115]"><img class="aligncenter" src="https://blog.sibvisions.com/wp-content/uploads/2017/01/databook.png" alt="DataBook Architecture" width="500" height="200" /></a></p>
<h3 style="padding-top: 10px">RowDefinition</h3>
<p>The RowDefinition defines what columns are available in the row and stores some additional information about them, like the names of the <a href="https://en.wikipedia.org/wiki/Unique_key">primary key</a> columns. You can think of the RowDefinition as the headers of a table.</p>
<p>Its creation and usage is rather simple, and if you're working with RemoteDataBooks there is no need to create one at all, as it is automatically created when the DataBook is opened. A RowDefinition holds and manages ColumnDefinitions, which define the columns.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">RowDefinition rowDefinition <span class="sy0">=</span> <span class="kw1">new</span> RowDefinition<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
rowDefinition.<span class="me1">addColumnDefinition</span><span class="br0">&#40;</span>columnDefinitionA<span class="br0">&#41;</span><span class="sy0">;</span><br />
rowDefinition.<span class="me1">addColumnDefinition</span><span class="br0">&#40;</span>columnDefinitionB<span class="br0">&#41;</span><span class="sy0">;</span><br />
rowDefinition.<span class="me1">addColumnDefinition</span><span class="br0">&#40;</span>columnDefinitionC<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">setRowDefinition</span><span class="br0">&#40;</span>rowDefinition<span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<h4 style="font-size: 100%;padding-top: 10px">ColumnDefinition</h4>
<p>The ColumnDefinition defines and provides all necessary information about the column, like its DataType, its size and if it is nullable or not. You can think of it as one column in a table.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">ColumnDefinition columnDefinition <span class="sy0">=</span> <span class="kw1">new</span> ColumnDefinition<span class="br0">&#40;</span><span class="st0">&quot;NAME&quot;</span>, <span class="kw1">new</span> StringDataType<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
columnDefinition.<span class="me1">setNullable</span><span class="br0">&#40;</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<h4 style="font-size: 100%;padding-top: 10px">MetaData</h4>
<p>Most of the ColumnDefinition is additional information about the column, like if it is nullable, the label of the column, default values, allowed values and similar information.</p>
<h4 style="font-size: 100%;padding-top: 10px">DataType</h4>
<p>Of course we must define what type the value in the column has, this is done by setting a DataType on the ColumnDefinition. The DataType defines what kind of values the column holds, like if it is a String, or a Number or something else. We do provide the widest used DataTypes out of the box:</p>
<ul>
<li>BigDecimal</li>
<li>BinaryData</li>
<li>Boolean</li>
<li>Long</li>
<li>Object</li>
<li>String</li>
<li>Timestamp</li>
</ul>
<p>It is possible to add new DataTypes by simply implementing IDataType.</p>
<h3 style="padding-top: 10px">DataRow</h3>
<p>The DataRow repesents a single row of data, it holds/references its own RowDefinition and of course provides access to the values of the row. Accessing the DataRow can be done either by column index or column name, and the methods do either return or accept Objects. Let's look at a simple usage example:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">DataRow dataRow <span class="sy0">=</span> <span class="kw1">new</span> MemDataRow<span class="br0">&#40;</span>rowDefinition<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="kw3">String</span> value <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw3">String</span><span class="br0">&#41;</span>dataRow.<span class="me1">getValue</span><span class="br0">&#40;</span><span class="st0">&quot;COLUMN_A&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataRow.<span class="me1">setValue</span><span class="br0">&#40;</span><span class="st0">&quot;COLUMN_A&quot;</span>, <span class="st0">&quot;New Value&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<h3 style="padding-top: 10px">DataPage</h3>
<p>The DataPage is basically a list of DataRows, it also holds its own RowDefinition which is shared with all the contained DataRows.</p>
<p>The main usage of DataPages is to allow paging in a master/detail relationship. If the master selects a different row, the detail databook does select the related DataPage.</p>
<h3 style="padding-top: 10px">DataBook</h3>
<p>The DataBook is the main model of JVx, it provides direct access to its current DataPage and DataRow by extending from IDataRow and IDataPage.</p>
<p>By default, the DataBook holds one DataPage and only has multiple DataPages if it is the detail in a master/detail relationship.</p>
<h3 style="padding-top: 10px">Usage example</h3>
<p>Here is a simple usage example of a MemDataBook, an IDataBook implementation which does only operate in memory:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">IDataBook dataBook <span class="sy0">=</span> <span class="kw1">new</span> MemDataBook<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">setName</span><span class="br0">&#40;</span><span class="st0">&quot;test&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">getRowDefinition</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addColumnDefinition</span><span class="br0">&#40;</span><span class="kw1">new</span> ColumnDefinition<span class="br0">&#40;</span><span class="st0">&quot;ID&quot;</span>, <span class="kw1">new</span> LongDataType<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">getRowDefinition</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addColumnDefinition</span><span class="br0">&#40;</span><span class="kw1">new</span> ColumnDefinition<span class="br0">&#40;</span><span class="st0">&quot;COLUMN_STRING&quot;</span>, <span class="kw1">new</span> StringDataType<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">insert</span><span class="br0">&#40;</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">setValue</span><span class="br0">&#40;</span><span class="st0">&quot;ID&quot;</span>, <span class="kw3">Long</span>.<span class="me1">valueof</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">setValue</span><span class="br0">&#40;</span><span class="st0">&quot;COLUMN_STRING&quot;</span>, <span class="st0">&quot;VALUE&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">insert</span><span class="br0">&#40;</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">setValue</span><span class="br0">&#40;</span><span class="st0">&quot;ID&quot;</span>, <span class="kw3">Long</span>.<span class="me1">valueof</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">setValue</span><span class="br0">&#40;</span><span class="st0">&quot;COLUMN_STRING&quot;</span>, <span class="st0">&quot;VALUE_A&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">saveSelectedRow</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">setSelectedRow</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">setValue</span><span class="br0">&#40;</span><span class="st0">&quot;COLUMN_STRING&quot;</span>, <span class="st0">&quot;VALUE_NEW&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">saveSelectedRow</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">setSelectedRow</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>dataBook.<span class="me1">delete</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<h4 style="font-size: 100%;padding-top: 10px">Accessing the data with Strings</h4>
<p>One of the major advantages of the DataBook concept is that there is no need to create new classes to represent each table, view or query result. One can always use the DataBook, directly and easily and model changes don't necessitate changes on the client side. The downside to this approach is that we lose compile time checks because we access the data dynamically. However, This can be mitigated by using <a href="https://marketplace.eclipse.org/content/eplug-jvx">EPlug, an Eclipse plugin</a> which provides compile time checks and many more features.</p>
<h4 style="font-size: 100%;padding-top: 10px">No primitives, Objects only</h4>
<p>We do not provide overloads to fetch primitives, that is because there are mainly three types of data inside a database:</p>
<ol>
<li>Numbers</li>
<li>Text</li>
<li>Binary Data</li>
</ol>
<p>Text and Binary Data are both objects (arrays of primitives are Objects after all) and Numbers are either primitives or Objects. Most of the time if we deal with numbers inside a database we want them to be of arbitrary precision, which means we must represent them as BigDecimal. Supporting double or float in these cases would be dangerously, because one might write a float into the database <a href="https://en.wikipedia.org/wiki/Floating-point_arithmetic">which might or might not end up with the correct value</a> in the database. To completely eliminate such problems, we do only support Objects, which means that one is "limited" to the usage of Number extensions like BigLong and BigDecimal, which do not suffer from such problems.</p>
<h4 style="font-size: 100%;padding-top: 10px">Where are the DataPages?</h4>
<p>What is not clear from this example is how and when DataPages are used. As a matter of fact, most of the time there is no need to think about DataPages because they are managed directly by the DataBook, and if used this like there is only one DataPage. Multiple DataPages will be used if there is a Master/Detail relationship defined in which case the DataBook does select the correct DataPage automatically.</p>
<h3 style="padding-top: 10px">Master/Detail</h3>
<p><a href="https://en.wikipedia.org/wiki/Master%E2%80%93detail_interface#Data_model">Master/Detail</a> is something that occurs in nearly every data model. It means simply that there is one master dataset which is referenced by one or multiple detail datasets. Or to express it in SQL:</p>
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;"><span class="kw1">SELECT</span><br />
&nbsp; <span class="sy0">*</span><br />
<span class="kw1">FROM</span><br />
&nbsp; MASTER m<br />
&nbsp; <span class="kw1">LEFT</span> <span class="kw1">JOIN</span> DETAIL d <span class="kw1">ON</span> m<span class="sy0">.</span>ID<span class="sy0">=</span>d<span class="sy0">.</span>MASTER_ID;</div>
</div>
<p>We can of course express a Master/Detail relationship when using DataBooks. For that we just create a ReferenceDefinition and assign it to the Detail DataBook:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">IDataBook masterDataBook <span class="sy0">=</span> <span class="kw1">new</span> MemDataBook<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
masterDataBook.<span class="me1">setName</span><span class="br0">&#40;</span><span class="st0">&quot;master&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
masterDataBook.<span class="me1">getRowDefinition</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addColumnDefinition</span><span class="br0">&#40;</span><span class="kw1">new</span> ColumnDefinition<span class="br0">&#40;</span><span class="st0">&quot;ID&quot;</span>, <span class="kw1">new</span> LongDataType<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
masterDataBook.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>IDataBook detailDataBook <span class="sy0">=</span> <span class="kw1">new</span> MemDataBook<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
detailDataBook.<span class="me1">setName</span><span class="br0">&#40;</span><span class="st0">&quot;detail&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
detailDataBook.<span class="me1">getRowDefinition</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addColumnDefinition</span><span class="br0">&#40;</span><span class="kw1">new</span> ColumnDefinition<span class="br0">&#40;</span><span class="st0">&quot;ID&quot;</span>, <span class="kw1">new</span> LongDataType<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
detailDataBook.<span class="me1">getRowDefinition</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addColumnDefinition</span><span class="br0">&#40;</span><span class="kw1">new</span> ColumnDefinition<span class="br0">&#40;</span><span class="st0">&quot;MASTER_ID&quot;</span>, <span class="kw1">new</span> LongDataType<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
detailDataBook.<span class="me1">setReferenceDefinition</span><span class="br0">&#40;</span><span class="kw1">new</span> ReferenceDefinition<span class="br0">&#40;</span><span class="kw1">new</span> Streing<span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span><span class="st0">&quot;MASTER_ID&quot;</span><span class="br0">&#125;</span>, masterDataBook, <span class="kw1">new</span> <span class="kw3">String</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span><span class="st0">&quot;ID&quot;</span><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
detailDataBook.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>Let's assume the following data for illustration purposes:</p>
<div class="codesnip-container" >
<div class="vb codesnip" style="font-family:monospace;">MASTER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DETAIL<br />
====== &nbsp; &nbsp; &nbsp; &nbsp;=================<br />
&nbsp; ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ID &nbsp;| MASTER_ID<br />
------ &nbsp; &nbsp; &nbsp; &nbsp;------|----------<br />
&nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1| &nbsp; &nbsp; &nbsp; &nbsp; 1<br />
&nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2| &nbsp; &nbsp; &nbsp; &nbsp; 1<br />
&nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3| &nbsp; &nbsp; &nbsp; &nbsp; 2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4| &nbsp; &nbsp; &nbsp; &nbsp; 2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5| &nbsp; &nbsp; &nbsp; &nbsp; 2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;6| &nbsp; &nbsp; &nbsp; &nbsp; 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;7| &nbsp; &nbsp; &nbsp; &nbsp; 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;8| &nbsp; &nbsp; &nbsp; &nbsp; 3</div>
</div>
<p>Now if we select the second row in the masterDataBook, the detailDataBook will just contain the rows with the corresponding MASTER_ID, so 3, 4 and 5.</p>
<div class="codesnip-container" >
<div class="vb codesnip" style="font-family:monospace;">MASTER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DETAIL<br />
====== &nbsp; &nbsp; &nbsp; &nbsp;=================<br />
&nbsp; ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ID &nbsp;| MASTER_ID<br />
------ &nbsp; &nbsp; &nbsp; &nbsp;------|----------<br />
&nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3| &nbsp; &nbsp; &nbsp; &nbsp; 2<br />
S &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4| &nbsp; &nbsp; &nbsp; &nbsp; 2<br />
&nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5| &nbsp; &nbsp; &nbsp; &nbsp; 2</div>
</div>
<p>The detailDataBook is automatically adjusted according to the selection in the masterDatabook. Of course this can have an arbitrary depth, too.</p>
<h3 style="padding-top: 10px">Conclusion</h3>
<p>The DataBook is the backbone of JVx, it provides a clean and easy way to access and manipulate data. At the same time, it is flexible and can be customized to specific needs with ease.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2017/05/01/jvx-reference-databooks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JVx Reference, Application Basics</title>
		<link>https://blog.sibvisions.com/2017/04/24/jvx-reference-application-basics/</link>
		<comments>https://blog.sibvisions.com/2017/04/24/jvx-reference-application-basics/#comments</comments>
		<pubDate>Mon, 24 Apr 2017 11:01:39 +0000</pubDate>
		<dc:creator>rzenz</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[JVx Reference]]></category>

		<guid isPermaLink="false">http://blog.sibvisions.com/?p=5955</guid>
		<description><![CDATA[Let's talk about the basics, how a JVx application starts, works and how the connection strings together the client and server side.
Multitier Architecture
JVx is designed to be Multitier by default. It allows a clean and easy separation of processes and makes it easy to build, maintain and extend applications by separating the client, server and [...]]]></description>
			<content:encoded><![CDATA[<p>Let's talk about the basics, how a JVx application starts, works and how the connection strings together the client and server side.</p>
<h3 style="padding-top: 10px">Multitier Architecture</h3>
<p>JVx is designed to be <a href="https://en.wikipedia.org/wiki/Multitier_architecture">Multitier</a> by default. It allows a clean and easy separation of processes and makes it easy to build, maintain and extend applications by separating the client, server and data storage.</p>
<h3 style="padding-top: 10px">Launchers</h3>
<p>The following method is a simplified way to launch a JVx application. Normally, you'd use the technology specific launcher to launch the application. These launchers do know exactly what is required to set it up and start the technology and the application. However, covering the launchers is out of scope for this post, so we will review them and their mechanics in a follow-up.</p>
<h3 style="padding-top: 10px">The simplest JVx application: Just the GUI</h3>
<p>But first, we will start without anything. The most simple application you can create with JVx is an application which does open a single window and only works with in memory data (if at all). This can be easily achieved by "just starting" the application.</p>
<p><a href="https://blog.sibvisions.com/2016/12/07/jvx-reference-of-technologies-and-factories/">The JVx GUI is a simple layer on top of the Technology</a> which implements the actual functionality. So if we want to have a GUI we'll need to initialize the factory before doing anything else:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">UIFactoryManager.<span class="me1">getFactoryInstance</span><span class="br0">&#40;</span>SwingFactory.<span class="kw1">class</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>With this little code we have initialized everything we need to create a simple Swing application. Now we can start to create and populate a window with something:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">UIFrame frame <span class="sy0">=</span> <span class="kw1">new</span> UIFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
frame.<span class="me1">setLayout</span><span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
frame.<span class="me1">addComponent</span><span class="br0">&#40;</span><span class="kw1">new</span> UILabel<span class="br0">&#40;</span><span class="st0">&quot;Hello World!&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>frame.<span class="me1">pack</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
frame.<span class="me1">setVisible</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>frame.<span class="me1">eventWindowClosed</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">-&gt;</span> <span class="kw3">System</span>.<span class="me1">exit</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>We can start to create and manipulate the GUI, in this case we are building a simple window with a label inside. Last but not least, we make sure that the JVM will exit when the window is closed.</p>
<p>A very good example and showcase for that is the <a href="https://github.com/sibvisions/jvx.kitchensink">JVx Kitchensink</a>.</p>
<p>That's it. That is the most simple way to start a JVx application. We can use all controls and we can use MemDataBooks without any problem or limitation. And best of all, we can simply switch to another Technology by using another factory.</p>
<h3 style="padding-top: 10px">Anatomy of a remote JVx application</h3>
<p>Of course JVx wouldn't be that useful if it would just provide static GUI components. Now, to explain what else is required for a remote JVx application I have to go far afield, so let's head down the rabbit hole.</p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2017/01/jvx-client-server.png" rel="lightbox[5955]"><img class="aligncenter" src="https://blog.sibvisions.com/wp-content/uploads/2017/01/jvx-client-server.png" alt="JVx Layers" width="500" height="200" /></a></p>
<p>What you are seeing here is a rough sketch of how the architecture of JVx looks like. Let's walk through the image step by step. We will look at each successive layer and work our way from the database on the server to the databook on the client.</p>
<h4 style="font-size: 100%;padding-top: 10px">DBAccess, accessing a database</h4>
<p>Accessing a database is easy when using DBAccess. All we must do is to set the <a href="https://en.wikipedia.org/wiki/Java_Database_Connectivity">JDBC</a> URL of the server and connect to it:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">DBAccess dbAccess <span class="sy0">=</span> DBAccess.<span class="me1">getDBAccess</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;jdbc:postgresql://server:5432/schema&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;username&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;password&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dbAccess.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>As a note, the instance returned by getDBAccess is the database specific DBAccess extension, which does know how to handle its database.</p>
<p>We can of course use DBAccess to directly access the database:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">dbAccess.<span class="me1">executeStatement</span><span class="br0">&#40;</span><span class="st0">&quot;insert into SOME_TABLE values (?, ?);&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">BigDecimal</span>.<span class="me1">valueOf</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Some Value&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>List<span class="sy0">&lt;</span>Bean<span class="sy0">&gt;</span> data <span class="sy0">=</span> dbAccess.<span class="me1">executeQuery</span><span class="br0">&#40;</span><span class="st0">&quot;select * from SOME_TABLE&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>...or manipulate the database, or query information about the database or execute procedures or do anything else.</p>
<h4 style="font-size: 100%;padding-top: 10px">DBStorage, preparing the database access for databooks</h4>
<p>The downside of using DBAccess is that everything must be database specific. To become database agnostic we must use DBStorage. DBStorage does not care which database it is connected to and can operate on any of them:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">DBStorage storage <span class="sy0">=</span> <span class="kw1">new</span> DBStorage<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
storage.<span class="me1">setDBAccess</span><span class="br0">&#40;</span>dbAccess<span class="br0">&#41;</span><span class="sy0">;</span><br />
storage.<span class="me1">setWritebackTable</span><span class="br0">&#40;</span><span class="st0">&quot;SOME_TABLE&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
storage.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>We can use this to insert, update, delete and fetch data. Additionally the DBStorage does retrieve and manage the metadata of the table we've set, which means that we can query all column names, what type they are, we can even access the indexes and the default values. Short, the DBStorage leaves little to be desired when it comes to operating on a database.</p>
<p>If we query data from the DBStorage we receive a List of rows. The rows are are either represented as Object array, IBean or a POJO and we can easily manipulate the data, like this:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">for</span> <span class="br0">&#40;</span>IBean row <span class="sy0">:</span> storage.<span class="me1">fetchBean</span><span class="br0">&#40;</span><span class="kw2">null</span>, <span class="kw2">null</span>, <span class="nu0">0</span>, <span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; row.<span class="me1">put</span><span class="br0">&#40;</span><span class="st0">&quot;SOME_COLUMN&quot;</span>, <span class="st0">&quot;newvalue&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; storage.<span class="me1">update</span><span class="br0">&#40;</span>row<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>As one can see, it looks quite familiar to the DataBook, which isn't a coincidence. The DBStorage "powers" the DataBooks on the server side, a DataBook will get its data from and will send its modified data to the DBStorage.</p>
<p>I've been using the DBStorage here as an example, but actually the Storage is not dependent on a database. IStorage can be implemented to provide any sort of data provider, like reading from an XML or JSON file, scraping data from a website, fetching data from a different process or reading it directly from a hardware sensor.</p>
<h4 style="font-size: 100%;padding-top: 10px">Life Cycle Objects, the business objects with all the logic</h4>
<p>Life Cycle Objects, or LCOs, are the server side business objects which contain and provide the business logic. <a href="https://forum.sibvisions.com/viewtopic.php?t=124">They are created and destroyed as is requested by the client-side</a> and are used to provide specific functionality to the client, like providing functionality specific to one screen or workflow. This is done by <a href="https://en.wikipedia.org/wiki/Remote_procedure_call">RPC, Remote Procedure Calls</a>, which means that the client is directly calling the methods defined in the LCOs, which includes getting the Storages for the DataBooks.</p>
<p>There is also a security aspect to these, as you can permit one client access to a certain LCO but lock out everyone else, which means that only that client can use the functionality provided by the LCO.</p>
<p>But let's not get ahead of our selves, there are three important "layers" of LCOs which we will look at.</p>
<h5 style="font-size: 90%;padding-top: 10px">Application</h5>
<p>The LCO for the application represents the application itself and provides functionality on the application layer. It is created once for the lifetime of the application and this instance is shared by all sessions.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> Application <span class="kw1">extends</span> GenericBean<br />
<span class="br0">&#123;</span><br />
<span class="br0">&#125;</span></div>
</div>
<h5 style="font-size: 90%;padding-top: 10px">Session</h5>
<p>The LCO for the session represents one session, which most of the time also equals one client connection. It provides functionality which should be session-local, like providing the database connection which can be used.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> Session <span class="kw1">extends</span> Application<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">protected</span> DBAccess getDBAccess<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Exception</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Code for initialization and caching of DBAccess goes here.</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<h5 style="font-size: 90%;padding-top: 10px">Sub-Session aka Screen</h5>
<p>The sub-session, also known as screen, LCO is the last in the chain. It provides functionality specific to a certain part of the application, like a single screen, and provides the storages required to power the databooks and other functionality.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> MySubSession <span class="kw1">extends</span> Session<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> DBStorage getTablename<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Exception</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Code for initialization and caching of DBStorage goes here.</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<h4 style="font-size: 100%;padding-top: 10px">Server, serving it up</h4>
<p>There really isn't much to say about the server, it accepts connections and hands out sessions. Of course it is not that easy, but for this guide we will not go into any further detail.</p>
<h4 style="font-size: 100%;padding-top: 10px">Connection, connecting to a server</h4>
<p>The connection which strings together the client and the server is used for the communication between them, obviously. It can be anything, from a simple direct connection which strings two objects together to a HTTP connection which talks with a server on the other side of the planet.</p>
<p>By default we provide different IConnection implementations, the DirectServerConnection, DirectObjectConnection, the HttpConnection and the VMConnection. The DirectServerConnection is a simple IConnection implementation which does simply forward method calls to known Objects - without serialization - and is used when the client and server reside inside the same JVM. The HttpConnection communicates with the server over a HTTP connection and is used whenever the client and server are not inside the same JVM. The DirectObjectConnection and VMConnection are used for unit tests.</p>
<p>As example we will use the DirectServerConnection, which serves as Server and Connection. It is used if the server and client reside in the same JVM.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">IConnection connection <span class="sy0">=</span> <span class="kw1">new</span> DirectServerConnection<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="co1">// The connection will be automatically opened by the MasterConnection.</span></div>
</div>
<h4 style="font-size: 100%;padding-top: 10px">Master- and SubConnections, client-side lifecycle management</h4>
<p>The MasterConnection is the main connection which is used to access the server and its functionality. When a MasterConnection is established, a Session LCO on the server is created.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">MasterConnection masterConnection <span class="sy0">=</span> <span class="kw1">new</span> MasterConnection<span class="br0">&#40;</span>connection<span class="br0">&#41;</span><span class="sy0">;</span><br />
masterConnection.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>A SubConnection is a sub connection of the MasterConnection and allows to access specific functionality encapsulated in an LCO. When a SubConnection is established, the requested/specified LCO on the server is created and can be accessed through the SubConnection.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">SubConnection subConnection <span class="sy0">=</span> masterConnection.<span class="me1">createSubConnection</span><span class="br0">&#40;</span><span class="st0">&quot;MySubSession&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
subConnection.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>The SubConnection can now access the functionality provided by the Application, the Session and the LCO which was specified.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">subConnection.<span class="me1">callAction</span><span class="br0">&#40;</span><span class="st0">&quot;doSomethingOnTheServer&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<h4 style="font-size: 100%;padding-top: 10px">DataSource, preparing the connection for the databook</h4>
<p>To provide data to the databooks we can use the connection which we've described earlier. However, the DataBook does not directly know about the connection, it expects an IDataSource, which is used as an intermediate:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">IDataSource dataSource <span class="sy0">=</span> <span class="kw1">new</span> RemoteDataSource<span class="br0">&#40;</span>subConnection<span class="br0">&#41;</span><span class="sy0">;</span><br />
dataSource.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>Of course the RemoteDataSource is just one possible implementation of IDataSource which can be used to provide data to the DataBook.</p>
<h4 style="font-size: 100%;padding-top: 10px">DataBook, accessing data</h4>
<p>And now we are at the other end of the chain, at the databook on the client side. We just need to tell our databook what datasource to use, and we are done.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">RemoteDataBook dataBook <span class="sy0">=</span> <span class="kw1">new</span> RemoteDataBook<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">setDataSource</span><span class="br0">&#40;</span>dataSource<span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">setName</span><span class="br0">&#40;</span><span class="st0">&quot;storagename&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
dataBook.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>The name of the DataBook is used to access the DBStorage object in the LCO provided by the datasource. The mechanism for that is a simple search for a getter with the set name.</p>
<h3 style="padding-top: 10px">Interactive Demo</h5>
<p>Here is an interactive demo which allows you to explore the connections between the client and server side. The complement classes are always highlighted and you can click on the names of the objects to receive additional information about them.</p>
<div class="pageview">
	
  <iframe src="https://blog.sibvisions.com/wp-content/uploads/2017/04/lifecycle-objects-demo.html" frameborder="0" style="" scrolling="yes" height="400px" width="100%">Get a better browser!</iframe>
</div>

<h3 style="padding-top: 10px">The JVx application: Manual example</h3>
<p>Now that we have seen all layers that make up the architecture of JVx, let us put all of that into code:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> JVxLocalMain<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">void</span> main<span class="br0">&#40;</span><span class="kw3">String</span><span class="br0">&#91;</span><span class="br0">&#93;</span> pArgs<span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Throwable</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// ############################## Server ##############################</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// ----------------------------- DBAccess -----------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// The DBAccess gives us access to the database.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DBAccess dbAccess <span class="sy0">=</span> DBAccess.<span class="me1">getDBAccess</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;jdbc:h2:mem:database&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dbAccess.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We'll insert some data for this example.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dbAccess.<span class="me1">executeStatement</span><span class="br0">&#40;</span><span class="st0">&quot;create table if not exists TEST(&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">+</span> <span class="st0">&quot;ID int primary key auto_increment,&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">+</span> <span class="st0">&quot;NAME varchar(128) default '' not null);&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dbAccess.<span class="me1">executeStatement</span><span class="br0">&#40;</span><span class="st0">&quot;insert into TEST values (1, 'Name A');&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dbAccess.<span class="me1">executeStatement</span><span class="br0">&#40;</span><span class="st0">&quot;insert into TEST values (2, 'Name B');&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dbAccess.<span class="me1">executeStatement</span><span class="br0">&#40;</span><span class="st0">&quot;insert into TEST values (3, 'Name C');&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// ---------------------------- DBStorage -----------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Our sole storage.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DBStorage testStorage<span class="sy0">=</span> <span class="kw1">new</span> DBStorage<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; testStorage.<span class="me1">setDBAccess</span><span class="br0">&#40;</span>dbAccess<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; testStorage.<span class="me1">setWritebackTable</span><span class="br0">&#40;</span><span class="st0">&quot;TEST&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; testStorage.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// -------------------- LCO / Session / Application -------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We are skipping the LCO, Session and Application in this example.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// ####################### Network / Connection #######################</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// For this example we are initializing a DirectObjectConnection, which</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// does not require a server.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// It is designed to be used mainly for unit testing.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DirectObjectConnection connection <span class="sy0">=</span> <span class="kw1">new</span> DirectObjectConnection<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; connection.<span class="me1">put</span><span class="br0">&#40;</span><span class="st0">&quot;test&quot;</span>, testStorage<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// ############################## Client ##############################</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// ------------------------- MasterConnection -------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; MasterConnection masterConnection <span class="sy0">=</span> <span class="kw1">new</span> MasterConnection<span class="br0">&#40;</span>connection<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; masterConnection.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// -------------------------- SubConnection ---------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We are skipping the SubConnection in this example.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// ---------------------------- DataSource ----------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; IDataSource dataSource <span class="sy0">=</span> <span class="kw1">new</span> RemoteDataSource<span class="br0">&#40;</span>masterConnection<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dataSource.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// ----------------------------- DataBook -----------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; RemoteDataBook dataBook <span class="sy0">=</span> <span class="kw1">new</span> RemoteDataBook<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dataBook.<span class="me1">setDataSource</span><span class="br0">&#40;</span>dataSource<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dataBook.<span class="me1">setName</span><span class="br0">&#40;</span><span class="st0">&quot;test&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dataBook.<span class="me1">open</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// You can use the DataBook here.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Perform cleanup of all opened objects here.</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>With this little example we have a completely working JVx application. We provide ways to create most of this out of the box and read most of it from configuration files, so there really is just little code to be written, see <a href="https://sourceforge.net/projects/jvxfirstapp/">the JVx FirstApp</a> as a perfect example for that. So there is rarely any need to write code like this, all you have to do is create a new application and start it.</p>
<p>Additionally, we could combine this long example with the simple one from before to initialize and create a GUI which could use our RemoteDataBook, like this:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="co1">// Insert after the RemoteDataBook has been created.</span></p>
<p><span class="co1">// Set the UI factory which should be used, in this case it is</span><br />
<span class="co1">// the SwingFactory.</span><br />
UIFactoryManager.<span class="me1">getFactoryInstance</span><span class="br0">&#40;</span>SwingFactory.<span class="kw1">class</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>UIFrame frame <span class="sy0">=</span> <span class="kw1">new</span> UIFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
frame.<span class="me1">setLayout</span><span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
frame.<span class="me1">add</span><span class="br0">&#40;</span><span class="kw1">new</span> UITable<span class="br0">&#40;</span>dataBook<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>frame.<span class="me1">pack</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
frame.<span class="me1">setVisible</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>frame.<span class="me1">eventWindowClosed</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">-&gt;</span> <span class="kw3">System</span>.<span class="me1">exit</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<h3 style="padding-top: 10px">Abstractions on every step</h3>
<p>As you can see, you always have full control over the framework and can always tailor it to your needs. There is always the possibility to provide a custom implementation to fulfill your needs:</p>
<ol>
<li>Accessing a not supported database can be achieved by extending DBAccess</li>
<li>Having a different service/way of providing data can be implemented on top of IStorage</li>
<li>Supporting a different connection can be implemented on top of IConnection</li>
<li>And a completely different way of providing data can be implemented on top of IDataSource</li>
</ol>
<p>You can swap out every layer and provide custom and customized implementations which exactly work as you require it.</p>
<h3 style="padding-top: 10px">Just like that</h3>
<p>Just like that we've walked through the whole stack of a JVx application, from the database which holds the data all the way to the client GUI. Of course there is much more going on in a full-blown JVx application, for example I've spared you here the details of the configuration, server, network and providing actual LCOs and similar. But all in all, this should get you going.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2017/04/24/jvx-reference-application-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JVx Reference, Custom Components</title>
		<link>https://blog.sibvisions.com/2017/01/16/jvx-reference-custom-components/</link>
		<comments>https://blog.sibvisions.com/2017/01/16/jvx-reference-custom-components/#comments</comments>
		<pubDate>Mon, 16 Jan 2017 19:30:01 +0000</pubDate>
		<dc:creator>rzenz</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[JVx Reference]]></category>

		<guid isPermaLink="false">http://blog.sibvisions.com/?p=6113</guid>
		<description><![CDATA[Let's talk about custom components, and how to create them.
The GUI of JVx
We've previously covered how the GUI of JVx works, and now we will have a look on how we can add custom components to the GUI.
In the terminology of JVx there are two different kinds of custom components:

UI based
Technology based

We will look at [...]]]></description>
			<content:encoded><![CDATA[<p>Let's talk about custom components, and how to create them.</p>
<h3 style="padding-top: 10px">The GUI of JVx</h3>
<p>We've <a href="https://blog.sibvisions.com/2016/12/07/jvx-reference-of-technologies-and-factories/">previously covered how the GUI of JVx works</a>, and now we will have a look on how we can add custom components to the GUI.</p>
<p>In the terminology of JVx there are two different kinds of custom components:</p>
<ol>
<li>UI based</li>
<li>Technology based</li>
</ol>
<p>We will look at both, of course.</p>
<h3 style="padding-top: 10px">Custom components at the UI layer</h3>
<p>The simplest way to create custom components is to extend and use already existing UI classes, like UIPanel or UIComponent. These custom components will be Technology independent because they use Technology independent components, there is no need to know about the underlying Technology. You can think of those as a "remix" of already existing components.</p>
<p>The upside is that you never have to deal with the underlying Technology, the downside is that you can only use already existing components (custom drawing is not possible, for example).</p>
<p>Let's look at a very simple example, we will extend the UILabel to always display a certain postfix along with the set text:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> PostfixedLabel <span class="kw1">extends</span> UILabel<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw3">String</span> postfix <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; <span class="co1">// We must store the original text so that we can return</span><br />
&nbsp; &nbsp; <span class="co1">// it if requested. Otherwise we could only return the text</span><br />
&nbsp; &nbsp; <span class="co1">// with the appended postfix, which works unless the postfix</span><br />
&nbsp; &nbsp; <span class="co1">// changes.</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw3">String</span> text <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> PostfixedLabel<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> PostfixedLabel<span class="br0">&#40;</span><span class="kw3">String</span> pText<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span>pText<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> PostfixedLabel<span class="br0">&#40;</span><span class="kw3">String</span> pText, <span class="kw3">String</span> pPostfix<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span>pText<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; setPostfix<span class="br0">&#40;</span>pPostfix<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw3">String</span> getText<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> text<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> setText<span class="br0">&#40;</span><span class="kw3">String</span> pText<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; text <span class="sy0">=</span> pText<span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>StringUtil.<span class="me1">isEmpty</span><span class="br0">&#40;</span>postfix<span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;&amp;</span>amp<span class="sy0">;</span> <span class="sy0">!</span>StringUtil.<span class="me1">isEmpty</span><span class="br0">&#40;</span>pText<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We translate the text and the postfix now separately,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// the underlying label will obviously try to translate</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// the concatenated version.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span>.<span class="me1">setText</span><span class="br0">&#40;</span>translate<span class="br0">&#40;</span>pText<span class="br0">&#41;</span> <span class="sy0">+</span> translate<span class="br0">&#40;</span>postfix<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span>.<span class="me1">setText</span><span class="br0">&#40;</span>pText<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw3">String</span> getPostfix<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> postfix<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> setPostfix<span class="br0">&#40;</span><span class="kw3">String</span> pPostfix<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; postfix <span class="sy0">=</span> pPostfix<span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// If the postfix changed, we must update the text.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; setText<span class="br0">&#40;</span>text<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>It will be treated just like another label, but every time a text is set, the postfix is appended to it.</p>
<p>Another example, we want a special type of component, one that always does the same but will be used in many different areas of the application, it should contain a label and two buttons. The best approach for a custom component which should not inherit any specific behavior is to extend UIComponent:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> BeepComponent <span class="kw1">extends</span> UIComponent<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw1">public</span> BeepComponent<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">super</span><span class="br0">&#40;</span><span class="kw1">new</span> UIPanel<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;UIButton highBeepButton <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="st0">&quot;High Beep&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;highBeepButton.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span>Beeper<span class="sy0">::</span>playHighBeep<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;UIButton lowBeepButton <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="st0">&quot;Low Beep&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;highBeepButton.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span>Beeper<span class="sy0">::</span>playLowBeep<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;UIFormLayout layout <span class="sy0">=</span> <span class="kw1">new</span> UIFormLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp;uiResource.<span class="me1">setLayout</span><span class="br0">&#40;</span>layout<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;uiResource.<span class="me1">add</span><span class="br0">&#40;</span><span class="kw1">new</span> UILabel<span class="br0">&#40;</span><span class="st0">&quot;Press for beeping...&quot;</span><span class="br0">&#41;</span>, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 0, <span class="sy0">-</span>1, 0<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;uiResource.<span class="me1">add</span><span class="br0">&#40;</span>highBeepButton, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>0, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;uiResource.<span class="me1">add</span><span class="br0">&#40;</span>lowBeepButton, layout.<span class="me1">getConstraints</span><span class="br0">&#40;</span>1, 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>So we extend UIComponent and set a new UIPanel as UIResource on it, which we can use later and which is the base for our new component. After that we added a label and two buttons which will play beep sounds if pressed. This component does not expose any specific behavior as it extends UIComponent, it only inherits the most basic properties, like background color and font settings, yet it can easily be placed anywhere in the application and will perform its duty.</p>
<h3 style="padding-top: 10px">Custom controls at the Technology layer</h3>
<p>The more complex option is to create a custom component at the Technology layer. That means that we have to go through a multiple steps process to create and use the component:</p>
<ol>
<li>Create an interface for the functionality you'd like to expose</li>
<li>Extend the Technology component (if needed)</li>
<li>Implement the necessary interfaces for JVx</li>
<li>Extend the factory to return the new component</li>
<li>Create a UIComponent for the new component</li>
<li>Use the new factory</li>
</ol>
<p>I will walk you through this process, step by step.</p>
<p>The upside is that we can use any component which is available to us in the Technology, the downside is that it is quite some work to build the correct chain, ideally for every technology.</p>
<h4 style="padding-top: 10px">Creating an interface</h4>
<p>The first step is to think about what functionality the component should expose, we will use a progress bar as example. We don't want anything fancy for now, a simple progress bar on which we set a percent value should be more than enough:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="co3">/**<br />
&nbsp;* The platform and technology independent definition for a progress bar.<br />
&nbsp;*/</span><br />
<span class="kw1">public</span> <span class="kw1">interface</span> IProgressBar <span class="kw1">extends</span> IComponent<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co3">/**<br />
&nbsp; &nbsp; &nbsp;* Gets the current value, in percent.<br />
&nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp;* @return the current value. Should be between {@code 0} and {@code 100}.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">int</span> getValue<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co3">/**<br />
&nbsp; &nbsp; &nbsp;* Sets the current value, in percent.<br />
&nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp;* @param pValue the value. Should be between {@code 0} and {@code 100}.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> setValue<span class="br0">&#40;</span><span class="kw4">int</span> pValue<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Might not be the most sophisticated example (especially in regards to documentation) but it will do for now. This interface will be the foundation for our custom component.</p>
<h4 style="padding-top: 10px">Extending the component, if needed</h4>
<p>We will be using Swing and the JProgressBar for this example, so the next step is to check if we must add additional functionality to the Technology component. In our case we don't, as we do not demand any behavior that is not provided by JProgressBar, but for the sake of the tutorial we will still create an extension on top of JProgressBar anyway.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> ExtendedProgressBar <span class="kw1">extends</span> <span class="kw3">JProgressBar</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> ExtendedProgressBar<span class="br0">&#40;</span><span class="kw4">int</span> pMin, <span class="kw4">int</span> pMax<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span>pMin, pMax<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Within this class we could now implement additional behavior independent of JVx. For example, we provide many extended components for Swing, JavaFX and Vaadin with additional features but without depending on JVx. The extension layer is the perfect place to extend already existing components with functionality which will be used by, but is not depending on, JVx.</p>
<h4 style="padding-top: 10px">Creating the Implementation</h4>
<p>The next step is to create an Implementation class which allows us to bind our newly extended JProgressBar to the JVx interfaces. Luckily there is the complete Swing Implementation infrastructure which we can use:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> SwingProgressBar<span class="sy0">&lt;</span>ExtendedProgressBar<span class="sy0">&gt;</span> <span class="kw1">extends</span> SwingComponent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">implements</span> IProgressBar<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> SwingProgressBar<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We can hardcode the min and max values here, because</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// we do not support anything else.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="kw1">new</span> ExtendedProgressBar<span class="br0">&#40;</span>0, 100<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">int</span> getValue<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> resource.<span class="me1">getValue</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> setValue<span class="br0">&#40;</span><span class="kw4">int</span> pValue<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resource.<span class="me1">setValue</span><span class="br0">&#40;</span>pValue<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>That's it already. Again, in this case it is quite simple because we do not expect a lot of behavior. The implementation layer is the place to "glue" the component to the JVx interface, implementing missing functionality which is depending on JVx and "translating" and forwarding values and properties.</p>
<h4 style="padding-top: 10px">Extending the factory</h4>
<p>Now we must extend the Factory to be aware of our new custom component, that is equally simple as our previous steps. First we extend the interface:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">interface</span> IProgressBarFactory <span class="kw1">extends</span> IFactory<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> IProgressBar createProgressBar<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>And afterwards we extend the SwingFactory:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> ProgressBarSwingFactory <span class="kw1">extends</span> SwingFactory <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">implements</span> IProgressBarFactory<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw1">public</span> IProgressBar createProgressBar<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SwingProgressBar progressBar <span class="sy0">=</span> <span class="kw1">new</span> SwingProgressBar<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span class="me1">setFactory</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> progressBar<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Again, it is that easy.</p>
<h4 style="padding-top: 10px">Creating the UIComponent</h4>
<p>So that we can use our new and shiny progress bar easily, and without having to call the factory directly, we wrap it one last time in a new UIComponent:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> UIProgressBar<span class="sy0">&lt;</span>IProgressBar<span class="sy0">&gt;</span> <span class="kw1">extends</span> UIComponent <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">implements</span> IProgressBar<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> UIProgressBar<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We'll assume that, whoever uses this component,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// is also using the correct factory.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="br0">&#40;</span>IProgressBarFactory<span class="br0">&#41;</span>UIFactoryManager.<span class="me1">getFactory</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">createProgressBar</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">int</span> getValue<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> uiResource.<span class="me1">getValue</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> setValue<span class="br0">&#40;</span><span class="kw4">int</span> pValue<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; uiResource.<span class="me1">setValue</span><span class="br0">&#40;</span>pValue<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Nearly done, we can nearly use our new and shiny component in our project.</p>
<h4 style="padding-top: 10px">Using thecustom factory</h4>
<p>Of course we have to tell JVx that we want to use our factory, and not the default one. Depending on the technology which is used, this has to be done at different places:</p>
<h5 style="padding-top: 10px">Swing and JavaFX</h5>
<p>Add the factory setting to the application.xml of the application:</p>
<div class="codesnip-container" >
<div class="xml codesnip" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;Launcher.uifactory<span class="re2">&gt;</span></span></span>your.package.with.custom.components.SwingProgressBarFactory<span class="sc3"><span class="re1">&lt;/Launcher.uifactory<span class="re2">&gt;</span></span></span></div>
</div>
<h5 style="padding-top: 10px">Vaadin</h5>
<p>Add the following setting to the web.xml under the WebUI Servlet configuration:</p>
<div class="codesnip-container" >
<div class="xml codesnip" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;init-param<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;param-name<span class="re2">&gt;</span></span></span>Launcher.uifactory<span class="sc3"><span class="re1">&lt;/param-name<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;param-value<span class="re2">&gt;</span></span></span>your.package.with.custom.components.VaadinProgressBarFactory<span class="sc3"><span class="re1">&lt;/param-value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/init-param<span class="re2">&gt;</span></span></span></div>
</div>
<h4 style="padding-top: 10px">Using our new component</h4>
<p>And now we are done, from here we can use our custom component like any other.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">UIProgressBar progressBar <span class="sy0">=</span> <span class="kw1">new</span> UIProgressBar<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
progressBar.<span class="me1">setValue</span><span class="br0">&#40;</span>65<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="co1">// Skip</span></p>
<p>add<span class="br0">&#40;</span>progressBar, constraints<span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<h3 style="padding-top: 10px">Wrapping custom components with UICustomComponent</h3>
<p>There is a third way to have Technology dependent custom components in JVx, you can wrap them within a UICustomComponent:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw3">JProgressBar</span> progressBar <span class="sy0">=</span> <span class="kw1">new</span> <span class="kw3">JProgressBar</span><span class="br0">&#40;</span>0, 100<span class="br0">&#41;</span><span class="sy0">;</span><br />
progressBar.<span class="me1">setValue</span><span class="br0">&#40;</span>100<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>UICustomComponent customProgressBar <span class="sy0">=</span> <span class="kw1">new</span> UICustomComponent<span class="br0">&#40;</span>progressBar<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="co1">// Skip</span></p>
<p>add<span class="br0">&#40;</span>customProgressBar, constraints<span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>This has the upside of being fast and easy, but the downside is that your code has to know about the currently used Technology and is not easily portable anymore.</p>
<h3 style="padding-top: 10px">Conclusion</h3>
<p>As you can see, there are multiple ways of extending the default set of components which are provided by JVx, depending on the use case and what custom components are required. It is very easy to extend JVx with all the components one does require.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2017/01/16/jvx-reference-custom-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JVx Reference, of Technologies and Factories</title>
		<link>https://blog.sibvisions.com/2016/12/07/jvx-reference-of-technologies-and-factories/</link>
		<comments>https://blog.sibvisions.com/2016/12/07/jvx-reference-of-technologies-and-factories/#comments</comments>
		<pubDate>Wed, 07 Dec 2016 13:25:36 +0000</pubDate>
		<dc:creator>rzenz</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[JVx Reference]]></category>

		<guid isPermaLink="false">http://blog.sibvisions.com/?p=5957</guid>
		<description><![CDATA[Let's talk about the UI layer, the implementations and the factory that powers it all.
The basics
For everyone who does not know, JVx allows you to write code once and run it on different GUI frameworks, without changing your code. This is achieved by hiding the concrete GUI implementations behind our own classes, the UI classes, [...]]]></description>
			<content:encoded><![CDATA[<p>Let's talk about the UI layer, the implementations and the factory that powers it all.</p>
<h3 style="padding-top: 10px">The basics</h3>
<p>For everyone who does not know, JVx allows you to write code once and run it on different GUI frameworks, without changing your code. This is achieved by hiding the concrete GUI implementations behind our own classes, the UI classes, and providing "bindings" for different GUI frameworks behind the scenes. Such a "Single Sourcing" approach has many advantages, and just one of them is that migrating to a new GUI framework requires only the change of a single line, the one which controls which factory is created.</p>
<h3 style="padding-top: 10px">The Factory Pattern</h3>
<p>The <a href="https://en.wikipedia.org/wiki/Factory_%28object-oriented_programming%29">Factory Pattern</a> is an important pattern in Object-Oriented-Programming, it empowers us to delegate the creation of Objects to another Object which must not be known at design and/or compile time. That allows us to use Objects which have not been created by us but merely "provided" to us by an, for us unknown, implementation.</p>
<h3 style="padding-top: 10px">Like an onion</h3>
<p>JVx is separated into different layers, with the UI layer being at the top and of the most concern to users.</p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2016/12/layers.png" rel="lightbox[5957]"><img class="aligncenter" src="https://blog.sibvisions.com/wp-content/uploads/2016/12/layers.png" alt="JVx Layers" width="500" height="400" /></a></p>
<h4 style="padding-top: 10px">Technology</h4>
<p>Obviously, the first one in the chain is the so called "technology" layer. It represents the UI technology, for example Swing, JavaFX or Vaadin, which is used to power the JVx application.</p>
<p>To put it into a more simple term:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> <span class="kw3">JButton</span> <span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</div>
<h4 style="padding-top: 10px">Extension</h4>
<p>Next comes the extension layer, components from the technology are extended to support needed features of JVx. This includes creating bindings for the databook, additional style options and changing of behavior if necessary. From time to time this also includes creating components from scratch if the provided ones do not meet the needs or there simply are none with the required functionality. For the most part, we do our best that these layers can be used without JVx, meaning that they represent a solitary extension to the technology. A very good example is our <a href="https://sourceforge.net/projects/jvxfx">JavaFX implementation</a>, which compiles into two separate jars, the first being the complete JVx/JavaFX stack, the second being stand-alone JavaFX extensions which can be used in any application and without JVx.</p>
<p>Theoretically one can skip this layer and directly jump to the Implementation layer, but so far it has proven necessary (for cleanliness of the code and object structure and sanity reasons) to create a separate extension layer.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> JExtendedButton <span class="kw1">extends</span> <span class="kw3">JButton</span> <span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</div>
<h4 style="padding-top: 10px">Implementation</h4>
<p>After that comes the implementation layer. The extended components are extended to implement JVx interfaces. This is some sort of "glue" layer, it binds the technology or extended components against the interfaces which are provided by JVx.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> SwingButton <span class="kw1">implements</span> IButton <span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</div>
<h4 style="padding-top: 10px">UI</h4>
<p>Last but for sure not least is the UI layer, which wraps the implementations. It is completely Implementation independent, that means that one can swap out the stack underneath:</p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2016/12/swappable-layers.png" rel="lightbox[5957]"><img class="aligncenter" src="https://blog.sibvisions.com/wp-content/uploads/2016/12/swappable-layers.png" alt="JVx Layers" width="500" height="400" /></a></p>
<p>This is achieved because the UI layer is not extending the Implementation layer, but wrapping instances provided by the factory. It is oblivious to what Technology is actually underneath it.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> UIButton <span class="kw1">implements</span> IButton <span class="br0">&#123;</span><span class="br0">&#125;</span></p>
<p>SwingButton resource <span class="sy0">=</span> SwingFactory.<span class="me1">createButton</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
<h3 style="padding-top: 10px">Why is the UI layer necessary?</h3>
<p>It isn't, not at all. The Implementations could be used directly without any problems, but having <em>yet another</em> layer has two key benefits:</p>
<ol>
<li>It allows easier usage.</li>
<li>It allows to add Technology independent features.</li>
</ol>
<p>By wrapping it one more time we gain a lot of freedom which we would not have otherwise, when it comes to features as when it comes to coding. The user does not need to call the factory directly and instead just needs to create a new object:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">IButton button <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>Internally, of course, the Factory is called and an implementation instance is created, but that is an implementation detail. If we would use the implementation layer directly, our code would either need to know about the implementations, which doesn't follow the Single-Sourcing principle:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">IButton button <span class="sy0">=</span> <span class="kw1">new</span> SwingButton<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>It also would be possible to directly use the factory (but this isn't modern coding style):</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">IButton button <span class="sy0">=</span> UIFactoryManager.<span class="me1">getFactory</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">createButton</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>Both can be avoided by using another layer which does the factory calls for us:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> UIButton <span class="kw1">implements</span> IButton<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> IButton resource<span class="sy0">;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> UIButton<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resource <span class="sy0">=</span> UIFactoryManager.<span class="me1">getFactory</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">createButton</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> someInterfaceMethod<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resource.<span class="me1">someInterfaceMethod</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Additionally this layer allows us to implement features which can be technology independent, our <a href="https://blog.sibvisions.com/2015/01/07/stress-testing-vaadin/">naming scheme, which we created during stress testing of an Vaadin application, is a very good example of that</a>. The names of the components are derived in the UI layer without any knowledge of the underlying Technology or Implementation.</p>
<p>Also it does provide us (and everyone else of course) with a layer which allows to rapidly and easily build compound components out of already existing ones, like this:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> LabeledButton <span class="kw1">extends</span> UIPanel<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> IButton button <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> ILabel label <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">public</span> LabeledButton <span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; initializeUI<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw4">void</span> initializeUI<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; label <span class="sy0">=</span> <span class="kw1">new</span> UILabel<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; setLayout<span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span class="br0">&#40;</span>label, UIBorderLayout.<span class="me1">LEFT</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span class="br0">&#40;</span>button, UIBorderLayout.<span class="me1">CENTER</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Of course that is not even close to sophisticated, or a good example for that matter. But it shows that one can build new components out of already existing ones without having to deal with the Technology or Implementation at all, creating truly cross-technology controls.</p>
<h3 style="padding-top: 10px">The Factory</h3>
<p>The heart piece of the UI layer is the Factory, which is creating the Implemented classes. It's a rather simple system, a <a href="https://en.wikipedia.org/wiki/Singleton_pattern">Singleton</a> which is set at the beginning to the Technology specific factory which can be retrieved later:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="co1">// At the start of the application.</span><br />
UIFactoryManager.<span class="me1">setFactoryInstance</span><span class="br0">&#40;</span><span class="kw1">new</span> SwingFactory<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="co1">// Or alternately:</span><br />
UIFactory.<span class="me1">getFactoryInstance</span><span class="br0">&#40;</span>SwingFactory.<span class="kw1">class</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="co1">// Later inside the UI wrappers.</span><br />
IButton button <span class="sy0">=</span> UIFactory.<span class="me1">getFactory</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">createButton</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>The complexity of the implementation of the factory is technology dependent, but for the most part it is devoid of any logic:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> SwingFactory <span class="kw1">implements</span> IFactory<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw1">public</span> IButton createButton<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SwingButton button <span class="sy0">=</span> <span class="kw1">new</span> SwingButton<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span class="me1">setFactory</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> button<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>It "just returns new objects" from the implementation layer. That's about it when it comes to the factory, it is as simple as that.</p>
<h3 style="padding-top: 10px">Piecing it together</h3>
<p>With all this in mind, we know now that JVx has swappable implementations underneath its UI layer for each technology it utilizes:</p>
<p style="text-align: center"><a href="https://blog.sibvisions.com/wp-content/uploads/2016/12/multi-layers.png" rel="lightbox[5957]"><img class="aligncenter" src="https://blog.sibvisions.com/wp-content/uploads/2016/12/multi-layers.png" alt="JVx Layers" width="500" height="200" /></a></p>
<p>Changing between them can be as easy as setting a different factory. I say "can", because that is only true for Swing, JavaFX and similar technologies, Vaadin, obviously, requires some more setup work. I mean, theoretically one could embed a complete application server and launch it when the factory for Vaadin is created, allowing the application to be basically stand-alone and be started as easily as a Swing application. That is possible.</p>
<h3 style="padding-top: 10px">What else?</h3>
<p>That is how JVx works in regards to the UI layer. It depends on "technology specific stacks" which can be swapped out and implemented for pretty much every GUI framework out there. We currently provide support for <a href="https://en.wikipedia.org/wiki/Swing_%28Java%29">Swing</a>, <a href="https://en.wikipedia.org/wiki/JavaFX">JavaFX<a> and <a>Vaadin</a>, but we also had implementations for <a href="https://en.wikipedia.org/wiki/Google_Web_Toolkit">GWT</a> and <a href="https://en.wikipedia.org/wiki/Qt_%28software%29">Qt</a>. Additionally we do support a "headless" implementation which allows to use lightweight objects which might be serialized and send over the wire without much effort.</p>
<h3 style="padding-top: 10px">Adding a new Technology</h3>
<p>Adding support for a new Technology is as straightforward as one can imagine, simply creating the Extensions/Implementations layers and implementing the factory for that Technology. Giving a complete manual would be out for scope for this post, but the most simple approach to adding a new stack to JVx is to start with stubbing out the IFactory and implementing IWindow. Once that one window shows up, it's just implementing one interface after another in a quite straightforward manner. And in the end, your application can switch to yet another GUI framework without the need to change your code.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2016/12/07/jvx-reference-of-technologies-and-factories/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JVx Reference, Events</title>
		<link>https://blog.sibvisions.com/2016/11/03/jvx-reference-events/</link>
		<comments>https://blog.sibvisions.com/2016/11/03/jvx-reference-events/#comments</comments>
		<pubDate>Thu, 03 Nov 2016 10:35:54 +0000</pubDate>
		<dc:creator>rzenz</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[JVx Reference]]></category>

		<guid isPermaLink="false">http://blog.sibvisions.com/?p=5895</guid>
		<description><![CDATA[Let's talk about events and event handling in JVx.
What are events...
Events are an important mechanism no matter to what programming language or framework you turn to. It allows us to react on certain actions and "defer" actions until something triggered them. Such triggers can be anything, like a certain condition is hit in another thread, [...]]]></description>
			<content:encoded><![CDATA[<p>Let's talk about events and event handling in JVx.</p>
<h3 style="padding-top: 10px">What are events...</h3>
<p>Events are <a href="https://en.wikipedia.org/wiki/Event-driven_programming">an important mechanism no matter to what programming language or framework you turn to</a>. It allows us to react on certain actions and "defer" actions until something triggered them. Such triggers can be anything, like a certain condition is hit in another thread, the user clicked a button or another action has finally finished. Long story short, you get notified that something happened, and that you can now do something.</p>
<h3 style="padding-top: 10px">...and why do I need to handle them?</h3>
<p>Well, you can't skip events, they are a cornerstone of JVx. Theoretically, you could use JVx without using any of its events, but you would not only miss out on a lot of functionality but also be unable to do anything useful. But don't worry, understanding the event system is easy, using it even easier.</p>
<h3 style="padding-top: 10px">Terminology</h3>
<p>For JVx the following terminology applies: An event is a property of an object, you can register listeners on that event which will get invoked if the event is dispatched (fired). Every event consists of the EventHandler class which allows to register, remove and manage the listeners and also dispatches the events, meaning invoking the listeners and notifying them that the event occurred. There is no single underlying listener interface.</p>
<p>Within the JVx framework, every event-property of an object does start with the prefix "event" to make it easily searchable and identifiable. But enough dry talk, let's get started.</p>
<h3 style="padding-top: 10px">Attaching listeners as class</h3>
<p>The easiest way to get notified of events is to attach a class (which is implementing the listener interface) to an event as listener, like this:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> MainFrame <span class="kw1">extends</span> UIFrame<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> MainFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; UIButton button <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="st0">&quot;Click me!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="kw1">new</span> <span class="kw3">ActionListener</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; setLayout<span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span class="br0">&#40;</span>button, UIBorderLayout.<span class="me1">CENTER</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">final</span> <span class="kw1">class</span> <span class="kw3">ActionListener</span> <span class="kw1">implements</span> IActionListener<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> action<span class="br0">&#40;</span>UIActionEvent pActionEvent<span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Throwable</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;Button clicked!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<h3 style="padding-top: 10px">Attaching listeners as inlined class</h3>
<p>Of course we can inline this listener class:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> MainFrame <span class="kw1">extends</span> UIFrame<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> MainFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; UIButton button <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="st0">&quot;Click me!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="kw1">new</span> IActionListener<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> action<span class="br0">&#40;</span>UIActionEvent pActionEvent<span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Throwable</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;Button clicked!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; setLayout<span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span class="br0">&#40;</span>button, UIBorderLayout.<span class="me1">CENTER</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<h3 style="padding-top: 10px">Attaching listeners JVx style</h3>
<p>So far, so normal. But in JVx we have support to attach listeners based on reflection, like this:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> MainFrame <span class="kw1">extends</span> UIFrame<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> MainFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; UIButton button <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="st0">&quot;Click me!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="kw1">this</span>, <span class="st0">&quot;doButtonClick&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; setLayout<span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span class="br0">&#40;</span>button, UIBorderLayout.<span class="me1">CENTER</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> doButtonClick<span class="br0">&#40;</span>UIActionEvent pActionEvent<span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Throwable</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;Button clicked&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>What is happening here is that, internally, a listener is created which references the given object and the named method. This allows to easily add and remove listeners from events and keeping the classes clean by allowing to have all related event listeners in one place and without additional class definitions.</p>
<h3 style="padding-top: 10px">Attaching listeners as lambdas</h3>
<p>Yet there is more, we can of course attach lambdas to the events as listeners, too:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> MainFrame <span class="kw1">extends</span> UIFrame<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> MainFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; UIButton button <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="st0">&quot;Click me!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="br0">&#40;</span>pActionEvent<span class="br0">&#41;</span> <span class="sy0">-&gt;</span> <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;Button clicked&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; setLayout<span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span class="br0">&#40;</span>button, UIBorderLayout.<span class="me1">CENTER</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<h3 style="padding-top: 10px">Attaching listeners as method references</h3>
<p>And last but not least, thanks to the new capabilities of Java 1.8, we can also use method references:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> MainFrame <span class="kw1">extends</span> UIFrame<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> MainFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; UIButton button <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="st0">&quot;Click me!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">::</span>doButtonClick<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; setLayout<span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span class="br0">&#40;</span>button, UIBorderLayout.<span class="me1">CENTER</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw4">void</span> doButtonClick<span class="br0">&#40;</span>UIActionEvent pActionEvent<span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Throwable</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;Button clicked&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<h3 style="padding-top: 10px">Parameters or no parameters? To throw or not to throw?</h3>
<p>By default we actually support two different classes of listeners, the specified event/listener interface itself, and (javax.rad.util.)IRunnable. Which means that you can also attach methods which do not have any parameters, like this:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> MainFrame <span class="kw1">extends</span> UIFrame<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> MainFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; UIButton button <span class="sy0">=</span> <span class="kw1">new</span> UIButton<span class="br0">&#40;</span><span class="st0">&quot;Click me!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">::</span>doButtonClickNoParameters<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span class="me1">eventAction</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">::</span>doButtonClickWithParameters<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; setLayout<span class="br0">&#40;</span><span class="kw1">new</span> UIBorderLayout<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span class="br0">&#40;</span>button, UIBorderLayout.<span class="me1">CENTER</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw4">void</span> doButtonClickNoParameters<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Throwable</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;Button clicked&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw4">void</span> doButtonClickWithParameters<span class="br0">&#40;</span>UIActionEvent pActionEvent<span class="br0">&#41;</span> <span class="kw1">throws</span> <span class="kw3">Throwable</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;Button clicked&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Additionally, all listeners and IRunnable itself do support to throw Throwable, which is then handled inside the EventHandler. So you are very flexible when it comes to what methods you can attach and use as listeners.</p>
<h3 style="padding-top: 10px">Creating your own events</h3>
<p>You can, of course, create your own EventHandlers and listeners to create your own events. All you need are two classes, an extension of EventHandler and a listener interface.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> CustomEvent <span class="kw1">extends</span> EventHandler<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> CustomEvent<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span>ICustomListener.<span class="kw1">class</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">public</span> <span class="kw1">interface</span> ICustomListener<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> somethingHappened<span class="br0">&#40;</span><span class="kw3">String</span> pName<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>And that's it, from here on you can use it:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">CustomEvent event <span class="sy0">=</span> <span class="kw1">new</span> CustomEvent<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
event.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="br0">&#40;</span>pName<span class="br0">&#41;</span> <span class="sy0">-&gt;</span> <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>pName <span class="sy0">+</span> <span class="st0">&quot; 1&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
event.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="br0">&#40;</span>pName<span class="br0">&#41;</span> <span class="sy0">-&gt;</span> <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>pName <span class="sy0">+</span> <span class="st0">&quot; 2&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
event.<span class="me1">addListener</span><span class="br0">&#40;</span><span class="br0">&#40;</span>pName<span class="br0">&#41;</span> <span class="sy0">-&gt;</span> <span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>pName <span class="sy0">+</span> <span class="st0">&quot; 3&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>event.<span class="me1">dispatchEvent</span><span class="br0">&#40;</span><span class="st0">&quot;Adam&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<h3 style="padding-top: 10px">More methods!</h3>
<p>You can also use an interface for listeners which has multiple methods, specifying in the constructor which method to invoke:</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> CustomEvent <span class="kw1">extends</span> EventHandler<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> CustomEvent<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span><span class="br0">&#40;</span>ICustomListener.<span class="kw1">class</span>, <span class="st0">&quot;somethingOtherHappened&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">public</span> <span class="kw1">interface</span> ICustomListener<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> somethingHappened<span class="br0">&#40;</span><span class="kw3">String</span> pName<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> somethingOtherHappened<span class="br0">&#40;</span><span class="kw3">String</span> pName, <span class="kw3">BigDecimal</span> pValue<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> nothingHappened<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Now every time the event is dispatched, the somethingOtherHappened method will be invoked. Anyway, don't use this. The upside of having a "simple" listener interface with just one method (SAM-type) is that it allows to use lambdas with it. A listener interface with multiple methods won't allow this.</p>
<p>In JVx we <a href="http://blog.sibvisions.com/2015/01/28/jvx-and-java-8-events-and-lambdas/">reduced our listener interfaces to just one method (in a backward compatible way)</a> to make sure all events can be used with lambdas.</p>
<h3 style="padding-top: 10px">Fire away!</h3>
<p>That's it for this short reference sheet, that is how our event system can and should be used. Of course, there is much more to it under the hood, for example listeners being wrapped in proxy classes, reflection used for invoking methods and some more stuff. If you feel adventurous, be my guest and have a good look at the internals of EventHandler, it is quite an interesting read.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2016/11/03/jvx-reference-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JVx SwingUI extensions</title>
		<link>https://blog.sibvisions.com/2010/09/02/jvx-swingui-extensions/</link>
		<comments>https://blog.sibvisions.com/2010/09/02/jvx-swingui-extensions/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 13:11:36 +0000</pubDate>
		<dc:creator>rjahn</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JVx]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://blog.sibvisions.com/?p=438</guid>
		<description><![CDATA[JVx defines a technology independent User Interface, with Interfaces. Each technology has to implement this interfaces for its components and controls, to be compatible with JVx. We have implemented all this interfaces for Swing.
In addition we have created some swing components with special features for business applications. This components are simple extensions to existing swing [...]]]></description>
			<content:encoded><![CDATA[<p>JVx defines a technology independent User Interface, with Interfaces. Each technology has to implement this interfaces for its components and controls, to be compatible with JVx. We have implemented all this interfaces for Swing.</p>
<p>In addition we have created some swing components with special features for business applications. This components are simple extensions to existing swing components and are supported from any Look and Feel. They can be used in any swing application with or without the whole JVx framework.</p>
<p>We will show here some of this components:</p>
<ul>
<li><strong>DesktopPane with tab or frame mode</strong>
<p>Switch between tab and frame view, Closable tabs (works with java 1.5 and is LaF independent), Drag and Drop Tabs, Tab navigation with keyboard, Modal frames, Background image.</p>
<table>
<tr>
<td>
<div id="attachment_440" class="wp-caption left nomargin" style="width: 160px"><a href="http://blog.sibvisions.com/wp-content/uploads/2010/09/desktop_frames.jpg" rel="lightbox[438]"><img src="http://blog.sibvisions.com/wp-content/uploads/2010/09/desktop_frames-150x150.jpg" alt="Frames" width="150" height="150" class="size-thumbnail wp-image-440" /></a><p class="wp-caption-text">Frame mode</p></div>
</td>
<td style="width:10px"></td>
<td>
<div id="attachment_442" class="wp-caption left nomargin" style="width: 160px"><a href="http://blog.sibvisions.com/wp-content/uploads/2010/09/desktop_tabs.jpg" rel="lightbox[438]"><img src="http://blog.sibvisions.com/wp-content/uploads/2010/09/desktop_tabs-150x150.jpg" alt="Tab mode" width="150" height="150" class="size-thumbnail wp-image-442" /></a><p class="wp-caption-text">Tab mode</p></div>
</td>
<td style="width:10px"></td>
<td><div id="attachment_467" class="wp-caption alignleft nomargin" style="width: 160px"><a href="http://blog.sibvisions.com/wp-content/uploads/2010/09/desktop_background.jpg" rel="lightbox[438]"><img src="http://blog.sibvisions.com/wp-content/uploads/2010/09/desktop_background-150x150.jpg" alt="Desktop Background" width="150" height="150" class="size-thumbnail wp-image-467" /></a><p class="wp-caption-text">Desktop Background</p></div></td>
</tr>
<tr>
<td style="height: 10px"></td>
</tr>
</table>
</li>
<li><strong>ComboBoxes with user-defined popup components</strong>
<p>A base implementation of a ComboBox called ComboBase. With this combo you can build your own ComboBox for e.g. input first and last name in separate fields. We implemented a date chooser and a table selector (header is:</p>
<table>
<tr>
<td>
<div id="attachment_454" class="wp-caption alignleft nomargin" style="width: 160px"><a href="http://blog.sibvisions.com/wp-content/uploads/2010/09/combobase_date.jpg" rel="lightbox[438]"><img src="http://blog.sibvisions.com/wp-content/uploads/2010/09/combobase_date-150x150.jpg" alt="Date Combo" width="150" height="150" class="size-thumbnail wp-image-454" /></a><p class="wp-caption-text">Date Combo</p></div>
</td>
<td style="width:10px"></td>
<td>
<div id="attachment_455" class="wp-caption alignleft nomargin" style="width: 160px"><a href="http://blog.sibvisions.com/wp-content/uploads/2010/09/combobase_table.jpg" rel="lightbox[438]"><img src="http://blog.sibvisions.com/wp-content/uploads/2010/09/combobase_table-150x150.jpg" alt="Table Combo" width="150" height="150" class="size-thumbnail wp-image-455" /></a><p class="wp-caption-text">Table Combo</p></div>
</td>
</tr>
<tr>
<td style="height: 10px"></td>
</tr>
</table>
</li>
<li><strong>Table with load-on-demand model and ready-to-use cell editors/renderers</strong>
<p>A table which uses an IDataBook implementation as model (e.g. MemDataBook) and shows cell editors and renderers dependent of the cell data types, e.g. a table with image renderer and multiple choice editor/renderer</p>
<table>
<tr>
<td>
<div id="attachment_456" class="wp-caption alignleft nomargin" style="width: 160px"><a href="http://blog.sibvisions.com/wp-content/uploads/2010/09/tables_editors.jpg" rel="lightbox[438]"><img src="http://blog.sibvisions.com/wp-content/uploads/2010/09/tables_editors-150x150.jpg" alt="Table with renderer and editor" width="150" height="150" class="size-thumbnail wp-image-456" /></a><p class="wp-caption-text">Table with renderer and editor</p></div>
</td>
</tr>
<tr>
<td style="height: 5px"></td>
</tr>
<tr>
<td>Following editors/renderer are available: <strong>Text</strong>, <strong>Number</strong> (only numbers are allowed), <strong>Date</strong>, <strong>Multiple Choice</strong>, <strong>Image</strong></td>
</tr>
<tr>
<td style="height: 10px"></td>
</tr>
</table>
</li>
<li><strong>Button</strong>
<p>A standard button and a toggle button with support for mouse-over borders.
</li>
<li><strong>Icon</strong>
<p>A special icon which supports image stretching and alignment.
</li>
</ul>
<p><span></span><br />
Our implementation includes not only Swing components. It also contains some useful layouts:</p>
<ul>
<li><strong>FormLayout</strong>
<p>Anchor based layouting. Supports margins, stretching, gaps, ... It is designed for simple and complex forms.
</li>
<li><strong>BorderLayout</strong>
<p>Supports margins.
</li>
<li><strong>SequenceLayout</strong>
<p>Supports component stretching, component orientation, intelligent wrapping.
</li>
</ul>
<p>If you are interested in JVx, leave a comment or join our community.<br />
You are welcome!</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2010/09/02/jvx-swingui-extensions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JVx 0.8 Beta 2 is verfügbar</title>
		<link>https://blog.sibvisions.com/2010/06/10/jvx-0-8-beta-2-is-verfugbar/</link>
		<comments>https://blog.sibvisions.com/2010/06/10/jvx-0-8-beta-2-is-verfugbar/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 15:03:37 +0000</pubDate>
		<dc:creator>rjahn</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JVx]]></category>

		<guid isPermaLink="false">http://blog.sibvisions.com/?p=294</guid>
		<description><![CDATA[Seit wenigen Minuten steht die 2. Beta Version von JVx 0.8 zum Download bereit. Die Änderungsliste ist diesmal etwas kürzer ausgefallen, doch unter der Haube wurde kräftig geschraubt.
Diese Version enthält vor allem im Hinblick auf das kommende WebUI einiges an Erweiterungen. Doch nähere Details dazu in einem der kommenden Posts
Was kann man von der Beta [...]]]></description>
			<content:encoded><![CDATA[<p>Seit wenigen Minuten steht die 2. Beta Version von JVx 0.8 zum <a href="http://www.sibvisions.com/de/downloadmreleases">Download</a> bereit. Die Änderungsliste ist diesmal etwas kürzer ausgefallen, doch unter der Haube wurde kräftig geschraubt.</p>
<p>Diese Version enthält vor allem im Hinblick auf das kommende WebUI einiges an Erweiterungen. Doch nähere Details dazu in einem der kommenden Posts</p>
<p><strong>Was kann man von der Beta 2 erwarten?</strong></p>
<ul>
<li><strong>Erhöhte Sicherheit</strong>
<p>Die Session steuert ab sofort den Zugriff auf Lifecycle Objekte und delegiert dies an den Security Managers. Sollten spezielle Zugrifssbeschränkungen existieren, wird der Zugriff nicht eingeschränkt.</p>
<p>Weiters ist die Passwort Verschlüsselung nun konfigurierbar, wahlweise MD5, SHA 512 oder eine Standard <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html">Java Security</a> konforme Implementierung.</li>
<li><strong>Neue Utility Klassen</strong> <em>(com.sibvisions.util)</em>
<p>Siehe <a href="http://www.sibvisions.com/files/jvx/0.8/api/">Javadoc</a></li>
<li><strong>Performance Optimierung</strong>
<p>Durch die Vermeidung von Instanz Erzeugung beim Zugriff auf die Datenbank und bei der Behandlung der Metadaten wird einerseits Speicher und andererseits Zeit eingespart. Abhängig von der Anzahl der Datensätze ist der Unterschied deutlich merkbar.
</li>
<li><strong>Bugfixing</strong>
<p>Datenbanzugriff mit HyperSQL und Oracle, Bildbibliothek laden aus unterschiedlichen Threads, Serialisierung, Layouting, XML Security Manager uvm.
</li>
</ul>
<p>Die <strong>Release 0.8</strong> von <strong>JVx</strong> wird <strong>zusammen mit der WebUI und QT Implementierung</strong> im Laufe des <strong>3. Quartals 2010</strong> verfügbar sein. Der <strong>Showcase</strong> unserer <strong>WebUI</strong> Implementierung wird bereits <strong>in den nächsten Wochen</strong> online sein.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sibvisions.com/2010/06/10/jvx-0-8-beta-2-is-verfugbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
