From b2f4bb7a485161b187419cd3f18d7e038aeed20e Mon Sep 17 00:00:00 2001 From: Joonas Lehtinen Date: Wed, 13 Jun 2007 15:51:27 +0000 Subject: [PATCH] Corrections for tabsheet svn changeset:1703/svn branch:trunk --- .../terminal/gwt/client/ui/TkTabsheet.java | 99 ++++++++++++++++--- 1 file changed, 86 insertions(+), 13 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkTabsheet.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkTabsheet.java index dfdf1c990a..373f869cbb 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkTabsheet.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkTabsheet.java @@ -1,40 +1,113 @@ 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++; } } - - } + } } -- 2.39.5