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.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. clear();
  17. if (uidl.hasAttribute("caption"))
  18. setTitle(uidl.getStringAttribute("caption"));
  19. int row = 0, column = 0;
  20. ArrayList detachdedPaintables = new ArrayList();
  21. for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
  22. UIDL r = (UIDL) i.next();
  23. if ("gr".equals(r.getTag())) {
  24. row++;
  25. column = 0;
  26. for (Iterator j = r.getChildIterator(); j.hasNext();) {
  27. UIDL c = (UIDL) j.next();
  28. if ("gc".equals(c.getTag())) {
  29. column++;
  30. int w;
  31. if (c.hasAttribute("w")) {
  32. w = c.getIntAttribute("w");
  33. } else
  34. w = 1;
  35. ((FlexCellFormatter) getCellFormatter()).setColSpan(
  36. row, column, w);
  37. UIDL u = c.getChildUIDL(0);
  38. if (u != null) {
  39. Widget child = client.getWidget(u);
  40. prepareCell(row, column);
  41. Widget oldChild = getWidget(row, column);
  42. if (child != oldChild) {
  43. if (oldChild != null) {
  44. CaptionWrapper cw = (CaptionWrapper) oldChild;
  45. detachdedPaintables.add(cw.getPaintable());
  46. widgetToCaptionWrapper.remove(oldChild);
  47. }
  48. CaptionWrapper wrapper = new CaptionWrapper(
  49. (Paintable) child);
  50. setWidget(row, column, wrapper);
  51. widgetToCaptionWrapper.put(child, wrapper);
  52. }
  53. ((Paintable) child).updateFromUIDL(u, client);
  54. }
  55. column += w - 1;
  56. }
  57. }
  58. }
  59. }
  60. // for loop detached widgets and unregister them unless they are
  61. // attached (case of widget which is moved to another cell)
  62. for (Iterator it = detachdedPaintables.iterator(); it.hasNext();) {
  63. Widget w = (Widget) it.next();
  64. if (!w.isAttached())
  65. client.unregisterPaintable((Paintable) w);
  66. }
  67. }
  68. public boolean hasChildComponent(Widget component) {
  69. if (widgetToCaptionWrapper.containsKey(component))
  70. return true;
  71. return false;
  72. }
  73. public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
  74. // TODO Auto-generated method stub
  75. }
  76. public void updateCaption(Paintable component, UIDL uidl) {
  77. CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper
  78. .get(component);
  79. wrapper.updateCaption(uidl);
  80. }
  81. }