can't easily add an extra icon to a tab *and* get a click event for it
Brought to you by:
smartgwtdev
Originally created by: antonucc...@gmail.com
Tab.setIcon() and Tab.setCanClose() are mutually esclusive.
As already argued in http://forums.smartclient.com/showthread.php?t=22713, if we want to add an icon on tab and have control on his icon click(e.g. to refresh data) and the tab is closeable, only the close icon is shown.
The solution posted in http://forums.smartclient.com/showpost.php?p=13289 not work!
This is what the showcase does in showSample() method:
tab.setTitle("<span>" + iconHTML + " " + tacTitle + "</span>");
this shows only the icon, but not allows to have control over the click
(-SmartGwt 3.0)
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: smartgwt...@gmail.com
For now, if you really need this you can add a click handler to the iconHTML (or add it programmatically via the low-level GWT Element API).
Summary: can't easily add an extra icon to a tab and get a click event for it
Labels: -Type-Defect -Priority-Medium Type-Enhancement Priority-Low
Status: Accepted
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: antonucc...@gmail.com
Trying to understand, I fixed so (using the eventproxy, because the GWT Element has no methods to add an handler, only the gwt.Widget has addAttachHandler):
350: protected void showSample(TreeNode node) {
351: boolean isExplorerTreeNode = node instanceof ExplorerTreeNode;
352: if (node instanceof CommandTreeNode) {
....
.... unchanged code ....
....
374: String icon = explorerTreeNode.getIcon();
375: if (icon == null) {
376: icon = "silk/plugin.png";
377: }
//create a foo Img to have an eventproxy attached
378: Img img0 = new Img(icon, 16, 16);
379: img0.setVisible(false);
380: img0.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
381: @Override
382: public void onClick(ClickEvent event) {
383: SC.say("it work");
384: }
385: });
//temporary attach the image to mainTabSet to have the DOM element rendered
386: mainTabSet.addChild(img0);
//retrieve the img0's eventproxy and attach it to the <img .. > tag
387: com.google.gwt.dom.client.Element img0El = img0.getDOM();
388: String eventProxy = img0El.getAttribute("eventproxy");
389: String imgHTML = img0El.getInnerHTML();
390: imgHTML = imgHTML.replaceAll(">", "eventProxy=\"" +eventProxy+ "\">" );
//finally set the title
391: tab.setTitle("<span>" + imgHTML + " " + sampleName + "</span>");
392: tab.setPane(panel);
393: tab.setCanClose(true);
//remove the foo img as it isn't necessary (the eventproxy has created) (it is dangerous: the garbage collector could reuse eventproxy for other handler)
394: mainTabSet.removeChild(img0);
395:
396: mainTabSet.addTab(tab);
397: mainTabSet.selectTab(tab);
398: } else {
399: mainTabSet.selectTab(tab);
400: }
401: }
402: }
403: }