Meld je nu aan voor de AgileMDD kennissessie op 30 maart
Geplaatst door Richard van der Laan in Uncategorized op maart 10, 2010
![]()
Luminis Software Development en ArchitecIT nodigen je graag uit voor een kennissessie over model-driven development.
We laten deze avond graag zien waarom modellen steeds belangrijker worden en hoe je er succesvol mee kunt zijn. De hele kennissessie zal in het teken staan van praktijkervaringen.
Aan de hand van vijf verschillende thema’s delen sprekers van diverse organisaties hun ervaringen met MDD in de praktijk: Thales Hengelo, Ministerie van Defensie, ArchitecIT, Delphino Consultancy en luminis.
In onze visie is het noodzakelijk om de ontwikkelkracht slimmer in te zetten, niet in de laatste plaats door de enorme toename van complexiteit in softwareintensieve systemen. In de praktijk zijn is er nog veel communicatie (overdrachtsmomenten) en bestaan de meeste ontwikkeltaken uit veel handwerk. Op basis van een pragmatische en doelgerichte aanpak kunnen ontwikkeltaken snel worden geautomatiseerd en kan de onderlinge communicatie worden verbeterd.
Datum: dinsdag 30 maart van 16:45 tot 20:00 uur
Locatie: IJsselburcht 3, 6825 BS, Arnhem
Voor wie: Architecten, ICT Managers en belangstellenden
Aanmelden: U kunt zich aanmelden per email door contact op te nemen met Inge Dokter
Het programma:
16:45 Opening in de grote zaal
17:00 Agile MDD: huidige trends en ontwikkelingen (Tony Sloos, Richard van der Laan)
17:30 MDA in realtime heterogene systemen (Rene van Hees, Alexander Broekhuis)
18:00 Lopend buffet
18:30 Microsoft DSL Toolkit in de praktijk (Gerrit Jan Timmermans, Erik Sanders)
19:00 MDD en software architectuur (Angelo Hulshout)
19:30 MDD kansen en risico’s (Andriy Levytskyy)
20:00 Afsluiting met borrel
Graag ontvangen we je aanmelding zo snel mogelijk, maar in iedergeval voor 12 maart. Aan deelname zijn geen kosten verbonden.
Je kan je aanmelding sturen naar Inge Dokter (inge.dokter@luminis.nl)
We hopen je te zien op dinsdag 30 maart!
Online video presentatie: Android & Augmented Reality
Geplaatst door Richard van der Laan in mobility op maart 8, 2010
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 hier (175mb) downloaden. Maar de eerste tien minuten zijn hieronder gelijk op YouTube te bekijken.
English: The whole presentation can be downloaded here (175mb).
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:
- Introductie over augmented reality: location based vs beeldherkenning;
- Wat is te krijgen in de markt? Layar, Wikitude, etc;
- Wat zijn de mogelijkheden om applicaties te ontwikkelen met de beschikbare frameworks;
- Hoe ontwikkel je zelf een augmented reality applicatie op Android?
De slides van de presentatie zijn te vinden op de NLJUG website.
Zen en de kunst van het software maken
Geplaatst door Richard de Zwart in social op februari 14, 2010
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 waarom ze me zo bezighouden. Tot ik een artikel las in Happinez (nee, daar heb ik geen abonnement op, ik las ‘m toevallig omdat mijn vrouw ‘m had gekocht…) dat ging over Robert M. Pirsig.
Hij schreef in 1974 het boek “Zen and the art of motorcycle maintenance” 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.
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’s “Dao De Jing”.
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.
Schoonheid is voor mij belangrijk omdat ik er blij van wordt. En ik heb liefst dagelijks een stukje blij in mijn leven.
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.
Software maken is bij uitstek een bezigheid waarbij kwaliteit en schoonheid een rol spelen. Floris schreef er vandaag ook over in zijn Blue Note 84: “…de kans neemt aanzienlijk toe dat het goede software is als de source code er ook mooi uit ziet”. Een vakman ziet dat. In één oogopslag: dit is wel of geen mooie code.
In ons vak zijn veel mensen die software maken, maar zijn het allemaal vaklui? Pirsig schrijft hierover:
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.
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: “wat is hier aan de hand, wat is eigenlijk het probleem?”.
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’n handig pennenbakje kun je met een spijker vastzetten aan de staander. O, laatjes erbij? Dan nemen we zo’n laatjesding en die zetten we op de plank; schuiven we gewoon wat boeken opzij.
En op een dag valt het hele gevaarte om, want in het begin had je de moeite niet genomen om ‘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.
Het is momenteel mijn werk om nog een plank aan zo’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.
Maar dat is niet mijn opdracht. Die kassa moet op die plank, en snel een beetje.
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?
Wat zou jij doen?
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.
About Non-Disclosure Argeements
Geplaatst door Richard de Zwart in mobility, social op januari 31, 2010
Last night I wrote a blogpost about the first application I built for the iPad. I’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.
So at 11 o’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.
Wow, did I? Yes, I did. When you download the beta of the iPhone 3.2 SDK there’s the following text:
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 “Apple Confidential Information”. No hits. Searched the legal department at apple.com/legal, no hits on beta software
Finally came up with the idea to search on the sub-site of the Apple Developer Centre. On the page on Pre-release software there is the rather clear text:
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.
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 “Terms and Conditions” PDF that has a section 7 on Pre-release software that essentially tells you that “You certify that pre-release software will only be used for testing and development purposes”. 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?
The PLCA (as they lovingly call it) is on page 5 of the PDF and has a section 4 on non-disclosure:
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
Well, there it is. No right to publish Confidential Information, which means no stuff that Apple hadn’t already published about. So I can write about the iPad, I can 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.
Is this really necessary? What good does it do Apple when I don’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?
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.
I don’t like secrets, I don’t like lawyer stuff that tries to protect (imprison?) ideas. I do like what Jeff Atwood wrote about ideas: 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’re not going to, then don’t blame the blogger, blame yourself.
Building iPhone applications using MonoTouch, howto: using a view without a controller
Geplaatst door Richard de Zwart in .NET, mobility, technical op januari 25, 2010
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’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 gives me a nice playground to find out new stuff.
So there is a “Loading playlist” message and a “Buffering audio” 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????).
I try to follow three rules when building the UI:
- All the UI is done with the Interface Builder. That allows me to leave the actual design to someone who knows designing.
- Every view is in a separate NIB. That way not all the UI has to be loaded at startup, which improves user-perceived performance
- Loosely couple the view, to make reuse easier. That means a simple interface (as in ‘programming interface’) to the rest of the world, and all the view-related code inside the NIB
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 “View Interface Definition”:
It’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.
What I came up with, is the following.
public class UIHelper { UIViewController _controller; BusyView _busyView; public UIHelper (UIViewController controller) { _controller = controller; NSArray views = NSBundle.MainBundle.LoadNib("BusyView", _controller, null); _busyView = new BusyView(views.ValueAt(0)); _controller.View.AddSubview(views); _controller.View.SendSubviewToBack(_busyView); } }
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 documentation says:
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.
So you get the top-elements (actually: the IntPtr’s of them) from the NIB. In a file with only one view the first one is probably (…fingers crossed) the right one.
I add the view to the SubViews of the controller and make sure it does not show before it was meant to.
Showing the view
Whenever I need the view to display I call:
_busyView.Show(message); _controller.View.BringSubviewToFront(_busyView);
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.
What’s not to like about this solution
Well, the magical string with the name of the NIB, “BusyView”. And the magical number 0 the denotes the right object in the list of objects in the NIB.
Any ideas for improvement? Please react!
Online video: Beyond OSGi software architecture
Geplaatst door Richard van der Laan in Uncategorized op januari 22, 2010
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. De gehele presentatie van 50 minuten kan je hier downloaden. Maar de eerste tien minuten zijn hieronder gelijk online te bekijken.
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’s) van die interfaces. Krachtige eigenschappen van dit model zijn:
- complexiteitsreductie door stricte scheiding van services;
- declaratieve services en dependency management (IoC);
- aspect oriëntatie op basis van stub services;
- security model.
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:
- applicaties deployen op allerlei platformen en omgevingen;
- applicaties automatisch installeren en updaten;
- applicaties voorzien van management interfaces;
- product software uitbreidbaar maken middels een SDK;
- product software verkopen als combinatie van standaard onderdelen en optionele uitbreidingen;
- modulaire User Interfaces.
De slides van de presentatie zijn te vinden op de NLJUG website.
Building iPhone applications using MonoTouch, part 5: software design considerations
Geplaatst door Richard de Zwart in .NET, mobility, technical op november 21, 2009
In the previous 4 posts (4, 3, 2, 1) 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?
Get SOLID
There are two things that I always try to keep in mind when making software: loose coupling and tight cohesion. In other words:
- make sure your classes don’t know things that they don’t need to know
- make sure your classes are good at one thing and one thing only
These guidelines are part of the 5 SOLID principles of class design by Uncle Bob Martin:
- Single Responsibility Principle
- Open Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
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’re happy with a 3rd Normal Form database. So I’m happy when I see code that complies with at least two of the above principles.
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.
Let me give you an example.
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:
public override bool FinishedLaunching (UIApplication app, NSDictionary options) { tableView.DataSource = new LeesPlankjeDataSource(); window.AddSubview (tableView); window.MakeKeyAndVisible (); return true; }
The class instantiated at line 3 is something like this:
public class LeesPlankjeDataSource : UITableViewDataSource { private string[] woordjes = new string[] {"aap", "noot", "mies"}; public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) { UITableViewCell cell = tableView.DequeueReusableCell("plankje"); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Default, "plankje"); } cell.TextLabel.Text = woordjes[indexPath.Row]; return cell; } public override int RowsInSection (UITableView tableview, int section) { return woordjes.Length; } }
On line 3 you see the actual “data store”, 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.
On to a more realistic implementation
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.
That changes my class to this:
public class LeesPlankjeDataSource : UITableViewDataSource { private string[] _dataStorage; public LeesPlankjeDataSource(string[] data) { _dataStorage = data; } public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) { UITableViewCell cell = tableView.DequeueReusableCell("plankje"); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Default, "plankje"); } cell.TextLabel.Text = _dataStorage[indexPath.Row]; return cell; } public override int RowsInSection (UITableView tableview, int section) { return _dataStorage.Length; } }
And the main.cs gets these lines:
string[] woordjes = File.ReadAllLines("woordjes.txt"); tableView.DataSource = new LeesPlankjeDataSource(woordjes);
Make sure when you have files that you want to be deployed with your app to set the build-action on the file to “content”:
That’s all neat. The DataSource gets it data from the outside and doesn’t care if it comes from a file or a network-connection.
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:
public class LeesPlankjeViewDelegate : UITableViewDelegate { public override void RowSelected (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) { } }
But what can I do in this method? Let’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’t have the data source itself in this class. I need some way to acces my original data store.
I could do somehting like this:
public override void RowSelected (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) { string message = tableView.DataSource.GetCell(tableView, indexPath).TextLabel.Text; using (var alert = new UIAlertView ("", message, null, "OK", null)) { alert.Show (); } }
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’t, because all the delegate needs to do is handle UI-interactions from the user. It should say “Hey, someone tapped me on this row, do something with it” and then leave the actual work to someone else.
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:
tableView.Delegate = new LeesPlankjeViewDelegate(tableViewController);
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…. even more code in my FinishedLaunching() method. I don’t want that, I want to hook up UI-parts with each other using the Interface Builder, not in code.
So, what to do now? I don’t know yet. Let me first deal with a problem that I didn’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.
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:
public override bool ShouldReloadForSearchString (UISearchDisplayController controller, string forSearchString) { Console.WriteLine("In ShouldReloadForSearchtring"); controller.SearchResultsDataSource = new LeesPlankjeDataSource(forSearchString); return true; }
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 “woordjes.txt” 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:
public override bool ShouldReloadForSearchString (UISearchDisplayController controller, string forSearchString) { Console.WriteLine("In ShouldReloadForSearchString"); var woordjes = ????????? var data = new LeesPlankjeDataSource(woordjes); controller.SearchResultsDataSource = data.FilterOn(forSearchString); return true; }
But where am I gonna get the “woordjes” 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.
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.
For tonight, I give up. The code you can download contains the solution that goes against IoC, but works none the less.
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’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.S.
Thanks to Alex York’s excellent post (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’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.
When working on the new solution I also renamed some classes (no more Dutch names, only Dutch words in the data…) and added a class that implements the model:
public class WordsModel { private List _dataStorage; public WordsModel () { _dataStorage = File.ReadAllLines("woordjes.txt").ToList(); _dataStorage.Sort(); } public string[] Data { get { return _dataStorage.ToArray();} } public string[] FilterOn(string searchText) { searchText = searchText.ToLower(); var result = _dataStorage.Where(t => t.ToLowerInvariant().StartsWith(searchText)); return result.ToArray(); } }
It is the place where the knowledge of words, where they come from and how you filter them, resides.
But Alex’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.
I solved this by implementing a general WordsDataSource that uses the WordsModel and has a constuctor for normal use and for filtering:
public class WordsDataSource : UITableViewDataSource { private WordsModel model = new WordsModel(); private string[] _dataStorage; public WordsDataSource() { _dataStorage = model.Data; } public WordsDataSource(string filter) : this() { _dataStorage = model.FilterOn(filter); } public string GetAt(int position) { return _dataStorage[position]; } public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) { UITableViewCell cell = tableView.DequeueReusableCell("plankje"); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Default, "plankje"); } cell.TextLabel.Text = _dataStorage[indexPath.Row]; return cell; } public override int RowsInSection (UITableView tableview, int section) { return _dataStorage.Length; } }
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.
And then I used that class in two places:
- as an internal property in my WordsTableViewController
- as a helper-class in the delegate of the UISearchDisplayController.
[MonoTouch.Foundation.Register("WordsTableViewController")] public partial class WordsTableViewController : UITableViewController { // Constructor invoked from the NIB loader public WordsTableViewController (IntPtr p) : base (p) { } // The data source for our TableView private WordsDataSource TableDataSource { get { return this.TableView.DataSource as WordsDataSource; } set { this.TableView.DataSource = value; } } // This class receives notifications that happen on the UITableView class TableDelegate : UITableViewDelegate { WordsTableViewController parentView; public TableDelegate (WordsTableViewController tableViewController) { parentView = tableViewController; } public override void RowSelected (UITableView tableView, NSIndexPath indexPath) { string selectedWord = parentView.TableDataSource.GetAt(indexPath.Row); using (var alert = new UIAlertView ("Selected", selectedWord, null, "OK", null)) alert.Show (); } } public override void ViewDidLoad () { base.ViewDidLoad (); TableView.Delegate = new TableDelegate (this); this.TableDataSource = new WordsDataSource (); } }
[MonoTouch.Foundation.Register("WordSearchDelegate")] public class WordSearchDelegate : UISearchDisplayDelegate { public override bool ShouldReloadForSearchString (UISearchDisplayController controller, string forSearchString) { UITableViewDataSource data = new WordsDataSource(forSearchString); controller.SearchResultsDataSource = data; return true; } }
I’m pretty happy with what I got by now. You can download the new version, if you like.
Swing & OSGi — please play nice!
Geplaatst door Angelo van der Sijpt in Uncategorized, java op november 18, 2009
In a recent blog 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.
Plugging Swing: it leaks?
Let’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.
You can find the code we used at the end of this entry (or, for the impatient, here).
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.
Or worse, you might end up with a UI that (sometimes) fails to start, and spits a stacktrace your way.
It leaks, but why?
Our host, and all components have been stored in separate bundles, meaning we don’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’s force one of those.
The project contains an Ant script to make things easier. From the root of the extracted project, run
$ > ant run1This starts the framework, installing the necessary bundles, but does not start them (note that this step uses Pax Runner, and therefore needs internet access). We can now start our bundles in the order we like.
A tale of two look-and-feels
After starting the framework, wait for the “Welcome to Felix” message, and run
[java] Welcome to Felix [java] ================ [java] start 2 start 1
The situation arises because the look and feel is a static concept in Swing. The menu bundle creates its JMenu before (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.
Tables, ScrollPanes and NPEs
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.
[java] Welcome to Felix [java] ================ [java] start 4 [java] Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException [java] at net.luminis.swingosgi.part1.scrolltable.impl.TableComponent$1.run(TableComponent.java:31) [java] at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) [java] at java.awt.EventQueue.dispatchEvent(EventQueue.java:633) [java] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) [java] at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) [java] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) [java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) [java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) [java] at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Let’s take a look at the line where this NPE happens:
JScrollPane scrollPane = new JScrollPane(table); scrollPane.getColumnHeader().setBackground(Color.blue); m_panel.add(scrollPane);
We know that the ColumnHeader is null. This is because its JTable’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; configureEnclosingScrollPane() creates the column header. This addNotify method comes from Component, and notifies of, exactly, the event of being added to an AWT container.
public void addNotify() { super.addNotify(); configureEnclosingScrollPane(); }
Order, order!
So, the static nature of Swing and the dynamic nature of OSGi seem to hurt each other seriously here.
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.
Regarding order, a few possible solutions spring to mind immediately,
- Put all UI stuff in one bundle
- Use OSGi bundle start levels
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.
What order?
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.

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.
- Resolve services Once the host bundle starts, we know all components are locked and loaded; the host can now start setting up Swing’s static elements like the look and feel.
- Create components 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.
- Initialize components 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.
To reach this situation, we introduce a new OSGi service that wraps the component.

