Exemple #1
0
  public StartView() {
    setSizeFull();
    setMargin(true);

    // Create a panel called login
    Panel panel = new Panel("Login");
    panel.setSizeUndefined(); // Shrink to fit content
    addComponent(panel);

    setComponentAlignment(panel, Alignment.MIDDLE_CENTER);

    // Create the content
    FormLayout content = new FormLayout();

    username.setWidth("300px");
    username.setRequired(true);
    username.setInputPrompt("Your username(eg. [email protected])");

    content.addComponent(username);

    password.setWidth("300px");
    password.setRequired(true);

    content.addComponent(password);

    HorizontalLayout buttonArea = new HorizontalLayout();
    buttonArea.setSizeFull();
    Button submit = new Button("Submit");
    Button clear = new Button("Clear");
    clear.addClickListener(
        new Button.ClickListener() {
          public void buttonClick(ClickEvent event) {
            username.setValue("");
            password.setValue("");
          }
        });

    submit.addClickListener(
        new Button.ClickListener() {
          public void buttonClick(ClickEvent event) {
            checkDatabase(username.getValue(), password.getValue());
          }
        });

    buttonArea.addComponent(clear);
    buttonArea.addComponent(submit);

    content.addComponent(buttonArea);
    content.setSizeFull();
    content.setMargin(true);

    panel.setContent(content);
  }
  public LoginViewImpl() {
    setSizeFull();

    login.setIcon(FontAwesome.HAND_O_RIGHT);

    // TODO remove these prefilled values used for testing
    username.setValue("admin");
    password.setValue("password");
    password.focus();

    Panel loginPanel = new Panel("Login to application");
    loginPanel.setSizeUndefined();

    loginPanel.setContent(
        new MVerticalLayout(username, password, login).withAlign(login, Alignment.BOTTOM_RIGHT));

    setCompositionRoot(
        new MVerticalLayout(loginPanel)
            .withAlign(loginPanel, Alignment.MIDDLE_CENTER)
            .withFullHeight());
  }
    public Layout buildLayout() {
      VerticalLayout layout = new VerticalLayout();
      VerticalLayout panelLayout = new VerticalLayout();
      panelLayout.setMargin(true);
      final Panel widePanel = new Panel("too big", panelLayout);
      widePanel.setSizeUndefined();
      widePanel.setWidth("2000px");
      widePanel.setHeight("200px");
      layout.addComponent(widePanel);
      Button button =
          new Button(
              "Change panel size",
              new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                  switch (step++ % 4) {
                    case 0:
                      widePanel.setWidth("200px");
                      break;
                    case 1:
                      widePanel.setHeight("2000px");
                      break;
                    case 2:
                      widePanel.setWidth("2000px");
                      break;
                    case 3:
                      widePanel.setHeight("200px");
                      break;
                  }
                }
              });
      panelLayout.addComponent(button);
      layout.setSizeUndefined();
      return layout;
    }
  private void buildView() {
    // main frame
    Panel pane = new Panel("Create New Password");
    pane.setSizeUndefined();

    // form layout
    mnth_sel = new NativeSelect("Birth Month");
    mnth_sel.addItems(
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December");
    mnth_sel.setValue("January");
    mnth_sel.setMultiSelect(false);
    mnth_sel.setNullSelectionAllowed(false);
    mnth_sel.setImmediate(true);

    day_sel = new NativeSelect("Birth Day");
    for (int i = 0; i < 31; i++) day_sel.addItem(i + 1);
    day_sel.setValue(1);
    day_sel.setMultiSelect(false);
    day_sel.setNullSelectionAllowed(false);
    day_sel.setImmediate(true);

    FormLayout form = new FormLayout();
    form.setSizeUndefined();
    form.addComponent(mnth_sel);
    form.addComponent(day_sel);

    // content layout
    info = new Label();
    info.setSizeUndefined();
    info.setValue("Please fill in all fields below");

    question_txt = new TextArea("Security Question");
    question_txt.setValue(emp.getRandomQuestion()); // query user for security question
    question_txt.setReadOnly(true);
    question_txt.setRows(2);
    question_txt.setWidth("20em");

    ans_txt = new TextArea("Answer");
    ans_txt.setRows(2);
    ans_txt.setWidth("20em");

    Label gap = new Label();
    gap.setHeight("1em");

    submit = new Button("Continue");
    submit.setDescription("Continue password creation!");
    submit.setSizeFull();
    submit.setStyleName("primary");

    cancel = new Button("Cancel");
    cancel.setDescription("Return to login screen!");
    cancel.setSizeFull();

    VerticalLayout content = new VerticalLayout();
    content.setSizeUndefined();
    content.setSpacing(true);
    content.setMargin(true);
    content.addComponent(info);
    content.setComponentAlignment(info, Alignment.MIDDLE_CENTER);
    content.addComponent(form);
    content.addComponent(question_txt);
    content.addComponent(ans_txt);
    content.addComponent(gap);
    content.addComponent(submit);
    content.addComponent(cancel);

    // add 'content' to 'main frame'
    pane.setContent(content);

    // root layout
    this.setMargin(true);
    this.addComponent(pane);
    this.setComponentAlignment(pane, Alignment.TOP_CENTER);

    //
    // user interaction
    //
    submit.addClickListener(event -> handleSubmit(event));
    cancel.addClickListener(event -> handleCancel(event));
  }