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?
 
zzynxSoftware 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
 
zolfAuthor Commented:
thanks
0
 
zzynxSoftware engineerCommented:
You're welcome.
Thanx 4 axxepting
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.