Cairngen 1.2: From 0 to Cairngorm in 10 seconds (well almost) July 23, 2007

Posted by Mark Ellul in : Cairngorm, Flex 2 , 1 comment so far

Cairngorm Version: 2.2 and below…
Introduction:

I don’t know about you all, but setting up my first cairngorm app was daunting to say the least.
I have set up a few Flex applications now using Cairngorm, and I found the most useful utility I have ever used to help setup a new Flex Application to use cairngorm had to be Cairngen.


Cairngen

Cairngen, found at the above link was created by Eric Feminella, a talented and generous engineer (as cairngen is free) which uses Ant in Eclipse to generate:

  1. The directory structure for you commands, events, views, model, vo’s and business logic.
  2. The Classes used for most parts of your appliction.

Installation

1. ANT - First make sure you have ant installed inside of your Flexbuilder or Eclipse programs..

Flexbuilder - Peter Elsts offers instructions on how to do so on his blog click here

Eclipse - There are plenty of links on how to do this, if you find any that are particularly useful, please post it in the comments.

2. Cairngen - Cairngen can be downloaded at the above link and is simple to install… Extract it into your flex application folder. I am not going to go into details as they are explained on Eric site..

NOTES:

  • I am not an journalist, and even though english is my first language, I prefer computer languages ;o)
  • When editing your project.properties, you can only create one command sequence and VO at a time, so you will find yourself editing that file over and over again… which is still better than doing it from scratch.
  • Eric uses a template approach, so if you want to make your commands or delegates inherit from different classes.. You can change the template necessary.

Summary

I hope this helps you in your cairngorm endeavours. It certainly has helped me.

P.S

I hope to be doing some more posts in the coming future

Regards

Mark Ellul

Sequencing multiple commands December 24, 2006

Posted by Bjorn Schultheiss in : Cairngorm, Cairngorm Code Examples, Flex 2 , 18 comments

In your cairngorm Flex 2 application you may require to string a sequence of commands together. This may occur in your application’s initialization process or in the view from a user gesture.

For example, in the case of an e-commerce application on initialization you may be required to get all categories, sub-categories related to a category and the products related to a sub-category all in one process.

In cairngorm each command requires an event to be fired in order to execute the command. Now where you create that next event to be fired is usually in the subsequent command, prior to setting it to that command’s nextEvent property.

Perhaps this approach may not be suitable depending on your commands (as in one my cases) so i created a utility for chaining events together so that a sequence of events can be fired at the developer’s desire.

To demonstrate a scenario of the usage of this utility i have created a small example (click here and right-click to download source) and an illustration of the example.

Event Chaining Diagram

What i’ve done is create a sub-class of CairngormEvent which has a public property called nextChainedEvent.
Then I’ve create a utility class called EventChainFactory with a method chainEvents, which accepts an array of ChainEvent instances as its only parameter with each event in the array ordered in the order you want your sequence of events fired in. The method returns a ChainEvent instance with each subsequent event set to the next event’s nextChainedEvent property.

Enjoy and dont hestitate to improve it.

Regards,
Bjorn Schultheiss

The SequenceCommand November 13, 2006

Posted by Bjorn Schultheiss in : Cairngorm, Flex 2 , 2 comments

Extending the SequenceCommand class is quite easy.
The SequenceCommand class is used for commands that wish to execute further commands.
Although the documentation explains its use well i thought i would post an example. Hopefully my example displays its correct usage :)

