dhbw.clippinggorilla.userinterface.views.AboutUsView.java Source code

Java tutorial

Introduction

Here is the source code for dhbw.clippinggorilla.userinterface.views.AboutUsView.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dhbw.clippinggorilla.userinterface.views;

import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;
import dhbw.clippinggorilla.utilities.language.Language;
import dhbw.clippinggorilla.utilities.language.Word;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/**
 * This is the class for the About us View
 *
 * @author frank
 */
public class AboutUsView extends VerticalLayout {

    private static final HashMap<VaadinSession, AboutUsView> SESSIONS = new HashMap<>();

    public static AboutUsView getCurrent() {
        return new AboutUsView();
    }

    public AboutUsView() {
        setMargin(true);
        setWidth("55%");

        Label aboutUsHeader = new Label();
        Language.set(Word.ABOUT_US, aboutUsHeader);
        aboutUsHeader.setStyleName(ValoTheme.LABEL_H1);
        addComponent(aboutUsHeader);

        Label aboutUsGroupHeadline = new Label();
        Language.set(Word.GROUP_PROJECT_OF_GROUP_4, aboutUsGroupHeadline);
        aboutUsGroupHeadline.setStyleName(ValoTheme.LABEL_H2);
        addComponent(aboutUsGroupHeadline);

        Label aboutUsText = new Label();
        Language.set(Word.GROUP_PROJECT_BODY, aboutUsText);
        aboutUsText.setWidth("100%");
        aboutUsText.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
        addComponent(aboutUsText);

        Label theTeamHeader = new Label();
        Language.set(Word.OUR_TEAM, theTeamHeader);
        theTeamHeader.setStyleName(ValoTheme.LABEL_H2);
        addComponent(theTeamHeader);

        Grid<Person> theTeamGrid = new Grid<>();
        List<Person> persons = Arrays.asList(new Person("Dan-Pierre", "Drehlich", Person.Function.TEAMLEADER),
                new Person("Stefan", "Schmid", Person.Function.RESPONSIBLE_FOR_RESEARCH),
                new Person("Jan", "Striegel", Person.Function.TECHNICAL_ASSISTANT),
                new Person("Lisa", "Hartung",
                        Person.Function.RESPONSIBLE_FOR_MODELING_QUALITY_ASSURANCE_AND_DOCUMENTATION),
                new Person("Tim", "Heinzelmann", Person.Function.RESPONSIBLE_FOR_TESTS),
                new Person("Josua", "Frank", Person.Function.RESPONSIBLE_FOR_IMPLEMENTATION));
        Grid.Column c1 = theTeamGrid.addColumn(p -> p.getFirstName());
        Language.setCustom(Word.FIRST_NAME, s -> c1.setCaption(s));
        Grid.Column c2 = theTeamGrid.addColumn(p -> p.getLastName());
        Language.setCustom(Word.LAST_NAME, s -> c2.setCaption(s));
        Grid.Column c3 = theTeamGrid.addColumn(p -> p.getResposibility());
        Language.setCustom(Word.RESPONSIBILITY, s -> {
            c3.setCaption(s);
            theTeamGrid.getDataProvider().refreshAll();
        });
        theTeamGrid.setItems(persons);
        theTeamGrid.setWidth("100%");
        theTeamGrid.setHeightByRows(6);
        addComponent(theTeamGrid);
        SESSIONS.put(VaadinSession.getCurrent(), this);
    }

    public static class Person implements Serializable {

        public static enum Function {
            TEAMLEADER, RESPONSIBLE_FOR_RESEARCH, TECHNICAL_ASSISTANT, RESPONSIBLE_FOR_MODELING_QUALITY_ASSURANCE_AND_DOCUMENTATION, RESPONSIBLE_FOR_TESTS, RESPONSIBLE_FOR_IMPLEMENTATION
        }

        String firstName;
        String lastName;
        Function responsibility;

        public Person(String firstName, String lastName, Function responsibility) {
            this.firstName = firstName;
            this.lastName = lastName;
            this.responsibility = responsibility;
        }

        public String getFirstName() {
            return firstName;
        }

        public String getLastName() {
            return lastName;
        }

        public String getResposibility() {
            return Language.get(Word.valueOf(responsibility.name()));
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 83 * hash + Objects.hashCode(this.firstName);
            hash = 83 * hash + Objects.hashCode(this.lastName);
            hash = 83 * hash + Objects.hashCode(this.responsibility);
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Person other = (Person) obj;
            if (!Objects.equals(this.firstName, other.firstName)) {
                return false;
            }
            if (!Objects.equals(this.lastName, other.lastName)) {
                return false;
            }
            return this.responsibility == other.responsibility;
        }

    }

}