Beispiel #1
0
  @Override
  public void enter(ViewChangeEvent event) {

    List<Mark> marks = Mark.loadAll();

    final User user = ui.getCurrentUser();
    boolean bustsOnMap = false;

    for (int i = marks.size() - 1; i >= 0; i--) {
      final Mark m = marks.get(i);

      if (!m.isApproved()) {
        if (user.isAdmin()) {
          CustomLayout layout = new CustomLayout("suggested-mark-row");
          Button title = new Button(marks.get(i).getTitle());
          title.setStyleName("mark-title");
          final int id = marks.get(i).getId();
          title.addClickListener(
              new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                  UI.getCurrent().getNavigator().navigateTo("suggestedmark/" + id);
                  // Notification.show("Title clicked");
                }
              });
          layout.addComponent(title, "suggested-mark-row-title");
          marksList.addComponent(layout);
          hasVisibleSuggestedMarks = true;
        }
        continue;
      }

      CustomLayout layout = new CustomLayout("mark-row");

      // Button to show BustsSubview with Busts under the clicked Mark
      int count = m.getBusts().size();
      Button title = new Button(marks.get(i).getTitle() + " (" + count + ")");
      title.setStyleName("mark-title");
      final int id = marks.get(i).getId();
      title.addClickListener(
          new Button.ClickListener() {

            public void buttonClick(ClickEvent event) {
              UI.getCurrent().getNavigator().navigateTo("busts/" + id + "/");
              // Notification.show("Title clicked");
            }
          });

      final Label voteCount = new Label((int) m.getVoteCount() + "");
      voteCount.setStyleName("vote-count");

      // Button to give upvote to Mark
      final Button upvoteButton = new VoteButton(m, VoteButton.Type.UP);
      upvoteButton.addClickListener(
          new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
              voteCount.setValue((int) m.getVoteCount() + "");
            }
          });

      // Button to give downvote to Mark
      final Button downvoteButton = new VoteButton(m, VoteButton.Type.DOWN);
      downvoteButton.addClickListener(
          new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
              voteCount.setValue((int) m.getVoteCount() + "");
            }
          });

      layout.addComponent(upvoteButton, "mark-row-upvote-arrow");
      layout.addComponent(voteCount, "mark-row-vote-count");
      layout.addComponent(downvoteButton, "mark-row-downvote-arrow");
      layout.addComponent(title, "mark-row-title");

      marksList.addComponent(layout);

      if (!bustsOnMap && count > 0) {
        ui.showBusts(marks.get(i));
        bustsOnMap = true;
      }
    }

    loginListener.login(null); // force login actions
  }
  /**
   * Constructor of the class
   *
   * @param nav
   * @param m
   */
  public Login(FatNavigator nav) {
    this.navigator = nav;

    // HTML Design
    InputStream layoutFile = getClass().getResourceAsStream("startpage.html");
    layout = null;
    try {
      layout = new CustomLayout(layoutFile);
    } catch (Exception e) {
      System.out.println("there was a problem");
    }
    layout.addStyleName("sada");

    // Layout Components
    Button okbutton = new Button("Login");
    okbutton.setClickShortcut(KeyCode.ENTER, null);
    textfield_user = new TextField();
    textfield_password = new PasswordField();
    Button neuerBenutzer = new Button("Neu?");
    textfield_user.setRequired(true);
    textfield_user.setRequiredError("Please set the Username");

    // Adding Components
    layout.addComponent(new Label("LOG IN"));
    layout.addComponent(textfield_user, "username");
    layout.addComponent(textfield_password, "password");
    layout.addComponent(okbutton, "okbutton");
    layout.addComponent(neuerBenutzer, "neuerBenutzer");

    // adding layout to webpage
    this.addComponent(layout);

    // Register Button Listener
    neuerBenutzer.addClickListener(new PinkShoes(navigator, Variables.REGISTER));

    // Login Listener
    okbutton.addClickListener(
        new Button.ClickListener() {
          public void buttonClick(ClickEvent event) {

            // Fetching value
            String inputUsername = textfield_user.getValue();
            String pw = textfield_password.getValue();

            // fetching all the users out of the DB
            List<User> res = QueryHelper.executeBasic("getUsers");

            // checking if username is known
            boolean found_user = false;
            for (User user : res) {
              if ((inputUsername.equals(user.getUsername()))) {
                found_user = true;

                if (user.getPassword().equals(pw)) {

                  // log in successful
                  String user_id = user.getID().longValue() + "";

                  // Navigate to startpage
                  new PinkShoes(navigator, Variables.STARTPAGE, inputUsername, user_id)
                      .navigation();
                } else {
                  Notification.show("False password", Notification.TYPE_WARNING_MESSAGE);
                }
              }
            }

            // Message
            if (!found_user) {
              Notification.show("Could not find username - please register! :)");
            }
          }
        });
  }