我有一个带有4个按钮的ribbonBar。现在,在点击的每个按钮上,我想执行一些操作。但我遇到的问题是如何知道点击了哪个按钮。有人可以指导我。下面是我的代码和截图。顺便说一句,我使用的是Button而不是如showcase中所示的IconButton。如果我使用这个按钮就可以了吗?
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)
{
SC.say(event.getSource().toString());
}
});
return cssButton;
}
答案 0 :(得分:1)
未经测试,但我认为这样的事情就是你想要的:
public class DBilling implements EntryPoint
{
private RibbonBar ribbonBar;
@Override
public void onModuleLoad()
{
VLayout vLayout = new VLayout();
vLayout.setWidth100();
this.ribbonBar = new RibbonBar();
this.ribbonBar.setLeft(0);
this.ribbonBar.setTop(0);
this.ribbonBar.setWidth100();
this.ribbonBar.setMembersMargin(2);
this.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));
this.ribbonBar.addMember(orderGroup);
this.ribbonBar.addMember(reportGroup);
this.ribbonBar.addMember(productGroup);
this.ribbonBar.addMember(systemGroup);
vLayout.addChild(this.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)
{
RibbonBar a;
for(Canvas b : a.getMembers()){
RibbonGroup c=(RibbonGroup)b;
for(Canvas d : c.getControls()){
Button e = (Button)d;
if(e.equals(event.getSource()))
SC.say(e.getTitle());
}
}
SC.say(event.getSource().toString());
}
});
return cssButton;
}
}
或者,如果您始终知道Button
仅将event.getSource()
投射到Button
,那么您可以获得((Button)event.getSource()).getTitle()