Introduction to Vaadin (#2247)

* deleted OpenNLP

* Introduction to Vaadin
This commit is contained in:
Jesus Boadas 2017-07-10 12:11:23 -04:00 committed by maibin
parent ecac42f3a1
commit 54c6928bfe
9 changed files with 13552 additions and 2 deletions

View File

@ -71,9 +71,78 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- Vaadin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>update-theme</goal>
<goal>update-widgetset</goal>
<goal>compile</goal>
<goal>compile-theme</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>src/main/webapp/VAADIN/themes</directory>
<includes>
<include>**/styles.css</include>
<include>**/styles.scss.cache</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- /Vaadin -->
</plugins> </plugins>
</build> </build>
<!-- Vaadin -->
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- /Vaadin -->
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/cglib/cglib --> <!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency> <dependency>
@ -379,6 +448,72 @@
<version>${org.hamcrest.java-hamcrest.version}</version> <version>${org.hamcrest.java-hamcrest.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- Vaadin -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-push</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-common</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.4.0</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<!-- /Vaadin -->
</dependencies> </dependencies>
<properties> <properties>
<multiverse.version>0.7.0</multiverse.version> <multiverse.version>0.7.0</multiverse.version>
@ -412,6 +547,52 @@
<pact.version>3.5.0</pact.version> <pact.version>3.5.0</pact.version>
<awaitility.version>3.0.0</awaitility.version> <awaitility.version>3.0.0</awaitility.version>
<org.hamcrest.java-hamcrest.version>2.0.0.0</org.hamcrest.java-hamcrest.version> <org.hamcrest.java-hamcrest.version>2.0.0.0</org.hamcrest.java-hamcrest.version>
<!-- Vaadin -->
<vaadin.version>7.7.10</vaadin.version>
<vaadin.plugin.version>8.0.6</vaadin.plugin.version>
<vaadin.theme>mytheme</vaadin.theme>
<!-- /Vaadin -->
</properties> </properties>
<profiles>
<!-- Vaadin -->
<profile>
<id>vaadin-prerelease</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<repositories>
<repository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</repository>
<repository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</pluginRepository>
<pluginRepository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<!-- Vaadin -->
</profiles>
</project> </project>

View File

@ -0,0 +1,221 @@
package com.baeldung.vaadin;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.FontAwesome;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.DateField;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.Grid;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.NativeButton;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.TwinColSelect;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
@Theme("mytheme")
public class VaadinUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.setSpacing(true);
verticalLayout.setMargin(true);
final GridLayout gridLayout = new GridLayout(3,2);
gridLayout.setSpacing(true);
gridLayout.setMargin(true);
final HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.setSpacing(true);
horizontalLayout.setMargin(true);
final FormLayout formLayout = new FormLayout();
formLayout.setSpacing(true);
formLayout.setMargin(true);
final GridLayout buttonLayout = new GridLayout(3, 5);
buttonLayout.setMargin(true);
buttonLayout.setSpacing(true);
final Label label = new Label();
label.setId("Label");
label.setValue("Label Value");
label.setCaption("Label");
gridLayout.addComponent(label);
final Link link = new Link("Baeldung",
new ExternalResource("http://www.baeldung.com/"));
link.setId("Link");
link.setTargetName("_blank");
gridLayout.addComponent(link);
final TextField textField = new TextField();
textField.setId("TextField");
textField.setCaption("TextField:");
textField.setValue("TextField Value");
textField.setIcon(FontAwesome.USER);
gridLayout.addComponent(textField);
final TextArea textArea = new TextArea();
textArea.setCaption("TextArea");
textArea.setId("TextArea");
textArea.setValue("TextArea Value");
gridLayout.addComponent(textArea);
final DateField dateField = new DateField("DateField", new Date(0));
dateField.setId("DateField");
gridLayout.addComponent(dateField);
final PasswordField passwordField = new PasswordField();
passwordField.setId("PasswordField");
passwordField.setCaption("PasswordField:");
passwordField.setValue("password");
gridLayout.addComponent(passwordField);
final RichTextArea richTextArea = new RichTextArea();
richTextArea.setCaption("Rich Text Area");
richTextArea.setValue("<h1>RichTextArea</h1>");
richTextArea.setSizeFull();
Panel richTextPanel = new Panel();
richTextPanel.setContent(richTextArea);
final InlineDateField inlineDateField = new InlineDateField();
inlineDateField.setValue(new Date(0));
inlineDateField.setCaption("Inline Date Field");
horizontalLayout.addComponent(inlineDateField);
Button normalButton = new Button("Normal Button");
normalButton.setId("NormalButton");
normalButton.addClickListener(e -> {
label.setValue("CLICK");
});
buttonLayout.addComponent(normalButton);
Button tinyButton = new Button("Tiny Button");
tinyButton.addStyleName("tiny");
buttonLayout.addComponent(tinyButton);
Button smallButton = new Button("Small Button");
smallButton.addStyleName("small");
buttonLayout.addComponent(smallButton);
Button largeButton = new Button("Large Button");
largeButton.addStyleName("large");
buttonLayout.addComponent(largeButton);
Button hugeButton = new Button("Huge Button");
hugeButton.addStyleName("huge");
buttonLayout.addComponent(hugeButton);
Button disabledButton = new Button("Disabled Button");
disabledButton.setDescription("This button cannot be clicked");
disabledButton.setEnabled(false);
buttonLayout.addComponent(disabledButton);
Button dangerButton = new Button("Danger Button");
dangerButton.addStyleName("danger");
buttonLayout.addComponent(dangerButton);
Button friendlyButton = new Button("Friendly Button");
friendlyButton.addStyleName("friendly");
buttonLayout.addComponent(friendlyButton);
Button primaryButton = new Button("Primary Button");
primaryButton.addStyleName("primary");
buttonLayout.addComponent(primaryButton);
NativeButton nativeButton = new NativeButton("Native Button");
buttonLayout.addComponent(nativeButton);
Button iconButton = new Button("Icon Button");
iconButton.setIcon(FontAwesome.ALIGN_LEFT);
buttonLayout.addComponent(iconButton);
Button borderlessButton = new Button("BorderLess Button");
borderlessButton.addStyleName("borderless");
buttonLayout.addComponent(borderlessButton);
Button linkButton = new Button("Link Button");
linkButton.addStyleName("link");
buttonLayout.addComponent(linkButton);
Button quietButton = new Button("Quiet Button");
quietButton.addStyleName("quiet");
buttonLayout.addComponent(quietButton);
horizontalLayout.addComponent(buttonLayout);
final CheckBox checkbox = new CheckBox("CheckBox");
checkbox.setValue(true);
checkbox.addValueChangeListener(e ->
checkbox.setValue(!checkbox.getValue()));
formLayout.addComponent(checkbox);
List<String> numbers = new ArrayList<String>();
numbers.add("One");
numbers.add("Ten");
numbers.add("Eleven");
ComboBox comboBox = new ComboBox("ComboBox");
comboBox.addItems(numbers);
formLayout.addComponent(comboBox);
ListSelect listSelect = new ListSelect("ListSelect");
listSelect.addItems(numbers);
listSelect.setRows(2);
formLayout.addComponent(listSelect);
NativeSelect nativeSelect = new NativeSelect("NativeSelect");
nativeSelect.addItems(numbers);
formLayout.addComponent(nativeSelect);
TwinColSelect twinColSelect = new TwinColSelect("TwinColSelect");
twinColSelect.addItems(numbers);
Grid grid = new Grid("Grid");
grid.setColumns(new Object[] {"Column1", "Column2", "Column3"});
grid.addRow(new Object[] {"Item1", "Item2", "Item3"});
grid.addRow(new Object[] {"Item4", "Item5", "Item6"});
Panel panel = new Panel("Panel");
panel.setContent(grid);
panel.setSizeUndefined();
verticalLayout.addComponent(gridLayout);
verticalLayout.addComponent(richTextPanel);
verticalLayout.addComponent(horizontalLayout);
verticalLayout.addComponent(formLayout);
verticalLayout.addComponent(twinColSelect);
verticalLayout.addComponent(panel);
setContent(verticalLayout);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = VaadinUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}

View File

@ -0,0 +1,7 @@
/* This file is automatically managed and will be overwritten from time to time. */
/* Do not manually edit this file. */
/* Import and include this mixin into your project theme to include the addon themes */
@mixin addons {
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -0,0 +1,38 @@
// If you edit this file you need to compile the theme. See README.md for details.
// Global variable overrides. Must be declared before importing Valo.
// Defines the plaintext font size, weight and family. Font size affects general component sizing.
//$v-font-size: 16px;
//$v-font-weight: 300;
//$v-font-family: "Open Sans", sans-serif;
// Defines the border used by all components.
//$v-border: 1px solid (v-shade 0.7);
//$v-border-radius: 4px;
// Affects the color of some component elements, e.g Button, Panel title, etc
//$v-background-color: hsl(210, 0%, 98%);
// Affects the color of content areas, e.g Panel and Window content, TextField input etc
//$v-app-background-color: $v-background-color;
// Affects the visual appearance of all components
//$v-gradient: v-linear 8%;
//$v-bevel-depth: 30%;
//$v-shadow-opacity: 5%;
// Defines colors for indicating status (focus, success, failure)
//$v-focus-color: valo-focus-color(); // Calculates a suitable color automatically
//$v-friendly-color: #2c9720;
//$v-error-indicator-color: #ed473b;
// For more information, see: https://vaadin.com/book/-/page/themes.valo.html
// Example variants can be copy/pasted from https://vaadin.com/wiki/-/wiki/Main/Valo+Examples
@import "../valo/valo.scss";
@mixin mytheme {
@include valo;
// Insert your own theme rules here
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
@import "mytheme.scss";
@import "addons.scss";
// This file prefixes all rules with the theme name to avoid causing conflicts with other themes.
// The actual styles should be defined in mytheme.scss
.mytheme {
@include addons;
@include mytheme;
}

View File

@ -0,0 +1,7 @@
/* This file is automatically managed and will be overwritten from time to time. */
/* Do not manually edit this file. */
/* Import and include this mixin into your project theme to include the addon themes */
@mixin addons {
}

View File

@ -0,0 +1,99 @@
package com.baeldung.vaadin;
import static org.junit.Assert.assertEquals;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.vaadin.server.DefaultUIProvider;
import com.vaadin.server.VaadinServlet;
public class VaadinUITests {
private WebDriver driver;
private Server server;
@Before
public void setUp() throws Exception{
startJettyServer();
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45,true);
driver.get("http://localhost:8080");
Thread.sleep(10000);
}
@Test
public void whenPageLoadedThenShouldSeeURL(){
String url = driver.getCurrentUrl();
assertEquals("http://localhost:8080/", url);
}
@Test
public void givenLabel_WhenGetValue_ThenValueMatch() {
WebElement label = driver.findElement(By.id("Label"));
assertEquals("Label Value", label.getText());
}
@Test
public void givenTextField_WhenGetValue_ThenValueMatch() {
WebElement textField = driver.findElement(By.id("TextField"));
assertEquals("TextField Value", textField.getAttribute("Value"));
}
@Test
public void givenTextArea_WhenGetValue_ThenValueMatch() {
WebElement textArea = driver.findElement(By.id("TextArea"));
assertEquals("TextArea Value", textArea.getAttribute("Value"));
}
@Test
public void givenDateField_WhenGetValue_ThenValueMatch() {
WebElement dateField = driver.findElement(By.id("DateField"));
assertEquals("12/31/69", dateField.getText());
}
@Test
public void givenPasswordField_WhenGetValue_ThenValueMatch() {
WebElement passwordField = driver.findElement(By.id("PasswordField"));
assertEquals("password", passwordField.getAttribute("Value"));
}
@After
public void cleanUp() throws Exception{
driver.close();
server.stop();
}
public void startJettyServer() throws Exception{
int maxThreads = 100;
int minThreads = 10;
int idleTimeout = 120;
QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads, minThreads, idleTimeout);
server = new Server(threadPool);
ServerConnector connector = new ServerConnector(server);
connector.setPort(8080);
server.setConnectors(new Connector[]{connector});
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
ServletHolder sh = new ServletHolder(new VaadinServlet());
contextHandler.addServlet(sh, "/*");
contextHandler.setInitParameter("ui", VaadinUI.class.getName());
contextHandler.setInitParameter(VaadinServlet.SERVLET_PARAMETER_UI_PROVIDER, DefaultUIProvider.class.getName());
server.setHandler(contextHandler);
server.start();
}
}