You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IGridLayout.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.itmill.toolkit.terminal.gwt.client.ui;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import com.google.gwt.user.client.ui.FlexTable;
  6. import com.google.gwt.user.client.ui.Widget;
  7. import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
  8. import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
  9. import com.itmill.toolkit.terminal.gwt.client.Container;
  10. import com.itmill.toolkit.terminal.gwt.client.Paintable;
  11. import com.itmill.toolkit.terminal.gwt.client.UIDL;
  12. public class IGridLayout extends FlexTable implements Paintable, Container {
  13. /** Widget to captionwrapper map */
  14. private HashMap widgetToCaptionWrapper = new HashMap();
  15. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  16. if (client.updateComponent(this, uidl, false))
  17. return;
  18. clear();
  19. if (uidl.hasAttribute("caption"))
  20. setTitle(uidl.getStringAttribute("caption"));
  21. int row = 0, column = 0;
  22. ArrayList detachdedPaintables = new ArrayList();
  23. for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
  24. UIDL r = (UIDL) i.next();
  25. if ("gr".equals(r.getTag())) {
  26. row++;
  27. column = 0;
  28. for (Iterator j = r.getChildIterator(); j.hasNext();) {
  29. UIDL c = (UIDL) j.next();
  30. if ("gc".equals(c.getTag())) {
  31. column++;
  32. int w;
  33. if (c.hasAttribute("cols")) {
  34. w = c.getIntAttribute("cols");
  35. } else
  36. w = 1;
  37. ((FlexCellFormatter) getCellFormatter()).setColSpan(
  38. row, column, w);
  39. UIDL u = c.getChildUIDL(0);
  40. if (u != null) {
  41. Widget child = client.getWidget(u);
  42. prepareCell(row, column);
  43. Widget oldChild = getWidget(row, column);
  44. if (child != oldChild) {
  45. if (oldChild != null) {
  46. CaptionWrapper cw = (CaptionWrapper) oldChild;
  47. detachdedPaintables.add(cw.getPaintable());
  48. widgetToCaptionWrapper.remove(oldChild);
  49. }
  50. CaptionWrapper wrapper = new CaptionWrapper(
  51. (Paintable) child);
  52. setWidget(row, column, wrapper);
  53. widgetToCaptionWrapper.put(child, wrapper);
  54. }
  55. ((Paintable) child).updateFromUIDL(u, client);
  56. }
  57. column += w - 1;
  58. }
  59. }
  60. }
  61. }
  62. // for loop detached widgets and unregister them unless they are
  63. // attached (case of widget which is moved to another cell)
  64. for (Iterator it = detachdedPaintables.iterator(); it.hasNext();) {
  65. Widget w = (Widget) it.next();
  66. if (!w.isAttached())
  67. client.unregisterPaintable((Paintable) w);
  68. }
  69. }
  70. public boolean hasChildComponent(Widget component) {
  71. if (widgetToCaptionWrapper.containsKey(component))
  72. return true;
  73. return false;
  74. }
  75. public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
  76. // TODO Auto-generated method stub
  77. }
  78. public void updateCaption(Paintable component, UIDL uidl) {
  79. CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper
  80. .get(component);
  81. wrapper.updateCaption(uidl);
  82. }
  83. }