1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.poc;
35
36 import static com.vaadin.server.Sizeable.Unit.*;
37
38 import info.magnolia.poc.extensions.StringFieldValidationExtension;
39
40 import java.util.stream.Collectors;
41 import java.util.stream.Stream;
42 import java.util.stream.StreamSupport;
43
44 import javax.servlet.annotation.WebServlet;
45
46 import org.vaadin.aceeditor.AceEditor;
47 import org.vaadin.aceeditor.AceMode;
48
49 import com.explicatis.ext_token_field.ExtTokenField;
50 import com.explicatis.ext_token_field.SimpleTokenizable;
51 import com.vaadin.annotations.Theme;
52 import com.vaadin.annotations.Title;
53 import com.vaadin.annotations.VaadinServletConfiguration;
54 import com.vaadin.annotations.Widgetset;
55 import com.vaadin.data.validator.StringLengthValidator;
56 import com.vaadin.server.VaadinRequest;
57 import com.vaadin.server.VaadinServlet;
58 import com.vaadin.ui.Button;
59 import com.vaadin.ui.ComboBox;
60 import com.vaadin.ui.FormLayout;
61 import com.vaadin.ui.PasswordField;
62 import com.vaadin.ui.UI;
63 import com.vaadin.ui.VerticalLayout;
64
65 @Theme("poctheme")
66 @Title("Magnolia 6 Resurface - Special Fields Components")
67 @Widgetset("info.magnolia.poc.Widgetset")
68 public class SpecialFieldsComponentUI extends UI {
69
70 @Override
71 protected void init(VaadinRequest vaadinRequest) {
72
73 FormLayout layout = new FormLayout();
74 layout.setMargin(true);
75 layout.setWidth(926, PIXELS);
76
77 AceEditor codeField = new AceEditor();
78 codeField.setStyleName("textcodefield");
79 codeField.setUseWorker(false);
80 codeField.setCaption("Code field");
81 codeField.setValue("class Resurface {\n" +
82 "\t{\n" +
83 "\t\tSystem.out.println(\"Hello Resurface\");\n" +
84 "\t}\n" +
85 "}\n");
86
87 String aceResourcePath = "/VAADIN/ace";
88 codeField.setModePath(aceResourcePath);
89 codeField.setWorkerPath(aceResourcePath);
90 codeField.setThemePath(aceResourcePath);
91 codeField.setMode(AceMode.java);
92
93 VerticalLayout passwordFieldLayout = new VerticalLayout();
94 passwordFieldLayout.setCaption("Password field");
95
96 PasswordField passwordField = new PasswordField("Please verify your entry");
97 passwordField.setValue("password");
98
99 PasswordField invalidPasswordField = new PasswordField("Please verify your entry");
100 final StringLengthValidator lengthValidator = new StringLengthValidator("Sorry, incorrect password.", 10, 100);
101 StringFieldValidationExtension.extendValidationFor(invalidPasswordField, lengthValidator);
102 invalidPasswordField.setValue("password");
103
104 passwordFieldLayout.addComponents(passwordField, invalidPasswordField);
105
106 ExtTokenField tokenField = new ExtTokenField();
107 tokenField.setCaption("Tag field");
108 tokenField.setEnableDefaultDeleteTokenAction(true);
109 tokenField.setTokenDragDropEnabled(true);
110
111 String[] tokens = {"adventure", "family", "kids", "asia", "travel", "active", "beach", "cultural", "off-path"};
112 ComboBox<SimpleTokenizable> comboBox = new ComboBox<>("", Stream.of(tokens)
113 .sorted()
114 .map(token -> new SimpleTokenizable(token.hashCode(), token))
115 .collect(Collectors.toList()));
116 comboBox.setItemCaptionGenerator(SimpleTokenizable::getStringValue);
117 comboBox.setEmptySelectionAllowed(false);
118 comboBox.addValueChangeListener(event -> {
119 if (event.getValue() != null) {
120 tokenField.addTokenizable(event.getValue());
121 event.getSource().setValue(null);
122 }
123 });
124 tokenField.setInputField(comboBox);
125 Stream.of(tokens)
126 .limit(5)
127 .map(token -> new SimpleTokenizable(token.hashCode(), token))
128 .collect(Collectors.toList())
129 .forEach(tokenField::addTokenizable);
130
131 layout.addComponents(
132 codeField,
133 passwordFieldLayout,
134 tokenField
135 );
136
137 StreamSupport.stream(layout.spliterator(), false)
138 .filter(component -> !(component instanceof Button))
139 .forEach(component -> component.setWidth(100, PERCENTAGE));
140
141 setContent(layout);
142 }
143
144 @WebServlet(value = "/special/*", asyncSupported = true)
145 @VaadinServletConfiguration(productionMode = false, ui = SpecialFieldsComponentUI.class)
146 public static class Servlet extends VaadinServlet {
147 }
148 }