First we add a constructor to our command. Here we can specify the event that is to be dispatched to execute our next command. Here we only create the event and store it. The event does not get dispatched until we call executeNextCommand();
public class GetMenuItemsCommand extends SequenceCommand implements ICommand, IResponder
{
public function GetMenuItemsCommand()
{
nextEvent = new CairngormEvent(StoreController.GET_SHARED_OBJECT_EVENT);
}

The execute method of the command requires the override modifier

override public function execute(event:CairngormEvent):void
{
var delegate:GetMenuItemsDelegate = new GetMenuItemsDelegate(this);
delegate.getMenu();
}

Calling executeNextCommand() will dispatch our next event.

public function result(data:Object):void
{
executeNextCommand();
}

I like the use of this class.
Its makes our commands more readible and provides a solid methodology of creating and dispatching events from a Command.

Bjorn

Cairngorm 2.1 and mx.rpc.IResponder November 11, 2006

Posted by Bjorn Schultheiss in : Cairngorm, Flex 2 , 3 comments

One of the inclusions to Cairngorm 2.1 is the encouraged use of mx.rpc.IResponder instead of the now deprecated Cairngorm Responder.

This invloves a couple changes to your Commands and Delegates and is of worthy benefit for developers to use.

For starters, this has been explained in details on Darron Schall’s blog here

Here’s an example of the code changes required.

Your commands now implement to new methods,

public function result( data:Object ):void
{
// Most of the time the data is a ResultEvent, so just cast it here
var event:ResultEvent = data as ResultEvent;
}
public function fault( info:Object ):void
{
// Most of the time the info is a FaultEvent, so just cast it here
var event:FaultEvent = info as FaultEvent;
}

And your delegates now use IResponder for the constructor param type.
Also when it comes to setting your result and fault handlers in your remote call just add your responder to your ASyncToken object.

// Inside of the MyDelegate class
public function makeRemoteCall():void
{
var call:AsyncToken = service.aRemoteMethod();
call.addResponder( responder );
}

Thanks Darron for the info.
Bjorn

ModelLocator and Databinding (Enterprise Flex RIA and the Cairngorm Microarchitecture – The developer’s experience) November 7, 2006

Posted by Bjorn Schultheiss in : Cairngorm, Flex 2 , 1 comment so far

ModelLocator and Databinding.

The ModelLocator and the use of Databinding to bind model data to views is one of the key advantages of developing Flex RIA’s with Cairngorm.

The ModelLocator provides developers with a single point of reference to client model data objects. It is important in MVC RIA development to ensure that model object instances are contained in a single object that is accessible from any area of the application without unnecessarily needing to instantiate further objects or creating copies of the data. This solution is provided by the singleton design pattern.

Databinding is the mechanism used to display model data in your views. Binding removes the need to code your own event dispatching system to update your views with up to date model data. For Flash developers considering learning Flex, Databinding may be the biggest drawcard. The main benefit is the small amount of code required to use Databinding.
Code examples can be found in Cairngorm Diagram Explorer.
From Developing Rich Clients with Macromedia Flex, the sample pdf chapter on Databinding.

I manage my views with data from the model. For example I have created a Model Class called UIControlsModel. Within this Class I store all my presets for my UI’s layout. My model objects are all instantiated in my modelLocator constructor. This way I am able to maintain a set beautifully constructed series of model object structures for efficient use throughout my application.

Cairngorm is a very useful framework and I recommend anybody learning flex 2 to also learn Cairngorm.

My next post we be on Delegates, ServiceLocator and my experience using Tomcat on my Macbook pro…

I have also completed a lengthy article that I divided into 3 posts on my flex journal that is on my personal blog.

Flex RIA Articles - Part 1 (The Background)
Flex RIA Articles - Part 1 (Front to Back Development)
Flex RIA Articles - Part 1 (Prototyping and Architecture)

Regards,
Bjorn

Distortion Effects November 6, 2006

Posted by Thomas Ruehl in : Flex 2 , add a comment

Hello Cairngormers,
didn’t see this anywhere around here, so…

Alex Uhlmann posted a neat sample applicaion, that adds support for distortion effects in Flex applications. His proof-of-concept shows, how to utilize the open source Flash 3D engine “Sandy” for use within Flex applications.

Find his blog here …and the example app here

Cheers, Thomas

Enterprise Flex RIA and the Cairngorm Microarchitecture – The developer’s experience November 4, 2006

Posted by Bjorn Schultheiss in : Cairngorm, Flex 2 , 1 comment so far

As promised I have began writing a series of articles based around my experience of implementing the Cairngorm Microarchitecture into my first Enterprise Flex RIA.

In tandem I am also writing a series on my personal blog ( http://flexcity.wordpress.com ) titled, ‘Building an Enterprise Level, Flex 2 RIA’ where I will be writing a lot more about the overall experience.

As a note, I am not going to be disclosing too much detail of the purpose of the application and will not be releasing any source code, although I may include snippets of code to help illustrate certain areas of the articles.

The RIA is a pure Flex 2 GUI and the back-end server application is built in Java. Our front-end team currently consists of 2 Flex Developers with another developer coming on board in a couple of weeks and hopefully more in the future.

Enjoy,

Bjorn Schultheiss