this.spacing = spacing;
}
protected void addComponentToMenu(Menu menu, Component c) {
if (c instanceof SeparatorToolItem) {
menu.add(new SeparatorMenuItem());
} else if (c instanceof SplitButton) {
final SplitButton sb = (SplitButton) c;
MenuItem item = new MenuItem(sb.getHtml(), sb.getIcon());
item.setEnabled(c.isEnabled());
item.setItemId(c.getItemId());
if (sb.getData("gxt-menutext") != null) {
item.setHtml(sb.getData("gxt-menutext").toString());
}
if (sb.getMenu() != null) {
item.setSubMenu(sb.getMenu());
}
item.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
ButtonEvent e = new ButtonEvent(sb);
e.setEvent(ce.getEvent());
sb.fireEvent(Events.Select, e);
}
});
menu.add(item);
} else if (c instanceof Button) {
final Button b = (Button) c;
MenuItem item = new MenuItem(b.getHtml(), b.getIcon());
item.setItemId(c.getItemId());
if (b.getData("gxt-menutext") != null) {
item.setHtml(b.getData("gxt-menutext").toString());
}
if (b.getMenu() != null) {
item.setHideOnClick(false);
item.setSubMenu(b.getMenu());
}
item.setEnabled(c.isEnabled());
item.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
ButtonEvent e = new ButtonEvent(b);
e.setEvent(ce.getEvent());
b.fireEvent(Events.Select, e);
}
});
menu.add(item);
} else if (c instanceof ButtonGroup) {
ButtonGroup g = (ButtonGroup) c;
g.setItemId(c.getItemId());
menu.add(new SeparatorMenuItem());
String heading = g.getHeadingHtml();
if (heading != null && heading.length() > 0 && !heading.equals(" ")) {
menu.add(new HeaderMenuItem(g.getHeadingHtml()));
}
for (Component c2 : g.getItems()) {
addComponentToMenu(menu, c2);
}
menu.add(new SeparatorMenuItem());
}
if (menu.getItemCount() > 0) {
if (menu.getItem(0) instanceof SeparatorMenuItem) {
menu.remove(menu.getItem(0));