Lets say we are using a list of HyperLinks to create a Navigation Bar/
Menu.
each Link takes us to a new Place.
when we go to a new place,
the Link for this new place needs to be highlighted to signal it is
active

so basically

Link#1    Link#2    Link#3   Link#4  Link#5

they all have a default style.
when in a place, we "add style" to that link.

I came up with a code which you can see below.
I don't think this is the correct way of implementing this
functionality,
and I believe there is a clean and easier solution.

what do you think of the code below,
do you have any suggestion for improving the code,
or to implement this functionality much simpler ?

Thank You

- do we also need to check which link was previously selected
inorder to remove its style ? this requires us to keep a reference
to previously selected link ?

and at some point from some other class we invoke setActiveLink(name)

do you think I need to put them in a Map in the Widget that contains
the links,
inorder to be able to look it up and add style to it, to signal its
become active.

you can see the code below:

public class NavBarWidget extends Composite {

HyperLink link1;
HyperLink link2;
HyperLink link3;
...
HyperLink linkN;

Map<String, HyperLink> map = new HashMap<String, HyperLink>();

HyperLink currently_active_link;

//UiBinder extends ....
public NavBarWidget() {
initWidget....

map.put(link1_name, link1);
map.put(link2_name, link2);
map.put(link3_name, link3);
....
map.put(linkN_name, linkN);

}

void setActiveLink(String name){

currently_active_link.removeStyle(xxx);
HyperLink toBeHighlighted = map.get(name);
toBeHighlighted.addStyle(xxx);
currently_active_link = toBeHighlighted;
}


}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to