Tuesday, July 13, 2010

Great tool for any programming : Logging

I found logging indispensable when I was developing for my software engineering class.
Being ignorant I created my own simple api to achieve my purpose. But as in my internship I discovered log4J an log4net. It was like a bliss when I was debugging.
Gwt natively has only one level of logging: to console using GWT.log().
I discovered this very cool logging api written by allen sauer and fred sauer. It is very much like log4j, but for gwt.
You can find it at
http://code.google.com/p/gwt-log/
and the tutorial to set it up at
http://developerlife.com/tutorials/?p=229
The above tutorial also teaches how to set up third party libraries with gwt.

Friday, July 9, 2010

How to use Enums in Switch (java)

In a small example I am going to tell you how to use enums in switch.
Enums is a good practice of grouping a list of items which fall in similar category. If you want to learn more about enums look in to here.

Now I assume that you know about enums and now lets see how do we swtich on them.
This is my enum set
public static enum Navigation{SCROLL,DROP_DOWN,NONE}

Now you need to switch on the enum.
we write
//choice is
Navigation navigationChoice = Navigation.SCROLL;
switch (navigationChoice) //once decide to switch on the Enumof type navigation choice.
{
Since we already are switching on the Naviagation enum Java knows to look only with the Navigation enum the context is set to Navigation enum so we need not have fully qualified name Navigation.SCROLL . We can just use SCROLL instead.

CORRECT WAY TO DO:
case SCROLL: {...}
CORRECT: We use the unqualified name i.e. SCROLL and Java will automatically know that we are asking for scroll in the navigation options as we are switching on a Navigation enum constant.

WRONG WAY TO DO:
case Navigation.DROP_DOWN: {...}
This will give you error the follwing error
ERROR: The qualified case label Navigation.DROP_DOWN must be replaced with the unqualified enum constant DROP_DOWN

WRONG WAY TO DO:
case (NONE): {...}
This will give you error the follwing error
ERROR: Enum constants cannot be surrounded by parenthesis
}


Thursday, April 22, 2010

Strange Error

I have project folder in my network drive. The url starts with a \\folder_name\.... I tried importing that project into my work space and It gives me this error.

java.lang.IllegalArgumentException: URI has an authority component
at java.io.File.(Unknown Source)

But when I change map my network drive to a letter. Now Path is E:\folder_name\...
I don't get this error any more. I guess this has something to do with file system and Java rather than Gwt. Any way an interesting pointer for people out there.
I will research more on this and update you.

Thursday, April 15, 2010

Examples for GWT 2.0

These are links to gwt 2.0 examples and articles. They are pretty good especially one on Ui binder stuff.

http://davidmaddison.blogspot.com/2010/03/building-gwt-declarative-interface.html

Wednesday, April 14, 2010

Event handing.

This was the first tough nut to crack. I am trying to learn event handling from the perspective of a widget creator, advanced widget creator. This post will be updated with all the links I find online and in the end I will write my own understanding.
Forget the links.
I am going to write what I think one should should learn handlers.
First of all.
Event: It is something that happens. In everyday words lets think about it as a being hungry. yes I feel hungry in the after noon thats an event. Well feeling hungry is physical event rather than mental because your stomach starts aching and all. and lets take another example, of feeling sad this is more on a mental feeling.
We can use the same analogy in Gwt events.
There are two kinds of events:
1. Dom events, which which actually happen like mouse move, mouse click, key up, etc..
2. Logical events, they are perceived events like close the object, before selecting some elements.

Now the key part how are events handled. every widget/object is responsible for responding and handling its own events.
As I perceived earlier their is NO super god kind of object which handles the events of all widgets.

How do you know what to do when you are hungry? Forget the biological instinct for now and lets assume that you are your mother taught you should eat when you are hungry.
you take this lesson and store it in your brain. and when ever you are hungry you execute the lesson. Gwt calls these lessons/instructions as handlers.

Same thing with widgets, every widget has a brain (No AI here in this context brain is a container for instructions on what to do when something happens.) This brain is called HandlerManager.

So HandlerManager is the brain. handlers are the instructions for responding to events.

So how do the events call the handlers when they are fired?
Who is doing the thinking here?
When we are programming we know what to do. suppose when something is closed. we will call some method called close(). We should call the close handlers for that widget/object there.
There is a method called called fire(event) on handler manager. We assume that the handlers are already added to the HandlerManager. On HandlerManager we called hey fire this event and we send in the information identifying the event which is nothing but the event's key.
Remember handler is an interface so how do we know which method to call?
in the fire method of the event we specify handler.onhungry(hungerevent)

Lets start this

Fortunately or unfortunately I have started out as a gwt framework developer and not like a application developers using gwt. I have just started learning Gwt at my new job. Being fresh out of college its a big adventure for me. Inspiration for this blog came from the need that I wanted to collect and store cool resources, which helped me learn the concepts and resources which will be helpful in the future. I will also try to post my own understanding of the topics just for my clarity. As they have you learn 100% of what you teach. So I will try to teach to my blog through my writing. Any one out there, wish me luck in this adventure.

See ya,