All components are handled by a service implementing ComponentProvider; 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.
public interface ComponentProvider { /** * Constant to identify ComponentProvider services. */ public static final String COMPONENT_ID_KEY = "component.id"; /** * 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. */ public JComponent getComponent(); /** * 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()}. */ public void addedToContainer(); }
The getComponent function is analogous to the create step above; the addedToContainer triggers the initialize.
Let’s try that out!
To check that this actually works OK, run
$ > ant run2from the root of the project, and start the bundles in any order you like. The UI will only show up once all required components are available; notice that the Table and the ScrollPane component can be used interchangeably.
Is it all good?
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 running application?
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 Apache Felix Dependency Manager in the past.
The project and the story
The project mentioned above is available as a zipped Eclipse project. You can directly import this into Eclipse, or just unzip it and run the Ant build file.
To run the examples, you will need Apache Ant. Also, since we use Pax Runner, you will need an internet connection.
The presentation we gave about this at Devoxx 09 is at SlideShare.
ApacheCon US 2009 – Celebrating a decade of open source leadership
Geplaatst door Marcel Offermans in java op november 10, 2009
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 track about OSGi, where all OSGi related Apache projects like Felix, ACE, Sling and Tuscany where present. The big announcement of the conference was the fact that Subversion wanted to join Apache. 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.
A conference like no other
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’s all about the code, the community and collaborating with each other. In that sense it’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.
What open source is all about
Brian Behlendorf summarized the three main cultural elements of Apache quite well:
- write good code and debate it to the bone
- be humble
- collaborate
In essence, Apache is a meritocracy, of which only individuals can become a member. It’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.
Presenting Apache ACE
Tuesday evenings “birds of a feather” 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:
- Using Apache Felix File Installer, which allows you to drop components in a local folder to have them installed.
- Using Apache Felix Karaf’s provisioning components, which allow you to define features which basically group components and allow you to define dependencies on other features.
- Using Apache ACE, which allows you to group components and automatically deploy them to many remote systems.
Friday’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.
Final thoughts
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’m already looking forward to the next one.
Oredev 2009
Geplaatst door Angelo van der Sijpt in Uncategorized op november 6, 2009
This past week (4 – 6 November), I went to Øredev, probably the largest developer conference in Scandinavia. I had been invited as a speaker, thanks for having me!
Great food, nice ambiance
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.
Highlights
Interactive Visualizations from Microsoft research – Eric Stollnitz (User Experience track)
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 Photosynth, which are cool, but not something we haven’t seen before. And besides, running Vista on a Mac, and having to kill Internet Explorer…?
Open source Java: ten things you didn’t know you could do – Terrence Barr (Java track)
Early in the talk it felt like a plug for the greatness of Sun, making Java open source. Later, however, it mentions some seriously cool technology that has become possible now! Some honorable mentions,
- The Maxine guest VM is an effort to run a Java VM directly on a HyperVisor, skipping the entire OS!
- IKVM.NET 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…
- Zero writes a Java VM in plain C without using assembler code, making it easier to port it to new platforms.
The Manager’s Guide to Agile Adoption – Mike Cottmeyer (PM In Practice track)
A great talk showing the issues that might hamper agile adoption, especially in larger organizations. Some snippets,
- “Agile adoption at the team level is not the issue, it’s adopting agile across teams.”
- Don’t speak of features of a system, speak of capabilities (think about that one!)
- 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 normalized backlog, intended to create some alignment along the teams. The team’s backlogs are based on this normalized backlog.
- Feature teams will break down at some level; at a certain system size, it’s no longer possible to create a top-to-bottom slice of the system which is small enough for a single team to manage.
In short, I really enjoyed this talk, and I feel there might be some applications for these ideas somewhere near me…
How Exactly Can Developers Create a Compelling User Experience? – Ben Galbraith (User Experience track)
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: About Face by Alan Cooper, which seems to be the standard volume on interaction design, and The humane interface by Jeff Raskin.
Reconsidering cherished design dogmas – Johannes Brodwall & Finn-Robert Kristensen (Architecture track)
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?
It’s a shame the talk didn’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.
Dynamic Deployment with OSGi – Angelo van der Sijpt (Java track)
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?
Modeling in the Age of Agility – Kevlin Henney (Agile Architecture track)
“Working software over comprehensive documentation” 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,
- “Agile is all about doing.” Actually, I did not know the word ‘Agile’ comes from the Latin verb for ‘to do’.
- “The most important aspect of modeling is the -ing.”
So?
Like I said, a great conference, and I’m sorry I missed the test track. I will leave you with a quote I picked up on Twitter (I don’t know which session it’s from),
“Don’t build frameworks, extract them”





