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.

CustomLayoutConnector.java 3.1KB

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