summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorMatti Hosio <mhosio@vaadin.com>2014-12-16 18:09:56 +0200
committerMatti Hosio <mhosio@vaadin.com>2014-12-16 18:09:56 +0200
commit8a0a1bdb4630f39214a039a2689bfa5a1431a413 (patch)
treeeee6dce4ccde342b5ecd6d876bcf0e41406848be /uitest
parent1ae161965d5b9b9bc6aae041ab80c906460ede83 (diff)
downloadvaadin-framework-8a0a1bdb4630f39214a039a2689bfa5a1431a413.tar.gz
vaadin-framework-8a0a1bdb4630f39214a039a2689bfa5a1431a413.zip
Improved potus demo (#7749)
Change-Id: I330d669238b2c79ca2afda396a5e07833f0af90a
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/declarative/Potus.java107
-rw-r--r--uitest/src/com/vaadin/tests/declarative/PotusCrud.html37
-rw-r--r--uitest/src/com/vaadin/tests/declarative/PotusCrud.java107
-rw-r--r--uitest/src/com/vaadin/tests/declarative/PotusCrudUI.java34
-rw-r--r--uitest/src/com/vaadin/tests/declarative/PotusForm.html16
-rw-r--r--uitest/src/com/vaadin/tests/declarative/PotusForm.java51
6 files changed, 320 insertions, 32 deletions
diff --git a/uitest/src/com/vaadin/tests/declarative/Potus.java b/uitest/src/com/vaadin/tests/declarative/Potus.java
new file mode 100644
index 0000000000..23448a9b7f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/declarative/Potus.java
@@ -0,0 +1,107 @@
+/*
+ * 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.declarative;
+
+import java.util.Date;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class Potus {
+ private String firstName;
+ private String lastName;
+ private String party;
+ private Date tookOffice;
+ private Date leftOffice;
+
+ /**
+ * @return the firstName
+ */
+ public String getFirstName() {
+ return firstName;
+ }
+
+ /**
+ * @param firstName
+ * the firstName to set
+ */
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ /**
+ * @return the lastName
+ */
+ public String getLastName() {
+ return lastName;
+ }
+
+ /**
+ * @param lastName
+ * the lastName to set
+ */
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ /**
+ * @return the party
+ */
+ public String getParty() {
+ return party;
+ }
+
+ /**
+ * @param party
+ * the party to set
+ */
+ public void setParty(String party) {
+ this.party = party;
+ }
+
+ /**
+ * @return the tookOffice
+ */
+ public Date getTookOffice() {
+ return tookOffice;
+ }
+
+ /**
+ * @param tookOffice
+ * the tookOffice to set
+ */
+ public void setTookOffice(Date tookOffice) {
+ this.tookOffice = tookOffice;
+ }
+
+ /**
+ * @return the leftOffice
+ */
+ public Date getLeftOffice() {
+ return leftOffice;
+ }
+
+ /**
+ * @param leftOffice
+ * the leftOffice to set
+ */
+ public void setLeftOffice(Date leftOffice) {
+ this.leftOffice = leftOffice;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/declarative/PotusCrud.html b/uitest/src/com/vaadin/tests/declarative/PotusCrud.html
index 1a73699b29..05acee9679 100644
--- a/uitest/src/com/vaadin/tests/declarative/PotusCrud.html
+++ b/uitest/src/com/vaadin/tests/declarative/PotusCrud.html
@@ -1,23 +1,14 @@
-<v-vertical-layout size-full margin="true" spacing>
- <v-horizontal-layout spacing margin width-full>
- <v-label size-auto>POTUS Database</v-label>
- <v-button :expand>Add new</v-button>
- </v-horizontal-layout>
- <v-table _id="potusList" :expand selectable size-full/>
- <v-vertical-layout _id="form" spacing margin>
- <v-horizontal-layout spacing>
- <v-text-field caption="First Name" width="300px" />
- <v-text-field caption="Last Name" width="300px" />
- </v-horizontal-layout>
- <v-horizontal-layout spacing>
- <v-combo-box caption="Party" width="300px" />
- <v-popup-date-field caption="Took Office" />
- <v-popup-date-field caption="Left Office" />
- </v-horizontal-layout>
- <v-horizontal-layout spacing width-full>
- <v-button style-name="primary">Save</v-button>
- <v-button>Revert</v-button>
- <v-button style-name="danger" :expand :right>Delete</v-button>
- </v-horizontal-layout>
- </v-vertical-layout>
-</v-vertical-layout>
+<head>
+ <meta name="package-mapping" content="x:com.vaadin.tests.declarative"/>
+</head>
+<body>
+ <v-vertical-layout size-full margin="true" spacing>
+ <v-horizontal-layout spacing margin width-full>
+ <v-label size-auto>POTUS Database</v-label>
+ <v-button :expand _id="addNew">Add new</v-button>
+ </v-horizontal-layout>
+ <v-table _id="potusList" :expand selectable size-full/>
+ <x-potus-form _id="potusForm" />
+ </v-vertical-layout>
+</body>
+
diff --git a/uitest/src/com/vaadin/tests/declarative/PotusCrud.java b/uitest/src/com/vaadin/tests/declarative/PotusCrud.java
index 3fc924fea4..76051525c0 100644
--- a/uitest/src/com/vaadin/tests/declarative/PotusCrud.java
+++ b/uitest/src/com/vaadin/tests/declarative/PotusCrud.java
@@ -15,18 +15,107 @@
*/
package com.vaadin.tests.declarative;
-import com.vaadin.annotations.Theme;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.ui.UI;
+import com.vaadin.annotations.DesignRoot;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.fieldgroup.FieldGroup;
+import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.declarative.Design;
-@Theme("valo")
-public class PotusCrud extends UI {
+@DesignRoot
+public class PotusCrud extends VerticalLayout {
- @Override
- protected void init(VaadinRequest request) {
- setContent(Design
- .read(getClass().getResourceAsStream("PotusCrud.html")));
+ public Table potusList;
+ public PotusForm potusForm;
+ public Button addNew;
+
+ private FieldGroup fg;
+
+ private BeanItemContainer<Potus> potusContainer = new BeanItemContainer<Potus>(
+ Potus.class);
+
+ public PotusCrud() {
+ Design.read(this);
+ init();
+ }
+
+ private void init() {
+ initTable();
+ initForm();
+ addNew.addClickListener(new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ doAdd();
+ }
+ });
+ }
+
+ private void initTable() {
+ potusList.setContainerDataSource(potusContainer);
+ potusList.addValueChangeListener(new ValueChangeListener() {
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ doEdit();
+ }
+ });
+ }
+
+ private void initForm() {
+ potusForm.save.addClickListener(new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ doSave();
+ }
+
+ });
+ potusForm.delete.addClickListener(new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ doDelete();
+ }
+ });
+ potusForm.revert.addClickListener(new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ doRevert();
+ }
+ });
+ }
+
+ protected void doRevert() {
+ fg.discard();
+ }
+
+ protected void doDelete() {
+ potusContainer.removeItem(potusList.getValue());
+ }
+
+ protected void doSave() {
+ try {
+ fg.commit();
+ } catch (CommitException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected void doAdd() {
+ potusContainer.addBean(new Potus());
+ }
+
+ protected void doEdit() {
+ if (potusList.getValue() != null) {
+ fg = new FieldGroup();
+ fg.setItemDataSource(potusList.getItem(potusList.getValue()));
+ fg.bindMemberFields(potusForm);
+ }
}
}
diff --git a/uitest/src/com/vaadin/tests/declarative/PotusCrudUI.java b/uitest/src/com/vaadin/tests/declarative/PotusCrudUI.java
new file mode 100644
index 0000000000..f1d94f7f16
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/declarative/PotusCrudUI.java
@@ -0,0 +1,34 @@
+/*
+ * 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.declarative;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.UI;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+@Theme("valo")
+public class PotusCrudUI extends UI {
+
+ @Override
+ protected void init(VaadinRequest request) {
+ setContent(new PotusCrud());
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/declarative/PotusForm.html b/uitest/src/com/vaadin/tests/declarative/PotusForm.html
new file mode 100644
index 0000000000..0542e1ee52
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/declarative/PotusForm.html
@@ -0,0 +1,16 @@
+<v-vertical-layout _id="form" spacing margin>
+ <v-horizontal-layout spacing>
+ <v-text-field _id="firstName" caption="First Name" null-representation="" width="300px" />
+ <v-text-field _id="lastName" caption="Last Name" null-representation="" width="300px" />
+ </v-horizontal-layout>
+ <v-horizontal-layout spacing>
+ <v-combo-box _id="party" caption="Party" width="300px" />
+ <v-popup-date-field _id="tookOffice" caption="Took Office" />
+ <v-popup-date-field _id="leftOffice" caption="Left Office" />
+ </v-horizontal-layout>
+ <v-horizontal-layout spacing width-full>
+ <v-button _id="save" style-name="primary">Save</v-button>
+ <v-button _id="revert">Revert</v-button>
+ <v-button _id="delete" style-name="danger" :expand :right>Delete</v-button>
+ </v-horizontal-layout>
+</v-vertical-layout> \ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/declarative/PotusForm.java b/uitest/src/com/vaadin/tests/declarative/PotusForm.java
new file mode 100644
index 0000000000..506a25f663
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/declarative/PotusForm.java
@@ -0,0 +1,51 @@
+/*
+ * 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.declarative;
+
+import com.vaadin.annotations.DesignRoot;
+import com.vaadin.data.fieldgroup.PropertyId;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.PopupDateField;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.declarative.Design;
+
+@DesignRoot
+public class PotusForm extends VerticalLayout {
+
+ @PropertyId("firstName")
+ public TextField firstName;
+ @PropertyId("lastName")
+ public TextField lastName;
+ @PropertyId("party")
+ public ComboBox party;
+ @PropertyId("tookOffice")
+ public PopupDateField tookOffice;
+ @PropertyId("leftOffice")
+ public PopupDateField leftOffice;
+
+ public Button save;
+ public Button revert;
+ public Button delete;
+
+ public PotusForm() {
+ Design.read(this);
+ party.addItems("Democratic Party");
+ party.addItems("Republican Party");
+ party.addItems("Independent");
+ }
+}