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.

WidgetSet.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client;
  5. import com.google.gwt.core.client.GWT;
  6. import com.google.gwt.user.client.ui.Widget;
  7. import com.vaadin.terminal.gwt.client.ui.VUnknownComponentPaintable;
  8. public class WidgetSet {
  9. /**
  10. * WidgetSet (and its extensions) delegate instantiation of widgets and
  11. * client-server matching to WidgetMap. The actual implementations are
  12. * generated with gwts generators/deferred binding.
  13. */
  14. private WidgetMap widgetMap = GWT.create(WidgetMap.class);
  15. /**
  16. * Create an uninitialized component that best matches given UIDL. The
  17. * component must be a {@link Widget} that implements
  18. * {@link ComponentConnector}.
  19. *
  20. * @param tag
  21. * component type tag for the component to create
  22. * @param client
  23. * the application connection that whishes to instantiate widget
  24. *
  25. * @return New uninitialized and unregistered component that can paint given
  26. * UIDL.
  27. */
  28. public ComponentConnector createWidget(String tag,
  29. ApplicationConfiguration conf) {
  30. /*
  31. * Yes, this (including the generated code in WidgetMap) may look very
  32. * odd code, but due the nature of GWT, we cannot do this any cleaner.
  33. * Luckily this is mostly written by WidgetSetGenerator, here are just
  34. * some hacks. Extra instantiation code is needed if client side widget
  35. * has no "native" counterpart on client side.
  36. */
  37. Class<? extends ComponentConnector> classType = resolveWidgetType(tag,
  38. conf);
  39. if (classType == null || classType == VUnknownComponentPaintable.class) {
  40. String serverSideName = conf
  41. .getUnknownServerClassNameByEncodedTagName(tag);
  42. VUnknownComponentPaintable c = GWT
  43. .create(VUnknownComponentPaintable.class);
  44. c.setServerSideClassName(serverSideName);
  45. return c;
  46. } else {
  47. /*
  48. * let the auto generated code instantiate this type
  49. */
  50. return widgetMap.instantiate(classType);
  51. }
  52. }
  53. protected Class<? extends ComponentConnector> resolveWidgetType(String tag,
  54. ApplicationConfiguration conf) {
  55. Class<? extends ComponentConnector> widgetClass = conf
  56. .getWidgetClassByEncodedTag(tag);
  57. return widgetClass;
  58. }
  59. /**
  60. * Due its nature, GWT does not support dynamic classloading. To bypass this
  61. * limitation, widgetset must have function that returns Class by its fully
  62. * qualified name.
  63. *
  64. * @param fullyQualifiedName
  65. * @param applicationConfiguration
  66. * @return
  67. */
  68. public Class<? extends ComponentConnector> getImplementationByClassName(
  69. String fullyqualifiedName) {
  70. if (fullyqualifiedName == null) {
  71. return VUnknownComponentPaintable.class;
  72. }
  73. Class<? extends ComponentConnector> implementationByServerSideClassName = widgetMap
  74. .getImplementationByServerSideClassName(fullyqualifiedName);
  75. return implementationByServerSideClassName;
  76. }
  77. public Class<? extends ComponentConnector>[] getDeferredLoadedWidgets() {
  78. return widgetMap.getDeferredLoadedWidgets();
  79. }
  80. public void loadImplementation(Class<? extends ComponentConnector> nextType) {
  81. widgetMap.ensureInstantiator(nextType);
  82. }
  83. }