<?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>A Place for John on the Web &#187; Uncategorized</title>
	<atom:link href="http://www.siberian.org/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.siberian.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 21 Mar 2010 14:51:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Enum based ComboBoxes in GXT</title>
		<link>http://www.siberian.org/2010/03/20/enum-based-comboboxes-in-gxt/</link>
		<comments>http://www.siberian.org/2010/03/20/enum-based-comboboxes-in-gxt/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 03:54:38 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[GWT/GXT]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.siberian.org/?p=240</guid>
		<description><![CDATA[Working with GXT is interesting. You combine utter frustration and time wasting with incredible breakthroughs that make you say &#8216;I could have never done that so easily in another framework.&#8217; In a way all frameworks are like this I suppose.
My most recent problem/breakthrough was around enums. The particular app in question uses GXT in the [...]]]></description>
			<content:encoded><![CDATA[<p>Working with GXT is interesting. You combine utter frustration and time wasting with incredible breakthroughs that make you say &#8216;I could have never done that so easily in another framework.&#8217; In a way all frameworks are like this I suppose.</p>
<p>My most recent problem/breakthrough was around enums. The particular app in question uses GXT in the browser, a set of native client apps on the users PC and an XML-RPC layer that glues them all together <em>(yes, I still love XML-RPC, give me type safety over syntactical sugar any day of the week. Plus, we have libraries that make syntax a non-issue. But I diverge..). </em>The client is written in C++/C# and does a lot of state tracking using, of course, enumerations, with a mirrored set of enums on the server-side.</p>
<p>These enums are natively persisted into the database using <a href="http://cwiki.apache.org/CAYDOC/modeling-enumerations.html" target="_blank">Cayenne&#8217;s Extended Enumeration</a> feature making the entire transaction fairly seamless, until I got to the browser level and realized that GXT likes to treat everything as a <a href="http://www.extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/store/Store.html">Store</a> and, beyond that, sending a native Cayenne class to the browser as a module was not going to work well since the Javascript Compiler would probably flip over and croak. After searching for awhile I finally came across a mix of recipes that works for me and thought I would commit my knowledge to Google and hope that I help others in the future.</p>
<h2>Step 1: Normalize your Enum into your GWT *.client.* package space.</h2>
<p>Yes, you must duplicate your enum OR move it to this space and change all accessors. Its a bit more complicated if your using a non-native enum (like the above mentioned Extended Enumeration for Cayenne). I ended up just making a copy of my Extended Enumerations as POE (Plain Ole Enumerations). Duplicative code AND prone to error when we change states but it worked.</p>
<p>Mine looks like this:</p>
<pre>public enum BudgetPeriod {
     DAILY("Daily"),WEEKLY("Weekly"),MONTHLY("Monthly"),QUARTERLY("Quarterly"),YEARLY("Yearly");
     private String value;
     BudgetPeriod(String value) {
		this.value = value;
     }
     public String toString() {
		return value;
     }
}</pre>
<h2>Step 2: Use the SimpleComboBox</h2>
<p>The combobox insists on a Store. At this point you can either convert your enum to ModelData and call it a day (which is what most people do) or realize that, since your using Dozer (well, I am), that this blows up fantastically and requires all sorts of conversion routines to move back and forth between ModelData and enum if Dozer is going to do its job right.</p>
<p>This is where the SimpleComboBox comes in, it allows you to bind any class to the combobox and thus gives you seamless abilities that glue your Enum directly to the form (and back again). It looks like this in my case:</p>
<pre>SimpleComboBox&lt;MyEnumClass&gt; theComboBox = new SimpleComboBox&lt;MyEnumClass&gt;();</pre>
<p>Now my box can move my enums around nicely in this combox format.</p>
<h2>Step 3: Populate the list</h2>
<p>Even a SimpleComboBox needs standards and its standard is either a Store or a List. We choose list and convert our Enum to that list for adding it to the list.</p>
<pre>java.util.List enumList = Arrays.asList(MyEnumClass.values());
theComboBox.add(enumList);</pre>
<div>This just takes all enum values and sticks them in the list for picking. Easy enough.</div>
<h2>Step 4: Pre-select whats in the database</h2>
<div>In an edit context we obviously must pre-select the currently selected item. Simple!</div>
<div>
<pre>theComboBox.setSimpleValue(entity.getEnum());</pre>
<h2>Step 5: Oh no! My Dropdown list clears itself if I pick something!</h2>
<p>This is trivial but important to understand. Since its a ComboBox at heart it is always filtering the list based on what you type. This is easily overridden by setting a trigger on the field that makes this behavior appear to go away and thus always show the list. This is a problem in two scenarios:</p>
<p>A) The user picked a value, thus narrowing the filter all the way to one item and clearing the picklist</p>
<p>B) You are in an update scenario so the pre-selection does (A) for the user (thanks!).</p>
<p>The answer is simple</p>
<pre>theComboBox.setTriggerAction(TriggerAction.ALL);</pre>
<p>This causes a lot of people confusion but it is what it is. By setting the trigger you&#8217;ll force the list to always display all of your enums (or anything else you may put in a ComboBox)</p>
<h2>Step 6: FormBinding: Not your friend with an Enum</h2>
<p>The next big trip-up comes when you try to bind your SimpleComboBox to the form so that it auto-updates the model and removes all that <em>CRUD</em> you hate so much. At the end of the day, even though we told the SimpleComboBox it contained MyEnumClass its value is just a string. When we try to bind a string to an enumeration in our backing model we get a big fat <span style="color: #ff0000;">CLASS CAST EXCEPTION</span>. Boo hiss.</p>
<p>The solution: Don&#8217;t bind the field, handle it manually in your create/update event right before you send your model out over RPC for commitment.</p>
<pre>myModel.setBudgetperiod(theComboBox.getSimpleValue());</pre>
<p>Since the combobox is pretending to hold real-enums it will pass the value of the users selecting to the model without causing that <span style="color: #ff0000;">CLASS CAST EXCEPTIO</span><span style="color: #ff0000;">N</span>. This is not truly creating Enum&lt;-&gt;Enum mapping but it is passing a value back that the model Enum *thinks* it understands and thus, making a mockery of data-types, it successfully updates the model which in turn can update the data-store transparently.</p>
<h2>Summary and Final Code</h2>
<p>There are other recipes for this as well as all sorts of trickery you can do for display purposes etc but in the end this worked well for my requirements. This app is really heavy on the enums and this, with a touch of code duplication and a bit more maintenance overhead for the few updates a year I may do, gave me seamless movement of enums from Windows Desktop-&gt;XML-RPC-&gt;Database-&gt;Browser/GXT-&gt;Database-&gt;XML-RPC-&gt;Windows Desktop.</p>
<p>Take that JSON! (just kidding, I love you also JSON. Sometimes..)</p>
<h4>Enum</h4>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">public enum BudgetPeriod {
     DAILY("Daily"),WEEKLY("Weekly"),MONTHLY("Monthly"),QUARTERLY("Quarterly"),YEARLY("Yearly");
     private String value;
     BudgetPeriod(String value) {
		this.value = value;
     }
     public String toString() {
		return value;
     }
}</pre>
<h4>SimpleComboBox creation</h4>
<p>A few notes here:</p>
<ul>
<li>I assign my list of enum values to a variable and then add that variable. You can do that in one fell swoop and avoid the assignment, this code is debugger friendly</li>
<li>Notice that I am NOT defining <em>theComboBox</em> here, just assigning it. You need to define it at the class level so that the update routine, which is usually anonymous in a GWT/GXT pattern, can access it without it being final.</li>
</ul>
<pre>theComboBox = new SimpleComboBox&lt;BudgetPeriod&gt;();
java.util.List periodList = Arrays.asList(MyEnumClass.values()); 
theComboBox.add(periodList);
theComboBox.setLazyRender(false);
theComboBox.setForceSelection(true);
theComboBox.setTriggerAction(TriggerAction.ALL);
theComboBox.setSimpleValue(project.getBudgetperiod());</pre>
<h4>Create/Update handler</h4>
<div id="_mcePaste">
<div id="_mcePaste">Your handle will be different, this is just an example of mine. The only line you care about is &#8216;myModel.setBudgetPeriod(&#8230;)&#8217;</div>
<pre>createButton.addListener(Events.Select, new Listener() {
     public void handleEvent(ButtonEvent e) {
         grid.mask("Saving..");
         myModel.setBudgetperiod(projectBudgetTimeSpan.getSimpleValue()); <strong>// THIS IS ALL YOU CARE ABOUT IN THIS CODE CHUNK</strong>
         MyRPC.Util.getInstance().createProject(project, ClientSession.getInstance().getSessionID(),
                                                new ProjectCreatedCallback(grid, index, myModelBean));
         }
});</pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.siberian.org/2010/03/20/enum-based-comboboxes-in-gxt/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bond, James Bond : Really Google?</title>
		<link>http://www.siberian.org/2010/01/28/bond-james-bond-really-google/</link>
		<comments>http://www.siberian.org/2010/01/28/bond-james-bond-really-google/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 20:23:05 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.siberian.org/?p=222</guid>
		<description><![CDATA[Running some sample translations for a demo I came across this fun one. Type &#8216;Bond&#8217; (upper case B counts), select English as source, Japanese as result.
Voila : 007
Shaken, not stirred.

]]></description>
			<content:encoded><![CDATA[<p>Running some sample translations for a demo I came across this fun one. Type &#8216;Bond&#8217; (upper case B counts), select English as source, Japanese as result.</p>
<p>Voila : 007</p>
<p>Shaken, not stirred.</p>
<p><a href="http://www.siberian.org/wp-content/uploads/2010/01/googletranslate.png"><img class="alignright size-medium wp-image-223" title="Bond, James Bond" src="http://www.siberian.org/wp-content/uploads/2010/01/googletranslate-300x151.png" alt="" width="300" height="151" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.siberian.org/2010/01/28/bond-james-bond-really-google/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things to dislike about the RicaVision SideShow Remote</title>
		<link>http://www.siberian.org/2007/10/05/things-to-dislike-about-the-ricavision-sideshow-remote/</link>
		<comments>http://www.siberian.org/2007/10/05/things-to-dislike-about-the-ricavision-sideshow-remote/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 22:08:26 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.siberian.org/2007/10/05/things-to-dislike-about-the-ricavision-sideshow-remote/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://www.siberian.org/2007/10/05/things-to-dislike-about-the-ricavision-sideshow-remote/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RicaVision SideShow Remote Arrived</title>
		<link>http://www.siberian.org/2007/10/03/ricavision-sideshow-remote-arrived/</link>
		<comments>http://www.siberian.org/2007/10/03/ricavision-sideshow-remote-arrived/#comments</comments>
		<pubDate>Wed, 03 Oct 2007 09:27:00 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.siberian.org/2007/10/03/ricavision-sideshow-remote-arrived/</guid>
		<description><![CDATA[For all 4 of you that have ever read anything on this site you'll know I am a bit of a Distributed A/V : SmartHome freak and part of that quest is creating a remote control system with an extremely high WAF(Wife Acceptance Factor). I thought I had that set with my Phillips Pronto and room based content switcher but then Microsoft introduced SideShow and the first devices started appearing in glass cages at tradeshows.

Devices with color screens, Media Player control and easy navigation.]]></description>
			<content:encoded><![CDATA[<p>For all 4 of you that have ever read anything on this site you&#8217;ll know I am a bit of a Distributed A/V : SmartHome freak and part of that quest is creating a remote control system with an extremely high WAF(Wife Acceptance Factor). I thought I had that set with my Phillips Pronto and room based content switcher but then Microsoft introduced SideShow and the first devices started appearing in glass cages at tradeshows. Devices with color screens, Media Player control and easy navigation.</p>
<p>For about 6 months I&#8217;ve had my eye on the <a href="http://www.ricavision.com/ricavision_webupdate/sideshow_remote.html">RicaVision SideShow Remote</a> but they were not available. Diligent monthly searches eventually turned up a purchase link for the Manufacturer Samples @ $249.99 and decided to go for it. My 2 year old really helped me out when he recently found a way to flip my Pronto into &#8216;<em>Toddler</em>&#8216; mode, meaning its bricked.</p>
<p>So 5 days later the RicaVision Remote has arrived and so far I am mostly impressed and very excited about the potential not just of this specific device but of SideShow in general. SideShow really is one under hyped platform that Vista enables and Microsoft is really not doing it justice.</p>
<p>Why this remote and why SideShow? Mostly because the default SideShow Gadget gives you full control of Windows Media player, that means headless song selection that is bi-directional! Cover Art on the remote, bluetooth control etc, you get the idea.</p>
<p>I am going to do a detailed review of it shortly but my initial impressions are :</p>
<p><strong>Packaging</strong> : NICE, came in a nice faux leather box</p>
<p><strong>Build Quality</strong> : Pretty good for a sample. The chrome is a bit chintzy and you can see waves in some of the plastic but really nothing that impacts usage or even is noticeable unless your looking for a problem</p>
<p><strong>Software</strong> : Drivers took immediately although I did have to remove/insert the device post driver install to get it to appear in the SideShow Control Panel.</p>
<p><strong>Configuration</strong> : None, it Just Works</p>
<p><strong>BlueTooth</strong> : So-so, it seems to lose connection randomly but just hitting back and enter tends to get the job done. Slightly annoying but I imagine they are fixing this with the new version coming out later this year. I was able to change songs from 50 feet down the hall so that was cool. Additionally, sometimes you have to hold the button for a full second or so to get a response. A second doesn&#8217;t seem like a lot but try it, you&#8217;ll see.</p>
<p><strong>IR</strong> : It includes an RC-6 Windows IR Receiver so its plug and play and works as expected</p>
<p><strong>Ergonomics</strong> : Pretty weird actually. The remote has 3 distinct &#8216;areas&#8217;, a top black area that controls the SideShow app (QVGA screen + 5 way thumbstick + Back + Menu buttons), a middle area that has another 4 way button pad for Media Center and then the bottom area with the standard Play/Pause buttons. Instinct is to always use the 4 buttons, not the thumbstick. You get used to it but a single 4 way with a selection switch might be nicer.</p>
<p><strong>Overall</strong> : I am impressed and excited. This remote will let me control the music in the backyard from the comfort of my lounge chair, no laptop required and no more NetRemote. It also controls Media Player in headless mode, this means you can use it on your primary PC and never see Media Player.</p>
<p>What is more exciting is how dead simple SideShow is to develop for. If you can output XML then you can start building basic SideShow apps. My current plan is to use SideShow to control my Matrix Switch and eventually my Sprinkler overrides. As I get those Gadgets rolling next week I will post about them.</p>
<p>So, more SideShow coming soon and a real review with photos this weekend.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.siberian.org/2007/10/03/ricavision-sideshow-remote-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
