PDA

View Full Version : Overflow ToolBar menu show Tooltip Text instead Text



terciofilho
23 Jul 2009, 9:19 AM
In the ToolBar, when it overflows it shows a Menu with all itens that didn't fit the visible area.

But if the button doesn't have a Text property set or it is zero in length it will show a menu only with the image, no text.

I think that it should verify if the text is null or zero in lenght, and if true, use the Tooltip text instead.

Example screenshots attached. The example is a PagingToolbar. In one I show the menu without text, and in the other the ToolTip that is shown when the mouse is over a button.

In my case I overrided the addComponentToMenu method from ToolBarLayout to work this way:



@Override
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.getText(), sb.getIcon());
// ##########################################
if (sb.getText() == null || sb.getText().length() == 0)
{
if (sb.getToolTip() != null && sb.getToolTip().getToolTipConfig() != null)
{
item.setText(sb.getToolTip().getToolTipConfig().getText());
}
}
// ##########################################
item.setEnabled(c.isEnabled());
item.setItemId(c.getItemId());
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.getText(), b.getIcon());
// ##########################################
if (b.getText() == null || b.getText().length() == 0)
{
if (b.getToolTip() != null && b.getToolTip().getToolTipConfig() != null)
{
item.setText(b.getToolTip().getToolTipConfig().getText());
}
}
// ##########################################
item.setItemId(c.getItemId());
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.getHeading();
if (heading != null && heading.length() > 0 && !heading.equals(" "))
{
menu.add(new HeaderMenuItem(g.getHeading()));
}
for (Component c2 : g.getItems())
{
this.addComponentToMenu(menu, c2);
}
menu.add(new SeparatorMenuItem());
}

if (menu.getItemCount() > 0)
{
if (menu.getItem(0) instanceof SeparatorMenuItem)
{
menu.remove(menu.getItem(0));
}
if (menu.getItemCount() > 0)
{
if (menu.getItem(menu.getItemCount() - 1) instanceof SeparatorMenuItem)
{
menu.remove(menu.getItem(menu.getItemCount() - 1));
}
}
}
}

sven
23 Jul 2009, 9:20 AM
This is not a bug. Moving this to the correct forum.

terciofilho
7 Aug 2009, 11:22 AM
Is that viable?