Best way to implement listener on multiple Button

Hello there,

I am implementing a web application using GWT and I have a situation where I have a RibbonBar with 4 buttons in it. I havea method which creates the button for each of the RibbonBar and now I want to implement the event handler for each of those buttons. I want to know how can i implement this event handler the efficient way. At present I have justa added the empty addClickHandler in the getButton method. Just to give you an idea.

cheers
Zolf

public class DBilling implements EntryPoint
{

	@Override
	public void onModuleLoad()
	{
		VLayout vLayout = new VLayout();
		vLayout.setWidth100();

		RibbonBar ribbonBar = new RibbonBar();
		ribbonBar.setLeft(0);
		ribbonBar.setTop(0);
		ribbonBar.setWidth100();

		ribbonBar.setMembersMargin(2);
		ribbonBar.setLayoutMargin(2);

		RibbonGroup orderGroup = new RibbonGroup();
		orderGroup.setTitle("New Order");
		orderGroup.setRowHeight(60);
		orderGroup.addControl(getButton("Order", "order", false));

		RibbonGroup reportGroup = new RibbonGroup();
		reportGroup.setTitle("Report");
		reportGroup.setRowHeight(60);
		reportGroup.addControl(getButton("Report", "report", false));

		RibbonGroup productGroup = new RibbonGroup();
		productGroup.setTitle("New Product");
		productGroup.setRowHeight(60);
		productGroup.addControl(getButton("Product", "cookies", false));

		RibbonGroup systemGroup = new RibbonGroup();
		systemGroup.setTitle("System");
		systemGroup.setRowHeight(60);
		systemGroup.addControl(getButton("System", "system", false));

		ribbonBar.addMember(orderGroup);
		ribbonBar.addMember(reportGroup);
		ribbonBar.addMember(productGroup);
		ribbonBar.addMember(systemGroup);

		vLayout.addChild(ribbonBar);
		vLayout.draw();

	}

	private Button getButton(String title, String iconName, boolean vertical)
	{
		final Button cssButton = new Button(title);  
        cssButton.setShowRollOver(true);  
        cssButton.setShowDisabled(true);  
        cssButton.setShowDown(true);  
        cssButton.setIcon(iconName + ".png"); 
        cssButton.setIconSize(32);
        cssButton.setWidth(120);
        cssButton.addClickHandler(new ClickHandler()
		{
			
			@Override
			public void onClick(ClickEvent event)
			{
				// TODO Auto-generated method stub
				
			}
		});
        return cssButton;
	}
}

Open in new window

zolfAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSr. Software engineerCommented:
You can make your DBilling class implement ClickHandler
Then in getButton() you can write
cssButton.addClickHandler(this);

Open in new window

Then in the onClick() method of your DBilling class, you can use the information that is in the ClickEvent to determine which button was clicked and then perform the required action.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zolfAuthor Commented:
thanks
0
zzynxSr. Software engineerCommented:
You're welcome.
Thanx 4 axxepting
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.