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.

DefaultWidgetSet.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client;
  5. import com.google.gwt.user.client.ui.Widget;
  6. import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout;
  7. import com.vaadin.terminal.gwt.client.ui.VAccordion;
  8. import com.vaadin.terminal.gwt.client.ui.VButton;
  9. import com.vaadin.terminal.gwt.client.ui.VCheckBox;
  10. import com.vaadin.terminal.gwt.client.ui.VCustomComponent;
  11. import com.vaadin.terminal.gwt.client.ui.VCustomLayout;
  12. import com.vaadin.terminal.gwt.client.ui.VDateFieldCalendar;
  13. import com.vaadin.terminal.gwt.client.ui.VEmbedded;
  14. import com.vaadin.terminal.gwt.client.ui.VFilterSelect;
  15. import com.vaadin.terminal.gwt.client.ui.VForm;
  16. import com.vaadin.terminal.gwt.client.ui.VFormLayout;
  17. import com.vaadin.terminal.gwt.client.ui.VGridLayout;
  18. import com.vaadin.terminal.gwt.client.ui.VHorizontalLayout;
  19. import com.vaadin.terminal.gwt.client.ui.VLabel;
  20. import com.vaadin.terminal.gwt.client.ui.VLink;
  21. import com.vaadin.terminal.gwt.client.ui.VListSelect;
  22. import com.vaadin.terminal.gwt.client.ui.VMenuBar;
  23. import com.vaadin.terminal.gwt.client.ui.VNativeSelect;
  24. import com.vaadin.terminal.gwt.client.ui.VOptionGroup;
  25. import com.vaadin.terminal.gwt.client.ui.VOrderedLayout;
  26. import com.vaadin.terminal.gwt.client.ui.VPanel;
  27. import com.vaadin.terminal.gwt.client.ui.VPasswordField;
  28. import com.vaadin.terminal.gwt.client.ui.VPopupCalendar;
  29. import com.vaadin.terminal.gwt.client.ui.VPopupView;
  30. import com.vaadin.terminal.gwt.client.ui.VProgressIndicator;
  31. import com.vaadin.terminal.gwt.client.ui.VScrollTable;
  32. import com.vaadin.terminal.gwt.client.ui.VSlider;
  33. import com.vaadin.terminal.gwt.client.ui.VSplitPanelHorizontal;
  34. import com.vaadin.terminal.gwt.client.ui.VSplitPanelVertical;
  35. import com.vaadin.terminal.gwt.client.ui.VTablePaging;
  36. import com.vaadin.terminal.gwt.client.ui.VTabsheet;
  37. import com.vaadin.terminal.gwt.client.ui.VTextArea;
  38. import com.vaadin.terminal.gwt.client.ui.VTextField;
  39. import com.vaadin.terminal.gwt.client.ui.VTextualDate;
  40. import com.vaadin.terminal.gwt.client.ui.VTree;
  41. import com.vaadin.terminal.gwt.client.ui.VTwinColSelect;
  42. import com.vaadin.terminal.gwt.client.ui.VUnknownComponent;
  43. import com.vaadin.terminal.gwt.client.ui.VUpload;
  44. import com.vaadin.terminal.gwt.client.ui.VUriFragmentUtility;
  45. import com.vaadin.terminal.gwt.client.ui.VVerticalLayout;
  46. import com.vaadin.terminal.gwt.client.ui.VWindow;
  47. import com.vaadin.terminal.gwt.client.ui.richtextarea.VRichTextArea;
  48. public class DefaultWidgetSet implements WidgetSet {
  49. /**
  50. * This is the entry point method. It will start the first
  51. */
  52. public void onModuleLoad() {
  53. ApplicationConfiguration.initConfigurations(this);
  54. ApplicationConfiguration.startNextApplication(); // start first app
  55. }
  56. public Paintable createWidget(UIDL uidl) {
  57. final Class classType = resolveWidgetType(uidl);
  58. if (VCheckBox.class == classType) {
  59. return new VCheckBox();
  60. } else if (VButton.class == classType) {
  61. return new VButton();
  62. } else if (VWindow.class == classType) {
  63. return new VWindow();
  64. } else if (VOrderedLayout.class == classType) {
  65. return new VOrderedLayout();
  66. } else if (VVerticalLayout.class == classType) {
  67. return new VVerticalLayout();
  68. } else if (VHorizontalLayout.class == classType) {
  69. return new VHorizontalLayout();
  70. } else if (VLabel.class == classType) {
  71. return new VLabel();
  72. } else if (VLink.class == classType) {
  73. return new VLink();
  74. } else if (VGridLayout.class == classType) {
  75. return new VGridLayout();
  76. } else if (VTree.class == classType) {
  77. return new VTree();
  78. } else if (VOptionGroup.class == classType) {
  79. return new VOptionGroup();
  80. } else if (VTwinColSelect.class == classType) {
  81. return new VTwinColSelect();
  82. } else if (VNativeSelect.class == classType) {
  83. return new VNativeSelect();
  84. } else if (VListSelect.class == classType) {
  85. return new VListSelect();
  86. } else if (VPanel.class == classType) {
  87. return new VPanel();
  88. } else if (VTabsheet.class == classType) {
  89. return new VTabsheet();
  90. } else if (VEmbedded.class == classType) {
  91. return new VEmbedded();
  92. } else if (VCustomLayout.class == classType) {
  93. return new VCustomLayout();
  94. } else if (VCustomComponent.class == classType) {
  95. return new VCustomComponent();
  96. } else if (VTextArea.class == classType) {
  97. return new VTextArea();
  98. } else if (VPasswordField.class == classType) {
  99. return new VPasswordField();
  100. } else if (VTextField.class == classType) {
  101. return new VTextField();
  102. } else if (VTablePaging.class == classType) {
  103. return new VTablePaging();
  104. } else if (VScrollTable.class == classType) {
  105. return new VScrollTable();
  106. } else if (VDateFieldCalendar.class == classType) {
  107. return new VDateFieldCalendar();
  108. } else if (VTextualDate.class == classType) {
  109. return new VTextualDate();
  110. } else if (VPopupCalendar.class == classType) {
  111. return new VPopupCalendar();
  112. } else if (VSlider.class == classType) {
  113. return new VSlider();
  114. } else if (VForm.class == classType) {
  115. return new VForm();
  116. } else if (VFormLayout.class == classType) {
  117. return new VFormLayout();
  118. } else if (VUpload.class == classType) {
  119. return new VUpload();
  120. } else if (VSplitPanelHorizontal.class == classType) {
  121. return new VSplitPanelHorizontal();
  122. } else if (VSplitPanelVertical.class == classType) {
  123. return new VSplitPanelVertical();
  124. } else if (VFilterSelect.class == classType) {
  125. return new VFilterSelect();
  126. } else if (VProgressIndicator.class == classType) {
  127. return new VProgressIndicator();
  128. } else if (VRichTextArea.class == classType) {
  129. return new VRichTextArea();
  130. } else if (VAccordion.class == classType) {
  131. return new VAccordion();
  132. } else if (VMenuBar.class == classType) {
  133. return new VMenuBar();
  134. } else if (VPopupView.class == classType) {
  135. return new VPopupView();
  136. } else if (VUriFragmentUtility.class == classType) {
  137. return new VUriFragmentUtility();
  138. } else if (VAbsoluteLayout.class == classType) {
  139. return new VAbsoluteLayout();
  140. }
  141. return new VUnknownComponent();
  142. }
  143. protected Class resolveWidgetType(UIDL uidl) {
  144. final String tag = uidl.getTag();
  145. if ("button".equals(tag)) {
  146. if ("switch".equals(uidl.getStringAttribute("type"))) {
  147. return VCheckBox.class;
  148. } else {
  149. return VButton.class;
  150. }
  151. } else if ("window".equals(tag)) {
  152. return VWindow.class;
  153. } else if ("orderedlayout".equals(tag)) {
  154. return VOrderedLayout.class;
  155. } else if ("verticallayout".equals(tag)) {
  156. return VVerticalLayout.class;
  157. } else if ("horizontallayout".equals(tag)) {
  158. return VHorizontalLayout.class;
  159. } else if ("label".equals(tag)) {
  160. return VLabel.class;
  161. } else if ("link".equals(tag)) {
  162. return VLink.class;
  163. } else if ("gridlayout".equals(tag)) {
  164. return VGridLayout.class;
  165. } else if ("tree".equals(tag)) {
  166. return VTree.class;
  167. } else if ("select".equals(tag)) {
  168. if (uidl.hasAttribute("type")) {
  169. final String type = uidl.getStringAttribute("type");
  170. if (type.equals("twincol")) {
  171. return VTwinColSelect.class;
  172. }
  173. if (type.equals("optiongroup")) {
  174. return VOptionGroup.class;
  175. }
  176. if (type.equals("native")) {
  177. return VNativeSelect.class;
  178. }
  179. if (type.equals("list")) {
  180. return VListSelect.class;
  181. }
  182. } else {
  183. if (uidl.hasAttribute("selectmode")
  184. && uidl.getStringAttribute("selectmode")
  185. .equals("multi")) {
  186. return VListSelect.class;
  187. } else {
  188. return VFilterSelect.class;
  189. }
  190. }
  191. } else if ("panel".equals(tag)) {
  192. return VPanel.class;
  193. } else if ("tabsheet".equals(tag)) {
  194. return VTabsheet.class;
  195. } else if ("accordion".equals(tag)) {
  196. return VAccordion.class;
  197. } else if ("embedded".equals(tag)) {
  198. return VEmbedded.class;
  199. } else if ("customlayout".equals(tag)) {
  200. return VCustomLayout.class;
  201. } else if ("customcomponent".equals(tag)) {
  202. return VCustomComponent.class;
  203. } else if ("textfield".equals(tag)) {
  204. if (uidl.getBooleanAttribute("richtext")) {
  205. return VRichTextArea.class;
  206. } else if (uidl.hasAttribute("multiline")) {
  207. return VTextArea.class;
  208. } else if (uidl.getBooleanAttribute("secret")) {
  209. return VPasswordField.class;
  210. } else {
  211. return VTextField.class;
  212. }
  213. } else if ("table".equals(tag)) {
  214. return VScrollTable.class;
  215. } else if ("pagingtable".equals(tag)) {
  216. return VTablePaging.class;
  217. } else if ("datefield".equals(tag)) {
  218. if (uidl.hasAttribute("type")) {
  219. if ("inline".equals(uidl.getStringAttribute("type"))) {
  220. return VDateFieldCalendar.class;
  221. } else if ("popup".equals(uidl.getStringAttribute("type"))) {
  222. return VPopupCalendar.class;
  223. }
  224. }
  225. // popup calendar is the default
  226. return VPopupCalendar.class;
  227. } else if ("slider".equals(tag)) {
  228. return VSlider.class;
  229. } else if ("form".equals(tag)) {
  230. return VForm.class;
  231. } else if ("formlayout".equals(tag)) {
  232. return VFormLayout.class;
  233. } else if ("upload".equals(tag)) {
  234. return VUpload.class;
  235. } else if ("hsplitpanel".equals(tag)) {
  236. return VSplitPanelHorizontal.class;
  237. } else if ("vsplitpanel".equals(tag)) {
  238. return VSplitPanelVertical.class;
  239. } else if ("progressindicator".equals(tag)) {
  240. return VProgressIndicator.class;
  241. } else if ("menubar".equals(tag)) {
  242. return VMenuBar.class;
  243. } else if ("popupview".equals(tag)) {
  244. return VPopupView.class;
  245. } else if ("urifragment".equals(tag)) {
  246. return VUriFragmentUtility.class;
  247. } else if (VAbsoluteLayout.TAGNAME.equals(tag)) {
  248. return VAbsoluteLayout.class;
  249. }
  250. return VUnknownComponent.class;
  251. }
  252. /**
  253. * Kept here to support 5.2 era widget sets
  254. *
  255. * @deprecated use resolveWidgetType instead
  256. */
  257. @Deprecated
  258. protected String resolveWidgetTypeName(UIDL uidl) {
  259. Class type = resolveWidgetType(uidl);
  260. return type.getName();
  261. }
  262. public boolean isCorrectImplementation(Widget currentWidget, UIDL uidl) {
  263. // TODO remove backwardscompatibility check
  264. return currentWidget.getClass() == resolveWidgetType(uidl)
  265. || currentWidget.getClass().getName().equals(
  266. resolveWidgetTypeName(uidl));
  267. }
  268. }