text-align: left /* Force default alignment */
}
-
.i-tabsheet-tabs {
empty-cells: hide;
border-collapse: collapse;
+ margin:0;
+ padding:0;
+ border:0;
height: 38px;
background: transparent url(tabsheet/img/tabs-bg.png) repeat-x bottom left;
width: 100%;
overflow:hidden;
}
+.i-tabsheet-tabs td {
+ margin:0;
+ padding:0;
+}
+
+.i-tabsheet-tabs .i-tabsheet-spacertd {
+ width: 100%;
+ height: 37px;
+ border: 1px solid #b6bbbc;
+}
+
.i-tabsheet-hidetabs .i-tabsheet-tabcontainer {
display: none;
}
white-space: nowrap;
}
-.i-tabsheet-tabs .gwt-TabBarFirst {
- display: none;
-}
-
-.i-tabsheet-tabs .gwt-TabBarRest {
- border: 1px solid #b6bbbc;
- background: #f8f9f9 url(tabsheet/img/tab-bg.png);
- height: 37px;
-}
-
-.i-tabsheet-tabs .gwt-TabBarItem {
+.i-tabsheet-tabs .i-tabsheet-tabitem {
border: 1px solid #b6bbbc;
border-right: none;
height: 20px;
cursor: pointer;
}
-.i-tabsheet-tabs .gwt-TabBarItem-selected {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected {
border: none;
background: transparent url(panel/img/top-left.png) no-repeat;
margin: 0;
color: #ee5311;
}
-.i-tabsheet-tabs .gwt-TabBarItem:hover {
+.i-tabsheet-tabs .i-tabsheet-tabitem:hover {
color: #4b5257;
}
-.i-tabsheet-tabs .gwt-TabBarItem-selected:hover {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected:hover {
color: #ee5311;
}
-.i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
background: transparent url(panel/img/top-right.png) repeat-x right top;
margin: 0 -1px 0 9px;
height: 18px;
/* Progress indication */
-.i-tabsheet-loading .i-tabsheet-tabs .gwt-TabBarItem-selected span{
+.i-tabsheet-loading .i-tabsheet-tabs .i-tabsheet-tabitem-selected span{
background: transparent url(common/img/ajax-loader.gif) no-repeat;
display: block;
margin-left: -10px;
height: 46px;
}
-* html .i-tabsheet-tabs .gwt-TabBarItem-selected {
+* html .i-tabsheet-tabs .i-tabsheet-tabitem-selected {
border: 1px solid #babfc0;
border-bottom: none;
background: #fff;
cursor: default;
color: #ee5311;
}
-*+html .i-tabsheet-tabs .gwt-TabBarItem-selected {
+*+html .i-tabsheet-tabs .i-tabsheet-tabitem-selected {
border: 1px solid #babfc0;
border-bottom: none;
background: #fff;
color: #ee5311;
}
-* html .i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+* html .i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
background: transparent;
padding: 0;
margin: 0;
}
-*+html .i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+*+html .i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
background: transparent;
padding: 0;
margin: 0;
text-align: left /* Force default alignment */
}
-
.i-tabsheet-tabs {
empty-cells: hide;
border-collapse: collapse;
+ margin:0;
+ padding:0;
+ border:0;
height: 38px;
background: transparent url(img/tabs-bg.png) repeat-x bottom left;
width: 100%;
overflow:hidden;
}
+.i-tabsheet-tabs td {
+ margin:0;
+ padding:0;
+}
+
+.i-tabsheet-tabs .i-tabsheet-spacertd {
+ width: 100%;
+ height: 37px;
+ border: 1px solid #b6bbbc;
+}
+
.i-tabsheet-hidetabs .i-tabsheet-tabcontainer {
display: none;
}
white-space: nowrap;
}
-.i-tabsheet-tabs .gwt-TabBarFirst {
- display: none;
-}
-
-.i-tabsheet-tabs .gwt-TabBarRest {
- border: 1px solid #b6bbbc;
- background: #f8f9f9 url(img/tab-bg.png);
- height: 37px;
-}
-
-.i-tabsheet-tabs .gwt-TabBarItem {
+.i-tabsheet-tabs .i-tabsheet-tabitem {
border: 1px solid #b6bbbc;
border-right: none;
height: 20px;
cursor: pointer;
}
-.i-tabsheet-tabs .gwt-TabBarItem-selected {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected {
border: none;
background: transparent url(../panel/img/top-left.png) no-repeat;
margin: 0;
color: #ee5311;
}
-.i-tabsheet-tabs .gwt-TabBarItem:hover {
+.i-tabsheet-tabs .i-tabsheet-tabitem:hover {
color: #4b5257;
}
-.i-tabsheet-tabs .gwt-TabBarItem-selected:hover {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected:hover {
color: #ee5311;
}
-.i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
background: transparent url(../panel/img/top-right.png) repeat-x right top;
margin: 0 -1px 0 9px;
height: 18px;
/* Progress indication */
-.i-tabsheet-loading .i-tabsheet-tabs .gwt-TabBarItem-selected span{
+.i-tabsheet-loading .i-tabsheet-tabs .i-tabsheet-tabitem-selected span{
background: transparent url(../common/img/ajax-loader.gif) no-repeat;
display: block;
margin-left: -10px;
height: 46px;
}
-* html .i-tabsheet-tabs .gwt-TabBarItem-selected {
+* html .i-tabsheet-tabs .i-tabsheet-tabitem-selected {
border: 1px solid #babfc0;
border-bottom: none;
background: #fff;
cursor: default;
color: #ee5311;
}
-*+html .i-tabsheet-tabs .gwt-TabBarItem-selected {
+*+html .i-tabsheet-tabs .i-tabsheet-tabitem-selected {
border: 1px solid #babfc0;
border-bottom: none;
background: #fff;
color: #ee5311;
}
-* html .i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+* html .i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
background: transparent;
padding: 0;
margin: 0;
}
-*+html .i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+*+html .i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
background: transparent;
padding: 0;
margin: 0;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.BrowserInfo;
import com.itmill.toolkit.terminal.gwt.client.Caption;
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
public IAccordion() {
super(CLASSNAME);
// IE6 needs this to calculate offsetHeight correctly
- if (Util.isIE6()) {
+ if (BrowserInfo.get().isIE6()) {
DOM.setStyleAttribute(getElement(), "zoom", "1");
}
}
}
protected void renderTab(UIDL tabUidl, int index, boolean selected) {
- // TODO check indexes, now new tabs get placed last (changing tab order
- // is not supported from server-side)
-
- StackItem item = new StackItem(tabUidl);
-
- if (stack.size() == 0) {
- item.addStyleDependentName("first");
+ StackItem item;
+ if (stack.size() <= index) {
+ item = new StackItem(tabUidl);
+ if (stack.size() == 0) {
+ item.addStyleDependentName("first");
+ }
+ stack.add(item);
+ add(item, getElement());
+ } else {
+ item = (StackItem) stack.get(index);
+ item.updateCaption(tabUidl);
}
- stack.add(item);
- add(item, getElement());
-
if (selected) {
item.open();
item.setContent(tabUidl.getChildUIDL(0));
} else if (tabUidl.getChildCount() > 0) {
- // updating a drawn child on hidden tab
- Paintable paintable = client.getPaintable(tabUidl.getChildUIDL(0));
- paintable.updateFromUIDL(tabUidl.getChildUIDL(0), client);
+ item.setContent(tabUidl.getChildUIDL(0));
}
}
private Caption caption;
private boolean open = false;
- private Element content;
- private Element captionNode;
+ private Element content = DOM.createDiv();
+ private Element captionNode = DOM.createDiv();
private Paintable paintable;
public StackItem(UIDL tabUidl) {
setElement(DOM.createDiv());
caption = new Caption(null, client);
caption.addClickListener(this);
- content = DOM.createDiv();
- captionNode = DOM.createDiv();
super.add(caption, captionNode);
DOM.appendChild(captionNode, caption.getElement());
DOM.appendChild(getElement(), captionNode);
DOM.setElementProperty(captionNode, "className", CLASSNAME
+ "-item-caption");
DOM.setStyleAttribute(content, "overflow", "auto");
- DOM.setStyleAttribute(content, "display", "none");
// Force 'hasLayout' in IE6 (prevents layout problems)
- if (Util.isIE6()) {
+ if (BrowserInfo.get().isIE6()) {
DOM.setStyleAttribute(content, "zoom", "1");
}
+ close();
- caption.updateCaption(tabUidl);
+ updateCaption(tabUidl);
}
public Element getContainerElement() {
public void open() {
open = true;
- DOM.setStyleAttribute(content, "display", "");
+ if (getPaintable() != null) {
+ remove(getPaintable());
+ }
+ DOM.setStyleAttribute(content, "visibility", "");
+ DOM.setStyleAttribute(content, "position", "");
addStyleDependentName("open");
if (getPaintable() != null) {
add(getPaintable(), content);
public void close() {
open = false;
- if (getPaintable() != null) {
- remove(getPaintable());
- }
- DOM.setStyleAttribute(content, "display", "none");
+ DOM.setStyleAttribute(content, "visibility", "hidden");
+ DOM.setStyleAttribute(content, "position", "absolute");
removeStyleDependentName("open");
}
public void setContent(UIDL contentUidl) {
final Paintable newPntbl = client.getPaintable(contentUidl);
- // due hack #1 in ITabsheetBase
- ((Widget) newPntbl).setVisible(true);
if (getPaintable() == null) {
add((Widget) newPntbl, content);
paintables.add(newPntbl);
public void onClick(Widget sender) {
onSelectTab(this);
}
+
+ public void updateCaption(UIDL uidl) {
+ caption.updateCaption(uidl);
+ }
}
protected void clearPaintables() {
return paintables.iterator();
}
+ public boolean hasChildComponent(Widget component) {
+ if (paintables.contains(component)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+ // TODO Auto-generated method stub
+ }
+
+ public void updateCaption(Paintable component, UIDL uidl) {
+ for (Iterator iterator = stack.iterator(); iterator.hasNext();) {
+ StackItem si = (StackItem) iterator.next();
+ if (si.getPaintable() == component) {
+ si.updateCaption(uidl);
+ return;
+ }
+ }
+ }
+
}
/** Update the layout from UIDL */
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
this.client = client;
- // Client manages general cases
- if (client.updateComponent(this, uidl, false)) {
+ // ApplicationConnection manages generic component features
+ if (client.updateComponent(this, uidl, true)) {
return;
}
- // Update PID
pid = uidl.getId();
if (!hasTemplate()) {
// Update HTML template only once
// Modify layout margins
handleMargins(uidl);
- // Ensure correct implementation
- if (client.updateComponent(this, uidl, false)) {
+ if (client.updateComponent(this, uidl, true)) {
return;
}
}\r
\r
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
- if (client.updateComponent(this, uidl, false)) {\r
+ if (client.updateComponent(this, uidl, true)) {\r
return;\r
}\r
\r
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
this.client = client;
- if (client.updateComponent(this, uidl, false)) {
+ if (client.updateComponent(this, uidl, true)) {
return;
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (client.updateComponent(this, uidl, false)) {
+ if (client.updateComponent(this, uidl, true)) {
return;
}
final MarginInfo margins = new MarginInfo(uidl
updateMarginAndSpacingSizesFromCSS(uidl);
// Update sizes, ...
- if (client.updateComponent(this, uidl, false)) {
+ if (client.updateComponent(this, uidl, true)) {
return;
}
package com.itmill.toolkit.terminal.gwt.client.ui;
+import java.util.HashMap;
import java.util.Iterator;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.ComplexPanel;
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.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Caption;
public class ITabsheet extends ITabsheetBase implements
ContainerResizedListener {
+ class TabBar extends ComplexPanel implements ClickListener {
+
+ private Element tr = DOM.createTR();
+
+ private Element spacerTd = DOM.createTD();
+
+ TabBar() {
+ Element el = DOM.createTable();
+ Element tbody = DOM.createTBody();
+ DOM.appendChild(el, tbody);
+ DOM.appendChild(tbody, tr);
+ setStyleName(spacerTd, CLASSNAME + "-spacertd");
+ DOM.appendChild(tr, spacerTd);
+ setElement(el);
+ }
+
+ protected Element getContainerElement() {
+ return tr;
+ }
+
+ private Widget oldSelected;
+
+ public int getTabCount() {
+ return getWidgetCount();
+ }
+
+ public void addTab(Caption c) {
+ Element td = DOM.createTD();
+ setStyleName(td, CLASSNAME + "-tabitemcell");
+ Element div = DOM.createTD();
+ setStyleName(div, CLASSNAME + "-tabitem");
+ DOM.appendChild(td, div);
+ DOM.insertBefore(tr, td, spacerTd);
+ c.addClickListener(this);
+ add(c, div);
+ }
+
+ public void onClick(Widget sender) {
+ int index = getWidgetIndex(sender);
+ onTabSelected(index);
+ }
+
+ public void selectTab(int index) {
+ Widget newSelected = getWidget(index);
+ Widget.setStyleName(DOM.getParent(newSelected.getElement()),
+ CLASSNAME + "-tabitem-selected", true);
+ if (oldSelected != null) {
+ Widget.setStyleName(DOM.getParent(oldSelected.getElement()),
+ CLASSNAME + "-tabitem-selected", false);
+ }
+ oldSelected = newSelected;
+ }
+
+ public void removeTab(int i) {
+ remove(i);
+ }
+
+ public boolean remove(Widget w) {
+ ((Caption) w).removeClickListener(this);
+ return super.remove(w);
+ }
+
+ public Caption getTab(int index) {
+ if (index >= getWidgetCount()) {
+ return null;
+ }
+ return (Caption) getWidget(index);
+ }
+
+ }
+
public static final String CLASSNAME = "i-tabsheet";
public static final String TABS_CLASSNAME = "i-tabsheet-tabcontainer";
private final ITabsheetPanel tp;
private final Element contentNode, deco;
+ private final HashMap captions = new HashMap();
+
private String height;
private String width;
*/
private Widget previousVisibleWidget;
- private final TabListener tl = new TabListener() {
-
- public void onTabSelected(SourcesTabEvents sender, final int tabIndex) {
- if (client != null && activeTabIndex != tabIndex) {
- addStyleDependentName("loading");
- // run updating variables in deferred command to bypass some
- // FF
- // optimization issues
- DeferredCommand.addCommand(new Command() {
- public void execute() {
- previousVisibleWidget = tp.getWidget(tp
- .getVisibleWidget());
- DOM.setStyleAttribute(previousVisibleWidget
- .getElement(), "visibility", "hidden");
- client.updateVariable(id, "selected", tabKeys.get(
- tabIndex).toString(), true);
- }
- });
- waitingForResponse = true;
- }
+ private void onTabSelected(final int tabIndex) {
+ if (disabled || waitingForResponse) {
+ return;
}
-
- public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex) {
- if (disabled || waitingForResponse) {
- return false;
- }
- final Object tabKey = tabKeys.get(tabIndex);
- if (disabledTabKeys.contains(tabKey)) {
- return false;
- }
-
- return true;
+ final Object tabKey = tabKeys.get(tabIndex);
+ if (disabledTabKeys.contains(tabKey)) {
+ return;
}
-
- };
+ if (client != null && activeTabIndex != tabIndex) {
+ addStyleDependentName("loading");
+ // run updating variables in deferred command to bypass some
+ // FF
+ // optimization issues
+ DeferredCommand.addCommand(new Command() {
+ public void execute() {
+ previousVisibleWidget = tp.getWidget(tp.getVisibleWidget());
+ DOM.setStyleAttribute(previousVisibleWidget.getElement(),
+ "visibility", "hidden");
+ client.updateVariable(id, "selected", tabKeys.get(tabIndex)
+ .toString(), true);
+ }
+ });
+ waitingForResponse = true;
+ }
+ }
public ITabsheet() {
super(CLASSNAME);
DOM.appendChild(tabs, scroller);
- tb.addTabListener(tl);
-
// TODO Use for Safari only. Fix annoying 1px first cell in TabBar.
- DOM.setStyleAttribute(DOM.getFirstChild(DOM.getFirstChild(DOM
- .getFirstChild(tb.getElement()))), "display", "none");
+ // DOM.setStyleAttribute(DOM.getFirstChild(DOM.getFirstChild(DOM
+ // .getFirstChild(tb.getElement()))), "display", "none");
}
}
protected void renderTab(final UIDL tabUidl, int index, boolean selected) {
- // TODO check indexes, now new tabs get placed last (changing tab order
- // is not supported from server-side)
- Caption c = new Caption(null, client);
+ Caption c = tb.getTab(index);
+ if (c == null) {
+ c = new Caption(null, client);
+ tb.addTab(c);
+ }
c.updateCaption(tabUidl);
- tb.addTab(c);
+ captions.put("" + index, c);
if (selected) {
renderContent(tabUidl.getChildUIDL(0));
tb.selectTab(index);
- } else if (tabUidl.getChildCount() > 0) {
- // updating a drawn child on hidden tab
- Paintable paintable = client.getPaintable(tabUidl.getChildUIDL(0));
- paintable.updateFromUIDL(tabUidl.getChildUIDL(0), client);
+ } else {
+ if (tabUidl.getChildCount() > 0) {
+ // updating a drawn child on hidden tab
+ Paintable paintable = client.getPaintable(tabUidl
+ .getChildUIDL(0));
+
+ if (tp.getWidgetIndex((Widget) paintable) < 0) {
+ tp.insert((Widget) paintable, index);
+ }
+ paintable.updateFromUIDL(tabUidl.getChildUIDL(0), client);
+ } else if (tp.getWidgetCount() <= index) {
+ tp.add(new Label(""));
+ }
}
- // Add place-holder content
- tp.add(new Label(""));
}
protected void selectTab(int index, final UIDL contentUidl) {
private void showAllTabs() {
scrollerIndex = 0;
+ Element tr = DOM.getFirstChild(DOM.getFirstChild(tb.getElement()));
for (int i = 0; i < tb.getTabCount(); i++) {
- DOM.setStyleAttribute(DOM.getChild(DOM.getFirstChild(DOM
- .getFirstChild(tb.getElement())), i + 1), "display", "");
+ DOM.setStyleAttribute(DOM.getChild(tr, i), "display", "");
}
}
}
tp.clear();
- // Get rid of unnecessary 100% cell heights in TabBar (really ugly hack)
- final Element tr = DOM.getChild(DOM.getChild(tb.getElement(), 0), 0);
- final Element rest = DOM.getChild(DOM.getChild(tr, DOM
- .getChildCount(tr) - 1), 0);
- DOM.removeElementAttribute(rest, "style");
-
}
protected Iterator getPaintableIterator() {
return tp.iterator();
}
+
+ public boolean hasChildComponent(Widget component) {
+ if (tp.getWidgetIndex(component) < 0) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+ int widgetIndex = tp.getWidgetIndex(oldComponent);
+ tp.remove(oldComponent);
+ tp.insert(newComponent, widgetIndex);
+ }
+
+ public void updateCaption(Paintable component, UIDL uidl) {
+ int i = tp.getWidgetIndex((Widget) component);
+ Caption c = (Caption) captions.get("" + i);
+ c.updateCaption(uidl);
+ }
}
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-abstract class ITabsheetBase extends ComplexPanel implements Paintable {
+abstract class ITabsheetBase extends ComplexPanel implements Container {
String id;
ApplicationConnection client;
protected final ArrayList tabKeys = new ArrayList();
- protected final ArrayList captions = new ArrayList();
protected int activeTabIndex = 0;
protected boolean disabled;
protected boolean readonly;
// Render content
final UIDL tabs = uidl.getChildUIDL(0);
- if (keepCurrentTabs(uidl)) {
- int index = 0;
- for (final Iterator it = tabs.getChildIterator(); it.hasNext();) {
- final UIDL tab = (UIDL) it.next();
- final boolean selected = tab.getBooleanAttribute("selected");
- if (selected) {
- selectTab(index, tab.getChildUIDL(0));
- } else if (tab.getChildCount() > 0) {
- // updating a drawn child on hidden tab
- Paintable paintable = client.getPaintable(tab
- .getChildUIDL(0));
- // TODO widget may flash on screen
- paintable.updateFromUIDL(tab.getChildUIDL(0), client);
- // Hack #1 in ITabsheetBase: due ITabsheets content has no
- // wrappers for each tab, we need to hide the actual widgets
- ((Widget) paintable).setVisible(false);
- }
- index++;
- }
- } else {
+ ArrayList oldPaintables = new ArrayList();
+ for (Iterator iterator = getPaintableIterator(); iterator.hasNext();) {
+ oldPaintables.add(iterator.next());
+ }
- ArrayList oldPaintables = new ArrayList();
- for (Iterator iterator = getPaintableIterator(); iterator.hasNext();) {
- oldPaintables.add(iterator.next());
- }
+ // Clear previous values
+ tabKeys.clear();
+ disabledTabKeys.clear();
- // Clear previous values
- tabKeys.clear();
- captions.clear();
- disabledTabKeys.clear();
-
- clearPaintables();
-
- int index = 0;
- for (final Iterator it = tabs.getChildIterator(); it.hasNext();) {
- final UIDL tab = (UIDL) it.next();
- final String key = tab.getStringAttribute("key");
- final boolean selected = tab.getBooleanAttribute("selected");
- String caption = tab.getStringAttribute("caption");
- if (caption == null) {
- caption = " ";
- }
+ int index = 0;
+ for (final Iterator it = tabs.getChildIterator(); it.hasNext();) {
+ final UIDL tab = (UIDL) it.next();
+ final String key = tab.getStringAttribute("key");
+ final boolean selected = tab.getBooleanAttribute("selected");
- if (tab.getBooleanAttribute("disabled")) {
- disabledTabKeys.add(key);
- }
+ if (tab.getBooleanAttribute("disabled")) {
+ disabledTabKeys.add(key);
+ }
- captions.add(caption);
- tabKeys.add(key);
+ tabKeys.add(key);
- if (selected) {
- activeTabIndex = index;
- }
- if (tab.getChildCount() > 0) {
- Paintable p = client.getPaintable(tab.getChildUIDL(0));
- oldPaintables.remove(p);
- }
- renderTab(tab, index, selected);
- index++;
+ if (selected) {
+ activeTabIndex = index;
+ }
+ if (tab.getChildCount() > 0) {
+ Paintable p = client.getPaintable(tab.getChildUIDL(0));
+ oldPaintables.remove(p);
}
+ renderTab(tab, index, selected);
+ index++;
+ }
- for (Iterator iterator = oldPaintables.iterator(); iterator
- .hasNext();) {
- Object oldPaintable = iterator.next();
- if (oldPaintable instanceof Paintable) {
- client.unregisterPaintable((Paintable) oldPaintable);
+ for (Iterator iterator = oldPaintables.iterator(); iterator.hasNext();) {
+ Object oldPaintable = iterator.next();
+ if (oldPaintable instanceof Paintable) {
+ Widget w = (Widget) oldPaintable;
+ if (w.isAttached()) {
+ w.removeFromParent();
}
+ client.unregisterPaintable((Paintable) oldPaintable);
}
}
*/
abstract protected void clearPaintables();
- protected boolean keepCurrentTabs(UIDL uidl) {
- final UIDL tabs = uidl.getChildUIDL(0);
- boolean retval = tabKeys.size() == tabs.getNumberOfChildren();
- for (int i = 0; retval && i < tabKeys.size(); i++) {
- String key = (String) tabKeys.get(i);
- UIDL tabUIDL = tabs.getChildUIDL(i);
- retval = key.equals(tabUIDL.getStringAttribute("key"))
- && captions.get(i).equals(
- tabUIDL.getStringAttribute("caption"))
- && (tabUIDL.hasAttribute("disabled") == disabledTabKeys
- .contains(key));
- }
- return retval;
- }
-
/**
* Implement in extending classes. This method should render needed elements
* and set the visibility of the tab according to the 'selected' parameter.
package com.itmill.toolkit.terminal.gwt.client.ui;\r
\r
import com.google.gwt.user.client.DOM;\r
+import com.google.gwt.user.client.Element;\r
import com.google.gwt.user.client.ui.ComplexPanel;\r
import com.google.gwt.user.client.ui.Widget;\r
\r
/**\r
* A panel that displays all of its child widgets in a 'deck', where only one\r
* can be visible at a time. It is used by\r
- * {@link com.itmill.toolkit.terminal.gwt.client.ui.ITabsheetPanel}.\r
+ * {@link com.itmill.toolkit.terminal.gwt.client.ui.ITabsheet}.\r
* \r
* This class has the same basic functionality as the GWT DeckPanel\r
* {@link com.google.gwt.user.client.ui.DeckPanel}, with the exception that it\r
public class ITabsheetPanel extends ComplexPanel {\r
\r
private Widget visibleWidget;\r
+ private boolean fullheight = false;\r
\r
/**\r
* Creates an empty tabsheet panel.\r
* the widget to be added\r
*/\r
public void add(Widget w) {\r
- super.add(w, getElement());\r
- initChildWidget(w);\r
+ Element el = createContainerElement();\r
+ DOM.appendChild(getElement(), el);\r
+ super.add(w, el);\r
+ }\r
+\r
+ private Element createContainerElement() {\r
+ Element el = DOM.createDiv();\r
+ hide(el);\r
+ return el;\r
}\r
\r
/**\r
* if <code>beforeIndex</code> is out of range\r
*/\r
public void insert(Widget w, int beforeIndex) {\r
- super.insert(w, getElement(), beforeIndex, true);\r
- initChildWidget(w);\r
+ Element el = createContainerElement();\r
+ DOM.insertChild(getElement(), el, beforeIndex);\r
+ super.insert(w, el, beforeIndex, false);\r
}\r
\r
public boolean remove(Widget w) {\r
+ final int index = getWidgetIndex(w);\r
final boolean removed = super.remove(w);\r
if (removed) {\r
- resetChildWidget(w);\r
-\r
if (visibleWidget == w) {\r
visibleWidget = null;\r
}\r
+ Element child = DOM.getChild(getElement(), index);\r
+ DOM.removeChild(getElement(), child);\r
+ unHide(child);\r
}\r
return removed;\r
}\r
Widget newVisible = getWidget(index);\r
if (visibleWidget != newVisible) {\r
if (visibleWidget != null) {\r
- visibleWidget.setVisible(false);\r
+ hide(DOM.getParent(visibleWidget.getElement()));\r
}\r
visibleWidget = newVisible;\r
- visibleWidget.setVisible(true);\r
+ unHide(DOM.getParent(visibleWidget.getElement()));\r
}\r
}\r
\r
- /**\r
- * Make the widget invisible, and set its width and height to full.\r
- */\r
- private void initChildWidget(Widget w) {\r
- w.setVisible(false);\r
+ public void setHeight(String height) {\r
+ super.setHeight(height);\r
+ if ("100%".equals(height) && !fullheight) {\r
+ int childCount = DOM.getChildCount(getElement());\r
+ for (int i = 0; i < childCount; i++) {\r
+ DOM.setStyleAttribute(DOM.getChild(getElement(), i), "height",\r
+ "100%");\r
+ }\r
+ fullheight = true;\r
+ } else if (fullheight) {\r
+ int childCount = DOM.getChildCount(getElement());\r
+ for (int i = 0; i < childCount; i++) {\r
+ DOM.setStyleAttribute(DOM.getChild(getElement(), i), "height",\r
+ "");\r
+ }\r
+ fullheight = false;\r
+ }\r
}\r
\r
- /**\r
- * Make the widget visible, and clear the widget's width and height\r
- * attributes. This is done so that any changes to the visibility, height,\r
- * or width of the widget that were done by the panel are undone.\r
- */\r
- private void resetChildWidget(Widget w) {\r
- w.setVisible(true);\r
+ private void hide(Element e) {\r
+ DOM.setStyleAttribute(e, "visibility", "hidden");\r
+ DOM.setStyleAttribute(e, "position", "absolute");\r
+ }\r
+\r
+ private void unHide(Element e) {\r
+ DOM.setStyleAttribute(e, "visibility", "");\r
+ DOM.setStyleAttribute(e, "position", "");\r
}\r
}\r
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
this.client = client;
- if (client.updateComponent(this, uidl, false)) {
+ if (client.updateComponent(this, uidl, true)) {
return;
}
*/
public String getCaption();
+ /**
+ * Sets the component's caption <code>String</code>. Caption is the
+ * visible name of the component. This method will trigger a
+ * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
+ *
+ * @param caption
+ * the new caption <code>String</code> for the component.
+ */
+ public void setCaption(String caption);
+
/**
* Gets the component's icon. A component may have a graphical icon
* associated with it, this method retrieves it if it is defined.
*/
public Resource getIcon();
+ /**
+ * Sets the component's icon. This method will trigger a
+ * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
+ *
+ * @param icon
+ * the icon to be shown with the component's caption.
+ */
+ public void setIcon(Resource icon);
+
/**
* Gets the component's parent window. If the component does not yet belong
* to a window <code>null</code> is returned.
package com.itmill.toolkit.ui;
import java.lang.reflect.Method;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
*/
private final LinkedList tabs = new LinkedList();
- /**
- * Tab -> caption mapping.
- */
- private final Hashtable tabCaptions = new Hashtable();
-
- /**
- * Tab -> icon mapping .
- */
- private final Hashtable tabIcons = new Hashtable();
-
/**
* Selected tab.
*/
super.removeComponent(c);
keyMapper.remove(c);
tabs.remove(c);
- tabCaptions.remove(c);
if (c.equals(selected)) {
if (tabs.isEmpty()) {
selected = null;
fireSelectedTabChange();
}
}
- c.removeListener(this);
requestRepaint();
}
}
}
/**
- * Adds a new tab into TabSheet with overridden caption and icon.
+ * Adds a new tab into TabSheet.
*
* @param c
* the component to be added onto tab.
* @param caption
- * the caption of the tab to be used instead of components
- * own.
+ * the caption to be set for the component and used rendered
+ * in tab bar
* @param icon
- * the icon of the tab to be used instead of components own.
+ * the icon to be set for the component and used rendered in
+ * tab bar
*/
public void addTab(Component c, String caption, Resource icon) {
if (c != null) {
- tabCaptions.put(c, caption != null ? caption : "");
+ if (caption != null) {
+ c.setCaption(caption);
+ }
if (icon != null) {
- tabIcons.put(c, icon);
+ c.setIcon(icon);
}
addTab(c);
}
}
super.addComponent(c);
requestRepaint();
- c.addListener(this);
}
}
* the component.
*/
public String getTabCaption(Component c) {
- String caption = (String) tabCaptions.get(c);
- if (caption == null) {
- caption = c.getCaption();
- }
- if (caption == null) {
- caption = "";
+ if (c.getCaption() == null) {
+ return "";
+ } else {
+ return c.getCaption();
}
- return caption;
}
/**
- * Sets overridden tab caption for given component.
- *
- * Normally TabSheet uses caption from component
+ * Sets tabs captions.
*
* @param c
* the component.
* the caption to set.
*/
public void setTabCaption(Component c, String caption) {
- tabCaptions.put(c, caption);
- requestRepaint();
+ if (tabs.contains(c)) {
+ c.setCaption(caption);
+ }
}
/**
* the component.
*/
public Resource getTabIcon(Component c) {
- if (tabIcons.containsKey(c)) {
- return (Resource) tabIcons.get(c);
- } else {
- return c.getIcon();
- }
+ return c.getIcon();
}
/**
* @param icon
*/
public void setTabIcon(Component c, Resource icon) {
- if (icon == null) {
- tabIcons.remove(c);
- } else {
- tabIcons.put(c, icon);
+ if (tabs.contains(c)) {
+ c.setIcon(icon);
}
- requestRepaint();
}
/**
}
/*
- * We need to repaint on child repaint due the way captions and icons are
- * handled
+ * If child is not rendered on the client we need to repaint on child
+ * repaint due the way captions and icons are handled.
*/
public void repaintRequested(RepaintRequestEvent event) {
- requestRepaint();
+ if (!paintedTabs.contains(event.getPaintable())) {
+ requestRepaint();
+ }
}
public void detach() {