<?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>Andrew Pietsch&#039;s Weblog &#187; Development</title>
	<atom:link href="http://pietschy.com/blog/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://pietschy.com/blog</link>
	<description>Things and stuff</description>
	<lastBuildDate>Mon, 15 Feb 2010 04:07:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using &lt;? extends T&gt; and &lt;? super T&gt; for reduce style functions that operate on collections</title>
		<link>http://pietschy.com/blog/2010/02/using-extends-t-and-super-t-for-reduce-style-functions-that-operate-on-collections/</link>
		<comments>http://pietschy.com/blog/2010/02/using-extends-t-and-super-t-for-reduce-style-functions-that-operate-on-collections/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 01:15:51 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[GWT]]></category>

		<guid isPermaLink="false">http://pietschy.com/blog/?p=226</guid>
		<description><![CDATA[


One of the cases I&#8217;ve had to deal with in gwt-pectin is creating Reduce style functions that operate on a collection of values.  The basic idea is to define interface of the&#160;form.
public interface Reduce&#60;R,T&#62; {
   R reduce(List&#60;T&#62; source);
}
I use this on my ReducingValueModel&#60;R,T&#62; to automatically compute fields such as a sum&#8217;s of numbers, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the cases I&#8217;ve had to deal with in <a href="http://code.google.com/p/gwt-pectin/">gwt-pectin</a> is creating Reduce style functions that operate on a collection of values.  The basic idea is to define interface of the&nbsp;form.</p>
<pre>public interface Reduce&lt;R,T&gt; {
   R reduce(List&lt;T&gt; source);
}</pre>
<p>I use this on my ReducingValueModel&lt;R,T&gt; to automatically compute fields such as a sum&#8217;s of numbers, or a string representation of a list and so forth.  So on my ReducingValueModel I have a method to configure the reducing function to use as&nbsp;follows.</p>
<pre>public class ReducingValueModel&lt;R,T&gt; {
<span style="color: #999999;">   // our function</span>
   private Reduce&lt;R,T&gt; function;
<span style="color: #999999;">   // and it's setter</span>
   public void setFunction(Reduce&lt;R,T&gt; function) {
      this.function = function;
      recompute();
   }
   <span style="color: #999999;">// and every thing else that makes it go
   ...
</span>}</pre>
<p>This works fine when define a new function for each different combination of R and T.  The trouble appears when you want to create a generic Reduce function that you can use on any ReductingValueModel.   Something like a generic &#8220;list to string&#8221; style function for&nbsp;example:</p>
<pre>public class ListToStringFunction&lt;String, Object&gt; {
<span style="color: #c0c0c0;">   // we can convert any list of objects to a string</span>
   public String reduce(List&lt;Object&gt; values) {
     <span style="color: #c0c0c0;">// concate our list values and return the result.</span>
     return ...;
   }
}</pre>
<p>So now lets try and use&nbsp;it.</p>
<pre>ReducingValueModel&lt;String, Integer&gt; reducingModel = ...;
<span style="color: #999999;">// This won't compile...</span>
reductingModel.setFunction(new ListToStringFunction());
</pre>
<p>But this won&#8217;t compile because ListToStringFunction is a Reduce&lt;String, Object&gt; and not Reduce&lt;String, Integer&gt;.  So we bung in the standard &lt;? super T&gt; clause on the ReducingValueModel so it can accept a function that works on any super&nbsp;type.</p>
<pre>public class ReducingValueModel&lt;R,T&gt; {
<pre>  private <strong>Reduce&lt;R, ? super T&gt;</strong> function;
<span style="color: #c0c0c0;">  <span style="color: #999999;">// now lets use &lt;? super S&gt; so we can use functions that
  // operate on any super source type.</span></span>
  public void setFunction(<strong>Reduce&lt;R,? super T&gt;</strong> function) {
    this.function = function;
    recompute();
  }
}</pre>
</pre>
<p>And while it looks like this should work, it doesn&#8217;t.  The problem is that were I&#8217;m using the Reduce function it&#8217;s now defined as a Reduce&lt;R, ? super T&gt; (making it a Reduce&lt;T,Object&gt; for all intents and purposes) so it can&#8217;t accept any old List&lt;T&gt; as an&nbsp;argument.</p>
<pre>public class ReducingValueModel&lt;R,T&gt; {

  private <strong>Reduce&lt;R, ? super T&gt;</strong> function;

  protected void recompute()  {
    ArrayList&lt;T&gt; values = ...;  // prepare the values..
    <span style="color: #999999;">// now this won't compile because our the function we
    // passed in only works on List&lt;? super T&gt; and not List&lt;T&gt;</span>
    <strong>R computedValue = function.compute(values);</strong>
    fireValueChangeEvent(computedValue);
  }
}</pre>
<p>Fortunately the fix is simple.  We need to update our Reduce&lt;R,T&gt; interface to accept any values that extend T. &nbsp;I.e.</p>
<pre>public interface Reduce&lt;R,T&gt; {
<span style="color: #999999;">  <span style="color: #999999;"> // this allows our Reduce&lt;R, ? super T&gt; to operate
   // on any list</span></span><span style="color: #999999;"> that extends T</span>
   T reduce(<strong>List&lt;? extends T&gt;</strong> source);
}</pre>
<p>Now our ReducingValueModel&lt;R,T&gt; can accept functions that work on any super type of T and our Reduce&lt;R,T&gt; can accept any list whose values that extend&nbsp;T.</p>
<p>So the two things to do&nbsp;are:</p>
<ol>
<li>Make sure your functions can operate on source collections of type &lt;? extends T&gt;. i.e.
<pre>public interface Reduce&lt;R,T&gt; {
   R reduce(<strong>List&lt;? extends T&gt;</strong> source)
}</pre>
</li>
<li>Allow users to configure functions use &lt;? super S&gt; for the source values.  i.e.
<pre>public void setFunction(<strong>Reduce&lt;R, ? super T&gt;</strong> function) {...}</pre>
</li>
</ol>
<p>All&nbsp;good.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2010/02/using-extends-t-and-super-t-for-reduce-style-functions-that-operate-on-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplifying</title>
		<link>http://pietschy.com/blog/2008/10/simplifying/</link>
		<comments>http://pietschy.com/blog/2008/10/simplifying/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 00:03:57 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=26</guid>
		<description><![CDATA[I always find it healthy to come back and use code you wrote a while ago.  There&#8217;s nothing like a bit of space to help see things in a new light.  Often too you can be so focused on solving one problem that you don&#8217;t get a chance to step back and see [...]]]></description>
			<content:encoded><![CDATA[<p>I always find it healthy to come back and use code you wrote a while ago.  There&#8217;s nothing like a bit of space to help see things in a new light.  Often too you can be so focused on solving one problem that you don&#8217;t get a chance to step back and see the bigger&nbsp;picture.</p>
<p>And so it was when using my binding framework the other day.  Don&#8217;t get me wrong, I really like it.  But the first pass gave me flexibililty I needed, but not the simplicity I needed for day to day regular use.  Who really wants to create presentation models using the&nbsp;following?</p>
<pre>// somewhere at startup
Pectin.registerMixin(ComponentMixin.instance());

// then when you need a presentation model
PresentationModel&lt;ComponentValueModel&gt; pm =
      new PresentationModel&lt;ComponentValueModel&gt;();

// and use the "firstName" value model..
pm.get("firstName").setEnabled(false);</pre>
<p>What&#8217;s a ComponentValueModel anyway and why do I need one?  As it turns out I almost always want one (since it gives my value models the common enabled, visible, and editable properties) so why do I have to specify it every time?  Then there&#8217;s validation, you almost always need that&nbsp;too.</p>
<p>So, short story long, I&#8217;ve layered the API.  The original classes have been moved to a lower level (i.e. GenericPresentationModel) and I&#8217;ve created new implementations that extend them and that come pre-configured with the default interfaces.   I&#8217;ve also installed the associated Mixins automatically so for everyday use it&#8217;s now&nbsp;just:</p>
<pre lang="java">// This is much better
PresentationModel pm = new PresentationModel();
pm.get("firstName").setEnabled(false);</pre>
<p>Much&nbsp;nicer.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2008/10/simplifying/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Farewell Tapestry and Hello GWT</title>
		<link>http://pietschy.com/blog/2008/06/farewell-tapestry-and-hello-gwt/</link>
		<comments>http://pietschy.com/blog/2008/06/farewell-tapestry-and-hello-gwt/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 03:52:13 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=24</guid>
		<description><![CDATA[With the upcoming release of Tapestry 5 I&#8217;ve decided to take the plunge and try out GWT.  I&#8217;ve long been a Tapestry fan (I can&#8217;t stand the goto development style of Struts), but this latest version has left me a little wanting.  In&#160;short:

It&#8217;s changing dramatically&#160;again.
 The framework now magically invokes methods if they [...]]]></description>
			<content:encoded><![CDATA[<p>With the upcoming release of Tapestry 5 I&#8217;ve decided to take the plunge and try out GWT.  I&#8217;ve long been a Tapestry fan (I can&#8217;t stand the goto development style of Struts), but this latest version has left me a little wanting.  In&nbsp;short:</p>
<ul>
<li>It&#8217;s changing dramatically&nbsp;again.</li>
<li> The framework now magically invokes methods if they follow particular&nbsp;conventions.</li>
<li> I hate method conventions.  Intellij IDEA is really good at telling me all kinds of useful things.  Method conventions bugger that up&nbsp;completely.</li>
<li> Tapestry documentation has always been lacking, this magnifies the previous gripe by a factor of&nbsp;100.</li>
</ul>
<p>Once I realised the depth of my grumpiness I decided to re-evaluate the webapp landscape.  Since I&#8217;m not interested in ruby/rails I decided to give GWT a&nbsp;whirl.</p>
<p>The GWT approach is different.  You don&#8217;t develop a web application with lots of pages etc, you write Javascript application which you then embed in a given web page (I.e. a bit like embedding an Applet in a page).  While it&#8217;s not a solution for generating websites, it&#8217;s great for developing web&nbsp;applications.</p>
<p>What&#8217;s more, you write your Javascript in Java.  Sweet.  I get everything  Java gives me (well a fair bit anyway) like packages, interfaces and type safe refactoring&nbsp;etc.</p>
<p>Some of the good points&nbsp;are:</p>
<ul>
<li>The documentation is great.  Well thought out and well&nbsp;written.</li>
<li>The shell environment is wonderful.  The best out of the box web development experience I&#8217;ve had&nbsp;yet.</li>
<li>The client aspects of the application are written using standard client techniques.  Observable models, reusable widgets, similar development&nbsp;approaches.</li>
<li>My server is&nbsp;stateless.</li>
</ul>
<p>Things that could be&nbsp;better:</p>
<ul>
<li>There&#8217;s no binding API.  Life without binding sucks.  There are apparently plans for one, but in the mean time it took me a week to migrate my Swing binding framework over to&nbsp;GWT.</li>
<li>It would be nice if there was an easier way to add servlet context listeners and context parameters to the shell&nbsp;environment.</li>
<li>Better documentation on writing compiler plugins would be&nbsp;nice.</li>
</ul>
<p>Other than that, the combination of GWT in the browser and simple servlets using Guice on the backend has been a&nbsp;delight.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2008/06/farewell-tapestry-and-hello-gwt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing with Google Guice: Look and Feel</title>
		<link>http://pietschy.com/blog/2008/05/playing-with-google-guice-look-and-feel/</link>
		<comments>http://pietschy.com/blog/2008/05/playing-with-google-guice-look-and-feel/#comments</comments>
		<pubDate>Mon, 12 May 2008 01:00:50 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=23</guid>
		<description><![CDATA[In this example I&#8217;m showing how I use the LookAndFeelService in conjection with the EnvironmentService to configure the LAF defaults based on the runtime environment.  The LookAndFeelModule allows me to configure various look and feel aspects based on the runtime&#160;environment.
The LookAndFeelModule is the starting point.  You configure it and it configures the LookAndFeelService&#160;appropriately.
// [...]]]></description>
			<content:encoded><![CDATA[<p>In this example I&#8217;m showing how I use the LookAndFeelService in conjection with the EnvironmentService to configure the LAF defaults based on the runtime environment.  The LookAndFeelModule allows me to configure various look and feel aspects based on the runtime&nbsp;environment.</p>
<p>The LookAndFeelModule is the starting point.  You configure it and it configures the LookAndFeelService&nbsp;appropriately.</p>
<pre>// create the module
LookAndFeelModule lafModule = new LookAndFeelModule();

// set the default look and feel.
lafModule.setDefaultLookAndFeel(UIManager.getSystemLookAndFeelClassName());

// now configure environment specific lafs
lafModule.registerLookAndFeel(MacOSX.class,
                              QuaquaLookAndFeel.class.getName());</pre>
<p>I also use a replacement for JOptionPane that supports application wide and document specific option panes as required by the Mac. This too needs to be configured based on the environment we&#8217;re running&nbsp;on.</p>
<pre>// Configure the MessagePaneProvider to use by default
lafModule.setDefaultMessagePaneProvider(new GenericMessagePaneProvider());

// now configure environment specific MessagePane providers
lafModule.registerMessagePaneProvider(MacOSX.class,
                                      new MacMessagePaneProvider());</pre>
<p>Then I simply pass the module to my application launcher.  The application retrieves the LookAndFeelService and invokes its configure&nbsp;method.</p>
<p>Launcher.launch(MyApplication.class, args,&nbsp;lafModule);</p>
<p>Of course instead of repeating this in every application I&#8217;ve created a default module implementation that&#8217;s preconfigured.  So all I need do&nbsp;is:</p>
<pre>Launcher.launch(MyApplication.class, args, new DefaultLookAndFeelModule());</pre>
<p>And everything just works.&nbsp;Nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2008/05/playing-with-google-guice-look-and-feel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing with Google Guice: Splash Screens</title>
		<link>http://pietschy.com/blog/2008/05/playing-with-google-guice-splash-screens/</link>
		<comments>http://pietschy.com/blog/2008/05/playing-with-google-guice-splash-screens/#comments</comments>
		<pubDate>Wed, 07 May 2008 03:22:15 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=22</guid>
		<description><![CDATA[The previous entry showed the creation of a (very) simple single frame application.  Splash screens are common, so lets add one.   Since there&#8217;s no easy way to do it for all occasions, we&#8217;ll use a Guice module to provide it for runtimes prior to Java&#160;6.
public static void main(String[] args)
{
   URL [...]]]></description>
			<content:encoded><![CDATA[<p>The previous entry showed the creation of a (very) simple single frame application.  Splash screens are common, so lets add one.   Since there&#8217;s no easy way to do it for all occasions, we&#8217;ll use a Guice module to provide it for runtimes prior to Java&nbsp;6.</p>
<pre>public static void main(String[] args)
{
   URL splashImage = Main.class.getResource("/images/splash.png");

   // create the splash module for pre Java 6 runtimes.
   Module splashModule = Java5SplashScreenModule(splashImage);
   Launcher.launch(MyApplication.class, args, splashModule);
}</pre>
<p>And that&#8217;s it.  The framework will display the splash screen and all will work fine.  Of course if you&#8217;re running on Java 6 you&#8217;d used the Java 6 version (that uses the new SplashScreen functionality).  Of course if we don&#8217;t define the service in one of our modules, the framework uses the default&nbsp;`NullSplashScreenService`.</p>
<p>If MyApplicationFrame (or any other class for that matter) wanted to use the splash screen service, it just needs to inject it into it&#8217;s&nbsp;constructor.</p>
<pre>public class MyApplicationFrame extends JFrame
{
   @Inject
   public MyApplicationFrame(SplashScreenService splashService)
   {
      // do stuff....
      splashService.setImageURL(nextImageURL);
   }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2008/05/playing-with-google-guice-splash-screens/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing with Google Guice</title>
		<link>http://pietschy.com/blog/2008/05/playing-with-google-guice/</link>
		<comments>http://pietschy.com/blog/2008/05/playing-with-google-guice/#comments</comments>
		<pubDate>Wed, 07 May 2008 02:26:40 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=21</guid>
		<description><![CDATA[It&#8217;s been a long time coming but I&#8217;ve finally started dabbling in dependency injection for my swing frameworks.  It&#8217;s taken me a quite a while to get a feel for where and how it can/should be used.   Given the complexity of even an average Swing application I&#8217;d been loathed to convert all [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time coming but I&#8217;ve finally started dabbling in dependency injection for my swing frameworks.  It&#8217;s taken me a quite a while to get a feel for where and how it can/should be used.   Given the complexity of even an average Swing application I&#8217;d been loathed to convert all my UI construction and wiring over to a container, but I&#8217;d also love to create a framework environment where I can install all my standard behaviours in one&nbsp;line.</p>
<p>I&#8217;d also been wanting to consolidate my various frameworks and utilities into a single application framework (along the lines of <a href="https://appframework.dev.java.net/">JSR-296</a>) but wanted to try out the dependency injection&nbsp;route.</p>
<p>Anyway, so far I&#8217;ve been very pleased with the results.  I&#8217;ve been able to create services for controlling the splash screen, determining the runtime environment and providing runtime environment services, configuring Look and Feel settings and so on. With Guice you can easily create default implementations of your services so you can have the basics going with zero&nbsp;configuration.</p>
<p>So the following useless example shows what&#8217;s necessary to get a frame up and create a file in the default application data&nbsp;directory.</p>
<pre>public class MyApplication
extends SingleFrameApplication
{
   public MyApplication()
   {
      super("MyApplication", MyApplicationFrame.class);
   }

   public void initialise(String[] args)
   {
      // The EnvironemntService ensures it's the correct location
      // based on the runtime platform.. i.e. `C:\AppData\MyApplication`
      // on windows and `~/Library/Application Support/MyApplication`
      // on the Mac.

      // AbstractApplication provides getters for standard services so
      // you don't have to magically discern their existence.
      EnvironmentService env = getEnvironmentServices();
      File logFile = env.getFileInAppDataDirectory("logs/my-app.log");

      // do stuff with the file...
      ....
   }
}</pre>
<p>Then the application can be simply started using the&nbsp;following.</p>
<pre>public static void main(String[] args)
{
   Launcher.launch(MyApplication.class, args);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2008/05/playing-with-google-guice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I generally avoid GUI Builders</title>
		<link>http://pietschy.com/blog/2008/02/why-i-generally-avoid-gui-builders/</link>
		<comments>http://pietschy.com/blog/2008/02/why-i-generally-avoid-gui-builders/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 23:55:41 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=12</guid>
		<description><![CDATA[How&#8217;s that for a non committal title&#160;(c:
Most of my own thoughts have been better explained by others.  Beware the GUI Builder is an excellent article on Hacknot, and a response by Karsten Lentzsch to this post sums up the design issues well (search for &#8220;Karsten Lentzsch&#8221; and you&#8217;ll find his&#160;comment).
The meta design issues described by [...]]]></description>
			<content:encoded><![CDATA[<p>How&#8217;s that for a non committal title&nbsp;(c:</p>
<p>Most of my own thoughts have been better explained by others.  <a href="http://www.hacknot.info/hacknot/action/showEntry?eid=76">Beware the GUI Builder</a> is an excellent article on <a href="http://www.hacknot.info/">Hacknot</a>, and a response by Karsten Lentzsch to <a href="http://weblogs.java.net/blog/joshy/archive/2007/06/a_response_to_g.html">this post</a> sums up the design issues well (search for &#8220;Karsten Lentzsch&#8221; and you&#8217;ll find his&nbsp;comment).</p>
<p>The meta design issues described by Karsten are a major sticking point for me.  The implication is that if you use GUI builders and your UI design requires that the label/component gap be 4 DLUs, or that section titles should have 12 DLUs of top padding, then every developer must know every rule and ensure they implement it correctly on every form.  You will have&nbsp;problems.</p>
<p>Custom layout builders on the other hand don&#8217;t generally suffer the same fate.  They&#8217;re able to capture the design rules in one place (i.e. the DRY principle) and your developers can live blissfully unaware of the nitty gritty requirements or implementation&nbsp;issues.</p>
<p>For larger projects you can also specialise the builders and integrate them with other infrastructure such as a binding or command&nbsp;framework.</p>
<pre>//  a trivial example that doesn't really make sense.
SimpleFormBuilder b = new SimpleFormBuilder();
b.setFormTitle("My Cool Form");
b.addTextField("First _Name", firstNameValueModel);</pre>
<p>Of course the real problems with layout builders is that you have to design and write them,  and there will always be cases that break the rules.  You can minimize this pain however if you start with a decent builder and layer your architecture so developers can drop down to &#8220;manual&#8221; for the edge&nbsp;cases.</p>
<p>This then is the real issue for me: if you only have a few static screens, then a GUI builder is probably an acceptable option, but once your project grows you&#8217;re heading for&nbsp;trouble.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2008/02/why-i-generally-avoid-gui-builders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing with ANTLR</title>
		<link>http://pietschy.com/blog/2007/09/playing-with-antlr/</link>
		<comments>http://pietschy.com/blog/2007/09/playing-with-antlr/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 08:03:32 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=16</guid>
		<description><![CDATA[One aspect that can be annoying when creating value models creating bindings for their enabled and visible states.  The following shows a simple example where certain components are enabled and disabled based on the value of&#160;others.

In this screen, the &#8220;Use Proxy&#8221; is only enabled when &#8220;Automatically Check for Updates&#8221; is selected, and both the [...]]]></description>
			<content:encoded><![CDATA[<p>One aspect that can be annoying when creating value models creating bindings for their enabled and visible states.  The following shows a simple example where certain components are enabled and disabled based on the value of&nbsp;others.</p>
<p><img src="/blog/wp-content/uploads/2007/09/mr-schedule-options.png" alt="Mr Schedule Options" title="Mr Schedule Options" width="344" height="435" class="aligncenter size-full wp-image-77" /></p>
<p>In this screen, the &#8220;Use Proxy&#8221; is only enabled when &#8220;Automatically Check for Updates&#8221; is selected, and both the &#8220;Host&#8221; and &#8220;Port&#8221; fields are only enabled when both check boxes are&nbsp;selected.</p>
<p>To simplify this kind of operation I&#8217;ve been playing around with <a href="http://www.antlr.org/">ANTLR</a> grammars.  First off, if you&#8217;re like me and have never built a language parser before, just go ahead and <a href="http://www.pragmaticprogrammer.com/titles/tpantlr/index.html">buy the book</a>.  Building an abstract syntax tree would have been near impossible without&nbsp;it.</p>
<p>So far I&#8217;ve been able to get a basic language up and going.  The syntax is simple and lets you assign model properties from simple expressions involving other models, for&nbsp;example:</p>
<pre>useProxy.enabled = checkForUpdates.value</pre>
<p>This binds the enabled property of &#8220;useProxy&#8221; to the value of &#8220;checkForUpdates&#8221;.   I also let you omit the &#8220;.value&#8221; for simplicity, so then we&nbsp;get:</p>
<pre>useProxy.enabled = checkForUpdates</pre>
<p>So state of the all the components in the above image is controlled by the three &#8220;bind&#8221; lines of code in the&nbsp;PresentationModel.</p>
<pre>// install the value models...
installValueModel("checkForUpdates", ..);
installValueModel("useProxy", ..);
installValueModel("proxyHost", ..);
installValueModel("proxyPort", ..);

// and create the bindings
bind("useProxy.enabled = checkForUpdates");
bind("proxyHost.enabled = checkForUpdates &#038;& useProxy");
bind("proxyPort.enabled = checkForUpdates &#038;& useProxy");
</pre>
<p>Normally I don&#8217;t like putting code in strings, but in this case I think it&#8217;s worth it.  To limit any possible issues the library barfs during the call to bind if any of the models are missing or don&#8217;t define the required&nbsp;properties. </p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2007/09/playing-with-antlr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>And then there were Mixins</title>
		<link>http://pietschy.com/blog/2007/09/and-then-there-were-mixins/</link>
		<comments>http://pietschy.com/blog/2007/09/and-then-there-were-mixins/#comments</comments>
		<pubDate>Fri, 31 Aug 2007 22:42:58 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=13</guid>
		<description><![CDATA[One of the key goals for my binding infrastructure has been to make it easy to extend the value models to suit your business requirements.  The idea was let you define a custom value model properties and have the library automatically manage them.  I had this working pretty well, but it was pretty [...]]]></description>
			<content:encoded><![CDATA[<p>One of the key goals for my binding infrastructure has been to make it easy to extend the value models to suit your business requirements.  The idea was let you define a custom value model properties and have the library automatically manage them.  I had this working pretty well, but it was pretty painful to set up, and definitely not something I&#8217;d wish on&nbsp;others.</p>
<p>Enter Mixins.  Somewhere along the line it occurred to me that I could create Mixins that provide standard ValueModel extensions and their handlers out of the box.  The first test was to convert my ComponentValueModel interfaces that defines standard component properties such as enabled, editable and&nbsp;visible.  </p>
<pre>public interface ComponentValueModel extends ValueModel
{
    @DefaultValue(true)
    public boolean isEnabled();
    public void setEnabled(boolean enabled);

    @DefaultValue(true)
    public boolean isEditable();
    public void setEditable(boolean editable);

    @DefaultValue(true)
    public boolean isVisible();
    public void setVisible(boolean visible);
}
</pre>
<p>Using this mixin is now as simple&nbsp;as..</p>
<pre>// install the mixin that defines the ComponentValueModel
// interface and standard handlers.
Pectin.registerMixin(ComponentMixin.instance());

// create a presentation model that vends ComponentValueModels
pm = new BeanPresentationModel&lt;Person, ComponentValueModel&gt;(...);

// all the value models returned by the presentation model will
// implement the mixin interface.
ComponentValueModel cvm = pm.get("firstName");

// changes to the mixin properties will be automatically handled
// by the mixin
cvm.setEnabled(true);
cvm.setEditable(false);
cvm.setVisible(true);
</pre>
<p>From here the mixin is responsible for updating the state of components bound to ComponentValueModels.  The mixin uses styles that map particular model properties to particular components allowing you to control the way particular properties effect particular&nbsp;components. </p>
<p>So far I&#8217;m really pleased with the&nbsp;progress.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2007/09/and-then-there-were-mixins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Value Model thoughts…</title>
		<link>http://pietschy.com/blog/2007/08/more-value-model-thoughts/</link>
		<comments>http://pietschy.com/blog/2007/08/more-value-model-thoughts/#comments</comments>
		<pubDate>Tue, 14 Aug 2007 07:30:32 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[UIs and Swing]]></category>

		<guid isPermaLink="false">http://pietschy.webfactional.com/blog/?p=17</guid>
		<description><![CDATA[In light of my previous post, I&#8217;ve long pondered how I could create a generic PresentationModel/ValueModel framework that can be customised on a per project&#160;basis.

Must be able to extend the ValueModel interface with real meta data&#160;methods.
Must be able to modify the behaviour of the component bindings to use use the custom ValueModel metadata defined&#160;above.
Must support [...]]]></description>
			<content:encoded><![CDATA[<p>In light of my previous post, I&#8217;ve long pondered how I could create a generic PresentationModel/ValueModel framework that can be customised on a per project&nbsp;basis.</p>
<ol>
<li>Must be able to extend the ValueModel interface with real meta data&nbsp;methods.</li>
<li>Must be able to modify the behaviour of the component bindings to use use the custom ValueModel metadata defined&nbsp;above.</li>
<li>Must support buffering&nbsp;natively.</li>
<li>Must be easy to use out of the box and easy to&nbsp;customise.</li>
</ol>
<p>I&#8217;d had a couple of goes at this in the past but yesterday I had a bit of a moment where I believed it might be possible (either rightly or&nbsp;wrongly).  </p>
<p>Ignoring any doubts I tried a few ideas and to my surprise it progressed pretty well.  I think this was partly because I&#8217;d been spending more time away from the Mac where my brain could think in&nbsp;peace.</p>
<p>Anyway, I shall continue plugging away and see how it turns&nbsp;out.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2007/08/more-value-model-thoughts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
