PDA

View Full Version : New to GXT - Two simple questions?



EvilTed
3 Jul 2008, 8:24 PM
How do I add my own buttons to a toolbar?
I just want a simple icon with a tooltip, but cannot see how to do this.

What is the recommended way to get click events from ToolBar and MenuBar items?

Thanks

ET

EvilTed
3 Jul 2008, 11:51 PM
OK, the menu click I solved.

myMenuItem.addListener(Events.Select, new Listener<MenuEvent>() {
public void handleEvent(MenuEvent me) {
// Further selection here
}
});

I take it this is the correct method?

Now, how do I add my own button to a ToolBar?

Thanks

ET

EvilTed
6 Jul 2008, 5:24 PM
Wow, 51 people viewed this and nobody knows how?

Come on people....

maku
6 Jul 2008, 11:15 PM
I would recommend to inspect the sample applications.

To style a toolbar button I would suggest to define an iconStyle (css).
The TextToolItem class has e.g. a constructor where you can specifiy the style.

HTH

Martin

EvilTed
7 Jul 2008, 12:30 PM
Thanks for the reply, but I did and neither the menu or the toolbar have events associated with them in the samples.

As far as the icon on the toolbar, I saw the CSS method and wondered if this was the only way to do it?
It seems rather clunky to have to use CSS and a ToolItem when if we had a ToolBarButton with a method such as setIcon(), it would be a lot easier, don't you agree?

Thanks

ET

EvilTed
7 Jul 2008, 1:09 PM
Actually, the correct way for menus (for anyone else that comes across this) is to add a Selection Listener to the individual menu items.

Here is a sample adding a "File" menu with "Print' and 'Exit:

ToolBar toolbar = new ToolBar();

// File Menu
Menu menuFile = new Menu();
TextToolItem ttiFile = new TextToolItem("File");
ttiFile.setMenu(menuFile);

// File - Print
MenuItem filePrintItem = new MenuItem();
filePrintItem.setText("Print");
filePrintItem.setId("file-print");
filePrintItem.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent me) {
System.out.println("File - Print clicked");
}
});
menuFile.add(filePrintItem);

// File - Exit
MenuItem fileExitItem = new MenuItem();
fileExitItem.setText("Exit");
fileExitItem.setId("file-exit");
fileExitItem.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent me) {
System.out.println("File - Exit clicked");
}
});
menuFile.add(fileExitItem);

// Add file menu to menubar
toolbar.add(ttiFile);

FWIW I got this from the Ext GWT 1.0 Online Help Center, not the samples.

zaccret
7 Jul 2008, 10:35 PM
As far as the icon on the toolbar, I saw the CSS method and wondered if this was the only way to do it?
It seems rather clunky to have to use CSS and a ToolItem when if we had a ToolBarButton with a method such as setIcon(), it would be a lot easier, don't you agree?

I think it is the only way to set the icon but I agree it would be nice to have a e.g. setIcon(Image) method

EvilTed
8 Jul 2008, 9:04 AM
Apart from code readability it allows us to use ImageBundles too - something I don't think we can do with CSS?

ET

zaccret
9 Jul 2008, 1:51 AM
I don't think we can do it with CSS. Good point about ImageBundle ;) I would also like to use ImageBundle for potential performance issues.