Archive for the ‘Desktop Client Programming’ Category

When you stuck upon Eclipse

Based on my experience, there is only two things you can do when you stuck upon Eclipse :

  1. Keep searching
  2. Wait for the next update to be released.

Eclipse is still growing after all …

powered by performancing firefox

Advertisements

Action or Handler

When I code using swing, I used to wrote the controller part of the MVC in Action classes. So, when I code in eclipse RCP, I wrote it also in Action classes.

I was wrong.

The code was fine until the program need to get the result of the business process operations. The Action class in eclipse RCP doesn’t return anything. After I searched the answer for two whole days, I found that there is a plugin called org.eclipse.core.command. The Action classes I was using is commonly used for handling events in a view’s menus. The Eclipse use command design pattern.

In command design pattern, there is a command, the invoker, and the handler of commands. The invoker is the view, which then issues commands, and the commands appoint which handler is supposed to handle the command.

In short, this is what happened after I changed my program :

View -> command registry -> command, and states -> handler -> business process -> handler -> View

And thats it. The handlers is able to return values using state.

How about the Action classes I mentioned earlier ?

The Action class is able to use the Command class to do the task. Then you can put the Action class in menus.

powered by performancing firefox

Introducing Eclipse RCP

One day near the deadline, a project teammate asked me about Eclipse RCP; something I used from the beginning of the project. I don’t have the 100% correct answer, but in my opinion, a Rich Client Platform is a platform we can use to simplify desktop client application development. All tedious things we frequently wrote, such as dialogs, wizards, preferences, help systems, up to update management is provided there in a good structure.

Eclipse RCP is one of them.

powered by performancing firefox

Listener styles

I remembered the first time I wrote a desktop form using java. I wrote everything inside a class, including the listeners, and the whole business process involving database access, data manipulation and so on. I didn’t realized that it’s a worst thing to do until my code gone beyond 1000 lines.

Picked a lesson from that, I begin to separate business process, data models, and user interface into something they called MVC. Upon trial and error, I came into a few style to create a desktop form:

  1. A view with one or more listeners as controllers.
  2. A view with one or more action classes as controllers connected by anonymous listeners.
  3. A view with one or more action classes as controllers accessed by private methods connected by listeners.

The first style looks like this :

Button a = new Button();
a.addListener(new AListener());

.
.
class AListener extends SelectionAdapter
{
    //extends methods and do all business process here
}

I found this style not flexible because in a large application, you might want to create more than one way to do something. A simple example is creating a button and a menu item to do the exact thing.

The second style looks like this :

Button a = new Button();
a.addListener(new Listener()
{
    AnAction x = new AnAction();
    x.run();
};

.
.
class An Action extends Action()
{
    public void run()
    {
       //do business process here
    }
}

I think this style is better than the first one, since the style allows me to put the action in any listener. But it still has a problem. Sometimes we want to modify the content of form element, say, a text field, or variable upon doing the business process. Our code become ugly because we have to put final keyword to variables we need to access inside the Listener class.

So, in order to cure the problem, I used this style :

Button a = new Button();
a.addListener(new Listener()
{
    doThings();
};

//we can access variables without using final keyword
private void doThings()
{
    AnAction x = new AnAction();
    x.run();  
}
.
.
class An Action extends Action()
{
    public void run()
    {
       //do business process here
    }
}

I think the last style is the best so far.

powered by performancing firefox