summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-02-07 18:30:54 +0200
committerTeemu Suo-Anttila <teemusa@vaadin.com>2016-05-11 14:47:08 +0300
commitb3b5c062b02ca5edfc5527090c027145704ee51a (patch)
tree138766400e5e6c20cdec27fa3df2777c75570ef1 /uitest
parent19ad71e9e21dfea2dd756f96e473e00c3077f35a (diff)
downloadvaadin-framework-b3b5c062b02ca5edfc5527090c027145704ee51a.tar.gz
vaadin-framework-b3b5c062b02ca5edfc5527090c027145704ee51a.zip
Use error styles for NativeSelect/ListSelect/TwinColSelect in Valo (#19550)
Change-Id: Ifc87f48b8145b56c7b83b9ce4aa1db8a698d7d49
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/validation/FieldErrorIndication.java115
1 files changed, 115 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/validation/FieldErrorIndication.java b/uitest/src/main/java/com/vaadin/tests/validation/FieldErrorIndication.java
new file mode 100644
index 0000000000..3135ce0592
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/validation/FieldErrorIndication.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.validation;
+
+import java.util.Set;
+
+import com.vaadin.data.Validator;
+import com.vaadin.data.validator.StringLengthValidator;
+import com.vaadin.server.UserError;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.AbstractField;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.ListSelect;
+import com.vaadin.ui.NativeSelect;
+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.VerticalLayout;
+
+public class FieldErrorIndication extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ HorizontalLayout hl = new HorizontalLayout();
+ addComponent(hl);
+
+ VerticalLayout vl = new VerticalLayout();
+ hl.addComponent(vl);
+
+ ComboBox comboBox = new ComboBox("ComboBox");
+ comboBox.addItem("ok");
+ comboBox.addItem("error");
+ comboBox.addValidator(new StringLengthValidator("fail", 0, 2, false));
+ comboBox.setValue("error");
+
+ ListSelect listSelect = new ListSelect("ListSelect");
+ listSelect.addItem("ok");
+ listSelect.addItem("error");
+ listSelect.addValidator(new StringLengthValidator("fail", 0, 2, false));
+ listSelect.setValue("error");
+
+ NativeSelect nativeSelect = new NativeSelect("NativeSelect");
+ nativeSelect.addItem("ok");
+ nativeSelect.addItem("error");
+ nativeSelect
+ .addValidator(new StringLengthValidator("fail", 0, 2, false));
+ nativeSelect.setValue("error");
+ TwinColSelect twinColSelect = new TwinColSelect("TwinColSelect");
+ twinColSelect.addItem("ok");
+ twinColSelect.addItem("error");
+ twinColSelect.addValidator(new Validator() {
+
+ @Override
+ public void validate(Object value) throws InvalidValueException {
+ if (value instanceof Set && ((Set) value).size() == 1
+ && ((Set) value).contains("ok")) {
+ return;
+ }
+
+ throw new InvalidValueException("fail");
+ }
+
+ });
+ twinColSelect.setValue("error");
+
+ vl.addComponents(comboBox, listSelect, nativeSelect, twinColSelect);
+
+ Class<? extends AbstractField>[] textFields = new Class[] {
+ TextField.class, TextArea.class, RichTextArea.class,
+ PasswordField.class };
+ vl = new VerticalLayout();
+ hl.addComponent(vl);
+ for (Class<? extends Field> fieldClass : textFields) {
+ vl.addComponent(getField(fieldClass));
+ }
+
+ }
+
+ /**
+ * @since
+ * @param fieldClass
+ * @return
+ */
+ private Component getField(Class<? extends Field> fieldClass) {
+ AbstractField f;
+ try {
+ f = (AbstractField) fieldClass.newInstance();
+ f.setCaption(fieldClass.getSimpleName());
+ f.setComponentError(new UserError("fail"));
+ return f;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}