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.

CreatingAReusableVaadinThemeInEclipse.asciidoc 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ---
  2. title: Creating A Reusable Vaadin Theme In Eclipse
  3. order: 22
  4. layout: page
  5. ---
  6. [[creating-a-reusable-vaadin-theme-in-eclipse]]
  7. = Creating a reusable Vaadin theme in Eclipse
  8. This tutorial teaches you how to create a standalone Vaadin theme that
  9. can be reused in other Vaadin projects as an add-on.
  10. *Requirements:*
  11. * https://www.eclipse.org/downloads/[Eclipse IDE for Java EE developers]
  12. * https://vaadin.com/eclipse/[Vaadin plug-in for Eclipse]
  13. [[create-a-project-for-your-theme]]
  14. Create a project for your theme
  15. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. Create a new Java project.
  17. image:img/New%20Java%20Project.png[Create a new Java project]
  18. https://vaadin.com/download[Download a Vaadin JAR] and add it to your
  19. project’s build path.
  20. image:img/Vaadin%20to%20build%20path.png[Add Vaadin to build path]
  21. In the src folder, create a class for your theme:
  22. [source,java]
  23. ....
  24. package com.example.mytheme;
  25. import com.vaadin.ui.themes.BaseTheme;
  26. public class MyTheme extends BaseTheme {
  27. public static final String THEME_NAME = "my-theme";
  28. }
  29. ....
  30. This makes your theme extend Vaadin’s
  31. https://vaadin.com/api/com/vaadin/ui/themes/BaseTheme.html[BaseTheme],
  32. which will let you fully customize your theme from scratch. On the other
  33. hand, if you don't have very specific theming needs and just want
  34. good-looking results quickly, try extending
  35. https://vaadin.com/api/com/vaadin/ui/themes/ChameleonTheme.html[ChameleonTheme]
  36. instead. In any case, both of these themes are designed for extension
  37. and therefore your best choices to start with.
  38. In the root of your project, create the following folder and files:
  39. * META-INF
  40. ** MANIFEST.MF
  41. * VAADIN
  42. ** themes
  43. *** my-theme
  44. **** addons.scss
  45. **** my-theme.scss
  46. **** styles.scss
  47. The MANIFEST.MF file should contain the following:
  48. ....
  49. Manifest-Version: 1.0
  50. Implementation-Title: My Theme
  51. Implementation-Version: 1.0.0
  52. Vaadin-Package-Version: 1
  53. Class-Path:
  54. ....
  55. Your `Implementation-Title` and `Implementation-Version` should reflect
  56. how you want your theme to be visible in the
  57. https://vaadin.com/directory[Vaadin directory].
  58. [[create-a-demo-app-for-your-theme]]
  59. Create a demo app for your theme
  60. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. Create a new Vaadin project.
  62. image:img/New%20Vaadin%20project%20(1).png[Create a new Vaadin project]
  63. image:img/New%20Vaadin%20project%20(2).png[Create a new Vaadin project 2]
  64. Add your *theme* project to your *demo* project’s Java build path.
  65. image:img/Theme%20to%20build%20path.png[Add theme to build path]
  66. Add your *theme* project to your *demo* project’s _deployment assembly_.
  67. This will automatically convert your theme project to a Java EE Utility
  68. project.
  69. image:img/Theme%20to%20deployment%20assembly.png[Add theme to Deployment Assembly]
  70. Now that your theme project is a Java EE Utility project, it will also
  71. have a deployment assembly. Add your *theme project*’s VAADIN folder to
  72. there and make sure you specify its deploy path as `VAADIN`.
  73. image:img/VAADIN%20to%20deployment%20assembly.png[Add theme to Deployment Assembly 2]
  74. In your *demo* application class, add the following line to your
  75. `init()` method:
  76. [source,java]
  77. ....
  78. setTheme(MyTheme.THEME_NAME);
  79. ....
  80. To try if it works, right-click on your *demo* project and choose _Run
  81. As > Run on Server_.
  82. [[develop-your-theme]]
  83. Develop your theme
  84. ~~~~~~~~~~~~~~~~~~
  85. Create a new style name constant in your theme class for each new CSS
  86. class name you add to your stylesheets. These can then be passed to the
  87. `Component.addStyleName(String)` method. This will make it easier for
  88. other developers to use your theme!
  89. Changes to your stylesheets will be visible in your demo app almost
  90. instantly. All you need to do is save the file, wait for the server to
  91. automatically pick up the changes, then refresh your browser.
  92. [[export-your-theme-as-a-vaadin-add-on]]
  93. Export your theme as a Vaadin add-on
  94. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. Right-click on your *theme* project, choose _Export… > Java > Jar file_
  96. and make sure your settings match those in the following two images.
  97. image:img/JAR%20Export%20(1).png[Export as JAR]
  98. image:img/JAR%20Export%20(2).png[Export as JAR 2]
  99. Finally, upload your theme add-on Jar to the
  100. https://vaadin.com/directory[Vaadin directory]!