Announcement

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

    CloseTabIcon missing

    Hi Isomorphic,

    I'm using SmartGWT Pro 2.5 branch (10/21/2011 nightly build).

    The Tab does not have a closeTabIcon by using the tab.setCanClose(true) if it was not set on Tab's creation.

    Please see the code:

    Code:
    public class TabTest implements EntryPoint {
      public void onModuleLoad() {
    
    	TabSet tabset = new TabSet();
        	tabset.setTabBarPosition(Side.TOP);  
        	tabset.setWidth100();
        	tabset.setHeight100();
        	
            Tab tab1 = new Tab("Tab1");
            tab1.setCanClose(new Boolean(true));
            tabset.addTab(tab1);
            
            Tab tab2 = new Tab("Tab2");
            tabset.addTab(tab2);
        	
            Canvas canvas = new Canvas();
            canvas.setWidth100();
            canvas.setHeight100();
            canvas.addChild(tabset);
            canvas.draw();
            
            tabset.addTabSelectedHandler(new TabSelectedHandler() {
    	    public void onTabSelected(TabSelectedEvent event)
    	    {
    	        Tab tab = event.getTab();
    	        if (tab.getCanClose() == false)
    	            tab.setCanClose(new Boolean(true));
    	    }
    	});
      }
    }
    The first tab1 has the closeTabIcon and can be closed.
    The second tab2 does not have the closeTabIcon after using the tab2.setCanClose(true) on tab's selection.

    How can I add the closeTabIcon to the second tab? I need to add it per request, not during the initialization.

    Thank you.

    #2
    For now you can achieve this using JSNI - here's some modified code that demonstrates this:
    Code:
    public class TabTest implements EntryPoint {
        public void onModuleLoad() {
    
            final TabSet tabset = new TabSet();
                tabset.setTabBarPosition(Side.TOP);  
                tabset.setWidth100();
                tabset.setHeight100();
                
                Tab tab1 = new Tab("Tab1");
    //            tab1.setCanClose(new Boolean(true));
                
                tabset.addTab(tab1);
                Canvas pane1 = new Canvas();
                pane1.setBackgroundColor("red");
                tab1.setPane(pane1);
                
                Tab tab2 = new Tab("Tab2");
                tabset.addTab(tab2);
                Canvas pane2 = new Canvas();
                pane2.setBackgroundColor("blue");
                tab2.setPane(pane2);
                
                Canvas canvas = new Canvas();
                canvas.setWidth100();
                canvas.setHeight100();
                canvas.addChild(tabset);
                canvas.draw();
                
                setCanCloseTab(tab1.getJsObj(), tabset.getJsObj(), new Boolean(true));
                
                tabset.addTabSelectedHandler(new TabSelectedHandler() {
                    public void onTabSelected(TabSelectedEvent event)
                    {
                        Tab tab = event.getTab();
                        setCanCloseTab(tab.getJsObj(), tabset.getJsObj(), new Boolean(true));
                    }
                });
                tabset.addTabDeselectedHandler(new TabDeselectedHandler() {
                    
                    @Override
                    public void onTabDeselected(TabDeselectedEvent event) {
                        Tab tab = event.getTab();
                        setCanCloseTab(tab.getJsObj(), tabset.getJsObj(), new Boolean(false));
                    }
                });
                    
          }
          private native void setCanCloseTab (JavaScriptObject tab, JavaScriptObject tabset, Boolean canClose) /*-{
              tabset.setCanCloseTab(tab, canClose == null ? null : canClose.@java.lang.Boolean::booleanValue()());
          }-*/;
    }
    This is relying on an undocumented method on the tabSet in JavaScript (setCanCloseTab) - this is not exposed in 2.5 as it stands. We'll update this thread when the API [or an equivalent] is explicitly exposed and supported in SmartGWT. You'll also notice I modified the code to get rid of the 'setCanClose()' call on the tab at initialization and used the same JSNI method to set this property up after the tabset has been initialized - this is currently required but we will ensure this limitation goes away when we add proper support for setting canClose at runtime

    Comment


      #3
      Thank you!

      Comment

      Working...
      X