Change-Id: I330d669238b2c79ca2afda396a5e07833f0af90atags/7.4.0.beta1
@@ -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; | |||
} | |||
} |
@@ -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> | |||
@@ -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); | |||
} | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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> |
@@ -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"); | |||
} | |||
} |