Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Tab.setIcon not working

    I am working on upgrading an existing product from using SmartGWT 5.1 to use SmartGWT 12.0.


    There are screens in our product that use TabSets. If there is a validation failure when data is saved, we set an error icon
    on the tab(s) that have invalid data provided. This is done by calling the Tab.setIcon API.

    I found that this call is not working in SmartGWT 12.0.


    Version information:
    SmartClient Version: v12.0p_2019-09-11/PowerEdition Deployment (built 2019-09-11)

    I put together a sample based on a sample from the showcase.
    In this sample (below), when the tab text is modified, it should display a + icon on the tab.

    If I have access to the TabSet directly, I can call tabSet.setTabIcon and pass in the Tab object. This works, and the icon is properly displayed.
    However, if I call tab.setIcon, it does not work. I found that in the decompiled SmartGWT code, tab.setIcon will call tabSet.setTabIcon(getID(), icon);
    Therefore, I also tried calling tabSet.setTabIcon(tab.getID(), icon) and, as I expected, it does not work either.



    Code:
    package com.smartgwt.sample.showcase.client.componentXML;
    
    /* 
     * Smart GWT (GWT for SmartClient) 
     * Copyright 2008 and beyond, Isomorphic Software, Inc. 
     * 
     * Smart GWT is free software; you can redistribute it and/or modify it 
     * under the terms of the GNU Lesser General Public License version 3 
     * as published by the Free Software Foundation.  Smart GWT is also 
     * available under typical commercial license terms - see 
     * http://smartclient.com/license 
     * 
     * This software is distributed in the hope that it will be useful, 
     * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
     * Lesser General Public License for more details. 
     */  
    
    /* 
     * Smart GWT (GWT for SmartClient) 
     * Copyright 2008 and beyond, Isomorphic Software, Inc. 
     * 
     * Smart GWT is free software; you can redistribute it and/or modify it 
     * under the terms of the GNU Lesser General Public License version 3 
     * is published by the Free Software Foundation.  Smart GWT is also 
     * available under typical commercial license terms - see 
     * http://smartclient.com/license 
     * 
     * This software is distributed in the hope that it will be useful, 
     * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
     * Lesser General Public License for more details. 
     */  
    
    import com.smartgwt.client.types.Side;  
    import com.smartgwt.client.types.TabTitleEditEvent;  
    import com.smartgwt.client.util.SC;  
    import com.smartgwt.client.widgets.Canvas;  
    import com.smartgwt.client.widgets.Img;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.tab.Tab;  
    import com.smartgwt.client.widgets.tab.TabSet;  
    import com.smartgwt.client.widgets.tab.events.TabTitleChangedEvent;  
    import com.smartgwt.client.widgets.tab.events.TabTitleChangedHandler;
    import com.smartgwt.sample.showcase.client.PanelFactory;
    import com.smartgwt.sample.showcase.client.ShowcasePanel;
    import com.google.gwt.core.client.EntryPoint;  
    
    public class TabsEditableTitlesSample extends ShowcasePanel {
    
        private static final String DESCRIPTION =
                    "Tabs Editable Titles Sample";
    
         public static class Factory implements PanelFactory {
    
                private String id;
    
                public ShowcasePanel create() {
                    TabsEditableTitlesSample panel = new TabsEditableTitlesSample();
                    id = panel.getID();
                    return panel;
                }
    
                public String getID() {
                    return id;
                }
    
                public String getDescription() {
                    return DESCRIPTION;
                }
            }
    
        public void onModuleLoad() {  
    
    
        }
    
        @Override
        public Canvas getViewPanel() {
        final TabSet tabSet = new TabSet();  
            tabSet.setTabBarPosition(Side.TOP);  
            tabSet.setTabBarAlign(Side.LEFT);  
            tabSet.setWidth(500);  
            tabSet.setHeight(200);  
    
            tabSet.setCanEditTabTitles(true);  
            tabSet.setTitleEditEvent(TabTitleEditEvent.DOUBLECLICK);  
            tabSet.setTitleEditorTopOffset(2);  
    
    
            Tab tab1 = new Tab("Blue");  
            //tab1.setIcon("pieces/16/pawn_blue.png", 16);  
    
            tab1.setCanClose(true);  
            Img img1 = new Img("pieces/48/pawn_blue.png", 48, 48);  
            tab1.setPane(img1);  
    
            Tab tab2 = new Tab("Green");  
            //tab2.setIcon("pieces/16/pawn_green.png", 16);  
            Img img2 = new Img("pieces/48/pawn_green.png", 48, 48);  
            tab2.setPane(img2);  
    
            final Tab validatedTab = new Tab("123-Yellow");  
            //validatedTab.setIcon("pieces/16/pawn_yellow.png", 16);  
            final Img validatedTabImg = new Img("pieces/48/pawn_yellow.png", 48, 48);  
            validatedTab.setPane(validatedTabImg);  
    
            final Tab uneditableTab = new Tab("Can't Change Me");  
            //uneditableTab.setIcon("pieces/16/pawn_red.png", 16);  
            uneditableTab.setCanEditTitle(false);  
            Img uneditableTabImg = new Img("pieces/48/pawn_red.png", 48, 48);  
            uneditableTab.setPane(uneditableTabImg);  
    
            tabSet.addTab(tab1);  
            tabSet.addTab(tab2);  
            tabSet.addTab(validatedTab);  
            tabSet.addTab(uneditableTab);  
    
            tabSet.addTabTitleChangedHandler(new TabTitleChangedHandler() {  
                @Override  
                public void onTabTitleChanged(TabTitleChangedEvent event) {  
                    Tab tab = event.getTab();  
                    if (tab.equals(validatedTab) && (event.getNewTitle() == null || !event.getNewTitle().substring(0, 4).equals("123-"))) {  
                        SC.warn("Tab title must start with the prefix \"123-\"");  
                        event.cancel();  
                    }  
    
                   tab.setIcon("icons/16/icon_add.png");                     // -- DOES NOT WORK
               // tabSet.setTabIcon(tab, "icons/16/icon_add.png");         // -- WORKS
                   // tabSet.setTabIcon(tab.getID(), "icons/16/icon_add.png");    // -- DOES NOT WORK
                }  
            });  
    
            final VLayout layout = new VLayout();
            layout.setWidth("100%");
            layout.setHeight("90%");
            layout.setMembersMargin(10);
            layout.setMembers(tabSet);
    
            return layout;
        }  
    
    }

    #2
    Per docs on setTabs(), having called setTabs(), any further modification of the tabs must be done via the TabSet - setTabIcon() is explicitly called out as an example of this. The "tab" is just a configuration object, similar to a Record, it is not a widget. It doesn't have an ID unless you give it one, which is why your second setTabIcon() call doesn't work. You can address a Tab by the Tab object, by index, or by an ID if you give it one.

    A call to tab.setIcon() after the TabSet has been drawn would not be expected to work in any version of SmartGWT. Best guess here is that you reordered code and/or operations as part of the upgrade process, such that a setIcon() call that previously before draw is now performed after draw. Regardless of the cause, setTabIcon() is the proper approach.

    Comment


      #3
      Hmmm there was absolutely no reordering of code. It was a straight replace of the smartgwt libraries and recompile. I will have to rewrite code to do the upgrade, thanks for the clarification.

      Comment

      Working...
      X