Advertisement
Guest User

myUi

a guest
Mar 15th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. package vaadin;
  2.  
  3. import javax.servlet.annotation.WebServlet;
  4.  
  5. import com.vaadin.annotations.Theme;
  6. import com.vaadin.annotations.VaadinServletConfiguration;
  7. import com.vaadin.navigator.Navigator;
  8. import com.vaadin.server.VaadinRequest;
  9. import com.vaadin.server.VaadinServlet;
  10. import com.vaadin.ui.Button;
  11. import com.vaadin.ui.Button.ClickEvent;
  12. import com.vaadin.ui.Component;
  13. import com.vaadin.ui.CssLayout;
  14. import com.vaadin.ui.GridLayout;
  15. import com.vaadin.ui.Label;
  16. import com.vaadin.ui.Notification;
  17. import com.vaadin.ui.PasswordField;
  18. import com.vaadin.ui.TextField;
  19. import com.vaadin.ui.UI;
  20. import com.vaadin.ui.VerticalLayout;
  21. import com.vaadin.ui.themes.Runo;
  22.  
  23. import vaadin.views.contestants.ContestantsView;
  24. import vaadin.views.registration.RegistrationView;
  25.  
  26. /**
  27. * This UI is the application entry point. A UI may either represent a browser window
  28. * (or tab) or some part of a html page where a Vaadin application is embedded.
  29. * <p>
  30. * The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be
  31. * overridden to add component to the user interface and initialize non-component functionality.
  32. */
  33. @Theme("mytheme")
  34. //@SuppressWarnings("serial")
  35. public class MyUI extends UI {
  36.  
  37.  
  38.  
  39. @Override
  40. protected void init(VaadinRequest vaadinRequest) {
  41. final VerticalLayout layout = new VerticalLayout();
  42. final CssLayout topBar = new CssLayout();
  43. final CssLayout viewLayout = new CssLayout();
  44. layout.addComponent(topBar);
  45. layout.addComponent(viewLayout);
  46.  
  47. /*final TextField name = new TextField();
  48. name.setCaption("Type your name here:");
  49.  
  50. Button button = new Button("Click Me");
  51. button.addClickListener( e -> {
  52. layout.addComponent(new Label("Thanks " + name.getValue()
  53. + ", it works!"));
  54. });
  55.  
  56. layout.addComponents(name, button);
  57. layout.setMargin(true);
  58. layout.setSpacing(true);*/
  59. setContent(layout);
  60.  
  61. final Navigator navigator = new Navigator(this, viewLayout);
  62. navigator.addView("Registration", RegistrationView.class);
  63. navigator.addView("Contestants", ContestantsView.class);
  64.  
  65. navigator.navigateTo("Contestants");
  66. for(String s: new String[]{"Registration", "Contestants"})
  67. topBar.addComponent(this.createNavigationButton(s, navigator, topBar));
  68.  
  69. topBar.addComponent(this.createLoginForm());
  70. }
  71.  
  72. private Button createNavigationButton(final String state, final Navigator navigator, final CssLayout topBar){
  73. return new Button(state, new Button.ClickListener() {
  74.  
  75. @Override
  76. public void buttonClick(ClickEvent event) {
  77. navigator.navigateTo(state);
  78. }
  79. });
  80. }
  81.  
  82. private Component createLoginForm(){
  83. GridLayout loginForm = new GridLayout(3,3);
  84. TextField username = new TextField("username");
  85. Label info = new Label("Don't have account yet?");
  86. PasswordField password = new PasswordField("password");
  87.  
  88. username.addStyleName("visibleformitem");
  89. password.addStyleName("visibleformitem");
  90.  
  91.  
  92. Button login = new Button("Log in");
  93. Button forgot = new Button("forgot password?");
  94. Button register = new Button("Registration");
  95.  
  96. Label loginInfo = new Label("This username is already taken");
  97.  
  98. login.addClickListener(new Button.ClickListener() {
  99.  
  100. @Override
  101. public void buttonClick(ClickEvent event) {
  102. Notification.show("Logging in is not yet supported.",Notification.Type.ERROR_MESSAGE);
  103.  
  104. }
  105. });
  106. forgot.addStyleName(Runo.BUTTON_LINK);
  107. forgot.addClickListener(new Button.ClickListener() {
  108.  
  109. @Override
  110. public void buttonClick(ClickEvent event) {
  111. UI.getCurrent().addWindow(new PasswordResetWindow());
  112. }
  113. });
  114.  
  115. // 1st line of Grid
  116. loginForm.addComponent(username);
  117. loginForm.addComponent(password);
  118. loginForm.addComponent(info);
  119.  
  120. // 2nd line of Grid
  121. loginForm.addComponent(login);
  122. loginForm.addComponent(forgot);
  123. loginForm.addComponent(register);
  124.  
  125. // 3rd line of Grid
  126. //loginForm.addComponent(loginInfo);
  127.  
  128. return loginForm;
  129. }
  130.  
  131. @WebServlet(value = "/*", asyncSupported = true)
  132. @VaadinServletConfiguration(productionMode = false, ui = MyUI.class)
  133. public static class MyUIServlet extends VaadinServlet {
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement