From: Marc Englund Date: Thu, 1 Nov 2007 14:58:01 +0000 (+0000) Subject: Fixes #1055 (clean tab content immediately when changing) and #1066 (re-render failed... X-Git-Tag: 6.7.0.beta1~5721 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6b273b035fb7c68b3977df29302c10d32f7ca62f;p=vaadin-framework.git Fixes #1055 (clean tab content immediately when changing) and #1066 (re-render failed if caption == null) svn changeset:2657/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheet.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheet.java index f51c897883..050a34f80f 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheet.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheet.java @@ -33,21 +33,25 @@ public class ITabsheet extends FlowPanel implements Paintable, int activeTabIndex = 0; - private TabBar tb; + private final TabBar tb; - private ITabsheetPanel tp; + private final ITabsheetPanel tp; - private Element deco; + private final Element deco; - private TabListener tl = new TabListener() { + private final TabListener tl = new TabListener() { public void onTabSelected(SourcesTabEvents sender, final int tabIndex) { - if (client != null && activeTabIndex != tabIndex) { + if (ITabsheet.this.client != null + && ITabsheet.this.activeTabIndex != tabIndex) { addStyleDependentName("loading"); + ITabsheet.this.tp.clear(); DeferredCommand.addCommand(new Command() { public void execute() { - ITabsheet.this.client.updateVariable(id, "selected", "" - + tabKeys.get(tabIndex), true); + ITabsheet.this.client.updateVariable(ITabsheet.this.id, + "selected", "" + + ITabsheet.this.tabKeys.get(tabIndex), + true); } }); } @@ -64,30 +68,31 @@ public class ITabsheet extends FlowPanel implements Paintable, public ITabsheet() { setStyleName(CLASSNAME); - tb = new TabBar(); - tp = new ITabsheetPanel(); - deco = DOM.createDiv(); + this.tb = new TabBar(); + this.tp = new ITabsheetPanel(); + this.deco = DOM.createDiv(); - tp.setStyleName(CLASSNAME + "-content"); + this.tp.setStyleName(CLASSNAME + "-content"); addStyleDependentName("loading"); // Indicate initial progress - tb.setStyleName(CLASSNAME + "-tabs"); - DOM.setElementProperty(deco, "className", CLASSNAME + "-deco"); + this.tb.setStyleName(CLASSNAME + "-tabs"); + DOM.setElementProperty(this.deco, "className", CLASSNAME + "-deco"); - add(tb); - add(tp); - DOM.appendChild(getElement(), deco); + add(this.tb); + add(this.tp); + DOM.appendChild(getElement(), this.deco); - tb.addTabListener(tl); + this.tb.addTabListener(this.tl); clearTabs(); } public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { this.client = client; - id = uidl.getId(); + this.id = uidl.getId(); - if (client.updateComponent(this, uidl, false)) + if (client.updateComponent(this, uidl, false)) { return; + } // Add proper stylenames for all elements if (uidl.hasAttribute("style")) { @@ -95,11 +100,11 @@ public class ITabsheet extends FlowPanel implements Paintable, String decoBaseClass = CLASSNAME + "-deco"; String decoClass = decoBaseClass; for (int i = 0; i < styles.length; i++) { - tb.addStyleDependentName(styles[i]); - tp.addStyleDependentName(styles[i]); + this.tb.addStyleDependentName(styles[i]); + this.tp.addStyleDependentName(styles[i]); decoClass += " " + decoBaseClass + "-" + styles[i]; } - DOM.setElementProperty(deco, "className", decoClass); + DOM.setElementProperty(this.deco, "className", decoClass); } // Adjust width and height @@ -114,34 +119,36 @@ public class ITabsheet extends FlowPanel implements Paintable, setHeight(h); } else { this.height = null; - tp.setHeight("auto"); + this.tp.setHeight("auto"); // We don't need overflow:auto when tabsheet height is not set // TODO reconsider, we might sometimes have wide, non-breaking // content - DOM.setStyleAttribute(tp.getElement(), "overflow", "hidden"); + DOM.setStyleAttribute(this.tp.getElement(), "overflow", "hidden"); } // Render content UIDL tabs = uidl.getChildUIDL(0); - boolean keepCurrentTabs = tabKeys.size() == tabs.getNumberOfChildren(); - for (int i = 0; keepCurrentTabs && i < tabKeys.size(); i++) - keepCurrentTabs = tabKeys.get(i).equals( + boolean keepCurrentTabs = this.tabKeys.size() == tabs + .getNumberOfChildren(); + for (int i = 0; keepCurrentTabs && i < this.tabKeys.size(); i++) { + keepCurrentTabs = this.tabKeys.get(i).equals( tabs.getChildUIDL(i).getStringAttribute("key")) - && captions.get(i).equals( + && this.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; + this.activeTabIndex = index; renderContent(tab.getChildUIDL(0)); } index++; } } else { - tabKeys.clear(); - captions.clear(); + this.tabKeys.clear(); + this.captions.clear(); clearTabs(); int index = 0; @@ -149,18 +156,22 @@ public class ITabsheet extends FlowPanel implements Paintable, UIDL tab = (UIDL) it.next(); String key = tab.getStringAttribute("key"); String caption = tab.getStringAttribute("caption"); + if (caption == null) { + caption = ""; + } - captions.add(caption); - tabKeys.add(key); + this.captions.add(caption); + this.tabKeys.add(key); // Add new tab (additional SPAN-element for loading indication) - tb.insertTab(""+caption+"", true, tb.getTabCount()); - + this.tb.insertTab("" + caption + "", true, this.tb + .getTabCount()); + // Add placeholder content - tp.add(new ILabel("")); + this.tp.add(new ILabel("")); if (tab.getBooleanAttribute("selected")) { - activeTabIndex = index; + this.activeTabIndex = index; renderContent(tab.getChildUIDL(0)); } index++; @@ -168,7 +179,7 @@ public class ITabsheet extends FlowPanel implements Paintable, } // Open selected tab - tb.selectTab(activeTabIndex); + this.tb.selectTab(this.activeTabIndex); // tp.showWidget(activeTabIndex); } @@ -177,24 +188,27 @@ public class ITabsheet extends FlowPanel implements Paintable, DeferredCommand.addCommand(new Command() { public void execute() { // Loading done, start drawing - Widget content = client.getWidget(contentUIDL); - tp.remove(activeTabIndex); - tp.insert(content, activeTabIndex); - tp.showWidget(activeTabIndex); - ((Paintable) content).updateFromUIDL(contentUIDL, client); + Widget content = ITabsheet.this.client.getWidget(contentUIDL); + ITabsheet.this.tp.remove(ITabsheet.this.activeTabIndex); + ITabsheet.this.tp + .insert(content, ITabsheet.this.activeTabIndex); + ITabsheet.this.tp.showWidget(ITabsheet.this.activeTabIndex); + ((Paintable) content).updateFromUIDL(contentUIDL, + ITabsheet.this.client); removeStyleDependentName("loading"); } }); } private void clearTabs() { - int i = tb.getTabCount(); - while (i > 0) - tb.removeTab(--i); - tp.clear(); + int i = this.tb.getTabCount(); + while (i > 0) { + this.tb.removeTab(--i); + } + this.tp.clear(); // Get rid of unnecessary 100% cell heights in TabBar (really ugly hack) - Element tr = DOM.getChild(DOM.getChild(tb.getElement(), 0), 0); + Element tr = DOM.getChild(DOM.getChild(this.tb.getElement(), 0), 0); Element rest = DOM.getChild( DOM.getChild(tr, DOM.getChildCount(tr) - 1), 0); DOM.removeElementAttribute(rest, "style"); @@ -206,18 +220,18 @@ public class ITabsheet extends FlowPanel implements Paintable, } public void iLayout() { - if (height != null) { + if (this.height != null) { // Make content zero height - tp.setHeight("0"); - DOM.setStyleAttribute(tp.getElement(), "overflow", "hidden"); + this.tp.setHeight("0"); + DOM.setStyleAttribute(this.tp.getElement(), "overflow", "hidden"); // First, calculate needed pixel height - super.setHeight(height); + super.setHeight(this.height); int neededHeight = getOffsetHeight(); super.setHeight(""); // Then calculate the size the content area needs to be int pixelHeight = getOffsetHeight(); - tp.setHeight(neededHeight - pixelHeight + "px"); - DOM.setStyleAttribute(tp.getElement(), "overflow", ""); + this.tp.setHeight(neededHeight - pixelHeight + "px"); + DOM.setStyleAttribute(this.tp.getElement(), "overflow", ""); } Util.runAncestorsLayout(this); }