Java tutorial
/* * 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.shared.ui.ContentMode; import com.vaadin.ui.Component; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; 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.util.Arrays; import java.util.List; import java.io.Serializable; import java.util.HashMap; import java.util.Objects; /** * This is the class for the Impressum View * * @author frank */ public class ImpressumView extends VerticalLayout { private static final HashMap<VaadinSession, ImpressumView> SESSIONS = new HashMap<>(); public static ImpressumView getCurrent() { return new ImpressumView(); } public ImpressumView() { setMargin(true); setWidth("55%"); Label impressumHeader = new Label(); Language.set(Word.IMPRESSUM, impressumHeader); impressumHeader.setStyleName(ValoTheme.LABEL_H1); addComponent(impressumHeader); Label impressumText = new Label(); Language.set(Word.IMPRESSUM_BODY, impressumText); impressumText.setWidth("100%"); impressumText.setContentMode(com.vaadin.shared.ui.ContentMode.HTML); addComponent(impressumText); Grid<Person> studentsGrid = 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)); Column c1 = studentsGrid.addColumn(p -> p.getFirstName()); Language.setCustom(Word.FIRST_NAME, s -> c1.setCaption(s)); Column c2 = studentsGrid.addColumn(p -> p.getLastName()); Language.setCustom(Word.LAST_NAME, s -> c2.setCaption(s)); Column c3 = studentsGrid.addColumn(p -> p.getResposibility()); Language.setCustom(Word.RESPONSIBILITY, s -> { c3.setCaption(s); studentsGrid.getDataProvider().refreshAll(); }); studentsGrid.setItems(persons); studentsGrid.setWidth("100%"); studentsGrid.setHeightByRows(6); addComponent(studentsGrid); Label liabilityHeadline = new Label(); Language.set(Word.LIABILITY, liabilityHeadline); liabilityHeadline.setStyleName(ValoTheme.LABEL_H1); addComponent(liabilityHeadline); Label liabilityContentHeadline = new Label(); Language.set(Word.LIABILITY_CONTENT, liabilityContentHeadline); liabilityContentHeadline.setStyleName(ValoTheme.LABEL_H2); addComponent(liabilityContentHeadline); Label liabilityContentText = new Label(); Language.set(Word.LIABILITY_CONTENT_BODY, liabilityContentText); liabilityContentText.setWidth("100%"); addComponent(liabilityContentText); Label liabilityLinksHeadline = new Label(); Language.set(Word.LIABILITY_LINKS, liabilityLinksHeadline); liabilityLinksHeadline.setStyleName(ValoTheme.LABEL_H2); addComponent(liabilityLinksHeadline); Label liabilityLinksText = new Label(); Language.set(Word.LIABILITY_LINKS_BODY, liabilityLinksText); liabilityLinksText.setWidth("100%"); addComponent(liabilityLinksText); Label copyrightHeadline = new Label(); Language.set(Word.COPYRIGHT, copyrightHeadline); copyrightHeadline.setStyleName(ValoTheme.LABEL_H2); addComponent(copyrightHeadline); Label copyrightText = new Label(); Language.set(Word.COPYRIGHT_BODY, copyrightText); copyrightText.setWidth("100%"); addComponent(copyrightText); Label dataProtectionHeadline = new Label(); Language.set(Word.DATAPROTECTION, dataProtectionHeadline); dataProtectionHeadline.setStyleName(ValoTheme.LABEL_H2); addComponent(dataProtectionHeadline); Label dataProtectionText = new Label(); Language.set(Word.DATAPROTECTION_BODY, dataProtectionText); dataProtectionText.setWidth("100%"); addComponent(dataProtectionText); 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; } } }