<?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>luminis Software Development</title>
	<atom:link href="http://lsd.luminis.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://lsd.luminis.nl</link>
	<description></description>
	<lastBuildDate>Mon, 08 Mar 2010 14:16:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>nl</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Online video presentatie: Android &amp; Augmented Reality</title>
		<link>http://lsd.luminis.nl/online-video-presentatie-android-augmented-reality/</link>
		<comments>http://lsd.luminis.nl/online-video-presentatie-android-augmented-reality/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 14:16:38 +0000</pubDate>
		<dc:creator>Richard van der Laan</dc:creator>
				<category><![CDATA[mobility]]></category>
		<category><![CDATA[acrossair]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[augmented reality]]></category>
		<category><![CDATA[EZDroid]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Google Android]]></category>
		<category><![CDATA[layar]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[nljug]]></category>
		<category><![CDATA[robotvision]]></category>
		<category><![CDATA[wikitude]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=665</guid>
		<description><![CDATA[Op 11 november 2009 gaf Arjan Schaaf op de NLJUG een presentatie over Android en Augmented Reality. De video van deze presentatie is inmiddels online beschikbaar.]]></description>
			<content:encoded><![CDATA[<p>Op 11 november 2009 gaf Arjan Schaaf op de NLJUG een presentatie over Android en Augmented Reality. De video van deze presentatie is inmiddels online beschikbaar. De gehele presentatie van 50 minuten kan je <a href="http://lsd.luminis.nl/wp-content/uploads/videos/Android%20and%20Augmented%20Reality.mp4">hier (175mb)</a> downloaden. Maar de eerste tien minuten zijn hieronder gelijk op YouTube te bekijken.</p>
<p>English: The whole presentation can be downloaded <a href="http://lsd.luminis.nl/wp-content/uploads/videos/Android%20and%20Augmented%20Reality.mp4">here (175mb)</a>.</p>
<p><!-- Smart Youtube --><span class="youtube"><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/tmGZHV-DFYM&amp;rel=1&amp;color1=e1600f&amp;color2=febd01&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0&amp;ap=%2526fmt%3D18" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="http://www.youtube.com/v/tmGZHV-DFYM&amp;rel=1&amp;color1=e1600f&amp;color2=febd01&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0&amp;ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowfullscreen="true" width="560" height="340" ></embed><param name="wmode" value="transparent" /></object></span></p>
<p>Augmented Reality op mobiele devices heeft een enorme vlucht genomen met de introductie van Google Android. Android biedt out-of-the-box de componenten om met augmented reality aan de slag te gaan. In deze sessie staan we stil bij de frameworks die beschikbaar zijn om augemented reality applicaties / content te deployen op Android. Aan de hand van een voorbeeld applicatie gaan we in op de mogelijkheden om zelf een augmented reality applicatie te ontwikkelen met de faciliteiten die door Android worden geboden. Praktische uitdagingen waarmee wij zijn geconfronteerd worden gedeeld en geven inzicht in de mogelijkheden en onmogelijkheden van het Android platform. Opbouw van de presentatie:</p>
<ul>
<li>Introductie over augmented reality: location based vs beeldherkenning;</li>
<li>Wat is te krijgen in de markt? Layar, Wikitude, etc;</li>
<li>Wat zijn de mogelijkheden om applicaties te ontwikkelen met de beschikbare frameworks;</li>
<li>Hoe ontwikkel je zelf een augmented reality applicatie op Android?</li>
</ul>
<p>De slides van de presentatie zijn te vinden op de <a href="http://www.nljug.org/pages/events/content/jfall_2009/sessions/00030/">NLJUG website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/online-video-presentatie-android-augmented-reality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zen en de kunst van het software maken</title>
		<link>http://lsd.luminis.nl/zen-en-de-kunst-van-het-software-maken/</link>
		<comments>http://lsd.luminis.nl/zen-en-de-kunst-van-het-software-maken/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 20:24:35 +0000</pubDate>
		<dc:creator>Richard de Zwart</dc:creator>
				<category><![CDATA[social]]></category>
		<category><![CDATA[Dao]]></category>
		<category><![CDATA[kwaliteit]]></category>
		<category><![CDATA[News Item]]></category>
		<category><![CDATA[Zen]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=651</guid>
		<description><![CDATA[Over vakmanschap, kwaliteit en schoonheid]]></description>
			<content:encoded><![CDATA[<p>Deze week speelde er veel  bij de klant waar ik nu zit. Zaken die me bezighielden tot ver buiten werktijd. En ik kon er maar niet achterkomen <em>waarom</em> ze me zo bezighouden. Tot ik een artikel las in Happinez (nee, daar heb ik geen abonnement op, ik las &#8216;m toevallig omdat mijn vrouw &#8216;m had gekocht&#8230;) dat ging over Robert M. Pirsig.</p>
<p>Hij schreef in 1974 het boek &#8220;Zen and the art of motorcycle maintenance&#8221; en ik las dat een jaar of 10-20 geleden voor het eerst. Het heeft een onuitwisbare indruk gemaakt, omdat het ging om een zoektocht naar de essentie van het bestaan en deze lastige materie verduidelijkt werd door begrijpelijke onderwerpen uit het motoronderhoud.</p>
<p>Pirsig stelt dat er één ding ten grondslag ligt aan alles, en dat is kwaliteit. Kwaliteit is dus geen eigenschap of kenmerk van dingen, maar iets dat er aan vooraf gaat. Net zoals de Dao in Lao Zi&#8217;s &#8220;Dao De Jing&#8221;.</p>
<p>Ok, dat is een hoop inleiding, maar het lezen van dat stukje triggerde onmiddellijk het besef dat kwaliteit ontzettend belangrijk is voor mij. Het vertaalt zich voor mij ook naar schoonheid. Ik hou van mooi: mensen, gebeurtenissen, materiele dingen. Als er een innerlijke kwaliteit is, dan komt die zichtbaar naar buiten en heeft schoonheid. Daarom kan ik een Toyota Prius mooi vinden: niet omdat ie estethisch aantrekkelijk vormgegeven is, maar omdat er een gedachte in huist die ik mooi vind. En vind ik windmolens geen horizon-vervuiling, maar een aanwinst voor het landschap, omdat het uitgangspunt ervan helemaal klopt.</p>
<p>Schoonheid is voor mij belangrijk omdat ik er blij van wordt. En ik heb liefst dagelijks een stukje blij in mijn leven.<br />
Schoonheid is voor mij de meetlat waarlangs ik dingen leg als ik twijfel of ze bij mij passen of niet. En dat was ik de laatste tijd vergeten in de problemen die bij de klant speelden: dat ik een meetlat heb om me te helpen keuzes te maken.</p>
<p>Software maken is bij uitstek een bezigheid waarbij kwaliteit en schoonheid een rol spelen. Floris schreef er vandaag ook over in zijn <a href="http://www.luminis.nl/?p=623" target="_blank">Blue Note 84</a>: &#8220;&#8230;de kans neemt aanzienlijk toe dat het goede software is als de source code er ook mooi uit ziet&#8221;. Een vakman ziet dat. In één oogopslag: dit is wel of geen mooie code.</p>
<p>In ons vak zijn veel mensen die software maken, maar zijn het allemaal vaklui? Pirsig schrijft hierover:</p>
<blockquote><p>Waarom deden die monteurs hun werk zo slecht? Het waren toch vakmensen, opgeleid in de techniek? Nee, al hadden ze misschien wel een technische opleiding gehad, vakmensen waren het zeker niet. Ze waren niet echt betrokken bij wat ze deden. Ze werkten gehaast, op de automatische piloot, zonder enig gevoel. Het waren net toeschouwers. Er bestond geen identificatie met het werk.</p></blockquote>
<p>Dit is waar het om gaat voor mij. Bij software maken in het bijzonder, maar eigenlijk bij leven in het algemeen: betrokkenheid, gevoel. Niet maar domweg snel iets fixen of even in elkaar draaien, maar de tijd nemen om een stapje terug te doen en je af te vragen: &#8220;wat is hier aan de hand, wat is eigenlijk het probleem?&#8221;.</p>
<p>Als je een plek nodig hebt om boeken te bewaren en misschien ook nog een paar sokken en onderbroeken, dan kom je goed weg met een IKEA kast; voordelig, en voor de meeste mensen eenvoudig in elkaar te zetten. Maar als je behoefte groeit en je voortdurend stukjes IKEA kast toevoegt, komt er een moment dat de wand vol begint te raken en het volgende kast-element gewoon niet meer past. Dan kun je natuurlijk van een ander model een stuk nemen, en daar misschien iets vanaf zagen. En zo&#8217;n handig pennenbakje kun je met een spijker vastzetten aan de staander. O, laatjes erbij? Dan nemen we zo&#8217;n laatjesding en die zetten we op de plank; schuiven we gewoon wat boeken opzij.</p>
<p>En op een dag valt het hele gevaarte om, want in het begin had je de moeite niet genomen om &#8216;m echt goed aan de muur vast te maken. Nergens voor nodig, want er zouden toch nooit meer dan 100 boeken en 20 paar sokken in komen. En nu is de ellende niet te overzien.</p>
<p>Het is momenteel mijn werk om nog een plank aan zo&#8217;n gedrocht te maken om een electronische kassa op te kunnen zetten. Ik heb al vaak aangegeven dat het gevaarte gevaarlijk staat te zwaaien en dat het beter is om de hele zaak eerst goed vast te zetten en misschien wel een flink stuk te vervangen door iets degelijkers.</p>
<p>Maar dat is niet mijn opdracht. Die kassa moet op die plank, en snel een beetje.</p>
<p>Na bovenstaande begrijp je mijn probleem. Kwaliteit en schoonheid zijn ver te zoeken. De dingen waar ik blij van wordt komen sporadisch langs. Moet ik dit blijven doen?</p>
<p>Wat zou jij doen?</p>
<p>P.S. Ik vraag niet letterlijk om je advies over wat ik zou moeten doen. Ik wil graag weten hoe je aankijkt tegen vakmanschap, kwaliteit, schoonheid en opdrachten die strijdig zijn met hetgeen waarvoor je graag wilt staan.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/zen-en-de-kunst-van-het-software-maken/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>About Non-Disclosure Argeements</title>
		<link>http://lsd.luminis.nl/about-non-disclosure-argeements/</link>
		<comments>http://lsd.luminis.nl/about-non-disclosure-argeements/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 19:56:29 +0000</pubDate>
		<dc:creator>Richard de Zwart</dc:creator>
				<category><![CDATA[mobility]]></category>
		<category><![CDATA[social]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[legal]]></category>
		<category><![CDATA[NDA]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=644</guid>
		<description><![CDATA[Writing about the new SDK for the iPhone/iPad I found out that I was legally prohibited to do that, since I accepted a Non-Disclosure Agreement.]]></description>
			<content:encoded><![CDATA[<p>Last night I wrote a blogpost about the first application I built for the iPad. I&#8217;m so happy with the (coming of) the new gadget and the possibilities that the MonoTouch created to rite .NET code for it, that I could not wait to write a sample app and to share my experiences with the rest of the world.</p>
<p>So at 11 o&#8217;clock I sent out a tweet with a link to the blog. About 60 seconds later I got a reply from someone that I trust knows what he is talking about, that I better remove the post since I agreed on a NDA.</p>
<p>Wow, did I? Yes, I did. When you download the beta of the iPhone 3.2 SDK there&#8217;s the following text:</p>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2010/01/NDA.png"><img class="aligncenter size-full wp-image-645" title="NDA" src="http://lsd.luminis.nl/wp-content/uploads/2010/01/NDA.png" alt="NDA" width="834" height="181" /></a></p>
<p>Yep, the beta is considered Apple Confidential Information. So I removed the post and went out to discover what I could and could not do under this NDA. Tried searching apple.com on the exact string &#8220;Apple Confidential Information&#8221;. No hits. Searched the legal department at apple.com/legal, no hits on beta software</p>
<p>Finally came up with the idea to search on the sub-site of the Apple Developer Centre. On the page on <a href="http://developer.apple.com/prereleasesoftware/" target="_blank">Pre-release software</a> there is the rather clear text:</p>
<blockquote><p>Pre-release software is Apple Confidential Information and your use of such software is subject to the Apple Developer Connection Terms and Conditions, including the Prototype License and Confidentiality Agreement attached thereto. Distributing the software to anyone other than an ADC member who is working for the same entity as you is considered a violation of your agreement with Apple and is damaging to both Apple and those who develop for the Apple platform. We sincerely appreciate your efforts to keep this software Confidential.</p></blockquote>
<p>The last part I understand: no distribution of the software. No problem. But I think the Confidentiality Agreement must hold more information. There is a &#8220;<a href="http://developer.apple.com/membership/pdf/terms.pdf" target="_blank">Terms and Conditions</a>&#8221; PDF that has a section 7 on Pre-release software that essentially tells you that &#8220;You certify that pre-release software will only be used for testing and development purposes&#8221;. Fine so far, but it also refers to the attached Prototype License and Confidentiality Agreement. So where is that agreement and what does it say?</p>
<p>The PLCA (as they lovingly call it) is on page 5 of the PDF and has a section 4 on non-disclosure:</p>
<blockquote><p>You agree not to disclose, publish, or disseminate Confidential Information to anyone other than employees and contractors working for the same entity as you who have an existing ADC membership</p></blockquote>
<p>Well, there it is. No right to publish Confidential Information, which means no stuff that Apple hadn&#8217;t already published about. So I <em>can</em> write about the iPad, I <em>can</em> write about the existence of the SDK, but I cannot write about a certain new UI-control that I used to build my demo app. Even though I like this new UI-control and love what it does for me.</p>
<p>Is this really necessary? What good does it do Apple when I don&#8217;t write about their products? About a product that they most certainly want as much coverage of as they can get: the brand new iPad?</p>
<p>Should I really be worried that they will sue me when I break my Vow of Silence? Of course, being Dutch, growing up in a country that is known around the world to be liberal, it is hard to believe someone will really sue you. Especially when you write nice about them.</p>
<p>I don&#8217;t like secrets, I don&#8217;t like lawyer stuff that tries to protect (imprison?) ideas. I do like what <a href="http://www.codinghorror.com/blog/" target="_blank">Jeff Atwood wrote about ideas</a>: ideas in itself are not very valuable, it is how you execute them. So my message to Apple: liberate your ideas, they are great, I love them. Allow others to rave and rant about them, who cares? You are the one that is going to execute them in the most profitable way, any way. Right? And if you&#8217;re not going to, then don&#8217;t blame the blogger, blame yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/about-non-disclosure-argeements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building iPhone applications using MonoTouch, howto: using a view without a controller</title>
		<link>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-howto-using-a-view-without-a-controller/</link>
		<comments>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-howto-using-a-view-without-a-controller/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 20:30:13 +0000</pubDate>
		<dc:creator>Richard de Zwart</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[mobility]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[MonoDevelop]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[NIB]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=615</guid>
		<description><![CDATA[Of course, a view without a controller is not very useful in itself, but in this post I want to show you how I solved a small re-usability problem.
I&#8217;m working on a small open-source project on Codeplex that aims to build a player for the Hanselminutes podcasts.  It is nothing very special, but it [...]]]></description>
			<content:encoded><![CDATA[<p>Of course, a view without a controller is not very useful in itself, but in this post I want to show you how I solved a small re-usability problem.</p>
<p>I&#8217;m working on a small open-source project on <a href="http://hanselminutesiphone.codeplex.com" target="_blank">Codeplex</a> that aims to build a player for the <a href="http://www.hanselminutes.com/"  target="_blank">Hanselminutes podcasts</a>.  It is nothing very special, but it gives me a nice playground to find out new stuff.</p>
<p>So there is a &#8220;Loading playlist&#8221; message and a &#8220;Buffering audio&#8221; message displayed at the appropriate moments. You can do that in a lot of ways, but in this application, a semi-transparent view was chosen that is overlaying the current view. It has a text (of course) and a UIActivityIndicatorView (who comes up with these names????).</p>
<p>I try to follow three rules when building the UI:</p>
<ol>
<li>All the UI is done with the Interface Builder. That allows me to leave the actual design to someone who knows designing.</li>
<li>Every view is in a separate NIB. That way not all the UI has to be loaded at startup, which improves user-perceived performance</li>
<li>Loosely couple the view, to make reuse easier. That means a simple interface (as in &#8216;programming interface&#8217;) to the rest of the world, and all the view-related code inside the NIB</li>
</ol>
<p>In this case I want a view that can be called from different controllers (re-usability), so when I add a file to my MonoDevelop project I choose &#8220;View Interface Definition&#8221;:</p>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2010/01/Screen-shot-2010-01-25-at-8.34.03-PM.png"><img class="alignleft size-medium wp-image-616" style="margin-left: 10px; margin-right: 10px;" title="Screen shot 2010-01-25 at 8.34.03 PM" src="http://lsd.luminis.nl/wp-content/uploads/2010/01/Screen-shot-2010-01-25-at-8.34.03-PM-300x196.png" alt="Screen shot 2010-01-25 at 8.34.03 PM" width="300" height="196" /></a></p>
<p>It&#8217;s no so different form what you do (at least, what I do) most of the time when you choose View Interface Definition with Controller. You add your UI-elements, define some outlets, but then  you want to activate this view from some controller, any controller.</p>
<p>What I came up with, is the following.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> UIHelper
<span style="color: #000000;">&#123;</span>
  UIViewController _controller<span style="color: #008000;">;</span>
  BusyView _busyView<span style="color: #008000;">;</span>
  <span style="color: #0600FF;">public</span> UIHelper <span style="color: #000000;">&#40;</span>UIViewController controller<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    _controller <span style="color: #008000;">=</span> controller<span style="color: #008000;">;</span>
    NSArray views <span style="color: #008000;">=</span> NSBundle.<span style="color: #0000FF;">MainBundle</span>.<span style="color: #0000FF;">LoadNib</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;BusyView&quot;</span>, _controller, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    _busyView <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BusyView<span style="color: #000000;">&#40;</span>views.<span style="color: #0000FF;">ValueAt</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    _controller.<span style="color: #0000FF;">View</span>.<span style="color: #0000FF;">AddSubview</span><span style="color: #000000;">&#40;</span>views<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    _controller.<span style="color: #0000FF;">View</span>.<span style="color: #0000FF;">SendSubviewToBack</span><span style="color: #000000;">&#40;</span>_busyView<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It is a helper class that loads the view at construction time. It gets passed in the controller that will display the view. Then I load the NIB where the view is in. This gives me back an array. Of what? Well as the <a href="http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/NSBundle_UIKitAdditions/Introduction/Introduction.html" target="_blank">documentation</a> says:</p>
<blockquote><p>An array containing the top-level objects in the nib file. The array does not contain references to the File’s Owner or any proxy objects; it contains only those objects that were instantiated when the nib file was unarchived. You should retain either the returned array or the objects it contains manually to prevent the nib file objects from being released prematurely.</p></blockquote>
<p>So you get the top-elements (actually: the IntPtr&#8217;s of them) from the NIB. In a file with only one view the first one is probably (&#8230;fingers crossed) the right one.<br />
I add the view to the SubViews of the controller and make sure it does not show before it was meant to.</p>
<h3>Showing the view</h3>
<p>Whenever I need the view to display I call:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	_busyView.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	_controller.<span style="color: #0000FF;">View</span>.<span style="color: #0000FF;">BringSubviewToFront</span><span style="color: #000000;">&#40;</span>_busyView<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The first line calls a method on the partial class in the NIB to set the text of a label. The second line makes the view visible.</p>
<h3>What&#8217;s not to like about this solution</h3>
<p>Well, the magical string with the name of the NIB, &#8220;BusyView&#8221;. And the magical number 0 the denotes the right object in the list of objects in the NIB.</p>
<p>Any ideas for improvement? Please react!</p>
<p><a href='http://lsd.luminis.nl/wp-content/uploads/2010/01/NibDemo.zip'>Download the code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-howto-using-a-view-without-a-controller/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Online video: Beyond OSGi software architecture</title>
		<link>http://lsd.luminis.nl/online-video-beyond-osgi-software-architecture/</link>
		<comments>http://lsd.luminis.nl/online-video-beyond-osgi-software-architecture/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 15:11:53 +0000</pubDate>
		<dc:creator>Richard van der Laan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[Apache Felix]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[lean]]></category>
		<category><![CDATA[nljug]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[Software architecture]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=601</guid>
		<description><![CDATA[Op 11 november 2009 gaf Marcel Offermans samen met Jeroen van Grondelle (Be Informed) een duo presentatie over "Beyond OSGi software architecture". De video van deze presentatie is inmiddels online beschikbaar.]]></description>
			<content:encoded><![CDATA[<p>Op 11 november 2009 gaf Marcel Offermans samen met Jeroen van Grondelle (Be Informed) een duo presentatie over &#8220;Beyond OSGi software architecture&#8221;. De video van deze presentatie is inmiddels online beschikbaar. De gehele presentatie van 50 minuten kan je <a href="http://lsd.luminis.nl/wp-content/uploads/videos/Beyond%20OSGi%20software%20architecture.mp4">hier</a> downloaden. Maar de eerste tien minuten zijn hieronder gelijk online te bekijken.</p>
<p><!-- Smart Youtube --><span class="youtube"><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/vwJD0mhgnmU&amp;rel=1&amp;color1=e1600f&amp;color2=febd01&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0&amp;ap=%2526fmt%3D18" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="http://www.youtube.com/v/vwJD0mhgnmU&amp;rel=1&amp;color1=e1600f&amp;color2=febd01&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0&amp;ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowfullscreen="true" width="560" height="340" ></embed><param name="wmode" value="transparent" /></object></span></p>
<p>OSGi is niet meer weg te denken uit het Enterprise Java domein. Dit lightweight framework krijgt al een aantal jaren flinke aandacht en is met name bekend om z’n modulaire applicaties op basis van bundles. Minder bekend is het services model, waarbij applicaties worden ontwikkeld op basis van service interfaces en van elkaar ontkoppelde implementaties (POJO&#8217;s) van die interfaces. Krachtige eigenschappen van dit model zijn:</p>
<ul>
<li>complexiteitsreductie door stricte scheiding van services;</li>
<li>declaratieve services en dependency management (IoC);</li>
<li>aspect oriëntatie op basis van stub services;</li>
<li>security model.</li>
</ul>
<p>Lean software is een nieuwe manier om enterprise applicaties te bouwen op basis van OSGi, die ook goed aansluit bij Agile methoden, waarbij non-functional requirements ingevuld kunnen worden in een compact gebleven framework. In die context kijken we naar:</p>
<ul>
<li>applicaties deployen op allerlei platformen en omgevingen;</li>
<li>applicaties automatisch installeren en updaten;</li>
<li>applicaties voorzien van management interfaces;</li>
<li>product software uitbreidbaar maken middels een SDK;</li>
<li>product software verkopen als combinatie van standaard onderdelen en optionele uitbreidingen;</li>
<li>modulaire User Interfaces.</li>
</ul>
<p>De slides van de presentatie zijn te vinden op de <a href="http://www.nljug.org/pages/events/content/jfall_2009/sessions/00018/">NLJUG website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/online-video-beyond-osgi-software-architecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building iPhone applications using MonoTouch, part 5: software design considerations</title>
		<link>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-5-software-design-considerations/</link>
		<comments>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-5-software-design-considerations/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 21:26:55 +0000</pubDate>
		<dc:creator>Richard de Zwart</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[mobility]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[MonoDevelop]]></category>
		<category><![CDATA[monotouch]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=574</guid>
		<description><![CDATA[(English) In this post I try to determine where some of my code should go and how I can keep the my application loosely coupled and tightly coherent.]]></description>
			<content:encoded><![CDATA[<p>In the previous 4 posts (<a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-4-the-uisearchdisplaycontroller/">4</a>, <a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-3-the-interface-builder/">3</a>, <a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-2/">2</a>, <a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-1/">1</a>) I gave a lot of attention to the overall structure of an iPhone application. In this post I want to talk about  a topic that is more concerned with general software design issues: where do I do what?</p>
<h3>Get SOLID</h3>
<p>There are two things that I always try to keep in mind when making software: loose coupling and tight cohesion. In other words:</p>
<ol>
<li>make sure your classes don&#8217;t know things that they don&#8217;t need to know</li>
<li>make sure your classes are good at one thing and one thing only</li>
</ol>
<p>These guidelines are part of the <a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod">5 SOLID principles</a> of class design by <a href="http://www.objectmentor.com/omTeam/martin_r.html">Uncle Bob Martin</a>:</p>
<ol>
<li>Single Responsibility Principle</li>
<li>Open Closed Principle</li>
<li>Liskov Substitution Principle</li>
<li>Interface Segregation Principle</li>
<li>Dependency Inversion Principle</li>
</ol>
<p>This stuff is really interesting and sort-of scientific, but it is also like making your database comply to the 5-th Normal Form: nobody does that. You&#8217;re happy with a 3rd Normal Form database. So I&#8217;m happy when I see code that complies with at least two of the above principles.</p>
<p>So what I do when building my iPhone apps is constantly asking myself: should this code be in this place? Sometimes I know right away that the answer is No, but still leave it there until I have a better idea on where to put it then. And with the (for me) rather unusual structure that the Cocao Framework forces upon me, it may take some time before I eventually find out where to put it.</p>
<p>Let me give you an example.</p>
<p>When you want to load data into a UITableView you must create a UITableViewDataSource and assign that to the DataSource property of your UITableViewController. Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> FinishedLaunching <span style="color: #000000;">&#40;</span>UIApplication app, NSDictionary options<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	tableView.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	window.<span style="color: #0000FF;">AddSubview</span> <span style="color: #000000;">&#40;</span>tableView<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	window.<span style="color: #0000FF;">MakeKeyAndVisible</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The class instantiated at line 3 is something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LeesPlankjeDataSource <span style="color: #008000;">:</span> UITableViewDataSource
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> woordjes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span><span style="color: #666666;">&quot;aap&quot;</span>, <span style="color: #666666;">&quot;noot&quot;</span>, <span style="color: #666666;">&quot;mies&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> UITableViewCell GetCell <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewCell cell <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DequeueReusableCell</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cell <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			cell <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UITableViewCell<span style="color: #000000;">&#40;</span>UITableViewCellStyle.<span style="color: #0600FF;">Default</span>, <span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		cell.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> woordjes<span style="color: #000000;">&#91;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> cell<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">int</span> RowsInSection <span style="color: #000000;">&#40;</span>UITableView tableview, <span style="color: #FF0000;">int</span> section<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> woordjes.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>On  line 3 you see the actual &#8220;data store&#8221;, and on line 4 an important override. This method gets called by Cocoa when loading data in your UITableView. So the controller has a data source and the appropriate methods get called by the framework.</p>
<h3>On to a more realistic implementation</h3>
<p>If I want to advance my class a bit, I could imagine that the data is not a fixed array of strings, but gets passed in at construction time. Maybe I read from a file or from a URL.</p>
<p>That changes my class to this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LeesPlankjeDataSource <span style="color: #008000;">:</span> UITableViewDataSource
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> _dataStorage<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> data<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_dataStorage <span style="color: #008000;">=</span> data<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> UITableViewCell GetCell <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewCell cell <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DequeueReusableCell</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cell <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			cell <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UITableViewCell<span style="color: #000000;">&#40;</span>UITableViewCellStyle.<span style="color: #0600FF;">Default</span>, <span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		cell.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> _dataStorage<span style="color: #000000;">&#91;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> cell<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">int</span> RowsInSection <span style="color: #000000;">&#40;</span>UITableView tableview, <span style="color: #FF0000;">int</span> section<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> _dataStorage.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And the main.cs gets these lines:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> woordjes <span style="color: #008000;">=</span> File.<span style="color: #0000FF;">ReadAllLines</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;woordjes.txt&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	tableView.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span>woordjes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Make sure when you have files that you want to be deployed with your app to set the build-action on the file to &#8220;content&#8221;:</p>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2009/11/BuildAction.png"><img class="alignleft size-medium wp-image-577" style="margin-left: 5px; margin-right: 5px;" title="BuildAction" src="http://lsd.luminis.nl/wp-content/uploads/2009/11/BuildAction-300x255.png" alt="BuildAction" width="300" height="255" /></a>That&#8217;s all neat. The DataSource gets it data from the outside and doesn&#8217;t care if it comes from a file or a network-connection.</p>
<p>So now we want some action when the user taps a row. You have no choice but to implement this in a delegate (a UITableViewDelegate of course) and then override the RowSelected() method. This method is called for you by Cocoa and as parameters you get a UITableView that the tapping happened on and the Row number that was tapped:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LeesPlankjeViewDelegate <span style="color: #008000;">:</span> UITableViewDelegate
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> RowSelected <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>But what can I do in this method? Let&#8217;s say I want to do a MessageBox-ish thing to show what word was chosen. All I have is an index to the row in my data source. But I don&#8217;t have the data source itself in this class. I need some way to acces my original data store.</p>
<p>I could do somehting like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> RowSelected <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #FF0000;">string</span> message <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DataSource</span>.<span style="color: #0000FF;">GetCell</span><span style="color: #000000;">&#40;</span>tableView,  indexPath<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var alert <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UIAlertView <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span>, message, <span style="color: #0600FF;">null</span>, <span style="color: #666666;">&quot;OK&quot;</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		alert.<span style="color: #0000FF;">Show</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So I ask the TableView for its data source, then ask the data source to give me the cell that is on the given index, and then ask the cell for the text of the label. It works, but it is butt-ugly. Why? Because now the delegate knows about the data source too. And I think it shouldn&#8217;t, because all the delegate needs to do is handle UI-interactions from the user. It should say &#8220;Hey, someone tapped me on this row, do something with it&#8221; and then leave the actual work to someone else.</p>
<p>I think it would be reasonable to leave the work to the controller. For me, a controller is always the man-in-the-middle, doing the real work brokering between the model and the view. But if I choose that, I have to pass in the controller when constructing the Delegate, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">tableView.<span style="color: #FF0000;">Delegate</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeViewDelegate<span style="color: #000000;">&#40;</span>tableViewController<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>And since the tableViewController is only known so far in the Interface Builder, I have to make the controller available in my code by creating an outlet. Sigh&#8230;. even more code in my FinishedLaunching() method. I don&#8217;t want that, I want to hook up UI-parts with each other using the Interface Builder, not in code.</p>
<p>So, what to do now? I don&#8217;t know yet. Let me first deal with a problem that I didn&#8217;t tell you about yet. It is in the code of the LeesPlankjeDataSource. I gave my LeesPlankjeDataSource a constuctor that accepts a string array, thereby enabling me to pass in the data that the data source needs to build a UITableView from.</p>
<p>The problem is, that the UISearchDisplayController re-uses my UITableViewController, including the DataSource. When I click search, it first simply overlays my view, but when I start typing in the search box, the ShouldReloadForSearchString () method gets called and that one resets the SearchResultDataSource with a filtered version of my LeesPlankjeDataSource:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> ShouldReloadForSearchString <span style="color: #000000;">&#40;</span>UISearchDisplayController controller, <span style="color: #FF0000;">string</span> forSearchString<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;In ShouldReloadForSearchtring&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	controller.<span style="color: #0000FF;">SearchResultsDataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span>forSearchString<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And how am I gonna feed this baby with the right data? How is the SearchResultsDataSource going to get a filtered list of the words in my &#8220;woordjes.txt&#8221; file? I chose to filter by using an overloaded constructor, but I could move that code to a normal method. That allows me to use the other constructor, passing in the data as before in the main.cs:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> ShouldReloadForSearchString <span style="color: #000000;">&#40;</span>UISearchDisplayController controller, <span style="color: #FF0000;">string</span> forSearchString<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;In ShouldReloadForSearchString&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	var woordjes <span style="color: #008000;">=</span> <span style="color: #008000;">?????????</span>
	var data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span>woordjes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	controller.<span style="color: #0000FF;">SearchResultsDataSource</span> <span style="color: #008000;">=</span> data.<span style="color: #0000FF;">FilterOn</span><span style="color: #000000;">&#40;</span>forSearchString<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>But where am I gonna get the &#8220;woordjes&#8221; variable from? Should I load the file again, like I did in main.cs? Or maybe my DataSource should know something about the model? In that case I will not pass data from the outside, but let the DataSource find out itself where to get the data. But that is so against the Dependency Inversion Principle (or Inversion of Control)! If classes depend on other classes, these dependencies had best be passed in from the outside, probably on construction time.</p>
<p>Shoot, I love the IoC pattern. Should I let it go, for the sake of simplicity? After all, I argued before that even the MVC-pattern was maybe to much of a burden for the simple applications we build on the iPhone most of the time.</p>
<p>For tonight, I give up. The <a href="http://lsd.luminis.nl/wp-content/uploads/2009/11/SearchProblems2.zip">code you can download</a> contains the solution that goes against IoC, but works none the less.</p>
<p>I would love to hear your ideas about how to build iPhone applications that are tightly coherent and loosely coupled. I know that we can get in some philosophical or religious discussions, but we&#8217;ll see what to do then. I just want to learn from you guys, as much as I want to teach you where I can.</p>
<p>P.S.<br />
Thanks to <a href="http://www.alexyork.net/blog/post/UINavigationController-with-MonoTouch-Building-a-simple-RSS-reader-Part-1.aspx">Alex York&#8217;s excellent post</a> (see his comment below) I was able to improve on my code. I had seen the idea of nesting the DataSource and Delegate into the UITableViewController before, but didn&#8217;t like it then. That dislike mostly came from the fact that you have to inherit from another class. There is no tighter couling between two classes then inheritance, so I believe you should only use it when absolutely necessary. Well, by now I think that it is absolutely necessary to inherit from the classes in the Cocoa framework. It is simply the way you work.</p>
<p>When working on the new solution I also renamed some classes (no more Dutch names, only Dutch words in the data&#8230;) and added a class that implements the model:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> WordsModel
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> List _dataStorage<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> WordsModel <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_dataStorage <span style="color: #008000;">=</span> File.<span style="color: #0000FF;">ReadAllLines</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;woordjes.txt&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		_dataStorage.<span style="color: #0000FF;">Sort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> Data <span style="color: #000000;">&#123;</span>
		get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _dataStorage.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> FilterOn<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> searchText<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		searchText <span style="color: #008000;">=</span> searchText.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		var result <span style="color: #008000;">=</span> _dataStorage.<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>t <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> t.<span style="color: #0000FF;">ToLowerInvariant</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span>searchText<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> result.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It is the place where the knowledge of words, where they come from and how you filter them, resides.</p>
<p>But Alex&#8217;s solution did not solve the problem that is typical of the use of the UISearchDisplayController: you have two instances of your DataSource: the one for your initial view, that just displays all the data (words in my case), and the one that is called upon by the UISearchDelegate when you start to search and filter.</p>
<p>I solved this by implementing a general WordsDataSource that uses the WordsModel and has a constuctor for normal use and for filtering:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> WordsDataSource <span style="color: #008000;">:</span> UITableViewDataSource
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> WordsModel model <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WordsModel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> _dataStorage<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> WordsDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_dataStorage <span style="color: #008000;">=</span> model.<span style="color: #0000FF;">Data</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> WordsDataSource<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> filter<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_dataStorage <span style="color: #008000;">=</span> model.<span style="color: #0000FF;">FilterOn</span><span style="color: #000000;">&#40;</span>filter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GetAt<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> position<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> _dataStorage<span style="color: #000000;">&#91;</span>position<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> UITableViewCell GetCell <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewCell cell <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DequeueReusableCell</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cell <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			cell <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UITableViewCell<span style="color: #000000;">&#40;</span>UITableViewCellStyle.<span style="color: #0600FF;">Default</span>, <span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		cell.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> _dataStorage<span style="color: #000000;">&#91;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> cell<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">int</span> RowsInSection <span style="color: #000000;">&#40;</span>UITableView tableview, <span style="color: #FF0000;">int</span> section<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> _dataStorage.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It inherits (yep I used the I-word) from UITableViewDataSource so can be called upon by the Cocoa framework when rendering the data for the UITableView.</p>
<p>And then I used that class in two places:</p>
<ol>
<li>as an internal property in my WordsTableViewController</li>
<li>as a helper-class in the delegate of the UISearchDisplayController.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WordsTableViewController&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> WordsTableViewController <span style="color: #008000;">:</span> UITableViewController
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Constructor invoked from the NIB loader</span>
    <span style="color: #0600FF;">public</span> WordsTableViewController <span style="color: #000000;">&#40;</span>IntPtr p<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span> <span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// The data source for our TableView</span>
    <span style="color: #0600FF;">private</span> WordsDataSource TableDataSource
    <span style="color: #000000;">&#123;</span>
	get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TableView</span>.<span style="color: #0000FF;">DataSource</span> <span style="color: #0600FF;">as</span> WordsDataSource<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TableView</span>.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// This class receives notifications that happen on the UITableView</span>
    <span style="color: #FF0000;">class</span> TableDelegate <span style="color: #008000;">:</span> UITableViewDelegate
    <span style="color: #000000;">&#123;</span>
	WordsTableViewController parentView<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> TableDelegate <span style="color: #000000;">&#40;</span>WordsTableViewController tableViewController<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
		parentView <span style="color: #008000;">=</span> tableViewController<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> RowSelected <span style="color: #000000;">&#40;</span>UITableView tableView, NSIndexPath indexPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
		<span style="color: #FF0000;">string</span> selectedWord <span style="color: #008000;">=</span> parentView.<span style="color: #0000FF;">TableDataSource</span>.<span style="color: #0000FF;">GetAt</span><span style="color: #000000;">&#40;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var alert <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UIAlertView <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Selected&quot;</span>, selectedWord, <span style="color: #0600FF;">null</span>, <span style="color: #666666;">&quot;OK&quot;</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			alert.<span style="color: #0000FF;">Show</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ViewDidLoad <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">ViewDidLoad</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        TableView.<span style="color: #FF0000;">Delegate</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TableDelegate <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TableDataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WordsDataSource <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WordSearchDelegate&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> WordSearchDelegate <span style="color: #008000;">:</span> UISearchDisplayDelegate
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> ShouldReloadForSearchString <span style="color: #000000;">&#40;</span>UISearchDisplayController controller, <span style="color: #FF0000;">string</span> forSearchString<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewDataSource data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WordsDataSource<span style="color: #000000;">&#40;</span>forSearchString<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		controller.<span style="color: #0000FF;">SearchResultsDataSource</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I&#8217;m pretty happy with what I got by now. You can <a href="http://lsd.luminis.nl/wp-content/uploads/2009/11/SearchProblems3.zip">download the new version</a>, if you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-5-software-design-considerations/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Swing &amp; OSGi &#8212; please play nice!</title>
		<link>http://lsd.luminis.nl/swing-and-osgi/</link>
		<comments>http://lsd.luminis.nl/swing-and-osgi/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 07:00:35 +0000</pubDate>
		<dc:creator>Angelo van der Sijpt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=421</guid>
		<description><![CDATA[OSGi is dynamic, Swing is static; these properties tend to bite each other. We will show some of the pitfalls you will encounter in a nontrivial OSGi-Swing application, and show how to give up a little bit of flexibility to get around them.]]></description>
			<content:encoded><![CDATA[<p>In a recent <a href="http://java.dzone.com/articles/plugable-swing-%E2%80%93-hello-world" target="_blank">blog</a> by Peter Karich, he showed how to create a pluggable Swing application using OSGi. While this works fine for smaller examples, you might run into more serious issues once you application starts to grow.</p>
<h2>Plugging Swing: it leaks?</h2>
<p>Let&#8217;s start with an application not unlike the one from aforementioned blog; it uses a window as host, and has a pluggable menu, and a pluggable table.</p>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2009/10/SWING_OSGI_Pluggable-components600.jpg"><img class="size-full wp-image-435 alignnone" title="SWING_OSGI_Pluggable components600" src="http://lsd.luminis.nl/wp-content/uploads/2009/10/SWING_OSGI_Pluggable-components600.jpg" alt="SWING_OSGI_Pluggable components600" width="350" height="150" /></a></p>
<p>You can find the code we used at the end of this entry (or, for the impatient, <a href="http://lsd.luminis.nl/wp-content/uploads/2009/10/swing_osgi.zip">here</a>).</p>
<p>Using this pluggable system, we could end up with several curious situations. For instance, you might have a mixed look and feel in you application.</p>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2009/10/SWING_OSGI_wrong_menus.png"><img class="size-full wp-image-444 alignnone" title="SWING_OSGI_wrong_menus" src="http://lsd.luminis.nl/wp-content/uploads/2009/10/SWING_OSGI_wrong_menus.png" alt="SWING_OSGI_wrong_menus" width="250" height="350" /></a></p>
<p>Or worse, you might end up with a UI that (sometimes) fails to start, and spits a stacktrace your way.</p>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2009/10/swing_osgi_NPE.png"><img class="alignnone size-full wp-image-528" title="swing_osgi_NPE" src="http://lsd.luminis.nl/wp-content/uploads/2009/10/swing_osgi_NPE.png" alt="swing_osgi_NPE" width="350" height="170" /></a></p>
<h2>It leaks, but why?</h2>
<p>Our host, and all components have been stored in separate bundles, meaning we don&#8217;t have full control about the order in which actions are performed (more about that later). However, we do know there are orders of execution that are less than ideal; let&#8217;s force one of those.</p>
<p>The <a href="http://lsd.luminis.nl/wp-content/uploads/2009/10/swing_osgi.zip">project</a> contains an Ant script to make things easier. From the root of the extracted project, run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">&amp;</span>gt; ant run1</pre></div></div>

<p>This starts the framework, installing the necessary bundles, but does not start them (note that this step uses <a href="http://paxrunner.ops4j.org">Pax Runner</a>, and therefore needs internet access). We can now start our bundles in the order we like.</p>
<h3>A tale of two look-and-feels</h3>
<p>After starting the framework, wait for the &#8220;Welcome to Felix&#8221; message, and run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span> Welcome to Felix
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span> ================
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>
start <span style="color: #000000;">2</span>
start <span style="color: #000000;">1</span></pre></div></div>

<p>The situation arises because the look and feel is a static concept in Swing. The menu bundle creates its <code>JMenu</code> <em>before</em> (see Menu.java, ln 30) the host sets its look and feel (Host.java, ln 51), and keep that look and feel, even when the host bundle changes it later.</p>
<h3>Tables, ScrollPanes and NPEs</h3>
<p>The NullPointerException above is a different story, but it goes back to the same staticness of Swing too. To force this situation, start only bundle 4.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span> Welcome to Felix
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span> ================
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>
start <span style="color: #000000;">4</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span> Exception <span style="color: #000000; font-weight: bold;">in</span> thread <span style="color: #ff0000;">&quot;AWT-EventQueue-0&quot;</span> java.lang.NullPointerException
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at net.luminis.swingosgi.part1.scrolltable.impl.TableComponent$1.run<span style="color: #7a0874; font-weight: bold;">&#40;</span>TableComponent.java:<span style="color: #000000;">31</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at java.awt.event.InvocationEvent.dispatch<span style="color: #7a0874; font-weight: bold;">&#40;</span>InvocationEvent.java:<span style="color: #000000;">209</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at java.awt.EventQueue.dispatchEvent<span style="color: #7a0874; font-weight: bold;">&#40;</span>EventQueue.java:<span style="color: #000000;">633</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at java.awt.EventDispatchThread.pumpOneEventForFilters<span style="color: #7a0874; font-weight: bold;">&#40;</span>EventDispatchThread.java:<span style="color: #000000;">296</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at java.awt.EventDispatchThread.pumpEventsForFilter<span style="color: #7a0874; font-weight: bold;">&#40;</span>EventDispatchThread.java:<span style="color: #000000;">211</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at java.awt.EventDispatchThread.pumpEventsForHierarchy<span style="color: #7a0874; font-weight: bold;">&#40;</span>EventDispatchThread.java:<span style="color: #000000;">201</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at java.awt.EventDispatchThread.pumpEvents<span style="color: #7a0874; font-weight: bold;">&#40;</span>EventDispatchThread.java:<span style="color: #000000;">196</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at java.awt.EventDispatchThread.pumpEvents<span style="color: #7a0874; font-weight: bold;">&#40;</span>EventDispatchThread.java:<span style="color: #000000;">188</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>java<span style="color: #7a0874; font-weight: bold;">&#93;</span>      at java.awt.EventDispatchThread.run<span style="color: #7a0874; font-weight: bold;">&#40;</span>EventDispatchThread.java:<span style="color: #000000;">122</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Let&#8217;s take a look at the line where this NPE happens:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">JScrollPane</span> scrollPane <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">JScrollPane</span><span style="color: #009900;">&#40;</span>table<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
scrollPane.<span style="color: #006633;">getColumnHeader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setBackground</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Color</span>.<span style="color: #006633;">blue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
m_panel.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>scrollPane<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We know that the <code>ColumnHeader</code> is null. This is because its <code>JTable</code>&#8217;s responsibility to create the header, but this is only done once the table knows it is part of an AWT hierarchy. The following lines come from the 1.5 JDK on a Mac; <code>configureEnclosingScrollPane()</code> creates the column header. This <code>addNotify</code> method comes from <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#addNotify%28%29">Component</a>, and notifies of, exactly, the event of being added to an AWT container.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addNotify<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">addNotify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  configureEnclosingScrollPane<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Order, order!</h2>
<p>So, the static nature of Swing and the dynamic nature of OSGi seem to hurt each other seriously here.</p>
<p>One way to get the application right is by fixing the order in which Swing components can be created. By starting bundle 1 first in our application, we at least fix the look and feel. Getting the scrolling table to run correctly is an entirely different story.</p>
<p>Regarding order, a few possible solutions spring to mind immediately,</p>
<ol>
<li>Put all UI stuff in one bundle</li>
<li>Use OSGi bundle start levels</li>
</ol>
<p>Sure, all UI in a single bundle will give you the control necessary, but it also defeats the purpose. OSGi start levels can at least solve the ordering issues, but will not get you out of the NullPointerException and might have more impact than you desire.</p>
<h3>What order?</h3>
<p>As we have seen, absolute order does not solve our problem. How about separating creation and initialization? Still, we need to impose some order, or at least some hierarchy.</p>
<p><img class="alignnone size-full wp-image-446" title="SWING_OSGI_Application composition600" src="http://lsd.luminis.nl/wp-content/uploads/2009/10/SWING_OSGI_Application-composition600.jpg" alt="SWING_OSGI_Application composition600" width="446" height="210" /></p>
<p>We represent each Swing component by an OSGi service, and leverage the OSGi service dependency resolution to build up our hierarchy; this way, we know the host service will be started last.</p>
<ol>
<li><strong>Resolve services</strong> Once the host bundle starts, we know all components are locked and loaded; the host can now start setting up Swing&#8217;s static elements like the look and feel.</li>
<li><strong>Create components</strong> Component creation ripples downward: the host gets its direct children, adding them to its container, and in the process triggering the children to get their child components.</li>
<li><strong>Initialize components</strong> Once the component creation is done, the host instructs each component to initialize; we can now be certain that all components are part of the AWT hierarchy.</li>
</ol>
<p>To reach this situation, we introduce a new OSGi service that wraps the component.</p>
<p><img class="alignnone size-full wp-image-447" title="SWING_OSGI_Using component provider600" src="http://lsd.luminis.nl/wp-content/uploads/2009/10/SWING_OSGI_Using-component-provider600.jpg" alt="SWING_OSGI_Using component provider600" width="447" height="219" /></p>
<p>All components are handled by a service implementing <code>ComponentProvider</code>; notice how methods are required to be called on the EventDispatchThread, making sure that all components are created on the EDT, while retaining the order necessary.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ComponentProvider <span style="color: #009900;">&#123;</span>
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Constant to identify ComponentProvider services.
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> COMPONENT_ID_KEY <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;component.id&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * This function should always be called from the EDT. The implementor
 * may assume that this function is called once and before {@link #addedToContainer()}
 *
 * @return the implementors (Swing) component which it provides.
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">JComponent</span> getComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Triggered when the component is added to a container. The implementation
 * can validate some stuff. This function must be called on the EDT.
 * Implementors may assume this function is called after {@link #getComponent()}.
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addedToContainer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The <code>getComponent</code> function is analogous to the <em>create</em> step above; the <code>addedToContainer</code> triggers the <em>initialize</em>.</p>
<h3>Let&#8217;s try that out!</h3>
<p>To check that this actually works OK, run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">&amp;</span>gt; ant run2</pre></div></div>

<p>from the root of the project, and start the bundles in any order you like. The UI will only show up once <em>all required</em> components are available; notice that the <code>Table</code> and the <code>ScrollPane</code> component can be used interchangeably.</p>
<h2>Is it all good?</h2>
<p>For the most part, yes. You do give up some flexibility: the UI is assembled at runtime, but it is no longer possible to (easily) plug components into a running system without special provisions. Then again, how often do you deploy new Swing-based functionality to a <em>running</em> application?</p>
<p>In the example application, we use ServiceTrackers to keep track of the components needed by the host. In a real system, you should consider using some dependency management mechanism; we have used the <a href="http://felix.apache.org/site/apache-felix-dependency-manager.html">Apache Felix Dependency Manager</a> in the past.</p>
<h2>The project and the story</h2>
<p>The project mentioned above is available as a zipped <a href="http://lsd.luminis.nl/wp-content/uploads/2009/10/swing_osgi.zip">Eclipse project</a>. You can directly import this into Eclipse, or just unzip it and run the Ant build file.</p>
<p>To run the examples, you will need <a href="http://ant.apache.org/">Apache Ant</a>. Also, since we use <a href="http://paxrunner.ops4j.org/space/Pax+Runner">Pax Runner</a>, you will need an internet connection.</p>
<p>The presentation we gave about this at Devoxx 09 is at SlideShare.</p>
<div style="width:425px;text-align:left" id="__ss_2527491"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/angelovds/swing-osgi-devoxx-09" title="Swing &amp; OSGi - Devoxx 09">Swing &amp; OSGi &#8211; Devoxx 09</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=swingandosgi-devoxx09-091118073831-phpapp01&#038;rel=0&#038;stripped_title=swing-osgi-devoxx-09" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=swingandosgi-devoxx09-091118073831-phpapp01&#038;rel=0&#038;stripped_title=swing-osgi-devoxx-09" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/angelovds">Angelo van der Sijpt</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/swing-and-osgi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ApacheCon US 2009 &#8211; Celebrating a decade of open source leadership</title>
		<link>http://lsd.luminis.nl/apachecon-us-2009-celebrating-a-decade-of-open-source-leadership/</link>
		<comments>http://lsd.luminis.nl/apachecon-us-2009-celebrating-a-decade-of-open-source-leadership/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 08:18:29 +0000</pubDate>
		<dc:creator>Marcel Offermans</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Apache ACE]]></category>
		<category><![CDATA[Apache Felix]]></category>
		<category><![CDATA[Apache Sling]]></category>
		<category><![CDATA[Apache Tuscany]]></category>
		<category><![CDATA[ApacheCon]]></category>
		<category><![CDATA[meritocracy]]></category>
		<category><![CDATA[News Item]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=520</guid>
		<description><![CDATA[The Apache Software Foundation celebrated its 10th anniversary last week at the ApacheCon US in Oakland, California. The event, which lasted from November 2nd to 6th, consisted of many different types of events, ranging from full-day trainings to lightning talks, from a hackathon to technical and marketing sessions. On friday, the event featured a full-day [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.apache.org/">Apache Software Foundation</a> celebrated its 10th anniversary last week at the ApacheCon US in Oakland, California. The event, which lasted from November 2nd to 6th, consisted of many different types of events, ranging from full-day trainings to lightning talks, from a hackathon to technical and marketing sessions. On friday, the event featured a full-day track about OSGi, where all OSGi related Apache projects like <a href="http://felix.apache.org/">Felix</a>, <a href="http://incubator.apache.org/ace/">ACE</a>, <a href="http://sling.apache.org/">Sling</a> and <a href="http://tuscany.apache.org/">Tuscany</a> where present. The big announcement of the conference was the fact that <a href="http://www.linuxpromagazine.com/Online/News/Subversion-Goes-to-Apache">Subversion wanted to join Apache</a>. In fact, during the event, just like with any other project, there was a vote to accept Subversion into the incubator. As with many projects, this triggered some discussion, debating the merits of doing a release during incubation, even though this is a project with many seasoned Apache committers on board.</p>
<h2>A conference like no other</h2>
<p>Apache probably is the strongest brand in the open source space, but the conference itself focusses strongly on content. Here you will see no sponsored talks by commercial vendors, no sales people trying to sell you anything, it&#8217;s all about the code, the community and collaborating with each other. In that sense it&#8217;s quite different from most other conferences and if you like meeting and discussing fellow developers, this is a great place to visit. Many events facilitate discussion, and power and internet connectivity are available everywhere.</p>
<h2>What open source is all about</h2>
<p>Brian Behlendorf summarized the three main cultural elements of Apache quite well:</p>
<ul>
<li>write good code and debate it to the bone</li>
<li>be humble</li>
<li>collaborate</li>
</ul>
<p>In essence, Apache is a meritocracy, of which only individuals can become a member. It&#8217;s sometimes also described as a do-ocracy as projects are driven by contributions: if you want something done, just do it. Another important aspect is that everything that is done on the Apache projects is discussed and archived on the mailing list. All discussions, code diffs and decisions must be recorded there.</p>
<h2>Presenting Apache ACE</h2>
<p>Tuesday evenings &#8220;birds of a feather&#8221; session featured a discussion about Apache ACE, where questions mostly centered around the use cases for ACE and possible integrations with other OSGi components. One of the conclusions is that there are probably three different phases of deployment:</p>
<ol>
<li>Using Apache Felix File Installer, which allows you to drop components in a local folder to have them installed.</li>
<li>Using Apache Felix Karaf&#8217;s provisioning components, which allow you to define features which basically group components and allow you to define dependencies on other features.</li>
<li>Using Apache ACE, which allows you to group components and automatically deploy them to many remote systems.</li>
</ol>
<p>Friday&#8217;s OSGi track started with an introduction to OSGi and moved into more advanced topics during the day. The Apache ACE talk was received well, with several people expressing an interest in wanting to use it and contribute to it.</p>
<h2>Final thoughts</h2>
<p>Summarizing the week, Floris and I had a great time talking to many interesting people and learning about various projects. ApacheCon is a great conference, and I&#8217;m already looking forward to the next one.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/apachecon-us-2009-celebrating-a-decade-of-open-source-leadership/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oredev 2009</title>
		<link>http://lsd.luminis.nl/oredev-2009/</link>
		<comments>http://lsd.luminis.nl/oredev-2009/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 22:44:59 +0000</pubDate>
		<dc:creator>Angelo van der Sijpt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[News Item]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[Øredev]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=486</guid>
		<description><![CDATA[4 - 6 November I went to Øredev, probably the largest developer conference in Scandinavia. Time for some highlights...]]></description>
			<content:encoded><![CDATA[<p>This past week (4 &#8211; 6 November), I went to <a href="http://www.oredev.com">Øredev</a>, probably the largest developer conference in Scandinavia. I had been invited as a speaker, thanks for having me!</p>
<h3>Great food, nice ambiance</h3>
<p>The first thing that strikes me about this conference is how well it has been prepared. The food is great, there is a good evening program, and overall both your inner geek and inner person are well looked after.</p>
<h3>Highlights</h3>
<p><strong>Interactive Visualizations from Microsoft research &#8211; Eric Stollnitz (User Experience track)<br />
<span style="font-weight: normal;">One of the rare talks I actually did not like. Having not read the session description properly, I had totally wrong expectations; the session demoed visual tools like <a href="http://livelabs.com/photosynth/">Photosynth</a>, which are cool, but not something we haven&#8217;t seen before. And besides, running Vista on a Mac, and having to kill Internet Explorer&#8230;?</span></strong></p>
<p><strong><span style="font-weight: normal;"><strong>Open source Java: ten things you didn&#8217;t know you could do &#8211; Terrence Barr (Java track) </strong><br />
Early in the talk it felt like a plug for the greatness of Sun, making Java open source. Later, however, it mentions some <em>seriously</em> cool technology that has become possible now! Some honorable mentions,</span></strong></p>
<ul>
<li>The <a href="http://research.sun.com/projects/maxine/">Maxine guest VM</a> is an effort to run a Java VM directly on a HyperVisor, skipping the entire OS!</li>
<li><a href="http://www.ikvm.net/">IKVM.NET</a> is a project aiming to run Java code on a .NET VM. Somehow, it turns out that Java bytecode and .NET assembly language are so similar, that an effort has been started to create automatic translation tools between compiled Java and compiled .NET (and vice versa). I would like to add that this is allows not only Java to run on a .NET VM, but likely any language that runs on the Java VM! Interesting&#8230;</li>
<li><a href="http://icedtea.classpath.org/wiki/ZeroSharkFaq#What_is_Zero.3F">Zero</a> writes a Java VM in plain C without using assembler code, making it easier to port it to new platforms.</li>
</ul>
<p><strong>The Manager&#8217;s Guide to Agile Adoption &#8211; Mike Cottmeyer (PM In Practice track)</strong><br />
A great talk showing the issues that might hamper agile adoption, especially in larger organizations. Some snippets,</p>
<ul>
<li>&#8220;Agile adoption at the team level is not the issue, it&#8217;s adopting agile <em>across</em> teams.&#8221;</li>
<li>Don&#8217;t speak of features of a system, speak of capabilities (think about that one!)</li>
<li>Depending on the amount of dependencies between teams, we could use a Scrum of Scrums (resource dependency), Product Owner team (requirements dependency), or a Product Owner team with Architects (technical dependencies). Whatever method is used, this higher level should build a <em>normalized</em> backlog, intended to create some alignment along the teams. The team&#8217;s backlogs are based on this normalized backlog.</li>
<li>Feature teams will break down at some level; at a certain system size, it&#8217;s no longer possible to create a top-to-bottom slice of the system which is small enough for a single team to manage.</li>
</ul>
<p>In short, I really enjoyed this talk, and I feel there might be some applications for these ideas somewhere near me&#8230;</p>
<p><strong>How Exactly Can Developers Create a Compelling User Experience? &#8211; Ben Galbraith (User Experience track)</strong><br />
Exactly the way I would expect a user experience talk to look (and feel!) like: polished imagery, a well-oiled story line, and lots of inspiration. Besides, I have two new books to add to my reading list: <a href="http://www.bol.com/nl/p/boeken-engels/about-face-3/1001004004709687/index.html">About Face</a> by Alan Cooper, which seems to be the standard volume on interaction design, and <a href="http://www.bol.com/nl/p/boeken-engels/the-humane-interface/1001004001047367/index.html">The humane interface</a> by Jeff Raskin.</p>
<p><strong>Reconsidering cherished design dogmas &#8211; Johannes Brodwall &amp; Finn-Robert Kristensen (Architecture track)</strong><br />
I actually had a beer with these guys a few days earlier, and they told me about their ideas. In short, there are a number of dogmas in software design we came to hold true, but are they actually true? For instance, is generic code really more reusable than specific code?</p>
<p>It&#8217;s a shame the talk didn&#8217;t really come across, and I could not put my finger on the problem; it might have something to do with the over-abstracted example they chose.</p>
<p><strong>Dynamic Deployment with OSGi &#8211; Angelo van der Sijpt (Java track)</strong><br />
Well, let the crowds decide on this one. Have you visited my talk, and have an opinion about it? Let me know in the comments?</p>
<p><strong>Modeling in the Age of Agility &#8211; Kevlin Henney (Agile Architecture track)</strong><br />
&#8220;Working software over comprehensive documentation&#8221; sounds good, but how about modeling? Are all models potential waste? Of course not, but when applying modeling because it is modeling, is sure to create models no one will ever look at, and the few good ones in there are buried. Some snippets,</p>
<ul>
<li>&#8220;Agile is all about doing.&#8221; Actually, I did not know the word &#8216;Agile&#8217; comes from the Latin verb for &#8216;to do&#8217;.</li>
<li>&#8220;The most important aspect of modeling is the -ing.&#8221;</li>
</ul>
<h3>So?</h3>
<p>Like I said, a great conference, and I&#8217;m sorry I missed the test track. I will leave you with a quote I picked up on Twitter (I don&#8217;t know which session it&#8217;s from),</p>
<p>&#8220;Don&#8217;t build frameworks, extract them&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/oredev-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building iPhone applications using MonoTouch, part 4: the UISearchDisplayController</title>
		<link>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-4-the-uisearchdisplaycontroller/</link>
		<comments>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-4-the-uisearchdisplaycontroller/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 20:21:25 +0000</pubDate>
		<dc:creator>Richard de Zwart</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[mobility]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[UIKit]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=415</guid>
		<description><![CDATA[In this post I explain how to hook the UISearchDisplayController to your code and vice versa.]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-3-the-interface-builder/">my previous post</a> I wrote about the Interface Builder and things like outlets. Last night (with the help of some colleagues) I cracked one of the more advanced Classes in the Interface Builder: the UISearchDisplayController.</p>
<p>In the previous version of my application I had a UITableView and a UISearchBar. I hooked them up with some code and it worked fine. But I didn&#8217;t get the effect that you see in (for instance) the iPod application. When you scroll up,  uncover the search-bar and start typing, the original view is greyed-out. And when your search gives no result, you get a &#8220;No Results&#8221; message. Like this:</p>
<p style="text-align: center;"><img class="size-medium wp-image-462 alignleft" title="SearchScreenShot" src="http://lsd.luminis.nl/wp-content/uploads/2009/11/SearchScreenShot-200x300.jpg" alt="SearchScreenShot" width="200" height="300" /> <a href="http://lsd.luminis.nl/wp-content/uploads/2009/11/NoResults.jpg"><img class="size-medium wp-image-475 aligncenter" title="NoResults" src="http://lsd.luminis.nl/wp-content/uploads/2009/11/NoResults-200x300.jpg" alt="NoResults" width="200" height="300" /></a></p>
<p>For that, you need the <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UISearchDisplayController_Class/Reference/Reference.html" target="_blank">UISearchDisplayController</a>. This controller does the work of hooking up a couple of UI-elements for you:</p>
<ol>
<li>The search bar</li>
<li>The view with the results from the search (called the searchContentsController)</li>
<li>The delegate that handles all the events that come from the search bar and the results view (called the searchResultsDelegate)</li>
<li>The data source that provides the data to search in (called the searchResultsDataSource)</li>
<li>Your original view</li>
</ol>
<p>When you drag a UISearchDisplayController and drop it at the top of your UITableViewController, all the outlets get connected to your controller automatically. Apparently the Interface Builder thinks that your class can play all these roles. This makes sense when you program Objective-C, since that language is quite capable of inheriting from lots of base classes (as is so eloquently explained in the <a href="http://cocoawithlove.com/2009/10/objective-c-niche-why-it-survives-in.html" target="_blank">Cocao With Love blog</a>), but asks some more attention when used from MonoTouch.</p>
<h3>Designers should not write code, and vice versa</h3>
<p>I will explain again what Interface Builder does for you. Maybe <em>you</em> already know, but I had to get used to it, and have to keep reminding myself that you use it to, well,  build interfaces. Nothing else. Interface Builder provides a clean separation between the GUI and the code, and that&#8217;s a good thing, right? Right. I love Design Patterns, and I try to convince as much progammers as possible to take at least notice of them. But iPhone apps are mostly very small apps with one or two screens, being very good in just one or two things. Do I need to implement this whole pattern for my simple app? Well, apparently. And so will you, so let me try to help you find out how to do some of these things.</p>
<h3>Steps to follow</h3>
<p>Begin with a UITableViewController. Then go to the Library Window, the Objects button and drag-n-drop a UISearchDisplayController just at the top of your UITableViewController.<br />
In the MainWindow you will have the UISearchDisplayController added. Click it there, and then go to the Outlets-tab in the Inspector Window. You will see that all the outlets will be connected to your UITableViewController, except for the searchBar-outlet since that is of course connected to the SearchBar.</p>
<p>When you run your app, you will have the Table-View and the SearchBar above it. When you tap the text-field you will see the desired gray-out and the &#8220;No Result&#8221; if you enter some text. So far so good.</p>
<h3>Providing the view with data</h3>
<p>Now we need to hook up some of our own code to the events that the UISearchDisplayController fires. Let&#8217;s start with some data in our own TableView to filter on.<br />
As said in one of my first posts, data for a view is delivered by a DataSource. In this case a UITableViewDataSource. So add a class to your project that inherits from UITableViewDataSource. Something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LeesPlankjeDataSource <span style="color: #008000;">:</span> UITableViewDataSource
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> woordjes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span><span style="color: #666666;">&quot;aap&quot;</span>, <span style="color: #666666;">&quot;noot&quot;</span>, <span style="color: #666666;">&quot;mies&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> filter<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		woordjes <span style="color: #008000;">=</span> woordjes.<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>f <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> f.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span>filter<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> UITableViewCell GetCell <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewCell cell <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DequeueReusableCell</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cell <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			cell <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UITableViewCell<span style="color: #000000;">&#40;</span>UITableViewCellStyle.<span style="color: #0600FF;">Default</span>, <span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		cell.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> woordjes<span style="color: #000000;">&#91;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> cell<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">int</span> RowsInSection <span style="color: #000000;">&#40;</span>UITableView tableview, <span style="color: #FF0000;">int</span> section<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> woordjes.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The complete code of this solution is at the bottom of this post.</p>
<p>The class has two constructors. The default constructor (at line 5) is called when initializing our own view, the constructor that takes a string (at line 9) will be called when filtering is started.<br />
The GetCell() and RowsInSection() methods need to be implemented to make your data source work. The implementation is pretty straightforward. The GetCell() method will be called &#8220;RowsInSection&#8221; times. The call to <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006943-CH3-DontLinkElementID_6" target="_blank">DequeueReusableCell</a>() is some trick to limit the amount of resources that your iPhone application will use. Just make sure you pass in some string that you reuse a few lines down.</p>
<p>To be able to set this datasource on the table-view we have to have some programmatic access to the view. Well, we did that before in the previous post. Go to Interface Builder, select the AppDelegate in the Library Window, add an outlet and connect it to your UITableViewController. Then you can have code like this in your main.cs:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> AppDelegate <span style="color: #008000;">:</span> UIApplicationDelegate
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// This method is invoked when the application has loaded its UI and its ready to run</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> FinishedLaunching <span style="color: #000000;">&#40;</span>UIApplication app, NSDictionary options<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		tableView.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// If you have defined a view, add it here:</span>
		window.<span style="color: #0000FF;">AddSubview</span> <span style="color: #000000;">&#40;</span>tableView<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		window.<span style="color: #0000FF;">MakeKeyAndVisible</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// This method is required in iPhoneOS 3.0</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnActivated <span style="color: #000000;">&#40;</span>UIApplication application<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>We simply set the DataSource on the tableView to our own DataSource and then add the tableView to the current window. Run your app and you will have some data in your view!</p>
<h3>Building the delegate</h3>
<p>Now we need some code to handle the events of the search bar. The most interesting event is &#8220;ShouldReloadForSearchtring()&#8221;. No that is not a typo, there really is an &#8220;S&#8221; missing in the method name. I filed a bug with the MonoTouch guys, so it is probably fixed in the next release, but we&#8217;ll have to live with it for now. And to be honest, that is not too hard.</p>
<p>Add a new class to your project that inherits from UISearchDisplayDelegate. The code should look something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;LeesPlankjeDelegate&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LeesPlankjeDelegate <span style="color: #008000;">:</span> UISearchDisplayDelegate
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> ShouldReloadForSearchtring <span style="color: #000000;">&#40;</span>UISearchDisplayController controller, <span style="color: #FF0000;">string</span> forSearchString<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;In ShouldReloadForSearchtring&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		controller.<span style="color: #0000FF;">SearchResultsDataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span>forSearchString<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
		<span style="color: #008080; font-style: italic;">//return base.ShouldReloadForSearchtring (controller, forSearchString);</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The first line is interesting. This is the magic that brings your classes into the Interface Builder. By registering the name of your class it will be added to the XIB (although not visible in the designer file). I&#8217;ll show you in a minute what you do with this in Interface Builder.</p>
<p>In the override of the ShouldReloadForSearchtring() I instantiate a new data source using the constructor that accepts a filter string. I set this on the SearchResultsDataSource property of the passed in controller object. As you can see in the code of the LeesPlankjeDataSource it will use a Lambda to filter the fixed array of words.</p>
<h3>Hooking up the UISearchDisplayController with your Delegate</h3>
<p>The Register-attribute on your delegate class makes it available in Interface Builder. So you go to the Library Window, choose the Objects button, then Controllers folder and then the general NSObject. Something like this: <img class="alignright size-medium wp-image-470" title="LibraryWindow" src="http://lsd.luminis.nl/wp-content/uploads/2009/11/LibraryWindow-252x300.png" alt="LibraryWindow" width="252" height="300" /></p>
<p>Drag it to the MainWindow, select it there, go to the Inspector, choose the Identity tab. Now change the class field to the name of your own class. LeesPlankjeDelegate in my case. Your class will not be listed, but that doesn&#8217;t matter. When you hit Enter, you&#8217;ll see in the MainWindow that both the class name and the instance name have changed. That is just fine.</p>
<p>Now the next magical thing: you have to connect the default delegate of the UISearchDisplayController to your Delegate class. Here is how: select the UISearchDisplayController in the MainWindow, go to the inspector, select the Outlets tab. The first outlet there is called &#8220;delegate&#8221; and is connected to your TableView. Now remove that connection by clicking the X. Then connect this delegate to your own Delegate class in the MainWindow.</p>
<p>Save in Interface Builder, go to MonoDevelop, run! Type something in the search and &#8220;Lo and behold!&#8221; it works!</p>
<p>Ain&#8217;t live sweet?</p>
<p>If it doesn&#8217;t work, feel free to leave a comment. I&#8217;ll see if I can help you.</p>
<p><a title="Download the source code here" href="http://lsd.luminis.nl/wp-content/uploads/2009/11/SearchProblems.zip">Download the source code<br />
</a></p>
<h3>P.S.</h3>
<p>The last step is actually more complex than it should have been. If I make my UISearchDisplayController visible to my AppDelegate by adding an outlet, I can do with just one more line of code in my main.cs:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">searchDisplayController.<span style="color: #FF0000;">Delegate</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDelegate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>That way I go one-way: from Interface Builder to MonoTouch. But I thought it more interesting to go the other way too: from MonoTouch to Interface Builder.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-4-the-uisearchdisplaycontroller/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
