We help IT Professionals succeed at work.
Get Started

Best way to implement listener on multiple Button

zolf
zolf asked
on
139 Views
Last Modified: 2015-03-09
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

Comment
Watch Question
Sr. Software engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE