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.

VCustomLayoutPaintable.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import java.util.HashSet;
  6. import java.util.Iterator;
  7. import java.util.Set;
  8. import com.google.gwt.core.client.GWT;
  9. import com.google.gwt.user.client.DOM;
  10. import com.google.gwt.user.client.ui.Widget;
  11. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  12. import com.vaadin.terminal.gwt.client.UIDL;
  13. import com.vaadin.terminal.gwt.client.ComponentConnector;
  14. public class VCustomLayoutPaintable extends AbstractComponentContainerConnector
  15. implements SimpleManagedLayout {
  16. /** Update the layout from UIDL */
  17. @Override
  18. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  19. getWidget().client = client;
  20. // ApplicationConnection manages generic component features
  21. super.updateFromUIDL(uidl, client);
  22. if (!isRealUpdate(uidl)) {
  23. return;
  24. }
  25. getWidget().pid = uidl.getId();
  26. if (!getWidget().hasTemplate()) {
  27. // Update HTML template only once
  28. getWidget().initializeHTML(uidl, client);
  29. }
  30. // Evaluate scripts
  31. VCustomLayout.eval(getWidget().scripts);
  32. getWidget().scripts = null;
  33. // TODO Check if this is needed
  34. client.runDescendentsLayout(getWidget());
  35. Set<Widget> oldWidgets = new HashSet<Widget>();
  36. oldWidgets.addAll(getWidget().locationToWidget.values());
  37. // For all contained widgets
  38. for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
  39. final UIDL uidlForChild = (UIDL) i.next();
  40. if (uidlForChild.getTag().equals("location")) {
  41. final String location = uidlForChild.getStringAttribute("name");
  42. UIDL childUIDL = uidlForChild.getChildUIDL(0);
  43. final ComponentConnector childPaintable = client
  44. .getPaintable(childUIDL);
  45. Widget childWidget = childPaintable.getWidget();
  46. try {
  47. getWidget().setWidget(childWidget, location);
  48. childPaintable.updateFromUIDL(childUIDL, client);
  49. } catch (final IllegalArgumentException e) {
  50. // If no location is found, this component is not visible
  51. }
  52. oldWidgets.remove(childWidget);
  53. }
  54. }
  55. for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator
  56. .hasNext();) {
  57. Widget oldWidget = iterator.next();
  58. if (oldWidget.isAttached()) {
  59. // slot of this widget is emptied, remove it
  60. getWidget().remove(oldWidget);
  61. }
  62. }
  63. // TODO Check if this is needed
  64. client.runDescendentsLayout(getWidget());
  65. }
  66. @Override
  67. public VCustomLayout getWidget() {
  68. return (VCustomLayout) super.getWidget();
  69. }
  70. @Override
  71. protected Widget createWidget() {
  72. return GWT.create(VCustomLayout.class);
  73. }
  74. public void updateCaption(ComponentConnector paintable, UIDL uidl) {
  75. getWidget().updateCaption(paintable, uidl);
  76. }
  77. public void layout() {
  78. getWidget().iLayoutJS(
  79. DOM.getFirstChild(getWidget().getElement()));
  80. }
  81. }