if (manageCaption) {
Layout parent = getParentLayout(component);
if (parent != null)
- parent.updateCaption(component, uidl);
+ parent.updateCaption((Paintable) component, uidl);
}
// Visibility, Disabling and read-only status
public class Caption extends HTML {
- private Widget owner;
+ private Paintable owner;
- public Caption(Widget component) {
+ public Caption(Paintable component) {
owner = component;
setStyleName("i-caption");
}
}
/**
- * Returns Widget (most likely Paintable) for which this Caption
+ * Returns Paintable for which this Caption
* belongs to.
*
* @return owner Widget
*/
- public Widget getOwner() {
+ public Paintable getOwner() {
return owner;
}
}
package com.itmill.toolkit.terminal.gwt.client;
+import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
-public class CaptionWrapper extends VerticalPanel {
+public class CaptionWrapper extends FlowPanel {
- Label caption;
- Widget widget;
+ Label caption = new Label();
+ Paintable widget;
- public CaptionWrapper(Widget toBeWrapped) {
+ public CaptionWrapper(Paintable toBeWrapped) {
+ add(caption);
widget = toBeWrapped;
- add(widget);
+ add((Widget) widget);
}
public void updateCaption(UIDL uidl) {
String c = uidl.getStringAttribute("caption");
// TODO Description and error messages
- if (c == null) {
- if (caption == null) return;
- remove(caption);
- caption = null;
- } else {
- if (caption == null) {
- caption = new Label(c);
- insert(caption, 0);
- }
- else
- caption.setText(c);
- }
+ if (c != null) {
+ caption.setText(c);
+ }
setVisible(!uidl.getBooleanAttribute("invisible"));
}
- public Widget getWidget() {
+ public Paintable getPaintable() {
return widget;
}
}
* @param uidl
* UIDL of the child component.
*/
- void updateCaption(Widget component, UIDL uidl);
+ void updateCaption(Paintable component, UIDL uidl);
}
}
/** Update caption for given widget */
- public void updateCaption(Widget component, UIDL uidl) {
+ public void updateCaption(Paintable component, UIDL uidl) {
CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper.get(component);
if (Caption.isNeeded(uidl)) {
if (wrapper == null) {
- String loc = getLocation(component);
- super.remove(component);
+ String loc = getLocation((Widget) component);
+ super.remove((Widget) component);
wrapper = new CaptionWrapper(component);
super.add(wrapper, (Element) locationToElement.get(loc));
widgetToCaptionWrapper.put(component, wrapper);
wrapper.updateCaption(uidl);
} else {
if (wrapper != null) {
- String loc = getLocation(component);
+ String loc = getLocation((Widget) component);
super.remove(wrapper);
- super.add(wrapper.getWidget(), (Element) locationToElement.get(loc));
+ super.add((Widget) wrapper.getPaintable(), (Element) locationToElement.get(loc));
widgetToCaptionWrapper.remove(component);
}
}
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.FlexTable;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
+import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-public class IGridLayout extends FlexTable implements Paintable {
+public class IGridLayout extends FlexTable implements Paintable, Layout {
+
+ /** Widget to captionwrapper map */
+ private HashMap widgetToCaptionWrapper = new HashMap();
+
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
clear();
if (uidl.hasAttribute("caption"))
setTitle(uidl.getStringAttribute("caption"));
int row = 0, column = 0;
+
+ ArrayList detachdedPaintables = new ArrayList();
+
for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
UIDL r = (UIDL) i.next();
if ("gr".equals(r.getTag())) {
UIDL u = c.getChildUIDL(0);
if (u != null) {
Widget child = client.getWidget(u);
- setWidget(row, column, child);
+ prepareCell(row, column);
+ Widget oldChild = getWidget(row, column);
+ if(child != oldChild) {
+ if(oldChild != null) {
+ CaptionWrapper cw = (CaptionWrapper) oldChild;
+ detachdedPaintables.add(cw.getPaintable());
+ widgetToCaptionWrapper.remove(oldChild);
+ }
+ CaptionWrapper wrapper = new CaptionWrapper((Paintable) child);
+ setWidget(row, column, wrapper);
+ widgetToCaptionWrapper.put(child, wrapper);
+ }
((Paintable) child).updateFromUIDL(u, client);
}
}
}
}
}
+
+ // for loop detached widgets and unregister them unless they are
+ // attached (case of widget which is moved to another cell)
+ for(Iterator it = detachdedPaintables.iterator();it.hasNext();) {
+ Widget w = (Widget) it.next();
+ if(!w.isAttached())
+ client.unregisterPaintable((Paintable) w);
+ }
+ }
+
+ public boolean hasChildComponent(Widget component) {
+ if(widgetToCaptionWrapper.containsKey(component))
+ return true;
+ return false;
+ }
+
+ public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void updateCaption(Paintable component, UIDL uidl) {
+ CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper.get(component);
+ wrapper.updateCaption(uidl);
}
}
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.ComplexPanel;
+import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Caption;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
/**
- * @author mattitahvonen
- *
+ * @author IT Mill Ltd
*/
public class IOrderedLayout extends ComplexPanel implements Paintable, Layout {
Caption c = (Caption) w;
// captions go into same container element as their
// owners
- Element container = DOM.getParent(c.getOwner().getElement());
+ Element container = DOM.getParent(((UIObject) c.getOwner()).getElement());
DOM.insertChild(container, w.getElement(), 0);
insert(w, null, beforeIndex);
} else {
return getWidgetIndex(component) >= 0;
}
- public void updateCaption(Widget component, UIDL uidl) {
+ public void updateCaption(Paintable component, UIDL uidl) {
Caption c = (Caption) componentToCaption.get(component);
if (Caption.isNeeded(uidl)) {
if (c == null) {
- int index = getWidgetIndex(component);
+ int index = getWidgetIndex((Widget) component);
c = new Caption(component);
insert(c, index);
componentToCaption.put(component, c);