diff options
author | Artur Signell <artur.signell@itmill.com> | 2009-10-27 07:57:12 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2009-10-27 07:57:12 +0000 |
commit | 6a3c715dae922edd723c9423b4308d5d7948b74e (patch) | |
tree | 46a007274681a9803afccf135ace5554f3e01e3a /src/com/vaadin/demo/SimpleAddressBook.java | |
parent | 931d75fef69deb9b738fad97001cf5621de9f43e (diff) | |
download | vaadin-framework-6a3c715dae922edd723c9423b4308d5d7948b74e.tar.gz vaadin-framework-6a3c715dae922edd723c9423b4308d5d7948b74e.zip |
Split demo and tests files to own source folders, for #3298
svn changeset:9390/svn branch:6.2
Diffstat (limited to 'src/com/vaadin/demo/SimpleAddressBook.java')
-rw-r--r-- | src/com/vaadin/demo/SimpleAddressBook.java | 143 |
1 files changed, 0 insertions, 143 deletions
diff --git a/src/com/vaadin/demo/SimpleAddressBook.java b/src/com/vaadin/demo/SimpleAddressBook.java deleted file mode 100644 index 22f9c171ed..0000000000 --- a/src/com/vaadin/demo/SimpleAddressBook.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.vaadin.demo; - -import com.vaadin.Application; -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.util.IndexedContainer; -import com.vaadin.ui.Button; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.SplitPanel; -import com.vaadin.ui.Table; -import com.vaadin.ui.TextField; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; -import com.vaadin.ui.Button.ClickEvent; - -@SuppressWarnings("serial") -public class SimpleAddressBook extends Application { - - private static String[] fields = { "First Name", "Last Name", "Company", - "Mobile Phone", "Work Phone", "Home Phone", "Work Email", - "Home Email", "Street", "Zip", "City", "State", "Country" }; - private static String[] visibleCols = new String[] { "Last Name", - "First Name", "Company" }; - - private Table contactList = new Table(); - private Form contactEditor = new Form(); - private HorizontalLayout bottomLeftCorner = new HorizontalLayout(); - private Button contactRemovalButton; - private IndexedContainer addressBookData = createDummyData(); - - @Override - public void init() { - initLayout(); - initContactAddRemoveButtons(); - initAddressList(); - initFilteringControls(); - } - - private void initLayout() { - SplitPanel splitPanel = new SplitPanel( - SplitPanel.ORIENTATION_HORIZONTAL); - setMainWindow(new Window("Address Book", splitPanel)); - VerticalLayout left = new VerticalLayout(); - left.setSizeFull(); - left.addComponent(contactList); - contactList.setSizeFull(); - left.setExpandRatio(contactList, 1); - splitPanel.addComponent(left); - splitPanel.addComponent(contactEditor); - contactEditor.setSizeFull(); - contactEditor.getLayout().setMargin(true); - contactEditor.setImmediate(true); - bottomLeftCorner.setWidth("100%"); - left.addComponent(bottomLeftCorner); - } - - private void initContactAddRemoveButtons() { - // New item button - bottomLeftCorner.addComponent(new Button("+", - new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - Object id = contactList.addItem(); - contactList.setValue(id); - } - })); - - // Remove item button - contactRemovalButton = new Button("-", new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - contactList.removeItem(contactList.getValue()); - contactList.select(null); - } - }); - contactRemovalButton.setVisible(false); - bottomLeftCorner.addComponent(contactRemovalButton); - } - - private String[] initAddressList() { - contactList.setContainerDataSource(addressBookData); - contactList.setVisibleColumns(visibleCols); - contactList.setSelectable(true); - contactList.setImmediate(true); - contactList.addListener(new Property.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - Object id = contactList.getValue(); - contactEditor.setItemDataSource(id == null ? null : contactList - .getItem(id)); - contactRemovalButton.setVisible(id != null); - } - }); - return visibleCols; - } - - private void initFilteringControls() { - for (final String pn : visibleCols) { - final TextField sf = new TextField(); - bottomLeftCorner.addComponent(sf); - sf.setWidth("100%"); - sf.setValue(pn); - sf.setImmediate(true); - bottomLeftCorner.setExpandRatio(sf, 1); - sf.addListener(new Property.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - addressBookData.removeContainerFilters(pn); - if (sf.toString().length() > 0 && !pn.equals(sf.toString())) { - addressBookData.addContainerFilter(pn, sf.toString(), - true, false); - } - getMainWindow().showNotification( - "" + addressBookData.size() + " matches found"); - } - }); - } - } - - private static IndexedContainer createDummyData() { - - String[] fnames = { "Peter", "Alice", "Joshua", "Mike", "Olivia", - "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene", - "Lisa", "Marge" }; - String[] lnames = { "Smith", "Gordon", "Simpson", "Brown", "Clavel", - "Simons", "Verne", "Scott", "Allison", "Gates", "Rowling", - "Barks", "Ross", "Schneider", "Tate" }; - - IndexedContainer ic = new IndexedContainer(); - - for (String p : fields) { - ic.addContainerProperty(p, String.class, ""); - } - - for (int i = 0; i < 1000; i++) { - Object id = ic.addItem(); - ic.getContainerProperty(id, "First Name").setValue( - fnames[(int) (fnames.length * Math.random())]); - ic.getContainerProperty(id, "Last Name").setValue( - lnames[(int) (lnames.length * Math.random())]); - } - - return ic; - } - -} |