nihad640 / smartgwt

Automatically exported from code.google.com/p/smartgwt
0 stars 0 forks source link

can't easily add an extra icon to a tab *and* get a click event for it #684

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 + "&nbsp;" + tacTitle + "</span>");
this shows only the icon, but not allows to have control over the click

(-SmartGwt 3.0)

Original issue reported on code.google.com by antonucc...@gmail.com on 13 Sep 2012 at 8:57

Attachments:

GoogleCodeExporter commented 9 years ago
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).

Original comment by smartgwt...@gmail.com on 13 Sep 2012 at 10:35

GoogleCodeExporter commented 9 years ago
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:    }

Original comment by antonucc...@gmail.com on 16 Sep 2012 at 9:35