]> source.dussan.org Git - vaadin-framework.git/commitdiff
Corrections for tabsheet
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Wed, 13 Jun 2007 15:51:27 +0000 (15:51 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Wed, 13 Jun 2007 15:51:27 +0000 (15:51 +0000)
svn changeset:1703/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/TkTabsheet.java

index dfdf1c990aeb9779e9bcfa6afd6f59022ce13b5e..373f869cbbe38238dbd98e9cc528c40ef6dae47e 100644 (file)
 package com.itmill.toolkit.terminal.gwt.client.ui;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 
+import com.google.gwt.user.client.ui.DeckPanel;
 import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.SourcesTabEvents;
+import com.google.gwt.user.client.ui.TabBar;
+import com.google.gwt.user.client.ui.TabListener;
 import com.google.gwt.user.client.ui.TabPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.Client;
 import com.itmill.toolkit.terminal.gwt.client.Paintable;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;
 
-public class TkTabsheet extends TabPanel implements
-               Paintable {
+public class TkTabsheet extends TabPanel implements Paintable {
 
        String id;
 
        Client client;
 
+       ArrayList tabKeys = new ArrayList();
+
+       ArrayList captions = new ArrayList();
+
+       int activeTabIndex = 0;
+
+       TabListener tl = new TabListener() {
+
+               public void onTabSelected(SourcesTabEvents sender, int tabIndex) {
+                       TkTabsheet.this.client.updateVariable(id, "selected", tabIndex,
+                                       true);
+               }
+
+               public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex) {
+                       return true;
+               }
+
+       };
+
        public TkTabsheet() {
+               addTabListener(new TabListener() {
+
+                       public void onTabSelected(SourcesTabEvents sender, int tabIndex) {
+                               if (client != null && activeTabIndex != tabIndex)
+                                       TkTabsheet.this.client.updateVariable(id, "selected", ""
+                                                       + tabKeys.get(tabIndex), true);
+                       }
+
+                       public boolean onBeforeTabSelected(SourcesTabEvents sender,
+                                       int tabIndex) {
+                               return true;
+                       }
+
+               });
+
        }
 
        public void updateFromUIDL(UIDL uidl, Client client) {
                this.client = client;
                id = uidl.getId();
-               
+
                UIDL tabs = uidl.getChildUIDL(0);
-               for(Iterator it = tabs.getChildIterator(); it.hasNext();) {
-                       UIDL tab = (UIDL) it.next();
-                       if(tab.getBooleanAttribute("selected")) {
-                               Widget content = client.createWidgetFromUIDL(tab.getChildUIDL(0));
-                               this.add(content, tab.getStringAttribute("caption"));
-                               this.selectTab(this.getWidgetIndex(content));
-                       } else {
-                               this.add(new Label(), tab.getStringAttribute("caption"));
+               boolean keepCurrentTabs = tabKeys.size() == tabs.getNumberOfChildren();
+               for (int i = 0; keepCurrentTabs && i < tabKeys.size(); i++)
+                       keepCurrentTabs = tabKeys.get(i).equals(
+                                       tabs.getChildUIDL(i).getStringAttribute("key"))
+                                       && captions.get(i).equals(
+                                                       tabs.getChildUIDL(i).getStringAttribute("caption"));
+               if (keepCurrentTabs) {
+                       int index = 0;
+                       for (Iterator it = tabs.getChildIterator(); it.hasNext();) {
+                               UIDL tab = (UIDL) it.next();
+                               if (tab.getBooleanAttribute("selected")) {
+                                       activeTabIndex = index;
+                                       Widget content = client.createWidgetFromUIDL(tab
+                                                       .getChildUIDL(0));
+                                       getTabBar().selectTab(index);
+                                       DeckPanel dp = getDeckPanel();
+                                       dp.remove(index);
+                                       dp.insert(content, index);
+                                       dp.showWidget(index);
+                               }
+                               index++;
+                       }
+               } else {
+                       tabKeys.clear();
+                       captions.clear();
+                       clear();
+                       int index = 0;
+                       for (Iterator it = tabs.getChildIterator(); it.hasNext();) {
+                               UIDL tab = (UIDL) it.next();
+                               String key = tab.getStringAttribute("key");
+                               String caption = tab.getStringAttribute("caption");
+                               captions.add(caption);
+                               tabKeys.add(key);
+                               if (tab.getBooleanAttribute("selected")) {
+                                       activeTabIndex = index;
+                                       Widget content = client.createWidgetFromUIDL(tab
+                                                       .getChildUIDL(0));
+                                       this.add(content, caption);
+                                       this.selectTab(this.getWidgetIndex(content));
+                               } else {
+                                       this.add(new Label(), caption);
+                               }
+                               index++;
                        }
                }
-               
-       }
 
+       }
 }