diff options
author | Artur Signell <artur@vaadin.com> | 2014-12-18 08:29:56 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-12-18 08:29:56 +0000 |
commit | 8e4ae3425733bdfdf05c1b9bd5125b35bcb5dce7 (patch) | |
tree | 3d91fc02f743e1c7065c9b63aa424a138e31c827 /uitest | |
parent | 8742e11f7cdd6b8f91d593b459ff4a0e9875754e (diff) | |
parent | ecb4c6e4e4b5ce50e85b5665d3a1f116081b0640 (diff) | |
download | vaadin-framework-8e4ae3425733bdfdf05c1b9bd5125b35bcb5dce7.tar.gz vaadin-framework-8e4ae3425733bdfdf05c1b9bd5125b35bcb5dce7.zip |
Merge "Merge remote-tracking branch 'origin/declarative'"
Diffstat (limited to 'uitest')
8 files changed, 502 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/declarative/DeclarativeEditor.java b/uitest/src/com/vaadin/tests/declarative/DeclarativeEditor.java new file mode 100644 index 0000000000..17942ee201 --- /dev/null +++ b/uitest/src/com/vaadin/tests/declarative/DeclarativeEditor.java @@ -0,0 +1,133 @@ +/* + * 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.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.apache.commons.io.IOUtils; +import org.apache.tools.ant.filters.StringInputStream; + +import com.vaadin.annotations.Theme; +import com.vaadin.data.Property.ReadOnlyException; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.Property.ValueChangeNotifier; +import com.vaadin.event.FieldEvents.TextChangeEvent; +import com.vaadin.event.FieldEvents.TextChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Component; +import com.vaadin.ui.HasComponents; +import com.vaadin.ui.HorizontalSplitPanel; +import com.vaadin.ui.Panel; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.Design; +import com.vaadin.ui.declarative.DesignContext; + +@Theme("valo") +public class DeclarativeEditor extends UI { + + private VerticalLayout treeHolder; + private TextArea editor; + private DesignContext dc; + private boolean disableEvents = false; + private HorizontalSplitPanel main; + + @Override + protected void init(VaadinRequest request) { + main = new HorizontalSplitPanel(); + editor = new TextArea(); + editor.setSizeFull(); + try { + editor.setValue(IOUtils.toString(getClass().getResourceAsStream( + "DeclarativeEditorInitial.html"))); + } catch (ReadOnlyException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + editor.addTextChangeListener(new TextChangeListener() { + + @Override + public void textChange(TextChangeEvent event) { + editor.setComponentError(null); + updateTree(event.getText()); + } + }); + + Panel editorPanel = new Panel(editor); + editorPanel.setSizeFull(); + treeHolder = new VerticalLayout(); + treeHolder.setSizeFull(); + + main.addComponents(editorPanel, treeHolder); + main.setSizeFull(); + + setContent(main); + updateTree(editor.getValue()); + } + + protected void updateTree(String string) { + if (disableEvents) { + return; + } + + dc = Design.read(new StringInputStream(string), null); + treeHolder.removeAllComponents(); + treeHolder.addComponent(dc.getRootComponent()); + + addValueChangeListeners(dc.getRootComponent()); + } + + protected void updateCode() { + if (disableEvents) { + return; + } + + ByteArrayOutputStream o = new ByteArrayOutputStream(); + try { + Design.write(treeHolder.getComponent(0), o); + disableEvents = true; + editor.setValue(o.toString("UTF-8")); + disableEvents = false; + } catch (IOException e1) { + e1.printStackTrace(); + } + + } + + private void addValueChangeListeners(Component component) { + if (component instanceof ValueChangeNotifier) { + ((ValueChangeNotifier) component) + .addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + updateCode(); + } + }); + } + + if (component instanceof HasComponents) { + for (Component c : ((HasComponents) component)) { + addValueChangeListeners(c); + } + } + + } + +} diff --git a/uitest/src/com/vaadin/tests/declarative/DeclarativeEditorInitial.html b/uitest/src/com/vaadin/tests/declarative/DeclarativeEditorInitial.html new file mode 100644 index 0000000000..17f7d6aa59 --- /dev/null +++ b/uitest/src/com/vaadin/tests/declarative/DeclarativeEditorInitial.html @@ -0,0 +1,23 @@ +<v-vertical-layout size-full margin 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 :expand :right>Delete</v-button> + </v-horizontal-layout> + </v-vertical-layout> +</v-vertical-layout>
\ No newline at end of file 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 new file mode 100644 index 0000000000..05acee9679 --- /dev/null +++ b/uitest/src/com/vaadin/tests/declarative/PotusCrud.html @@ -0,0 +1,14 @@ +<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 new file mode 100644 index 0000000000..70ad956045 --- /dev/null +++ b/uitest/src/com/vaadin/tests/declarative/PotusCrud.java @@ -0,0 +1,124 @@ +/* + * 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.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; + +@DesignRoot +public class PotusCrud extends VerticalLayout { + + 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(); + } + }); + fg = new FieldGroup(); + } + + protected void doRevert() { + fg.discard(); + } + + protected void doDelete() { + potusContainer.removeItem(potusList.getValue()); + fg.setItemDataSource(null); + } + + 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.setItemDataSource(potusList.getItem(potusList.getValue())); + fg.bindMemberFields(potusForm); + } else { + fg.setItemDataSource(null); + } + } + +} 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"); + } +} |