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.

clientside-widget.asciidoc 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ---
  2. title: Creating a Custom Widget
  3. order: 5
  4. layout: page
  5. ---
  6. [[clientside.widget]]
  7. = Creating a Custom Widget
  8. Creating a new Vaadin component usually begins from making a client-side widget,
  9. which is later integrated with a server-side counterpart to enable server-side
  10. development. In addition, you can also choose to make pure client-side widgets,
  11. a possibility which we also describe later in this section.
  12. [[clientside.widget.simple]]
  13. == A Basic Widget
  14. All widgets extend the [classname]#Widget# class or some of its subclasses. You
  15. can extend any core GWT or supplementary Vaadin widgets. Perhaps typically, an
  16. abstraction such as [classname]#Composite#. The basic GWT widget component
  17. hierarchy is illustrated in <<figure.clientside.widgets>>. Please see the GWT
  18. API documentation for a complete description of the widget classes.
  19. [[figure.clientside.widgets]]
  20. .GWT widget base class hierarchy
  21. image::img/gwt-widgets-hi.png[]
  22. For example, we could extend the [classname]#Label# widget to display some
  23. custom text.
  24. ----
  25. package com.example.myapp.client;
  26. import com.google.gwt.user.client.ui.Label;
  27. public class MyWidget extends Label {
  28. public static final String CLASSNAME = "mywidget";
  29. public MyWidget() {
  30. setStyleName(CLASSNAME);
  31. setText("This is MyWidget");
  32. }
  33. }
  34. ----
  35. The above example is largely what the Eclipse plugin generates as a widget stub.
  36. It is a good practice to set a distinctive style class for the widget, to allow
  37. styling it with CSS.
  38. The client-side source code __must__ be contained in a [filename]#client#
  39. package under the package of the descriptor file, which is covered later.
  40. [[clientside.widget.using]]
  41. == Using the Widget
  42. You can use a custom widget just like you would use any widget, possibly
  43. integrating it with a server-side component, or in pure client-side modules such
  44. as the following:
  45. ----
  46. public class MyEntryPoint implements EntryPoint {
  47. @Override
  48. public void onModuleLoad() {
  49. // Use the custom widget
  50. final MyWidget mywidget = new MyWidget();
  51. RootPanel.get().add(mywidget);
  52. }
  53. }
  54. ----