diff options
author | Artur Signell <artur.signell@itmill.com> | 2010-10-07 05:46:50 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2010-10-07 05:46:50 +0000 |
commit | 065ae70535a49e151a47c3057fb1ab69824fc88b (patch) | |
tree | 7ffd7aeb9bf62fb03364b6ae2d82d2aadc5d2066 /tests | |
parent | d58427161526fee2acb1a00dc7f361602c2128f8 (diff) | |
download | vaadin-framework-065ae70535a49e151a47c3057fb1ab69824fc88b.tar.gz vaadin-framework-065ae70535a49e151a47c3057fb1ab69824fc88b.zip |
Book examples are nowadays in /doc/book-examples/
svn changeset:15426/svn branch:6.5
Diffstat (limited to 'tests')
37 files changed, 0 insertions, 4090 deletions
diff --git a/tests/src/com/vaadin/tests/book/BookTestApplication.java b/tests/src/com/vaadin/tests/book/BookTestApplication.java deleted file mode 100644 index cba0f15e01..0000000000 --- a/tests/src/com/vaadin/tests/book/BookTestApplication.java +++ /dev/null @@ -1,1893 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import java.net.URL; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import com.vaadin.data.Item; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.Property.ValueChangeListener; -import com.vaadin.data.Validator; -import com.vaadin.data.util.QueryContainer; -import com.vaadin.data.validator.StringLengthValidator; -import com.vaadin.terminal.ClassResource; -import com.vaadin.terminal.DownloadStream; -import com.vaadin.terminal.ExternalResource; -import com.vaadin.terminal.ParameterHandler; -import com.vaadin.terminal.Sizeable; -import com.vaadin.terminal.StreamResource; -import com.vaadin.terminal.URIHandler; -import com.vaadin.terminal.UserError; -import com.vaadin.terminal.gwt.server.WebApplicationContext; -import com.vaadin.ui.AbsoluteLayout; -import com.vaadin.ui.AbstractSelect; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.Component; -import com.vaadin.ui.CustomLayout; -import com.vaadin.ui.DateField; -import com.vaadin.ui.Embedded; -import com.vaadin.ui.Form; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.InlineDateField; -import com.vaadin.ui.Label; -import com.vaadin.ui.Layout.AlignmentHandler; -import com.vaadin.ui.Link; -import com.vaadin.ui.MenuBar; -import com.vaadin.ui.MenuBar.MenuItem; -import com.vaadin.ui.NativeSelect; -import com.vaadin.ui.Panel; -import com.vaadin.ui.PopupDateField; -import com.vaadin.ui.ProgressIndicator; -import com.vaadin.ui.RichTextArea; -import com.vaadin.ui.Select; -import com.vaadin.ui.TabSheet; -import com.vaadin.ui.Table; -import com.vaadin.ui.TextField; -import com.vaadin.ui.Tree; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; - -public class BookTestApplication extends com.vaadin.Application { - Window main = new Window("Application window"); - - TheButton butts1; - TheButtons butts2; - TheButtons2 butts3; - - Label mylabel1; - Label mylabel2; - Label mylabel3; - - StreamResource strres; - VerticalLayout ol; - int getwincount = 0; - - @Override - public void init() { - setTheme("tests-book"); - - setMainWindow(main); - - main.getContent().setSizeFull(); - - // Demo the use of parameter and URI handlers - main.addParameterHandler(new MyParameterHandler()); - main.addURIHandler(new MyURIHandler()); - - MyDynamicResource myresource = new MyDynamicResource(); - main.addParameterHandler(myresource); - main.addURIHandler(myresource); - - main.addURIHandler(new BookTestURIHandler()); - } - - class MyParameterHandler implements ParameterHandler { - public void handleParameters(Map parameters) { - // Print out the parameters to standard output - for (Iterator it = parameters.keySet().iterator(); it.hasNext();) { - String key = (String) it.next(); - String value = ((String[]) parameters.get(key))[0]; - System.out.println("Key: " + key + ", value: " + value); - } - } - } - - class MyURIHandler implements URIHandler { - public DownloadStream handleURI(URL context, String relativeUri) { - System.out.println("Context: " + context.toString() - + ", relative: " + relativeUri); - return null; // Let the Application provide the response - } - } - - class BookTestURIHandler implements URIHandler { - public DownloadStream handleURI(URL context, String relativeUri) { - String example; - String param = null; - - final int slashPos = relativeUri.indexOf("/"); - if (slashPos > 0) { - example = relativeUri.substring(0, slashPos); - param = relativeUri.substring(slashPos + 1); - } else { - example = relativeUri; - } - - /* Remove existing components and windows. */ - main.removeAllComponents(); - final Set childwindows = main.getChildWindows(); - for (final Iterator cwi = childwindows.iterator(); cwi.hasNext();) { - final Window child = (Window) cwi.next(); - main.removeWindow(child); - } - - // The index is listed inside a grid layout - main.setLayout(new VerticalLayout()); - GridLayout grid = new GridLayout(4, 4); - grid.addStyleName("index"); - main.addComponent(grid); - - if (example.equals("index")) { - final String examples[] = { "defaultbutton", "label", - "labelcontent", "tree", "embedded", "textfield", - "textfieldvalidation", "datefield", "button", - "select/select", "select/native", "select/optiongroup", - "select/twincol", "filterselect", "validator", "table", - "table/select", "table/component", "table/paging", - "table/editable", "upload", "link", "gridlayout", - "orderedlayout", "formlayout", "form", "form/simple", - "form/layout", "panel", "expandlayout", - "expandlayout/root", "tabsheet", "alignment", - "alignment/grid", "window", "window/opener", - "window/multiple", "classresource", "usererror", - "progress/window", "progress/thread", "progress", - "customlayout", "spacing", "margin", "clientinfo", - "fillinform/templates", "notification", "print", - "richtextfield", "querycontainer", "menubar", - "absolutelayout", "layout/intro" }; - for (int i = 0; i < examples.length; i++) { - grid.addComponent(new Label("<a href='" - + context.toString() + examples[i] + "'>" - + examples[i] + "</a>", Label.CONTENT_XHTML)); - } - return null; - } - - if (example.equals("defaultbutton")) { - example_defaultButton(main, param); - } else if (example.equals("label")) { - example_Label(main, param); - } else if (example.equals("labelcontent")) { - example_LabelContent(main, param); - } else if (example.equals("tree")) { - example_Tree(main, param); - } else if (example.equals("embedded")) { - example_Embedded(main, param); - } else if (example.equals("textfield")) { - example_TextField(main, param); - } else if (example.equals("textfieldvalidation")) { - example_TextFieldValidation(main, param); - } else if (example.equals("usererror")) { - example_UserError(main, param); - } else if (example.equals("datefield")) { - example_DateField(main, param); - } else if (example.equals("button")) { - example_Button(main, param); - } else if (example.equals("checkbox")) { - example_CheckBox(main, param); - } else if (example.equals("select")) { - example_Select(main, param); - } else if (example.equals("filterselect")) { - example_FilterSelect(main, param); - } else if (example.equals("validator")) { - example_Validator(main, param); - } else if (example.equals("table")) { - example_Table(main, param); - } else if (example.equals("upload")) { - example_Upload(main, param); - } else if (example.equals("link")) { - example_Link(main, param); - } else if (example.equals("gridlayout")) { - example_GridLayout(main, param); - } else if (example.equals("orderedlayout")) { - example_OrderedLayout(main, param); - } else if (example.equals("formlayout")) { - example_FormLayout(main, param); - } else if (example.equals("form")) { - example_Form(main, param); - } else if (example.equals("tabsheet")) { - example_TabSheet(main, param); - } else if (example.equals("panel")) { - example_Panel(main, param); - } else if (example.equals("expandlayout")) { - example_ExpandLayout(main, param); - } else if (example.equals("alignment")) { - example_Alignment(main, param); - } else if (example.equals("window")) { - example_Window(main, param); - } else if (example.equals("classresource")) { - example_ClassResource(main, param); - } else if (example.equals("progress")) { - example_ProgressIndicator(main, param); - } else if (example.equals("customlayout")) { - example_CustomLayout(main, param); - } else if (example.equals("spacing")) { - example_Spacing(main, param); - } else if (example.equals("margin")) { - example_Margin(main, param); - } else if (example.equals("clientinfo")) { - example_ClientInfo(main, param); - } else if (example.equals("fillinform")) { - example_FillInForm(main, param); - } else if (example.equals("notification")) { - example_Notification(main, param); - } else if (example.equals("print")) { - example_Print(main, param); - } else if (example.equals("richtextfield")) { - example_RichTextArea(main, param); - } else if (example.equals("querycontainer")) { - example_QueryContainer(main, param); - } else if (example.equals("menubar")) { - example_MenuBar(main, param); - } else if (example.equals("absolutelayout")) { - example_AbsoluteLayout(main, param); - } else if (example.equals("layout")) { - example_Layout(main, param); - } else { - ; // main.addComponent(new - // Label("Unknown test '"+example+"'.")); - } - - return null; - } - } - - /* - * public Window getWindow(String name) { Window superwin = - * super.getWindow(name); if (superwin != null) return superwin; - * - * main.addComponent(new Label("Request 2 for window '"+name+"'.")); if - * (name.equals("panel")) { Window window = new Window("Other Window " + - * getwincount++); example_Panel(window, null); return window; } return - * null; } - */ - public void handleButton(Button.ClickEvent event) { - ol.addStyleName("myLayout2"); - } - - void example_defaultButton(Window main, String param) { - main.addComponent(new DefaultButtonExample()); - } - - void example_Label(Window main, String param) { - /* Some container for the Label. */ - final Panel panel = new Panel("Panel Containing a Label"); - main.addComponent(panel); - - panel.addComponent(new Label( - "This is a Label inside a Panel. There is enough " - + "text in the label to make the text wrap if it " - + "exceeds the width of the panel.")); - } - - void example_LabelContent(Window main, String param) { - final GridLayout labelgrid = new GridLayout(2, 1); - labelgrid.addStyleName("labelgrid"); - labelgrid.addComponent(new Label("CONTENT_DEFAULT")); - labelgrid.addComponent(new Label( - "This is a label in default mode: <plain text>", - Label.CONTENT_DEFAULT)); - labelgrid.addComponent(new Label("CONTENT_PREFORMATTED")); - labelgrid - .addComponent(new Label( - "This is a preformatted label.\nThe newline character \\n breaks the line.", - Label.CONTENT_PREFORMATTED)); - labelgrid.addComponent(new Label("CONTENT_RAW")); - labelgrid - .addComponent(new Label( - "This is a label in raw mode.<br>It can contain, for example, unbalanced markup.", - Label.CONTENT_RAW)); - labelgrid.addComponent(new Label("CONTENT_TEXT")); - labelgrid.addComponent(new Label( - "This is a label in (plain) text mode", Label.CONTENT_TEXT)); - labelgrid.addComponent(new Label("CONTENT_XHTML")); - labelgrid.addComponent(new Label( - "<i>This</i> is an <b>XHTML<b> formatted label", - Label.CONTENT_XHTML)); - labelgrid.addComponent(new Label("CONTENT_XML")); - labelgrid.addComponent(new Label( - "This is an <myelement>XML</myelement> formatted label", - Label.CONTENT_XML)); - main.addComponent(labelgrid); - - final ClassResource labelimage = new ClassResource("smiley.jpg", this); - main.addComponent(new Label("Here we have an image <img src=\"" - + getRelativeLocation(labelimage) + "\"/> within some text.", - Label.CONTENT_XHTML)); - } - - void example_Tree(Window main, String param) { - final Object[][] planets = new Object[][] { - new Object[] { "Mercury" }, - new Object[] { "Venus" }, - new Object[] { "Earth", "The Moon" }, - new Object[] { "Mars", "Phobos", "Deimos" }, - new Object[] { "Jupiter", "Io", "Europa", "Ganymedes", - "Callisto" }, - new Object[] { "Saturn", "Titan", "Tethys", "Dione", "Rhea", - "Iapetus" }, - new Object[] { "Uranus", "Miranda", "Ariel", "Umbriel", - "Titania", "Oberon" }, - new Object[] { "Neptune", "Triton", "Proteus", "Nereid", - "Larissa" } }; - - final Tree tree = new Tree(); - - // Add planets as root items in the tree. - for (int i = 0; i < planets.length; i++) { - final String planet = (String) (planets[i][0]); - tree.addItem(planet); - - if (planets[i].length == 1) { - // The planet has no moons so make it a leaf. - tree.setChildrenAllowed(planet, false); - } else { - // Add children (moons) under the planets. - for (int j = 1; j < planets[i].length; j++) { - final String moon = (String) planets[i][j]; - - // Add the item as a regular item. - tree.addItem(moon); - - // Set it to be a child. - tree.setParent(moon, planet); - - // Make the moons look like leaves. - tree.setChildrenAllowed(moon, false); - } - - // Expand the subtree. - tree.expandItemsRecursively(planet); - } - } - - // Horizontal layout with the tree on the left and a details panel on - // the right. - final HorizontalLayout horlayout = new HorizontalLayout(); - horlayout.addStyleName("treeexample"); - horlayout.setSizeFull(); - - final Panel treepanel = new Panel("The Planets and Major Moons"); - treepanel.addComponent(tree); - horlayout.addComponent(treepanel); - - final Panel detailspanel = new Panel("Details"); - horlayout.addComponent(detailspanel); - horlayout.setExpandRatio(detailspanel, 1); - - final VerticalLayout detailslayout = new VerticalLayout(); - detailspanel.setLayout(detailslayout); - - // Allow null selection - this is the default actually. - tree.setNullSelectionAllowed(true); - - // When a tree item (planet or moon) is clicked, open the item in - // Details view. - tree.setImmediate(true); - tree.addListener(new ValueChangeListener() { - String lastselected = null; - - public void valueChange(ValueChangeEvent event) { - String planet = (String) tree.getValue(); - - // Reselect a selected item if it is unselected by clicking it. - if (planet == null) { - planet = lastselected; - tree.setValue(planet); - } - lastselected = planet; - - detailspanel.setCaption("Details on " + planet); - detailslayout.removeAllComponents(); - - // Put some stuff in the Details view. - detailslayout.addComponent(new Label("Where is the cat?")); - detailslayout.addComponent(new Label("The cat is in " + planet - + ".")); - - } - }); - - main.setLayout(horlayout); - } - - void example_Select(Window main, String param) { - final HorizontalLayout layout = new HorizontalLayout(); - layout.addStyleName("aligntop"); - - if (param.equals("twincol")) { - final SelectExample select1 = new SelectExample(this, param, - "Select some items", true); - layout.addComponent(select1); - } else if (param.equals("filter")) { - final SelectExample select1 = new SelectExample(this, param, - "Enter containing substring", false); - layout.addComponent(select1); - } else { - final SelectExample select1 = new SelectExample(this, param, - "Single Selection Mode", false); - final SelectExample select2 = new SelectExample(this, param, - "Multiple Selection Mode", true); - layout.addComponent(select1); - layout.addComponent(select2); - } - main.addComponent(layout); - } - - void example_FilterSelect(Window main, String param) { - final Select select = new Select("Enter containing substring"); - main.addComponent(select); - - select.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS); - - /* Fill the component with some items. */ - final String[] planets = new String[] { "Mercury", "Venus", "Earth", - "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" }; - - for (int i = 0; i < planets.length; i++) { - for (int j = 0; j < planets.length; j++) { - select.addItem(planets[j] + " to " + planets[i]); - } - } - } - - void example_TextField(Window main, String param) { - /* Add a single-line text field. */ - final TextField subject = new TextField("Subject"); - subject.setColumns(40); - main.addComponent(subject); - - /* Add a multi-line text field. */ - final TextField message = new TextField("Message"); - message.setRows(7); - message.setColumns(40); - main.addComponent(message); - } - - void example_TextFieldValidation(Window main, String param) { - // Create a text field with a label - final TextField username = new TextField("Username"); - main.addComponent(username); - - // Set visible length to 16 characters - username.setColumns(16); - - // Set content length to minimum of 6 and maximum of 16 characters. - // The string also may not be null. - username.addValidator(new StringLengthValidator( - "Must be 6 to 16 characters long", 6, 16, false)); - - // Setting component immediate causes a ValueChangeEvent to occur - // when the TextField loses focus. - username.setImmediate(true); - - // Listen for ValueChangeEvents and handle them - username.addListener(new ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - // Get the source of the event - final TextField username = (TextField) (event.getProperty()); - - try { - // Validate the field value. - username.validate(); - } catch (final Validator.InvalidValueException e) { - // The value was not ok. The error was set. - } - } - }); - } - - void example_UserError(final Window main, String param) { - if (param != null) { - if (param.equals("form")) { - - final FormLayout layout = new FormLayout(); - main.addComponent(layout); - - final TextField textfield = new TextField("Enter code"); - layout.addComponent(textfield); - textfield.setComponentError(null); - - final Button button = new Button("Ok!"); - layout.addComponent(button); - - button.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - if (((String) textfield.getValue()).length() == 0) { - textfield.setComponentError(new UserError( - "Must be letters and numbers.")); - } else { - textfield.setComponentError(null); - } - } - }); - } - } else { - main.setLayout(new HorizontalLayout()); - - // Create a field. - final TextField textfield = new TextField("Enter code"); - main.addComponent(textfield); - - // Let the component error be initially clear. (It actually is by - // default.) - textfield.setComponentError(null); - - // Have a button right of the field (and align it properly). - final Button button = new Button("Ok!"); - main.addComponent(button); - ((HorizontalLayout) main.getLayout()).setComponentAlignment(button, - HorizontalLayout.ALIGNMENT_LEFT, - HorizontalLayout.ALIGNMENT_BOTTOM); - - // Handle button clicks - button.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - // If the field value is bad, set its error. - // (Here the content must be only alphanumeric characters.) - if (!((String) textfield.getValue()).matches("^\\w*$")) { - // Put the component in error state and set the error - // message. - textfield.setComponentError(new UserError( - "Must be letters and numbers")); - } else { - // Otherwise clear it. - textfield.setComponentError(null); - } - } - }); - } - } - - void example_DateField(Window main, String param) { - HorizontalLayout layout = new HorizontalLayout(); - - /* Create a DateField with the calendar style. */ - final DateField popupdate = new PopupDateField("Popup calendar field"); - - /* Set resolution of the date/time display. */ - popupdate.setResolution(DateField.RESOLUTION_MIN); - - /* Set the date and time to present. */ - popupdate.setValue(new java.util.Date()); - - /* Create a DateField with the calendar style. */ - final DateField inlinedate = new InlineDateField( - "Inline calendar field"); - - /* Set locale of the DateField to American English. */ - inlinedate.setLocale(new Locale("en", "US")); - - /* Set the date and time to present. */ - inlinedate.setValue(new java.util.Date()); - - /* Set resolution of the date/time display. */ - inlinedate.setResolution(DateField.RESOLUTION_MIN); - - layout.addComponent(popupdate); - layout.addComponent(inlinedate); - layout.setSpacing(true); - main.addComponent(layout); - } - - void example_Validator(Window main, String param) { - if (param != null && param.equals("required")) { - Form form = new Form(); - form.setCaption("My Form"); - form.setRequired(true); - main.addComponent(form); - - TextField text = new TextField("This is a required text field"); - text.setRequired(true); - text.setImmediate(true); - form.getLayout().addComponent(text); - return; - } - main.addComponent(new SSNField()); - } - - // TODO add ClientWidget annotation if test is in use - class PagingTable extends Table { - } - - void example_Table(Window main, String param) { - if (param != null) { - if (param.equals("select")) { - main.addComponent(new TableExample2()); - } else if (param.equals("component")) { - main.addComponent(new TableExample3()); - } else if (param.equals("editable")) { - main.addComponent(new TableEditable()); - } else if (param.equals("bean")) { - main.addComponent(new TableEditableBean()); - } else if (param.equals("long")) { - main.addComponent(new TableExample()); - } else if (param.equals("cellstyle")) { - main.addComponent(new TableCellStyle()); - } else if (param.equals("huge")) { - main.addComponent(new TableHuge()); - } else if (param.equals("paging")) { - PagingTable table = new PagingTable(); - table.addContainerProperty("Column 1", String.class, null); - for (int i = 0; i < 100; i++) { - table.addItem(new Object[] { "Item " + i }, new Integer(i)); - } - main.addComponent(table); - } - } else { - main.addComponent(new TableExample1()); - } - } - - void example_Upload(Window main, String param) { - main.addComponent(new MyUploader()); - } - - void example_Link(Window main, String param) { - - /* Create a link that opens the popup window. */ - final Link alink = new Link(); - - /* Set the resource to be opened in the window. */ - alink.setResource(new ExternalResource("http://www.vaadin.com/")); - - main.addComponent(alink); - - final ClassResource mydocument = new ClassResource("mydocument.pdf", - this); - main.addComponent(new Link("The document (pdf)", mydocument)); - main.addComponent(new Link("link to a resource", new ExternalResource( - "http://www.vaadin.com/"))); - } - - void example_Button(Window main, String param) { - if (param != null) { - if (param.equals("buttons")) { - main.addComponent(new TheButton()); - } - return; - } - - // butts1 = new TheButton (); - // main.addComponent(butts1); - - // butts2 = new TheButtons (main); - // butts3 = new TheButtons2 (main); - - // Button checkbox = new Button ("This is a checkbox"); - - // main.addComponent(checkbox); - final Button button = new Button("My Button"); - main.addComponent(button); - } - - void example_CheckBox(Window main, String param) { - /* A check box with default state (not checked, i.e., false). */ - final CheckBox checkbox1 = new CheckBox("My CheckBox"); - checkbox1.addStyleName("mybox"); - main.addComponent(checkbox1); - - /* Another check box with explicitly set checked state. */ - final CheckBox checkbox2 = new CheckBox("Checked CheckBox"); - /* - * @TODO: Build fails here, why? checkbox2.setValue(true); - */ - main.addComponent(checkbox2); - - /* - * Make some application logic. We use anynymous listener classes here. - * The above references were defined as "final" to allow accessing them - * from inside anonymous classes. - */ - checkbox1.addListener(new ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - /* Copy the value to the other checkbox. */ - checkbox2.setValue(checkbox1.getValue()); - } - }); - checkbox2.addListener(new ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - /* Copy the value to the other checkbox. */ - checkbox1.setValue(checkbox2.getValue()); - } - }); - } - - void example_Panel(Window main, String param) { - // Create a panel with a caption. - final Panel panel = new Panel("Contact Information"); - - // Create a layout inside the panel - final FormLayout form = new FormLayout(); - - // Set the layout as the root layout of the panel - panel.setLayout(form); - - // Add some components - form.addComponent(new TextField("Name")); - form.addComponent(new TextField("Email")); - - // Add the panel to the main window - final ClassResource icon = new ClassResource("smiley.jpg", - main.getApplication()); - form.addComponent(new Embedded("Image", icon)); - panel.setIcon(icon); - panel.addComponent(form); - main.addComponent(panel); - } - - void example_GridLayout(Window main, String param) { - if (param.equals("embedded")) { - final GridLayout grid = new GridLayout(3, 3); - for (int i = 0; i < 3 * 3; i++) { - ClassResource img = new ClassResource("smiley.jpg", - main.getApplication()); - Embedded embedded = new Embedded("", img); - grid.addComponent(embedded); - } - main.addComponent(grid); - return; - } - /* Create a 4 by 4 grid layout. */ - final GridLayout grid = new GridLayout(4, 4); - grid.addStyleName("example-gridlayout"); - - /* Fill out the first row using the cursor. */ - grid.addComponent(new Button("R/C 1")); - for (int i = 0; i < 3; i++) { - grid.addComponent(new Button("Col " + (grid.getCursorX() + 1))); - } - - /* Fill out the first column using coordinates. */ - for (int i = 1; i < 4; i++) { - grid.addComponent(new Button("Row " + i), 0, i); - } - - /* Add some components of various shapes. */ - grid.addComponent(new Button("3x1 button"), 1, 1, 3, 1); - grid.addComponent(new Label("1x2 cell"), 1, 2, 1, 3); - final InlineDateField date = new InlineDateField("A 2x2 date field"); - date.setResolution(DateField.RESOLUTION_DAY); - grid.addComponent(date, 2, 2, 3, 3); - - main.addComponent(grid); - } - - void example_Alignment(Window main, String param) { - if (param.equals("grid")) { - /* Create a 3 by 3 grid layout. */ - final GridLayout layout = new GridLayout(3, 3); - // OrderedLayout layout = new - // OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - main.setLayout(layout); - layout.addStyleName("example-alignment"); - - layout.setWidth(400, Sizeable.UNITS_PIXELS); - layout.setHeight(400, Sizeable.UNITS_PIXELS); - - /* Define cells and their layouts to create. */ - - Object cells[][] = { - { new Button("Top Left"), - new Integer(AlignmentHandler.ALIGNMENT_LEFT), - new Integer(AlignmentHandler.ALIGNMENT_TOP) }, - { - new Label("Top Center"), - new Integer( - AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER), - new Integer(AlignmentHandler.ALIGNMENT_TOP) }, - { new Label("Top Right"), - new Integer(AlignmentHandler.ALIGNMENT_RIGHT), - new Integer(AlignmentHandler.ALIGNMENT_TOP) }, - { - new Button("Center Left"), - new Integer(AlignmentHandler.ALIGNMENT_LEFT), - new Integer( - AlignmentHandler.ALIGNMENT_VERTICAL_CENTER) }, - { - new Button("Center Center"), - new Integer( - AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER), - new Integer( - AlignmentHandler.ALIGNMENT_VERTICAL_CENTER) }, - { - new Button("Center Right"), - new Integer(AlignmentHandler.ALIGNMENT_RIGHT), - new Integer( - AlignmentHandler.ALIGNMENT_VERTICAL_CENTER) }, - { new Button("Bottom Left"), - new Integer(AlignmentHandler.ALIGNMENT_LEFT), - new Integer(AlignmentHandler.ALIGNMENT_BOTTOM) }, - { - new Button("Bottom Center"), - new Integer( - AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER), - new Integer(AlignmentHandler.ALIGNMENT_BOTTOM) }, - { new Button("Bottom Right"), - new Integer(AlignmentHandler.ALIGNMENT_RIGHT), - new Integer(AlignmentHandler.ALIGNMENT_BOTTOM) } }; - - for (int i = 0; i < 9; i++) { - HorizontalLayout celllayout = new HorizontalLayout(); - celllayout.addComponent((Component) cells[i][0]); - if (i == 0) { - celllayout.setExpandRatio((Component) cells[i][0], 1); - } - - celllayout.setComponentAlignment((Component) cells[i][0], - ((Integer) cells[i][1]).intValue(), - ((Integer) cells[i][2]).intValue()); - layout.addComponent(celllayout); - // layout.setComponentAlignment((Component)cells[i][0], - // ((Integer)cells[i][1]).intValue(), - // ((Integer)cells[i][2]).intValue()); - } - } else { - final Panel panel = new Panel("A Panel with a Layout"); - main.addComponent(panel); - - // panel.addComponent(new ) - } - } - - void example_OrderedLayout(Window main, String param) { - final VerticalLayout layout = new VerticalLayout(); - layout.addComponent(new TextField("Name")); - layout.addComponent(new TextField("Street address")); - layout.addComponent(new TextField("Postal code")); - main.addComponent(layout); - } - - void example_FormLayout(Window main, String param) { - final FormLayout layout = new FormLayout(); - layout.addComponent(new TextField("Text Field")); - layout.addComponent(new CheckBox("Check Box")); - layout.addComponent(new Select("Select")); - main.addComponent(layout); - } - - void example_Form(Window main, String param) { - if (param != null && param.equals("simple")) { - main.addComponent(new FormExample2()); - } else if (param != null && param.equals("layout")) { - Form form = new Form(); - form.setCaption("Form Caption"); - form.setDescription("This is a description of the Form that is " - + "displayed in the upper part of the form. You normally enter some " - + "descriptive text about the form and its use here."); - - // Add a field directly to the layout. This field will not be bound - // to - // the data source Item of the form. - form.getLayout().addComponent(new TextField("A Field")); - - // Add a field and bind it to an named item property. - form.addField("another", new TextField("Another Field")); - - form.setComponentError(new UserError( - "This is the error indicator of the Form.")); - - // Set the footer layout and add some text. - form.setFooter(new VerticalLayout()); - form.getFooter() - .addComponent( - new Label( - "This is the footer area of the Form. " - + "You can use any layout here. This is nice for buttons.")); - - // Add an Ok (commit), Reset (discard), and Cancel buttons for the - // form. - HorizontalLayout okbar = new HorizontalLayout(); - okbar.setHeight("25px"); - Button okbutton = new Button("OK", form, "commit"); - okbar.addComponent(okbutton); - okbar.setExpandRatio(okbutton, 1); - okbar.setComponentAlignment(okbutton, - AlignmentHandler.ALIGNMENT_RIGHT, - AlignmentHandler.ALIGNMENT_TOP); - okbar.addComponent(new Button("Reset", form, "discard")); - okbar.addComponent(new Button("Cancel")); - form.getFooter().addComponent(okbar); - - main.addComponent(form); - } else { - main.addComponent(new FormExample()); - } - } - - void example_ExpandLayout(Window main, String param) { - if (param != null && param.equals("centered")) { - Label widget = new Label("Here is text"); - - HorizontalLayout layout = new HorizontalLayout(); - layout.addComponent(widget); - layout.setExpandRatio(widget, 1); - layout.setComponentAlignment(widget, - AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER, - AlignmentHandler.ALIGNMENT_VERTICAL_CENTER); - layout.setWidth(100, Sizeable.UNITS_PERCENTAGE); - layout.setHeight(100, Sizeable.UNITS_PERCENTAGE); - - main.setLayout(layout); - - return; - } else if (param != null && param.equals("window")) { - Window window = new Window("Progress"); - window.setHeight(100, Sizeable.UNITS_PIXELS); - window.setWidth(200, Sizeable.UNITS_PIXELS); - main.addWindow(window); - - ProgressIndicator progress = new ProgressIndicator(new Float(0.4)); - progress.addStyleName("fullwidth"); - progress.setPollingInterval(1000000); - progress.setIndeterminate(false); - - HorizontalLayout layout = new HorizontalLayout(); - layout.setHeight(100, Sizeable.UNITS_PERCENTAGE); - layout.setComponentAlignment(progress, - HorizontalLayout.ALIGNMENT_HORIZONTAL_CENTER, - HorizontalLayout.ALIGNMENT_VERTICAL_CENTER); - window.setLayout(layout); - window.addComponent(progress); - - return; - } else if (param != null && param.equals("root")) { - final Window mainwin = main; - - // Layout to switch to - final VerticalLayout expand2 = new VerticalLayout(); - expand2.addComponent(new Label("I am layout too.")); - - // Original layout - final VerticalLayout expand1 = new VerticalLayout(); - Button switchButton = new Button("Switch to other layout"); - switchButton.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - mainwin.setLayout(null); - mainwin.setLayout(expand2); - } - }); - expand1.addComponent(switchButton); - main.setLayout(expand1); - - return; - } else if (param != null && param.equals("size")) { - VerticalLayout layout = new VerticalLayout(); - layout.setSizeFull(); - main.setLayout(layout); - - Button button = new Button("This is a button in middle of nowhere"); - layout.addComponent(button); - layout.setComponentAlignment(button, - VerticalLayout.ALIGNMENT_HORIZONTAL_CENTER, - VerticalLayout.ALIGNMENT_VERTICAL_CENTER); - layout.setExpandRatio(button, 1.0f); - return; - } - - for (int w = 0; w < 2; w++) { - final VerticalLayout layout = new VerticalLayout(); - - /* Set the expanding layout as the root layout of a child window. */ - final Window window = new Window("A Child Window", layout); - main.addWindow(window); - - /* Add some component above the expanding one. */ - layout.addComponent(new Label("Here be some component.")); - - /* Create the expanding component. */ - final Table table = new Table("My Ever-Expanding Table"); - /* - * FIXME Java 5 -> 1.4 for (int i=0; i<5; i++) - * table.addContainerProperty("col "+(i+1), Integer.class, 0); for - * (int j=0; j<20; j++) table.addItem(new Object[]{1j,2j,3j,4j,5j}, - * j); - */ - layout.addComponent(table); - - /* Designate the table to be the expanding component. */ - layout.setExpandRatio(table, 1.0f); - - /* Set it to use all available area. */ - table.setSizeFull(); - - /* Add some component below the expanding one. */ - final Button button2 = new Button("Ok"); - layout.addComponent(button2); - layout.setComponentAlignment(button2, - AlignmentHandler.ALIGNMENT_RIGHT, 0); - } - } - - void example_TabSheet(Window main, String param) { - if (param != null) { - if (param.equals("simple")) { - // Create an empty tab sheet. - TabSheet tabsheet = new TabSheet(); - - // Create a component to put in a tab and put - // some content in it. - VerticalLayout myTab = new VerticalLayout(); - myTab.addComponent(new Label("Hello, I am a Tab!")); - - // Add the component to the tab sheet as a new tab. - tabsheet.addTab(myTab); - - // Get the Tab holding the component and set its caption. - tabsheet.getTab(myTab).setCaption("My Tab"); - - } else if (param.equals("icon")) { - final TabSheet tabsheet = new TabSheet(); - - tabsheet.addTab( - new Label("Contents of the first tab"), - "First Tab", - new ClassResource("images/Mercury_small.png", main - .getApplication())); - tabsheet.addTab(new Label("Contents of the second tab"), - "Second Tab", new ClassResource( - "images/Venus_small.png", this)); - tabsheet.addTab(new Label("Contents of the third tab"), - "Third tab", new ClassResource( - "images/Earth_small.png", this)); - - main.addComponent(tabsheet); - // main.addComponent(new Embedded("Emb", new ClassResource - // ("images/Mercury_small.png", this))); - } else if (param.equals("expanding")) { - // Create the layout - VerticalLayout layout = new VerticalLayout(); - - // It is important to set the expanding layout as the root - // layout - // of the containing window, in this case the main window, and - // not - // use addComponent(), which would place the layout inside the - // default root layout. - main.setLayout(layout); - - // Create a tab sheet that fills the expanding layout - final TabSheet tabsheet = new TabSheet(); - tabsheet.addTab(new Label("Contents of the first tab"), - "First Tab", null); - tabsheet.addTab(new Label("Contents of the second tab"), - "Second Tab", null); - tabsheet.addTab(new Label("Contents of the third tab"), - "Third tab", null); - - // Set the tabsheet to scale to full size inside its container - tabsheet.setWidth(100, Sizeable.UNITS_PERCENTAGE); - tabsheet.setHeight(100, Sizeable.UNITS_PERCENTAGE); - - // Add the tab sheet to the layout as usual - layout.addComponent(tabsheet); - - // Set the tab sheet to be the expanding component - layout.setExpandRatio(tabsheet, 1); - } else if (param.equals("ordered")) { - // Create the layout - VerticalLayout layout = new VerticalLayout(); - - // It is important to set the expanding layout as the root - // layout - // of the containing window, in this case the main window, and - // not - // use addComponent(), which would place the layout inside the - // default root layout. - main.setLayout(layout); - - // Create a tab sheet that fills the expanding layout - final TabSheet tabsheet = new TabSheet(); - tabsheet.addTab(new Label("Contents of the first tab"), - "First Tab", null); - tabsheet.addTab(new Label("Contents of the second tab"), - "Second Tab", null); - tabsheet.addTab(new Label("Contents of the third tab"), - "Third tab", null); - - // Set the tabsheet to scale to full size inside its container - tabsheet.setWidth(100, Sizeable.UNITS_PERCENTAGE); - // tabsheet().setHeight(100, Sizeable.UNITS_PERCENTAGE); - - // Add the tab sheet to the layout as usual - layout.addComponent(tabsheet); - } - } else { - main.addComponent(new TabSheetExample()); - } - } - - void example_Embedded(Window main, String param) { - final Embedded image = new Embedded("", new ClassResource("smiley.jpg", - this)); - image.addStyleName("omaimage"); - main.addComponent(image); - - final EmbeddedButton button = new EmbeddedButton(new ClassResource( - "smiley.jpg", this)); - main.addComponent(button); - } - - void example_Window(Window main, String param) { - if (param != null) { - if (param.equals("opener")) { - main.addComponent(new WindowOpener("Window Opener", main)); - } else if (param.equals("multiple")) { - /* Create a new window. */ - final Window mywindow = new Window("Second Window"); - mywindow.setName("mywindow"); - mywindow.addComponent(new Label("This is a second window.")); - - /* Add the window to the application. */ - main.getApplication().addWindow(mywindow); - - /* Add link to the second window in the main window. */ - main.addComponent(new Label("Second window: <a href='" - + mywindow.getURL() + "'>middle-click to open</a>", - Label.CONTENT_XHTML)); - main.addComponent(new Label( - "The second window can be accessed through URL: " - + mywindow.getURL())); - } - return; - } - - /* Create a new window. */ - final Window mywindow = new Window("My Window"); - mywindow.setName("mywindow"); - - /* Add some components in the window. */ - mywindow.addComponent(new Label("A text label in the window.")); - final Button okbutton = new Button("OK"); - mywindow.addComponent(okbutton); - - /* Set window size. */ - mywindow.setHeight("200px"); - mywindow.setWidth("400px"); - - /* Set window position. */ - mywindow.setPositionX(200); - mywindow.setPositionY(50); - - /* Add the window to the Application object. */ - main.addWindow(mywindow); - - } - - void example_ClassResource(Window main, String param) { - final DateField df = new DateField(); - main.addComponent(df); - df.setIcon(new ClassResource("smiley.jpg", main.getApplication())); - main.addComponent(new Embedded("This is Embedded", new ClassResource( - "smiley.jpg", main.getApplication()))); - } - - void example_ProgressIndicator(final Window main, String param) { - if (param != null) { - if (param.equals("thread")) { - - // Create the indicator - final ProgressIndicator indicator = new ProgressIndicator( - new Float(0.0)); - main.addComponent(indicator); - - // Set polling frequency to 0.5 seconds. - indicator.setPollingInterval(1000); - - // indicator.addStyleName("invisible"); - final Label text = new Label("-- Not running --"); - main.addComponent(text); - - // Add a button to start the progress - final Button button = new Button("Click to start"); - main.addComponent(button); - - // Another thread to do some work - class WorkThread extends Thread { - @Override - public void run() { - double current = 0.0; - while (true) { - // Do some "heavy work" - try { - sleep(50); // Sleep for 50 milliseconds - } catch (InterruptedException e) { - } - - // Grow the progress value until it reaches 1.0. - current += 0.01; - if (current > 1.0) { - indicator.setValue(new Float(1.0)); - } else { - indicator.setValue(new Float(current)); - } - - // After the progress is full for a while, stop. - if (current > 1.2) { - // Restore the state to initial. - indicator.setValue(new Float(0.0)); - button.setVisible(true); - break; - } - } - } - } - - // Clicking the button creates and runs a work thread - button.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - final WorkThread thread = new WorkThread(); - thread.start(); - - // The button hides until the work is done. - button.setVisible(false); - } - }); - } else if (param.equals("window")) { - // Create a table in the main window to hold items added in the - // second window - final Table table = new Table(); - table.setPageLength(5); - table.setWidth(100, Sizeable.UNITS_PERCENTAGE); - table.addContainerProperty("Name", String.class, ""); - main.addComponent(table); - - // Create the second window - final Window adderWindow = new Window("Add Items"); - adderWindow.setName("win-adder"); - main.getApplication().addWindow(adderWindow); - - // Create selection component to add items to the table - final NativeSelect select = new NativeSelect( - "Select item to add"); - select.setImmediate(true); - adderWindow.addComponent(select); - - // Add some items to the selection - String items[] = new String[] { "-- Select --", "Mercury", - "Venus", "Earth", "Mars", "Jupiter", "Saturn", - "Uranus", "Neptune" }; - for (int i = 0; i < items.length; i++) { - select.addItem(items[i]); - } - select.setNullSelectionItemId(items[0]); - - // When an item is selected in the second window, add - // table in the main window - select.addListener(new ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - // If the selected value is something else but null - // selection item. - if (select.getValue() != null) { - // Add the selected item to the table in the main - // window - table.addItem(new Object[] { select.getValue() }, - new Integer(table.size())); - } - } - }); - - // Link to open the selection window - Link link = new Link("Click to open second window", - new ExternalResource(adderWindow.getURL()), "_new", 50, - 200, Link.TARGET_BORDER_DEFAULT); - main.addComponent(link); - - // Enable polling to update the main window - ProgressIndicator poller = new ProgressIndicator(); - poller.addStyleName("invisible"); - main.addComponent(poller); - } else if (param.equals("centered")) { - /* - * GridLayout grid = new GridLayout(3,3); main.setLayout(grid); - * grid().setWidth(100, Sizeable.UNITS_PERCENTAGE); - * - * ExpandLayout layout2 = new - * ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); - * layout2().setWidth(50, Sizeable.UNITS_PERCENTAGE); - * - * ProgressIndicator poller = new ProgressIndicator(new - * Float(0.4)); poller.setPollingInterval(1000000); - * poller.setIndeterminate(false); layout2.addComponent(poller); - * - * grid.addComponent(layout2, 1, 1); - */ - - // ExpandLayout layout2 = new - // ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); - /* - * ProgressIndicator poller = new ProgressIndicator(new - * Float(0.4)); poller.setPollingInterval(1000000); - * poller.setIndeterminate(false); - */ - /* - * layout2.addComponent(poller); layout2().setWidth(50, - * Sizeable.UNITS_PERCENTAGE); - */ - - // layout.setComponentAlignment(poller, - // AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER, - // AlignmentHandler.ALIGNMENT_VERTICAL_CENTER); - /* - * GridLayout grid = new GridLayout(1,1); - * grid.addComponent(layout2, 0, 0); grid().setWidth(100, - * Sizeable.UNITS_PERCENTAGE); - */ - - /* - * GridLayout layout = new GridLayout(1,1); - * //OrderedLayout.ORIENTATION_HORIZONTAL); - * layout.addComponent(poller); //layout.expand(poller); - * layout.setComponentAlignment(poller, - * AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER, - * AlignmentHandler.ALIGNMENT_VERTICAL_CENTER); - * layout().setWidth(100, Sizeable.UNITS_PERCENTAGE); - * layout().setHeight(100, Sizeable.UNITS_PERCENTAGE); - */ - - } - } else { - ProgressIndicator poller = new ProgressIndicator(new Float(0.0)); - poller.setPollingInterval(1000000); - poller.setIndeterminate(true); - main.addComponent(poller); - } - } - - void example_CustomLayout(final Window main, String param) { - Window sub = new Window("Login"); - sub.setModal(true); - main.addWindow(sub); - - // Create the custom layout and set it as the root layout of - // the containing window. - final CustomLayout custom = new CustomLayout("layoutname"); - sub.setLayout(custom); - - // Create components and bind them to the location tags - // in the custom layout. - TextField username = new TextField(); - custom.addComponent(username, "username"); - - TextField password = new TextField(); - custom.addComponent(password, "password"); - - final Button ok = new Button("Login"); - custom.addComponent(ok, "okbutton"); - - final Button deny = new Button("No can do!"); - - Button.ClickListener listener = new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - // Switch between ok and deny - if (custom.getComponent("okbutton") == ok) { - System.out.println("Changing to deny button."); - custom.addComponent(deny, "okbutton"); - } else { - System.out.println("Changing to ok button."); - custom.addComponent(ok, "okbutton"); - } - } - }; - - ok.addListener(listener); - deny.addListener(listener); - } - - void example_Spacing(final Window main, String param) { - VerticalLayout containinglayout = new VerticalLayout(); - main.setLayout(containinglayout); - - GridLayout grid = new GridLayout(4, 3); - grid.addStyleName("spacingexample"); - containinglayout.addComponent(grid); - grid.addComponent(new Label(""), 0, 0); - grid.addComponent(new Label(""), 1, 0); - - grid.addComponent(new Label("No spacing:"), 0, 1); - HorizontalLayout layout1 = new HorizontalLayout(); - grid.addComponent(layout1, 1, 1); - layout1.addStyleName("spacingexample"); - layout1.addComponent(new Button("Component 1")); - layout1.addComponent(new Button("Component 2")); - layout1.addComponent(new Button("Component 3")); - - grid.addComponent(new Label("Horizontal spacing:"), 0, 2); - HorizontalLayout layout2 = new HorizontalLayout(); - grid.addComponent(layout2, 1, 2); - layout2.addStyleName("spacingexample"); - layout2.setSpacing(true); - layout2.addComponent(new Button("Component 1")); - layout2.addComponent(new Button("Component 2")); - layout2.addComponent(new Button("Component 3")); - - grid.addComponent(new Label("No spacing:"), 2, 0); - VerticalLayout layout3 = new VerticalLayout(); - grid.addComponent(layout3, 2, 1, 2, 2); - layout3.addStyleName("spacingexample"); - layout3.addComponent(new Button("Component 1")); - layout3.addComponent(new Button("Component 2")); - layout3.addComponent(new Button("Component 3")); - - grid.addComponent(new Label("Vertical spacing:"), 3, 0); - VerticalLayout layout4 = new VerticalLayout(); - grid.addComponent(layout4, 3, 1, 3, 2); - layout4.addStyleName("spacingexample"); - layout4.setSpacing(true); - layout4.addComponent(new Button("Component 1")); - layout4.addComponent(new Button("Component 2")); - layout4.addComponent(new Button("Component 3")); - } - - void example_Margin(final Window main, String param) { - HorizontalLayout hor = new HorizontalLayout(); - main.setLayout(hor); - - VerticalLayout containinglayout = new VerticalLayout(); - hor.addComponent(containinglayout); - - VerticalLayout layout1 = new VerticalLayout(); - containinglayout.addComponent(new Label("Regular layout margins:")); - containinglayout.addComponent(layout1); - layout1.addStyleName("marginexample1"); - layout1.addComponent(new Button("Component 1")); - layout1.addComponent(new Button("Component 2")); - layout1.addComponent(new Button("Component 3")); - - // Create a layout - VerticalLayout layout2 = new VerticalLayout(); - containinglayout.addComponent(new Label( - "Layout with a special margin element:")); - containinglayout.addComponent(layout2); - - // Set style name for the layout to allow styling it - layout2.addStyleName("marginexample2"); - - // Have margin on all sides around the layout - layout2.setMargin(true); - - // Put something inside the layout - layout2.addComponent(new Button("Component 1")); - layout2.addComponent(new Button("Component 2")); - layout2.addComponent(new Button("Component 3")); - } - - void example_ClientInfo(final Window main, String param) { - // Get the client identification string - WebApplicationContext context2 = (WebApplicationContext) getContext(); - String browserApplication = context2.getBrowser() - .getBrowserApplication(); - - // Add a browser-dependent style name for the main window - if (browserApplication.indexOf("Firefox/2") != -1) { - main.addStyleName("firefox2"); - } - - // Display the client identification string - main.addComponent(new Label(browserApplication)); - } - - void example_FillInForm(final Window main, String param) { - if (param.equals("templates")) { - // Create a custom layout from the fill-in-form.html template. - CustomLayout fillinlayout = new CustomLayout("fill-in-form"); - - // The style will set the display to be "inline". - fillinlayout.addStyleName("fillinlayout"); - - // Create the fields that occur in the text. - TextField field1 = new TextField(); - TextField field2 = new TextField(); - fillinlayout.addComponent(field1, "q1"); - fillinlayout.addComponent(field2, "q2"); - - main.addComponent(fillinlayout); - } else { - String fillintext = "The <q1> is mightier than <q2>."; - int pos = 0; - while (pos < fillintext.length()) { - int nexttag = fillintext.indexOf("<", pos); - if (nexttag == -1) { - - } - } - } - } - - void example_Notification(final Window main, String param) { - // final Window sub1 = new Window(""); - // main.addWindow(sub1); - if (param.equals("example")) { - main.showNotification("This is the caption", - "This is the description"); - return; - } else if (param.equals("type")) { - main.showNotification("This is a warning", - "<br/>This is the <i>last</i> warning", - Window.Notification.TYPE_WARNING_MESSAGE); - return; - } else if (param.equals("pos")) { - // Create a notification with the default settings for a warning. - Window.Notification notif = new Window.Notification("Be warned!", - "This message lurks in the top-left corner!", - Window.Notification.TYPE_WARNING_MESSAGE); - - // Set the position. - notif.setPosition(Window.Notification.POSITION_TOP_LEFT); - - // Let it stay there until the user clicks it - notif.setDelayMsec(-1); - - // Show it in the main window. - main.showNotification(notif); - return; - } - - main.setLayout(new HorizontalLayout()); - - final Integer type_humanized = Window.Notification.TYPE_HUMANIZED_MESSAGE; - final Integer type_warning = Window.Notification.TYPE_WARNING_MESSAGE; - final Integer type_error = Window.Notification.TYPE_ERROR_MESSAGE; - final Integer type_tray = Window.Notification.TYPE_TRAY_NOTIFICATION; - final NativeSelect types = new NativeSelect(); - main.addComponent(types); - types.addItem(type_humanized); - types.addItem(type_warning); - types.addItem(type_error); - types.addItem(type_tray); - types.setItemCaption(type_humanized, "Humanized"); - types.setItemCaption(type_warning, "Warning"); - types.setItemCaption(type_error, "Error"); - types.setItemCaption(type_tray, "Tray"); - - Button show = new Button("Show Notification"); - main.addComponent(show); - - show.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - String caption = ""; - String description = ""; - switch (((Integer) types.getValue()).intValue()) { - case Window.Notification.TYPE_HUMANIZED_MESSAGE: - caption = "Humanized message"; - description = "<br/>For minimal annoyance"; - break; - case Window.Notification.TYPE_WARNING_MESSAGE: - caption = "Warning message"; - description = "<br/>For notifications of medium importance"; - break; - case Window.Notification.TYPE_ERROR_MESSAGE: - caption = "Error message"; - description = "<br/>For important notifications"; - break; - case Window.Notification.TYPE_TRAY_NOTIFICATION: - caption = "Tray notification"; - description = "<br/>Stays up longer - but away"; - } - // main.showNotification("The default notification"); - Window.Notification notif = new Window.Notification(caption, - description, (Integer) types.getValue()); - // notif.setPosition(Window.Notification.POSITION_TOP_LEFT); - notif.setDelayMsec(-1); - main.showNotification(notif); - } - }); - - // Notification notif = new Notification("Title"); - } - - void example_Print(final Window main, String param) { - if (param != null && param.equals("simple")) { - main.addComponent(new Label( - "<input type='button' onClick='print()' value='Click to Print'/>", - Label.CONTENT_XHTML)); - return; - } - - // A button to open the printer-friendly page. - Button printButton = new Button("Click to Print"); - main.addComponent(printButton); - printButton.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - // Create a window that contains stuff you want to print. - Window printWindow = new Window("Window to Print"); - - // Have some content to print. - printWindow.addComponent(new Label( - "Here's some dynamic content.")); - - // To execute the print() JavaScript, we need to run it - // from a custom layout. - CustomLayout scriptLayout = new CustomLayout("printpage"); - printWindow.addComponent(scriptLayout); - - // Add the printing window as an application-level window. - main.getApplication().addWindow(printWindow); - - // Open the printing window as a new browser window - main.open(new ExternalResource(printWindow.getURL()), "_new"); - } - }); - - // main.addComponent(new - // Label("<p>Print this!</p>\n<script type='text/javascript'>print();</script>", - // Label.CONTENT_XHTML)); - } - - void example_RichTextArea(final Window main, String param) { - main.setLayout(new HorizontalLayout()); - - // Create a rich text area - final RichTextArea rtarea = new RichTextArea(); - rtarea.addStyleName("richtextexample"); - // rtarea.setCaption("My Rich Text Area"); - - // Set initial content as HTML - rtarea.setValue("<h1>Hello</h1>\n<p>This rich text area contains some text.</p>"); - - // Show the text edited in the rich text area as HTML. - final Button show = new Button("Show HTML"); - final Label html = new Label((String) rtarea.getValue()); - show.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - html.setValue(rtarea.getValue()); - } - }); - - Panel rtPanel = new Panel("Rich Text Area"); - rtPanel.addComponent(rtarea); - rtPanel.addComponent(show); - - Panel valuePanel = new Panel("Value"); - valuePanel.addComponent(html); - - main.addComponent(rtPanel); - main.addComponent(valuePanel); - } - - void example_QueryContainer(final Window main, String param) { - try { - // Create a database connection - Class.forName("org.hsqldb.jdbcDriver"); - final Connection connection = DriverManager.getConnection( - "jdbc:hsqldb:mem:qcexample", "sa", ""); - - // Create an example table and put some data in it. - Statement st = connection.createStatement(); - st.executeQuery("CREATE TABLE Prisoners (id INTEGER, name VARCHAR)"); - st.close(); - for (int i = 0; i < 100; i++) { - st = connection.createStatement(); - st.executeQuery("INSERT INTO Prisoners (id, name) VALUES (" + i - + ",'I am number " + (i + 1) + "')"); - st.close(); - } - - // Query the database - final QueryContainer qc = new QueryContainer( - "SELECT id,name FROM Prisoners", connection); - - // Create a component for selecting a query result item. - Select select = new Select("Select an item"); - - // The items shown in the selection component are obtained from the - // query. - select.setContainerDataSource(qc); - - // The item captions are obtained from a field in the query result. - select.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY); - - // Set the name of the field from which the item captions are - // obtained. - select.setItemCaptionPropertyId("name"); - - // When selection changes, display the selected item. - select.setImmediate(true); - final Label selection = new Label("Currently selected: -"); - select.addListener(new ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - // Get the item id of the currently selected item - Integer itemId = (Integer) event.getProperty().getValue(); - - // Use the item ID to get the actual row from the query - // result. - Item qrItem = qc.getItem(itemId); - - // Display the item ID - selection.setValue("Currently selected: result row " - + itemId.intValue() + " (id=" - + qrItem.getItemProperty("id") + ", " + "name=" - + qrItem.getItemProperty("name") + ")"); - } - }); - - main.addComponent(select); - main.addComponent(selection); - } catch (SQLException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } - - void example_MenuBar(final Window main, String param) { - // Create a menu bar - final MenuBar menubar = new MenuBar(); - main.addComponent(menubar); - - // A feedback component - final Label selection = new Label(""); - main.addComponent(selection); - - // Define a common menu command for all the menu items. - MenuBar.Command mycommand = new MenuBar.Command() { - public void menuSelected(MenuItem selectedItem) { - selection.setValue("Ordered a " + selectedItem.getText() - + " from menu."); - } - }; - - // Put some items in the menu hierarchically - MenuBar.MenuItem beverages = menubar.addItem("Beverages", null, null); - MenuBar.MenuItem hot_beverages = beverages.addItem("Hot", null, null); - hot_beverages.addItem("Tea", null, mycommand); - hot_beverages.addItem("Coffee", null, mycommand); - MenuBar.MenuItem cold_beverages = beverages.addItem("Cold", null, null); - cold_beverages.addItem("Milk", null, mycommand); - - // Another top-level item - MenuBar.MenuItem snacks = menubar.addItem("Snacks", null, null); - snacks.addItem("Weisswurst", null, mycommand); - snacks.addItem("Salami", null, mycommand); - - // Yet another top-level item - MenuBar.MenuItem services = menubar.addItem("Services", null, null); - services.addItem("Car Service", null, mycommand); - } - - void example_AbsoluteLayout(final Window main, String param) { - AbsoluteLayout layout = new AbsoluteLayout(); - layout.setWidth("400px"); - layout.setHeight("400px"); - main.setContent(layout); - - final Button button = new Button("This could be anywhere"); - layout.addComponent(button, "top: 100px; left: 50px;"); - } - - void example_Layout(final Window main, String param) { - if (param.equals("intro")) { - // Set the root layout (VerticalLayout is actually the default). - VerticalLayout root = new VerticalLayout(); - main.setContent(root); - - // Add some components. - Label title = new Label("The Ultimate Cat Finder"); - main.addComponent(title); - - // Horizontal layout with selection tree on the left and - // a details panel on the right. - HorizontalLayout horlayout = new HorizontalLayout(); - main.addComponent(horlayout); - - // Layout for the left-hand side - VerticalLayout treeContainer = new VerticalLayout(); - horlayout.addComponent(treeContainer); - - // Add some instructions. - treeContainer - .addComponent(new Label("The Planets and Major Moons")); - - // A selection tree, fill it later. - Tree tree = new Tree(); - treeContainer.addComponent(tree); - - // A panel for the right size area. - Panel detailspanel = new Panel("Details"); - detailspanel.setSizeFull(); - horlayout.addComponent(detailspanel); - - // Have a vertical layout in the Details panel. - VerticalLayout detailslayout = new VerticalLayout(); - detailspanel.setContent(detailslayout); - - // Put some stuff in the Details view. - detailslayout.addComponent(new Label("Where is the cat?")); - detailslayout.addComponent(new Label("I don't know!")); - - // // // // // // - - horlayout.setExpandRatio(detailspanel, 1); - horlayout.setExpandRatio(treeContainer, 0); - horlayout.setSizeFull(); - horlayout.setSpacing(true); - - root.addStyleName("layoutexample"); - root.setSizeFull(); - root.setExpandRatio(horlayout, 1); - - title.addStyleName("title"); - tree.setSizeUndefined(); - tree.setHeight("100%"); - treeContainer.addStyleName("treecontainer"); - treeContainer.setSizeUndefined(); - treeContainer.setHeight("100%"); - treeContainer.setExpandRatio(tree, 1); - detailspanel.addStyleName("light"); - - for (Iterator i = detailslayout.getComponentIterator(); i.hasNext();) { - Label c = (Label) i.next(); - detailslayout.setComponentAlignment(c, Alignment.MIDDLE_CENTER); - c.setSizeUndefined(); - } - - final Object[][] planets = new Object[][] { - new Object[] { "Mercury" }, - new Object[] { "Venus" }, - new Object[] { "Earth", "The Moon" }, - new Object[] { "Mars", "Phobos", "Deimos" }, - new Object[] { "Jupiter", "Io", "Europa", "Ganymedes", - "Callisto" }, - new Object[] { "Saturn", "Titan", "Tethys", "Dione", - "Rhea", "Iapetus" }, - new Object[] { "Uranus", "Miranda", "Ariel", "Umbriel", - "Titania", "Oberon" }, - new Object[] { "Neptune", "Triton", "Proteus", "Nereid", - "Larissa" } }; - - // Add planets as root items in the tree. - for (int i = 0; i < planets.length; i++) { - final String planet = (String) (planets[i][0]); - tree.addItem(planet); - - if (planets[i].length == 1) { - // The planet has no moons so make it a leaf. - tree.setChildrenAllowed(planet, false); - } else { - // Add children (moons) under the planets. - for (int j = 1; j < planets[i].length; j++) { - final String moon = (String) planets[i][j]; - - // Add the item as a regular item. - tree.addItem(moon); - - // Set it to be a child. - tree.setParent(moon, planet); - - // Make the moons look like leaves. - tree.setChildrenAllowed(moon, false); - } - - // Expand the subtree. - tree.expandItemsRecursively(planet); - } - } - - } - } -} diff --git a/tests/src/com/vaadin/tests/book/ChatApplication.java b/tests/src/com/vaadin/tests/book/ChatApplication.java deleted file mode 100644 index d6470dcc4f..0000000000 --- a/tests/src/com/vaadin/tests/book/ChatApplication.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.vaadin.tests.book; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import com.vaadin.Application; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.ProgressIndicator; -import com.vaadin.ui.Table; -import com.vaadin.ui.TextField; -import com.vaadin.ui.Window; - -public class ChatApplication extends Application implements - Button.ClickListener { - /* - * ChatApplication instances of different users. Warning: a hack, not safe, - * because sessions can expire. - */ - static List users = new ArrayList(); - - /* Messages as a shared list. */ - static List messages = new ArrayList(); - int localSize = 0; - - /* User interface. */ - Table messageTable = new Table(); - TextField username = new TextField("Username:"); - TextField message = new TextField("Message:"); - - @Override - public void init() { - final Window main = new Window("Chat"); - setMainWindow(main); - setTheme("tests-magi"); - users.add(this); - - main.addComponent(username); - - main.addComponent(messageTable); - messageTable.addContainerProperty("Sender", String.class, ""); - messageTable.addContainerProperty("Message", String.class, ""); - updateTable(); - - main.addComponent(message); - - Button send = new Button("Send"); - send.addListener(this); - main.addComponent(send); - - // Poll for new messages once a second. - ProgressIndicator poller = new ProgressIndicator(); - poller.addStyleName("invisible"); - main.addComponent(poller); - } - - public void buttonClick(ClickEvent event) { - synchronized (users) { - // Create the new message in the shared list. - messages.add(new String[] { - new String((String) username.getValue()), - new String((String) message.getValue()) }); - - // Update the message tables for all users. - for (Iterator i = users.iterator(); i.hasNext();) { - ((ChatApplication) i.next()).updateTable(); - } - } - } - - void updateTable() { - if (localSize == messages.size()) { - return; // No updating needed - } - - // Add new messages to the table - while (localSize < messages.size()) { - messageTable.addItem((Object[]) messages.get(localSize++), - new Integer(localSize - 1)); - } - } -} diff --git a/tests/src/com/vaadin/tests/book/DefaultButtonExample.java b/tests/src/com/vaadin/tests/book/DefaultButtonExample.java deleted file mode 100644 index c1520c208d..0000000000 --- a/tests/src/com/vaadin/tests/book/DefaultButtonExample.java +++ /dev/null @@ -1,94 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.event.Action; -import com.vaadin.event.Action.Handler; -import com.vaadin.event.ShortcutAction; -import com.vaadin.ui.Button; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Panel; -import com.vaadin.ui.TextField; - -public class DefaultButtonExample extends CustomComponent implements Handler { - // Define and create user interface components - Panel panel = new Panel("Login"); - FormLayout formlayout = new FormLayout(); - TextField username = new TextField("Username"); - TextField password = new TextField("Password"); - HorizontalLayout buttons = new HorizontalLayout(); - - // Create buttons and define their listener methods. - Button ok = new Button("OK", this, "okHandler"); - Button cancel = new Button("Cancel", this, "cancelHandler"); - - // Have the unmodified Enter key cause an event - Action action_ok = new ShortcutAction("Default key", - ShortcutAction.KeyCode.ENTER, null); - - // Have the C key modified with Alt cause an event - Action action_cancel = new ShortcutAction("Alt+C", - ShortcutAction.KeyCode.C, - new int[] { ShortcutAction.ModifierKey.ALT }); - - public DefaultButtonExample() { - // Set up the user interface - setCompositionRoot(panel); - panel.addComponent(formlayout); - formlayout.addComponent(username); - formlayout.addComponent(password); - formlayout.addComponent(buttons); - buttons.addComponent(ok); - buttons.addComponent(cancel); - - // Set focus to username - username.focus(); - - // Set this object as the action handler - System.out.println("adding ah"); - panel.addActionHandler(this); - - System.out.println("start done."); - } - - /** - * Retrieve actions for a specific component. This method will be called for - * each object that has a handler; in this example just for login panel. The - * returned action list might as well be static list. - */ - public Action[] getActions(Object target, Object sender) { - System.out.println("getActions()"); - return new Action[] { action_ok, action_cancel }; - } - - /** - * Handle actions received from keyboard. This simply directs the actions to - * the same listener methods that are called with ButtonClick events. - */ - public void handleAction(Action action, Object sender, Object target) { - if (action == action_ok) { - okHandler(); - } - if (action == action_cancel) { - cancelHandler(); - } - } - - public void okHandler() { - // Do something: report the click - formlayout.addComponent(new Label("OK clicked. " + "User=" - + username.getValue() + ", password=" + password.getValue())); - // - } - - public void cancelHandler() { - // Do something: report the click - formlayout.addComponent(new Label("Cancel clicked. User=" - + username.getValue() + ", password=" + password.getValue())); - } -} diff --git a/tests/src/com/vaadin/tests/book/EmbeddedButton.java b/tests/src/com/vaadin/tests/book/EmbeddedButton.java deleted file mode 100644 index 2ed67f0305..0000000000 --- a/tests/src/com/vaadin/tests/book/EmbeddedButton.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.terminal.Resource; -import com.vaadin.ui.Button; -import com.vaadin.ui.CustomComponent; - -public class EmbeddedButton extends CustomComponent implements - Button.ClickListener { - Button thebutton; - - public EmbeddedButton(Resource icon) { - /* Create a Button without a caption. */ - thebutton = new Button(); - - /* Set the icon of the button from a resource. */ - thebutton.setIcon(icon); - - /* - * Set the style to link; this leaves out the button frame so you just - * have the image in the link. - */ - thebutton.setStyle("link"); - - /* Listen for ClickEvents. */ - thebutton.addListener(this); - - setCompositionRoot(thebutton); - } - - /** Handle button click events from the button. */ - public void buttonClick(Button.ClickEvent event) { - thebutton.setIcon(null); - thebutton.setCaption("You successfully clicked on the icon"); - } -} diff --git a/tests/src/com/vaadin/tests/book/FormExample.java b/tests/src/com/vaadin/tests/book/FormExample.java deleted file mode 100644 index 0c50df736b..0000000000 --- a/tests/src/com/vaadin/tests/book/FormExample.java +++ /dev/null @@ -1,228 +0,0 @@ -package com.vaadin.tests.book; - -import java.util.Vector; - -import com.vaadin.data.Container; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.Validator; -import com.vaadin.data.util.BeanItem; -import com.vaadin.ui.Button; -import com.vaadin.ui.Component; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.ExpandLayout; -import com.vaadin.ui.Field; -import com.vaadin.ui.FieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Select; -import com.vaadin.ui.TextField; - -/** - * This example demonstrates the most important features of the Form component: - * binding Form to a JavaBean so that form fields are automatically generated - * from the bean properties, creation of fields with proper types for each bean - * properly using a FieldFactory, buffering (commit/discard), and validation. - * - * The Form is used with a FormLayout, which automatically lays the components - * out in a format typical for forms. - */ -public class FormExample extends CustomComponent { - /** Contact information data model. */ - public class Contact { - String name = ""; - String address = ""; - int postalCode = 20540; - String city; - } - - /** Bean wrapper for the data model. */ - public class ContactBean extends Contact { - public ContactBean() { - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getAddress() { - return address; - } - - public void setPostalCode(String postalCode) { - try { - if (postalCode != null) { - this.postalCode = Integer.parseInt(postalCode); - } else { - this.postalCode = 0; - } - } catch (NumberFormatException e) { - this.postalCode = 0; - } - } - - public String getPostalCode() { - if (postalCode > 0) { - return String.valueOf(postalCode); - } else { - return ""; - } - } - - public void setCity(String city) { - this.city = city; - } - - public String getCity() { - return city; - } - } - - /** - * Factory to create the proper type of field for each property type. We - * need to implement just one of the factory methods. - */ - class MyFieldFactory implements FieldFactory { - - public Field createField(Class type, Component uiContext) { - return null; - } - - public Field createField(Property property, Component uiContext) { - return null; - } - - public Field createField(Item item, Object propertyId, - Component uiContext) { - String pid = (String) propertyId; - - if (pid.equals("name")) { - return new TextField("Name"); - } - - if (pid.equals("address")) { - return new TextField("Street Address"); - } - - if (pid.equals("postalCode")) { - TextField field = new TextField("Postal Code"); - field.setColumns(5); - Validator postalCodeValidator = new Validator() { - - public boolean isValid(Object value) { - if (value == null || !(value instanceof String)) { - return false; - } - - return ((String) value).matches("[0-9]{5}"); - } - - public void validate(Object value) - throws InvalidValueException { - if (!isValid(value)) { - throw new InvalidValueException( - "Postal code must be a number 10000-99999."); - } - } - }; - field.addValidator(postalCodeValidator); - return field; - } - - if (pid.equals("city")) { - Select select = new Select("City"); - final String cities[] = new String[] { "Amsterdam", "Berlin", - "Helsinki", "Hong Kong", "London", "Luxemburg", - "New York", "Oslo", "Paris", "Rome", "Stockholm", - "Tokyo", "Turku" }; - for (int i = 0; i < cities.length; i++) { - select.addItem(cities[i]); - } - return select; - } - return null; - } - - public Field createField(Container container, Object itemId, - Object propertyId, Component uiContext) { - return null; - } - } - - public FormExample() { - // Create a form. It will use FormLayout as its layout by default. - final Form form = new Form(); - - // Set form caption and description texts. - form.setCaption("Contact Information"); - form.setDescription("Please enter valid name and address. Fields marked with * are required."); - - // Use custom field factory to create the fields in the form. - form.setFieldFactory(new MyFieldFactory()); - - // Create the custom bean. - ContactBean bean = new ContactBean(); - - // Create a bean item that is bound to the bean. - BeanItem item = new BeanItem(bean); - - // Bind the bean item as the data source for the form. - form.setItemDataSource(item); - - // Set the order of the items in the form. - Vector order = new Vector(); - order.add("name"); - order.add("address"); - order.add("postalCode"); - order.add("city"); - form.setVisibleItemProperties(order); - - // Set required fields. The required error is displayed in - // the error indication are of the Form if a required - // field is empty. If it is not set, no error is displayed - // about an empty required field. - form.getField("name").setRequired(true); - form.getField("name").setRequiredError("Name is missing"); - form.getField("address").setRequired(true); // No error message - - // Set the form to act immediately on user input. This is - // necessary for the validation of the fields to occur immediately when - // the input focus changes and not just on commit. - form.setImmediate(true); - - // Set buffering so that commit() must be called for the form - // before input is written to the data. (Input is not written - // immediately through). - form.setWriteThrough(false); - form.setReadThrough(false); - - // Add Commit and Discard controls to the form. - ExpandLayout footer = new ExpandLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); - - // The Commit button calls form.commit(). - Button commit = new Button("Commit", form, "commit"); - - // The Discard button calls form.discard(). - Button discard = new Button("Discard", form, "discard"); - footer.addComponent(commit); - footer.setComponentAlignment(commit, ExpandLayout.ALIGNMENT_RIGHT, - ExpandLayout.ALIGNMENT_TOP); - footer.setHeight("25px"); - footer.addComponent(discard); - form.setFooter(footer); - - OrderedLayout root = new OrderedLayout(); - root.setWidth(400, OrderedLayout.UNITS_PIXELS); - root.addComponent(form); - setCompositionRoot(root); - } -} diff --git a/tests/src/com/vaadin/tests/book/FormExample2.java b/tests/src/com/vaadin/tests/book/FormExample2.java deleted file mode 100644 index d19a317966..0000000000 --- a/tests/src/com/vaadin/tests/book/FormExample2.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.vaadin.tests.book; - -import java.util.Vector; - -import com.vaadin.data.Container; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.util.BeanItem; -import com.vaadin.ui.Component; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Field; -import com.vaadin.ui.FieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Select; -import com.vaadin.ui.TextField; - -/** - * This example demonstrates the most important features of the Form component: - * binding Form to a JavaBean so that form fields are automatically generated - * from the bean properties, creation of fields with proper types for each bean - * properly using a FieldFactory, buffering (commit/discard), and validation. - * - * The Form is used with a FormLayout, which automatically lays the components - * out in a format typical for forms. - */ -public class FormExample2 extends CustomComponent { - /** A simple JavaBean. */ - public class PersonBean { - String name = ""; - String city = ""; - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setCity(String city) { - this.city = city; - } - - public String getCity() { - return city; - } - } - - /** - * Factory to create the proper type of field for each property type. We - * need to implement just one of the factory methods. - */ - class MyFieldFactory implements FieldFactory { - - public Field createField(Class type, Component uiContext) { - return null; - } - - public Field createField(Property property, Component uiContext) { - return null; - } - - public Field createField(Item item, Object propertyId, - Component uiContext) { - String pid = (String) propertyId; - if (pid.equals("name")) { - return new TextField("Name"); - } else if (pid.equals("city")) { - Select select = new Select("City"); - select.addItem("Berlin"); - select.addItem("Helsinki"); - select.addItem("London"); - select.addItem("New York"); - select.addItem("Turku"); - select.setNewItemsAllowed(true); - return select; - } - return null; - } - - public Field createField(Container container, Object itemId, - Object propertyId, Component uiContext) { - return null; - } - } - - public FormExample2() { - // Create a form and use FormLayout as its layout. - final Form form = new Form(); - - // Set form caption and description texts - form.setCaption("Contact Information"); - form.setDescription("Please specify name of the person and the city where the person lives in."); - - // Use the custom field factory to create the fields in the form. - form.setFieldFactory(new MyFieldFactory()); - - // Create the custom bean. - PersonBean bean = new PersonBean(); - - // Create a bean item that is bound to the bean. - BeanItem item = new BeanItem(bean); - - // Bind the bean item as the data source for the form. - form.setItemDataSource(item); - - // Set the order of the items in the form. - Vector order = new Vector(); - order.add("name"); - order.add("city"); - form.setVisibleItemProperties(order); - - form.getField("name").setRequired(true); - form.getField("name").setRequiredError("You must enter a name."); - form.getField("city").setRequired(true); - - OrderedLayout root = new OrderedLayout(); - root.setWidth(300, OrderedLayout.UNITS_PIXELS); - root.addComponent(form); - setCompositionRoot(root); - } -} diff --git a/tests/src/com/vaadin/tests/book/MyDynamicResource.java b/tests/src/com/vaadin/tests/book/MyDynamicResource.java deleted file mode 100644 index db013df085..0000000000 --- a/tests/src/com/vaadin/tests/book/MyDynamicResource.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.vaadin.tests.book; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Map; - -import javax.imageio.ImageIO; - -import com.vaadin.terminal.DownloadStream; -import com.vaadin.terminal.ParameterHandler; -import com.vaadin.terminal.URIHandler; - -/** - * Demonstrates handling URI parameters and the URI itself to create a dynamic - * resource. - */ -public class MyDynamicResource implements URIHandler, ParameterHandler { - String textToDisplay = "- no text given -"; - - /** - * Handle the URL parameters and store them for the URI handler to use. - */ - public void handleParameters(Map parameters) { - // Get and store the passed HTTP parameter. - if (parameters.containsKey("text")) { - textToDisplay = ((String[]) parameters.get("text"))[0]; - } - } - - /** - * Provides the dynamic resource if the URI matches the resource URI. The - * matching URI is "/myresource" under the application URI context. - * - * Returns null if the URI does not match. Otherwise returns a download - * stream that contains the response from the server. - */ - public DownloadStream handleURI(URL context, String relativeUri) { - // Catch the given URI that identifies the resource, otherwise let other - // URI handlers or the Application to handle the response. - if (!relativeUri.startsWith("myresource")) { - return null; - } - - // Create an image and draw some background on it. - BufferedImage image = new BufferedImage(200, 200, - BufferedImage.TYPE_INT_RGB); - Graphics drawable = image.getGraphics(); - drawable.setColor(Color.lightGray); - drawable.fillRect(0, 0, 200, 200); - drawable.setColor(Color.yellow); - drawable.fillOval(25, 25, 150, 150); - drawable.setColor(Color.blue); - drawable.drawRect(0, 0, 199, 199); - - // Use the parameter to create dynamic content. - drawable.setColor(Color.black); - drawable.drawString("Text: " + textToDisplay, 75, 100); - - try { - // Write the image to a buffer. - ByteArrayOutputStream imagebuffer = new ByteArrayOutputStream(); - ImageIO.write(image, "png", imagebuffer); - - // Return a stream from the buffer. - ByteArrayInputStream istream = new ByteArrayInputStream( - imagebuffer.toByteArray()); - return new DownloadStream(istream, null, null); - } catch (IOException e) { - return null; - } - } -} diff --git a/tests/src/com/vaadin/tests/book/MyUploader.java b/tests/src/com/vaadin/tests/book/MyUploader.java deleted file mode 100644 index cc953e79cf..0000000000 --- a/tests/src/com/vaadin/tests/book/MyUploader.java +++ /dev/null @@ -1,81 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; - -import com.vaadin.terminal.FileResource; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Embedded; -import com.vaadin.ui.Label; -import com.vaadin.ui.Panel; -import com.vaadin.ui.Upload; - -public class MyUploader extends CustomComponent implements - Upload.SucceededListener, Upload.FailedListener, Upload.Receiver { - Panel root; // Root element for contained components. - Panel imagePanel; // Panel that contains the uploaded image. - File file; // File to write to. - - MyUploader() { - root = new Panel("My Upload Component"); - setCompositionRoot(root); - - // Create the Upload component. - final Upload upload = new Upload("Upload the file here", this); - upload.setButtonCaption("Upload Now"); - - // Listen for Upload.SucceededEvent and FailedEvent events. - upload.addListener((Upload.SucceededListener) this); - upload.addListener((Upload.FailedListener) this); - - root.addComponent(upload); - root.addComponent(new Label( - "Click 'Browse' to select a file and then click 'Upload'.")); - - // Create a panel for displaying the uploaded file (image). - imagePanel = new Panel("Uploaded image"); - imagePanel.addComponent(new Label("No image uploaded yet")); - root.addComponent(imagePanel); - } - - // Callback method to begin receiving the upload. - public OutputStream receiveUpload(String filename, String MIMEType) { - FileOutputStream fos = null; // Output stream to write to. - file = new File("/tmp/uploads/" + filename); - try { - // Open the file for writing. - fos = new FileOutputStream(file); - } catch (final java.io.FileNotFoundException e) { - // Error while opening the file. Not reported here. - e.printStackTrace(); - return null; - } - - return fos; // Return the output stream to write to - } - - // This is called if the upload is finished successfully. - public void uploadSucceeded(Upload.SucceededEvent event) { - // Log the upload on screen. - root.addComponent(new Label("File " + event.getFilename() - + " of type '" + event.getMIMEType() + "' uploaded.")); - - // Display the uploaded file in the image panel. - final FileResource imageResource = new FileResource(file, - getApplication()); - imagePanel.removeAllComponents(); - imagePanel.addComponent(new Embedded("", imageResource)); - } - - // This is called if the upload fails. - public void uploadFailed(Upload.FailedEvent event) { - // Log the failure on screen. - root.addComponent(new Label("Uploading " + event.getFilename() - + " of type '" + event.getMIMEType() + "' failed.")); - } -} diff --git a/tests/src/com/vaadin/tests/book/SSNField.java b/tests/src/com/vaadin/tests/book/SSNField.java deleted file mode 100644 index 029b905eed..0000000000 --- a/tests/src/com/vaadin/tests/book/SSNField.java +++ /dev/null @@ -1,98 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.Validator; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.TextField; - -/* Finnish Social Security Number input field that validates the value. */ -public class SSNField extends CustomComponent implements - Property.ValueChangeListener { - OrderedLayout layout = new FormLayout(); - // new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); //;new - // FormLayout(); - TextField myfield; - Label myerror; - - /** Validator for Finnish Social Security Number. */ - class SSNValidator implements Validator { - - /** The isValid() is simply a wrapper for the validate() method. */ - public boolean isValid(Object value) { - try { - validate(value); - } catch (final InvalidValueException e) { - return false; - } - return true; - } - - /** Validate the given SSN. */ - public void validate(Object value) throws InvalidValueException { - final String ssn = (String) value; - if (ssn.length() == 0) { - return; - } - - if (ssn.length() != 11) { - throw new InvalidValueException("Invalid SSN length"); - } - - final String numbers = ssn.substring(0, 6) + ssn.substring(7, 10); - final int checksum = new Integer(numbers).intValue() % 31; - if (!ssn.substring(10).equals( - "0123456789ABCDEFHJKLMNPRSTUVWXY".substring(checksum, - checksum + 1))) { - throw new InvalidValueException("Invalid SSN checksum"); - } - } - } - - SSNField() { - setCompositionRoot(layout); - layout.setOrientation(FormLayout.ORIENTATION_VERTICAL); - - /* Create the text field for the SSN. */ - myfield = new TextField("Social Security Number"); - myfield.setColumns(11); - - /* Create and set the validator object for the field. */ - myfield.addValidator(new SSNValidator()); - - /* - * ValueChageEvent will be generated immediately when the component - * loses focus. - */ - myfield.setImmediate(true); - - /* Listen for ValueChangeEvent events. */ - myfield.addListener(this); - - layout.addComponent(myfield); - - /* The field will have an error label, normally invisible. */ - myerror = new Label(); - layout.addComponent(myerror); - } - - public void valueChange(ValueChangeEvent event) { - try { - /* Validate the field value. */ - myfield.validate(); - - /* The value was correct. */ - myerror.setValue("Ok"); - } catch (final Validator.InvalidValueException e) { - /* Report the error message to the user. */ - myerror.setValue(e.getMessage()); - } - } -} diff --git a/tests/src/com/vaadin/tests/book/SelectExample.java b/tests/src/com/vaadin/tests/book/SelectExample.java deleted file mode 100644 index f301e85c3f..0000000000 --- a/tests/src/com/vaadin/tests/book/SelectExample.java +++ /dev/null @@ -1,119 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.Application; -import com.vaadin.data.Property; -import com.vaadin.ui.AbstractSelect; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Label; -import com.vaadin.ui.NativeSelect; -import com.vaadin.ui.OptionGroup; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Select; -import com.vaadin.ui.TwinColSelect; - -/* Let us add an implementation of the ValueChangeListener interface. */ -public class SelectExample extends CustomComponent implements - Property.ValueChangeListener { - - class Planet extends Object { - String planetName; - - Planet(String name) { - planetName = name; - } - - @Override - public String toString() { - return "The Planet " + planetName; - } - } - - /* Create the Select object with a caption. */ - AbstractSelect select; - - OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - Label status = new Label(""); - - SelectExample(Application application, String param, String caption, - boolean multiselect) { - if (param.equals("optiongroup")) { - select = new OptionGroup(caption); - select.setMultiSelect(multiselect); - } else if (param.equals("twincol")) { - select = new TwinColSelect(caption); - } else if (param.equals("native")) { - select = new NativeSelect(caption); - } else if (param.equals("filter")) { - select = new Select(caption); - ((Select) select) - .setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS); - } else { - select = new Select(caption); - select.setMultiSelect(multiselect); - } - - layout.addComponent(select); - setCompositionRoot(layout); - - /* Fill the component with some items. */ - final String[] planets = new String[] { "Mercury", "Venus", "Earth", - "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" }; - - for (int i = 0; i < planets.length; i++) { - select.addItem(planets[i]); - - /* Create an item with an Integer as the Item ID. */ - // select.addItem(i); - // select.addItem(new Planet(planets[i])); - /* Set the visible caption of the item. */ - // select.setItemCaption(i, planets[i]); - /* - * ClassResource icon = new ClassResource - * ("images/"+planets[i]+"_symbol.png", application); - * layout.addComponent(new Embedded ("Icon", icon)); - * select.setItemIcon(i, icon); - */ - } - - /* - * By default, the change event is not triggered immediately when the - * selection changes. This enables it. - */ - select.setImmediate(true); - - /* Listen for changes in the selection. */ - select.addListener(this); - - // select.setStyle("twincol"); - // select.setMultiSelect(true); - // select.setNewItemsAllowed(true); - // int a=1; - - // select.setItemCaptionMode(Select.ITEM_CAPTION_MODE_ICON_ONLY); - // select.setNullSelectionItemId("-- select somethingd --"); - // select.setNullSelectionAllowed(false); - - layout.addComponent(status); - } - - /* Respond to change in the selection. */ - public void valueChange(Property.ValueChangeEvent event) { - /* - * The event.getProperty() returns the component. The currently selected - * item is the property of the component, retrievable with getValue(). - */ - if (false) { - status.setValue("Currently selected item ID: " - + event.getProperty().getValue() + "<br/>" - + "Class of the Item ID: " - + event.getProperty().getValue().getClass().getName() - + "<br/>" + "Caption: " - + select.getItemCaption(event.getProperty().getValue())); - status.setContentMode(Label.CONTENT_XHTML); - } - } -} diff --git a/tests/src/com/vaadin/tests/book/TabSheetExample.java b/tests/src/com/vaadin/tests/book/TabSheetExample.java deleted file mode 100644 index 766f20ff0c..0000000000 --- a/tests/src/com/vaadin/tests/book/TabSheetExample.java +++ /dev/null @@ -1,70 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Label; -import com.vaadin.ui.TabSheet; -import com.vaadin.ui.TabSheet.SelectedTabChangeEvent; - -public class TabSheetExample extends CustomComponent implements - Button.ClickListener, TabSheet.SelectedTabChangeListener { - TabSheet tabsheet = new TabSheet(); - Button tab1 = new Button("Push this button"); - Label tab2 = new Label("Contents of Second Tab"); - Label tab3 = new Label("Contents of Third Tab"); - - TabSheetExample() { - setCompositionRoot(tabsheet); - - // Listen for changes in tab selection. - tabsheet.addListener(this); - - // First tab contains a button, for which we - // listen button click events. - tab1.addListener(this); - - // This will cause a selectedTabChange() call. - tabsheet.addTab(tab1, "First Tab", null); - - // A tab that is initially invisible. - tabsheet.addTab(tab2, "Second Tab", null); - tabsheet.getTab(tab2).setVisible(false); - - // A tab that is initially disabled. - tabsheet.addTab(tab3, "Third tab", null); - tabsheet.getTab(tab3).setEnabled(false); - } - - public void buttonClick(ClickEvent event) { - // Enable the invisible and disabled tabs. - tabsheet.getTab(tab2).setVisible(true); - tabsheet.getTab(tab3).setEnabled(true); - - // Change selection automatically to second tab. - tabsheet.setSelectedTab(tab2); - } - - public void selectedTabChange(SelectedTabChangeEvent event) { - // Cast to a TabSheet. This isn't really necessary in - // this example, as we have only one TabSheet component, - // but would be useful if there were multiple TabSheets. - final TabSheet source = (TabSheet) event.getSource(); - - if (source == tabsheet) { - // If the first tab was selected. - if (source.getSelectedTab() == tab1) { - // The 2. and 3. tabs may not have been set yet. - if (tabsheet.getTab(tab2) != null - && tabsheet.getTab(tab3) != null) { - tabsheet.getTab(tab2).setVisible(false); - tabsheet.getTab(tab3).setEnabled(false); - } - } - } - } -} diff --git a/tests/src/com/vaadin/tests/book/TableCellStyle.java b/tests/src/com/vaadin/tests/book/TableCellStyle.java deleted file mode 100644 index d61b590a1d..0000000000 --- a/tests/src/com/vaadin/tests/book/TableCellStyle.java +++ /dev/null @@ -1,62 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Table; - -public class TableCellStyle extends CustomComponent { - public TableCellStyle() { - Table table = new Table("Table with Cell Styles"); - table.addStyleName("checkerboard"); - - // Add some columns in the table. In this example, the property IDs - // of the container are integers so we can determine the column number - // easily. - table.addContainerProperty("0", String.class, null, "", null, null); // Row - // header - for (int i = 0; i < 8; i++) { - table.addContainerProperty("" + (i + 1), String.class, null, - String.valueOf((char) (65 + i)), null, null); - } - - // Add some items in the table. - table.addItem(new Object[] { "1", "R", "N", "B", "Q", "K", "B", "N", - "R" }, new Integer(0)); - table.addItem(new Object[] { "2", "P", "P", "P", "P", "P", "P", "P", - "P" }, new Integer(1)); - for (int i = 2; i < 6; i++) { - table.addItem(new Object[] { String.valueOf(i + 1), "", "", "", "", - "", "", "", "" }, new Integer(i)); - } - table.addItem(new Object[] { "7", "P", "P", "P", "P", "P", "P", "P", - "P" }, new Integer(6)); - table.addItem(new Object[] { "8", "R", "N", "B", "Q", "K", "B", "N", - "R" }, new Integer(7)); - table.setPageLength(8); - - // Set cell style generator - table.setCellStyleGenerator(new Table.CellStyleGenerator() { - public String getStyle(Object itemId, Object propertyId) { - int row = ((Integer) itemId).intValue(); - int col = Integer.parseInt((String) propertyId); - - // The first column. - if (col == 0) { - return "rowheader"; - } - - // Other cells. - if ((row + col) % 2 == 1) { - return "black"; - } else { - return "white"; - } - } - }); - - setCompositionRoot(table); - } -} diff --git a/tests/src/com/vaadin/tests/book/TableEditable.java b/tests/src/com/vaadin/tests/book/TableEditable.java deleted file mode 100644 index 3e5dc0e613..0000000000 --- a/tests/src/com/vaadin/tests/book/TableEditable.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Table; - -public class TableEditable extends CustomComponent { - /* A layout needed for the example. */ - OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - - TableEditable() { - setCompositionRoot(layout); - - // Create a table. It is by default not editable. - final Table table = new Table(); - - // Define the names and data types of columns. - table.addContainerProperty("Date", Date.class, null); - table.addContainerProperty("Work", Boolean.class, null); - table.addContainerProperty("Comments", String.class, null); - - // Add a few items in the table. - for (int i = 0; i < 100; i++) { - Calendar calendar = new GregorianCalendar(2008, 0, 1); - calendar.add(Calendar.DAY_OF_YEAR, i); - - // Create the table row. - table.addItem( - new Object[] { calendar.getTime(), Boolean.FALSE, "" }, - new Integer(i)); // Item identifier - } - - table.setPageLength(8); - layout.addComponent(table); - - final CheckBox switchEditable = new CheckBox("Editable"); - switchEditable.addListener(new Property.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - table.setEditable(((Boolean) event.getProperty().getValue()) - .booleanValue()); - } - }); - switchEditable.setImmediate(true); - layout.addComponent(switchEditable); - } -} diff --git a/tests/src/com/vaadin/tests/book/TableEditableBean.java b/tests/src/com/vaadin/tests/book/TableEditableBean.java deleted file mode 100644 index e3828d29ee..0000000000 --- a/tests/src/com/vaadin/tests/book/TableEditableBean.java +++ /dev/null @@ -1,242 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import java.util.Collection; -import java.util.Vector; - -import com.vaadin.data.Container; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.util.BeanItem; -import com.vaadin.ui.AbstractField; -import com.vaadin.ui.BaseFieldFactory; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.Component; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Field; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Table; - -/** - * Shows how to bind a bean to a table and make it editable. - */ -public class TableEditableBean extends CustomComponent { - /** - * Let's have a simple example bean. - */ - public class MyBean { - boolean selected; - String text; - - public MyBean() { - selected = false; - text = ""; - } - - public boolean isSelected() { - System.out.println("isSelected() called: " + selected); - return selected; - } - - public void setSelected(boolean selected) { - this.selected = selected; - System.out.println("setSelected1(" + selected + ") called."); - } - - public String getText() { - System.out.println("getText() called: " + text); - return text; - } - - public void setText(String text) { - this.text = text; - System.out.println("setText(" + text + ") called."); - } - }; - - /** - * Custom field factory that sets the fields as immediate for debugging - * purposes. This is not normally necessary, unless you want to have some - * interaction that requires it. - */ - public class MyFieldFactory extends BaseFieldFactory { - @Override - public Field createField(Class type, Component uiContext) { - // Let the BaseFieldFactory create the fields - Field field = super.createField(type, uiContext); - - // ...and just set them as immediate - ((AbstractField) field).setImmediate(true); - - return field; - } - } - - /** - * This is a custom container that allows adding BeanItems inside it. The - * BeanItem objects must be bound to a MyBean object. The item ID is an - * Integer from 0 to 99. - * - * Most of the interface methods are implemented with just dummy - * implementations, as they are not needed in this example. - */ - public class MyContainer implements Container { - Item[] items; - int current = 0; - - public MyContainer() { - items = new Item[100]; // Yeah this is just a test - } - - public boolean addContainerProperty(Object propertyId, Class<?> type, - Object defaultValue) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public Item addItem(Object itemId) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public Object addItem() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - /** - * This addItem method is specific for this container and allows adding - * BeanItem objects. The BeanItems must be bound to MyBean objects. - */ - public void addItem(BeanItem item) throws UnsupportedOperationException { - items[current++] = item; - } - - public boolean containsId(Object itemId) { - if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); - if (pos >= 0 && pos < 100) { - return items[pos] != null; - } - } - return false; - } - - /** - * The Table will call this method to get the property objects for the - * columns. It uses the property objects to determine the data types of - * the columns. - */ - public Property getContainerProperty(Object itemId, Object propertyId) { - if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); - if (pos >= 0 && pos < 100) { - Item item = items[pos]; - - // The BeanItem provides the property objects for the items. - return item.getItemProperty(propertyId); - } - } - return null; - } - - /** Table calls this to get the column names. */ - public Collection getContainerPropertyIds() { - // This container can contain only BeanItems bound to MyBeans. - Item item = new BeanItem(new MyBean()); - - // The BeanItem knows how to get the property names from the bean. - return item.getItemPropertyIds(); - } - - public Item getItem(Object itemId) { - if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); - if (pos >= 0 && pos < 100) { - return items[pos]; - } - } - return null; - } - - public Collection getItemIds() { - Vector ids = new Vector(); - for (int i = 0; i < 100; i++) { - ids.add(Integer.valueOf(i)); - } - return ids; - } - - public Class getType(Object propertyId) { - return BeanItem.class; - } - - public boolean removeAllItems() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public boolean removeContainerProperty(Object propertyId) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public boolean removeItem(Object itemId) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public int size() { - return current; - } - - } - - TableEditableBean() { - /* A layout needed for the example. */ - OrderedLayout layout = new OrderedLayout( - OrderedLayout.ORIENTATION_VERTICAL); - setCompositionRoot(layout); - - // Create a table. It is by default not editable. - final Table table = new Table(); - layout.addComponent(table); - table.setPageLength(8); - - // Use the custom container as the data source - MyContainer myContainer = new MyContainer(); - table.setContainerDataSource(myContainer); - - // Add a few items in the table. - for (int i = 0; i < 5; i++) { - // Create the bean - MyBean item = new MyBean(); - item.setText("MyBean " + i); - - // Have an Item that is bound to the bean - BeanItem bitem = new BeanItem(item); - - // Add the item directly to the container using the custom addItem() - // method. We could otherwise add it to the Table as well, but - // the Container interface of Table does not allow adding items - // as such, just item IDs. - myContainer.addItem(bitem); - } - - // Use custom field factory that sets the checkboxes in immediate mode. - // This is just for debugging purposes and is not normally necessary. - table.setFieldFactory(new MyFieldFactory()); - - // Have a check box to switch the table between normal and editable - // mode. - final CheckBox switchEditable = new CheckBox("Editable"); - switchEditable.addListener(new Property.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - table.setEditable(((Boolean) event.getProperty().getValue()) - .booleanValue()); - } - }); - switchEditable.setImmediate(true); - layout.addComponent(switchEditable); - } -} diff --git a/tests/src/com/vaadin/tests/book/TableExample.java b/tests/src/com/vaadin/tests/book/TableExample.java deleted file mode 100644 index 5ee1f8f952..0000000000 --- a/tests/src/com/vaadin/tests/book/TableExample.java +++ /dev/null @@ -1,76 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Label; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Table; - -public class TableExample extends CustomComponent { - /* Create the table with a caption. */ - Table table = new Table("This is my Table"); - - /* A layout needed for the example. */ - OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - - /* Feedback for selecting items from the table. */ - Label current = new Label("Selected: -"); - - TableExample() { - setCompositionRoot(layout); - layout.addComponent(table); - - /* Define the names, data types, and default values of columns. */ - table.addContainerProperty("First Name", String.class, - "(no first name)"); - table.addContainerProperty("Last Name", String.class, "(no last name)"); - table.addContainerProperty("Year", Integer.class, null); - - /* We use these entries to generate random items in a table. */ - final String[] firstnames = new String[] { "Donald", "Patty", "Sally", - "Douglas" }; - final String[] lastnames = new String[] { "Smith", "Jones", "Adams", - "Knuth" }; - - /* Add some items in the table and assign them an Item ID (IID). */ - for (int i = 0; i < 1000; i++) { - /* Add a randomly generated item in the Table. */ - table.addItem( - new Object[] { - firstnames[(int) (Math.random() * (firstnames.length - 0.01))], - lastnames[(int) (Math.random() * (lastnames.length - 0.01))], - new Integer((int) (1900 + Math.random() * 100)) }, - new Integer(i)); - } - - /* Set the number of items visible in the table. */ - table.setPageLength(10); - - /* Enable some UI features for the table. */ - table.setColumnReorderingAllowed(true); - table.setColumnCollapsingAllowed(true); - - /* Allow selecting items from the table. */ - table.setSelectable(true); - - /* - * When an item is selected, the selection is sent immediately to - * server. - */ - table.setImmediate(true); - - /* Handle selection change. */ - table.addListener(new Property.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - current.setValue("Selected: " + table.getValue().toString()); - } - }); - - layout.addComponent(current); - } -} diff --git a/tests/src/com/vaadin/tests/book/TableExample1.java b/tests/src/com/vaadin/tests/book/TableExample1.java deleted file mode 100644 index 62b189f4ff..0000000000 --- a/tests/src/com/vaadin/tests/book/TableExample1.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Table; - -public class TableExample1 extends CustomComponent { - /* A layout needed for the example. */ - OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - - TableExample1() { - setCompositionRoot(layout); - - /* Create the table with a caption. */ - Table table = new Table("This is my Table"); - - /* - * Define the names and data types of columns. The "default value" - * parameter is meaningless here. - */ - table.addContainerProperty("First Name", String.class, null); - table.addContainerProperty("Last Name", String.class, null); - table.addContainerProperty("Year", Integer.class, null); - - /* Add a few items in the table. */ - table.addItem(new Object[] { "Nicolaus", "Copernicus", - new Integer(1473) }, new Integer(1)); - table.addItem(new Object[] { "Tycho", "Brahe", new Integer(1546) }, - new Integer(2)); - table.addItem(new Object[] { "Giordano", "Bruno", new Integer(1548) }, - new Integer(3)); - table.addItem(new Object[] { "Galileo", "Galilei", new Integer(1564) }, - new Integer(4)); - table.addItem(new Object[] { "Johannes", "Kepler", new Integer(1571) }, - new Integer(5)); - table.addItem(new Object[] { "Isaac", "Newton", new Integer(1643) }, - new Integer(6)); - - /* Set number of visible rows. */ - table.setPageLength(5); - - layout.addComponent(table); - } -} diff --git a/tests/src/com/vaadin/tests/book/TableExample2.java b/tests/src/com/vaadin/tests/book/TableExample2.java deleted file mode 100644 index b2d8b2bc45..0000000000 --- a/tests/src/com/vaadin/tests/book/TableExample2.java +++ /dev/null @@ -1,73 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Label; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Table; - -public class TableExample2 extends CustomComponent { - /* A layout needed for the example. */ - OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - - TableExample2() { - setCompositionRoot(layout); - - /* Create the table with a caption. */ - final Table table = new Table(); - - /* - * Define the names and data types of columns. The "default value" - * parameter is meaningless here. - */ - table.addContainerProperty("First Name", String.class, null); - table.addContainerProperty("Last Name", String.class, null); - table.addContainerProperty("Year", Integer.class, null); - - /* Add a few items in the table. */ - table.addItem(new Object[] { "Nicolaus", "Copernicus", - new Integer(1473) }, new Integer(1)); - table.addItem(new Object[] { "Tycho", "Brahe", new Integer(1546) }, - new Integer(2)); - table.addItem(new Object[] { "Giordano", "Bruno", new Integer(1548) }, - new Integer(3)); - table.addItem(new Object[] { "Galileo", "Galilei", new Integer(1564) }, - new Integer(4)); - table.addItem(new Object[] { "Johannes", "Kepler", new Integer(1571) }, - new Integer(5)); - table.addItem(new Object[] { "Isaac", "Newton", new Integer(1643) }, - new Integer(6)); - - /* Set number of visible rows. */ - table.setPageLength(5); - - /* Allow selecting items from the table. */ - table.setSelectable(true); - - /* - * When an item is selected, the selection is sent immediately to - * server. - */ - table.setImmediate(true); - - /* Feedback from selection. */ - final Label current = new Label("Selected: -"); - - /* Handle selection change. */ - table.addListener(new Property.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - current.setValue("Selected: " + table.getValue()); - } - }); - - table.setNullSelectionAllowed(false); - - layout.addComponent(table); - layout.addComponent(current); - } -} diff --git a/tests/src/com/vaadin/tests/book/TableExample3.java b/tests/src/com/vaadin/tests/book/TableExample3.java deleted file mode 100644 index 2fba7ec469..0000000000 --- a/tests/src/com/vaadin/tests/book/TableExample3.java +++ /dev/null @@ -1,83 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Label; -import com.vaadin.ui.OrderedLayout; -import com.vaadin.ui.Table; -import com.vaadin.ui.TextField; - -public class TableExample3 extends CustomComponent { - /* A layout needed for the example. */ - OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - - TableExample3() { - setCompositionRoot(layout); - - // Create a table and add a style to allow setting the row height in - // theme. - final Table table = new Table(); - table.addStyleName("components-inside"); - - /* - * Define the names and data types of columns. The "default value" - * parameter is meaningless here. - */ - table.addContainerProperty("Sum", Label.class, null); - table.addContainerProperty("Is Transferred", CheckBox.class, null); - table.addContainerProperty("Comments", TextField.class, null); - table.addContainerProperty("Details", Button.class, null); - - /* Add a few items in the table. */ - for (int i = 0; i < 100; i++) { - // Create the fields for the current table row - Label sumField = new Label(String.format( - "Sum is <b>$%04.2f</b><br/><i>(VAT incl.)</i>", - new Object[] { new Double(Math.random() * 1000) }), - Label.CONTENT_XHTML); - CheckBox transferredField = new CheckBox("is transferred"); - - // Multiline text field. This required modifying the height of the - // table row. - TextField commentsField = new TextField(); - commentsField.setRows(3); - - // The Table item identifier for the row. - Integer itemId = new Integer(i); - - // Create a button and handle its click. A Button does not know - // the item it is contained in, so we have to store the item - // ID as user-defined data. - Button detailsField = new Button("show details"); - detailsField.setData(itemId); - detailsField.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - // Get the item identifier from the user-defined data. - Integer itemId = (Integer) event.getButton().getData(); - getWindow().showNotification( - "Link " + itemId.intValue() + " clicked."); - } - }); - detailsField.addStyleName("link"); - - // Create the table row. - table.addItem(new Object[] { sumField, transferredField, - commentsField, detailsField }, itemId); - } - - // Show just three rows because they are so high. - table.setPageLength(3); - - // Initially show the 50th item in the top of the table. - table.setCurrentPageFirstItemIndex(50); - // table.setCurrentPageFirstItemId(initial); - - layout.addComponent(table); - } -} diff --git a/tests/src/com/vaadin/tests/book/TableHuge.java b/tests/src/com/vaadin/tests/book/TableHuge.java deleted file mode 100644 index b4264daadd..0000000000 --- a/tests/src/com/vaadin/tests/book/TableHuge.java +++ /dev/null @@ -1,197 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import java.util.Collection; -import java.util.Vector; - -import com.vaadin.data.Container; -import com.vaadin.data.Container.Indexed; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.util.BeanItem; -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.data.util.PropertysetItem; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Table; - -public class TableHuge extends CustomComponent { - - /** - * This is a virtual container that generates the items on the fly when - * requested. - */ - public class HugeContainer implements Container, Indexed { - int numberofitems; - - public HugeContainer(int numberofitems) { - this.numberofitems = numberofitems; - } - - public boolean addContainerProperty(Object propertyId, Class<?> type, - Object defaultValue) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public Item addItem(Object itemId) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public Object addItem() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - /** - * This addItem method is specific for this container and allows adding - * BeanItem objects. The BeanItems must be bound to MyBean objects. - */ - public void addItem(BeanItem item) throws UnsupportedOperationException { - } - - public boolean containsId(Object itemId) { - if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); - if (pos >= 0 && pos < numberofitems) { - return true; - } - } - return false; - } - - /** - * The Table will call this method to get the property objects for the - * columns. It uses the property objects to determine the data types of - * the columns. - */ - public Property getContainerProperty(Object itemId, Object propertyId) { - if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); - if (pos >= 0 && pos < numberofitems) { - return new ObjectProperty<String>("This is the item " + pos - + " in the huge table"); - } - } - return null; - } - - /** Table calls this to get the column names. */ - public Collection getContainerPropertyIds() { - Vector ids = new Vector(); - ids.add("id"); - return ids; - } - - public Item getItem(Object itemId) { - if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); - if (pos >= 0 && pos < numberofitems) { - Item item = new PropertysetItem(); - item.addItemProperty("id", new ObjectProperty<String>( - "This is the item " + pos + " in the huge table")); - return item; - } - } - return null; - } - - public Collection getItemIds() { - System.out.println("We can't do this."); - return null; - } - - public Class getType(Object propertyId) { - return PropertysetItem.class; - } - - public boolean removeAllItems() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public boolean removeContainerProperty(Object propertyId) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public boolean removeItem(Object itemId) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - public int size() { - return numberofitems; - } - - public Object addItemAt(int index) throws UnsupportedOperationException { - // TODO Auto-generated method stub - return null; - } - - public Item addItemAt(int index, Object newItemId) - throws UnsupportedOperationException { - // TODO Auto-generated method stub - return null; - } - - public Object getIdByIndex(int index) { - return Integer.valueOf(index); - } - - public int indexOfId(Object itemId) { - return ((Integer) itemId).intValue(); - } - - public Object addItemAfter(Object previousItemId) - throws UnsupportedOperationException { - // TODO Auto-generated method stub - return null; - } - - public Item addItemAfter(Object previousItemId, Object newItemId) - throws UnsupportedOperationException { - // TODO Auto-generated method stub - return null; - } - - public Object firstItemId() { - return new Integer(0); - } - - public boolean isFirstId(Object itemId) { - return ((Integer) itemId).intValue() == 0; - } - - public boolean isLastId(Object itemId) { - return ((Integer) itemId).intValue() == (numberofitems - 1); - } - - public Object lastItemId() { - return new Integer(numberofitems - 1); - } - - public Object nextItemId(Object itemId) { - int pos = indexOfId(itemId); - if (pos >= numberofitems - 1) { - return null; - } - return getIdByIndex(pos + 1); - } - - public Object prevItemId(Object itemId) { - int pos = indexOfId(itemId); - if (pos <= 0) { - return null; - } - return getIdByIndex(pos - 1); - } - } - - public TableHuge() { - Table table = new Table("HUGE table, REALLY HUGE"); - table.setContainerDataSource(new HugeContainer(500000)); - table.setPageLength(20); - - setCompositionRoot(table); - } -} diff --git a/tests/src/com/vaadin/tests/book/TheButton.java b/tests/src/com/vaadin/tests/book/TheButton.java deleted file mode 100644 index 716aaa64d7..0000000000 --- a/tests/src/com/vaadin/tests/book/TheButton.java +++ /dev/null @@ -1,27 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.Button; -import com.vaadin.ui.CustomComponent; - -public class TheButton extends CustomComponent implements Button.ClickListener { - Button thebutton; - - public TheButton() { - /* Create a Button with the given caption. */ - thebutton = new Button("Do not push this button"); - - /* Listen for ClickEvents. */ - thebutton.addListener(this); - - setCompositionRoot(thebutton); - } - - /** Handle button click events from the button. */ - public void buttonClick(Button.ClickEvent event) { - thebutton.setCaption("Do not push this button again"); - } -} diff --git a/tests/src/com/vaadin/tests/book/TheButtons.java b/tests/src/com/vaadin/tests/book/TheButtons.java deleted file mode 100644 index ed7ef00cc4..0000000000 --- a/tests/src/com/vaadin/tests/book/TheButtons.java +++ /dev/null @@ -1,33 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.AbstractComponentContainer; -import com.vaadin.ui.Button; - -public class TheButtons implements Button.ClickListener { - Button thebutton; - Button secondbutton; - - /** Creates two buttons into given container. */ - public TheButtons(AbstractComponentContainer container) { - thebutton = new Button("Do not push this button"); - thebutton.addListener(this); - container.addComponent(thebutton); - - secondbutton = new Button("I am a button too"); - secondbutton.addListener(this); - container.addComponent(secondbutton); - } - - /** Handle button click events from the two buttons. */ - public void buttonClick(Button.ClickEvent event) { - if (event.getButton() == thebutton) { - thebutton.setCaption("Do not push this button again"); - } else if (event.getButton() == secondbutton) { - secondbutton.setCaption("I am not a number"); - } - } -} diff --git a/tests/src/com/vaadin/tests/book/TheButtons2.java b/tests/src/com/vaadin/tests/book/TheButtons2.java deleted file mode 100644 index c96ed51773..0000000000 --- a/tests/src/com/vaadin/tests/book/TheButtons2.java +++ /dev/null @@ -1,33 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.AbstractComponentContainer; -import com.vaadin.ui.Button; - -public class TheButtons2 { - Button thebutton; - Button secondbutton; - - /** Creates two buttons in given container. */ - public TheButtons2(AbstractComponentContainer container) { - thebutton = new Button("Do not push this button"); - thebutton.addListener(Button.ClickEvent.class, this, "theButtonClick"); - container.addComponent(thebutton); - - secondbutton = new Button("I am a button too"); - secondbutton.addListener(Button.ClickEvent.class, this, - "secondButtonClick"); - container.addComponent(secondbutton); - } - - public void theButtonClick(Button.ClickEvent event) { - thebutton.setCaption("Do not push this button again"); - } - - public void secondButtonClick(Button.ClickEvent event) { - secondbutton.setCaption("I am not a number!"); - } -} diff --git a/tests/src/com/vaadin/tests/book/TheButtons3.java b/tests/src/com/vaadin/tests/book/TheButtons3.java deleted file mode 100644 index 9b77e7855a..0000000000 --- a/tests/src/com/vaadin/tests/book/TheButtons3.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.AbstractComponentContainer; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; - -/** This example demonstrates the use of inline classes for event listeners. */ -public class TheButtons3 { - Button thebutton; /* This component is stored as a member variable. */ - - /** Creates two buttons in given container. */ - public TheButtons3(AbstractComponentContainer container) { - thebutton = new Button("Do not push this button"); - thebutton.addListener(new Button.ClickListener() { - /* - * Define the method in the local class to handle the click. - */ - public void buttonClick(ClickEvent event) { - thebutton.setCaption("Do not push this button again"); - } - }); - container.addComponent(thebutton); - - /* - * Have the second button as a local variable in the constructor. Only - * "final" local variables can be accessed from an anonymous class. - */ - final Button secondbutton = new Button("I am a button too"); - secondbutton.addListener(new Button.ClickListener() { - /* - * Define the method in the local class to handle the click. - */ - public void buttonClick(ClickEvent event) { - secondbutton.setCaption("I am not a number!"); - } - }); - container.addComponent(secondbutton); - } -} diff --git a/tests/src/com/vaadin/tests/book/WindowOpener.java b/tests/src/com/vaadin/tests/book/WindowOpener.java deleted file mode 100644 index f159c48b30..0000000000 --- a/tests/src/com/vaadin/tests/book/WindowOpener.java +++ /dev/null @@ -1,80 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.vaadin.tests.book; - -import com.vaadin.ui.Button; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Label; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; -import com.vaadin.ui.Window.CloseEvent; - -/** Component contains a button that allows opening a window. */ -public class WindowOpener extends CustomComponent implements - Window.CloseListener { - Window mainwindow; // Reference to main window - Window mywindow; // The window to be opened - Button openbutton; // Button for opening the window - Button closebutton; // A button in the window - Label explanation; // A descriptive text - - public WindowOpener(String label, Window main) { - mainwindow = main; - - /* The component consists of a button that opens the window. */ - final VerticalLayout layout = new VerticalLayout(); - - openbutton = new Button("Open Window", this, "openButtonClick"); - explanation = new Label("Explanation"); - layout.addComponent(openbutton); - layout.addComponent(explanation); - - setCompositionRoot(layout); - } - - /** Handle the clicks for the two buttons. */ - public void openButtonClick(Button.ClickEvent event) { - /* Create a new window. */ - mywindow = new Window("My Dialog"); - mywindow.setPositionX(200); - mywindow.setPositionY(100); - mywindow.getLayout().setSizeUndefined(); - - /* Add the window inside the main window. */ - mainwindow.addWindow(mywindow); - - /* Listen for close events for the window. */ - mywindow.addListener(this); - - /* Add components in the window. */ - mywindow.addComponent(new Label("A text label in the window.")); - closebutton = new Button("Close", this, "closeButtonClick"); - mywindow.addComponent(closebutton); - - /* Allow opening only one window at a time. */ - openbutton.setEnabled(false); - - explanation.setValue("Window opened"); - } - - /** Handle Close button click and close the window. */ - public void closeButtonClick(Button.ClickEvent event) { - /* Windows are managed by the application object. */ - mainwindow.removeWindow(mywindow); - - /* Return to initial state. */ - openbutton.setEnabled(true); - - explanation.setValue("Closed with button"); - } - - /** In case the window is closed otherwise. */ - public void windowClose(CloseEvent e) { - /* Return to initial state. */ - openbutton.setEnabled(true); - - explanation.setValue("Closed with window controls"); - } -} diff --git a/tests/src/com/vaadin/tests/book/WindowTestApplication.java b/tests/src/com/vaadin/tests/book/WindowTestApplication.java deleted file mode 100644 index 4e80122b96..0000000000 --- a/tests/src/com/vaadin/tests/book/WindowTestApplication.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.vaadin.tests.book; - -import java.util.HashMap; - -import com.vaadin.Application; -import com.vaadin.terminal.ExternalResource; -import com.vaadin.ui.Label; -import com.vaadin.ui.Link; -import com.vaadin.ui.Window; -import com.vaadin.ui.Window.CloseEvent; - -public class WindowTestApplication extends Application { - Window anotherpage = null; - - // Storage for extra window objects - there could be many. - HashMap windows = new HashMap(); - - /* - * (non-Javadoc) - * - * @see com.vaadin.Application#init() - */ - @Override - public void init() { - final Window main = new Window("Window Test Application"); - setMainWindow(main); - setTheme("tests-book"); - - /* Create a new window. */ - final Window mywindow = new Window("Second Window"); - - /* Manually set the name of the window. */ - mywindow.setName("mywindow"); - - /* Add some content to the window. */ - mywindow.addComponent(new Label("This is a second window.")); - - /* Add the window to the application. */ - addWindow(mywindow); - - // /* Add a button to open a new window. */ - // main.addComponent(new Button("Click to open new window", - // new Button.ClickListener() { - // public void buttonClick(ClickEvent event) { - // // Open the window. - // main.open(new ExternalResource(mywindow.getURL()), - // "_new"); - // } - // })); - // - // /* Add a link to the second window. */ - // Link link = new Link("Click to open second window", - // new ExternalResource(mywindow.getURL())); - // link.setTargetName("_new"); - // main.addComponent(link); - // - // // Add the link manually inside a Label. - // main.addComponent(new Label("Second window: <a href='" - // + mywindow.getURL() + "' target='_new'>click to open</a>", - // Label.CONTENT_XHTML)); - // main.addComponent(new Label( - // "The second window can be accessed through URL: " - // + mywindow.getURL())); - - // Add links to windows that do not yet exist, but are created - // dynamically when the URL is called. - - main.addComponent(new Label("Click a link to open a new window:")); - - // Have some IDs for the separate windows. - final String[] items = new String[] { "mercury", "venus", "earth", - "mars", "jupiter", "saturn", "uranus", "neptune" }; - - // Create a list of links to each of the available window. - for (int i = 0; i < items.length; i++) { - // Create a URL for the window. - String windowUrl = getURL() + "planet-" + items[i]; - - // Create a link to the window URL. - // Using the window ID for the target also opens it in a new - // browser window (or tab). - main.addComponent(new Link("Open window about " + items[i], - new ExternalResource(windowUrl), items[i], -1, -1, - Window.BORDER_DEFAULT)); - } - } - - @Override - /* - * This method is called for every client request for this application. It - * needs to return the correct window for the given identifier. - */ - public Window getWindow(String name) { - // If a dynamically created window is requested, but it does - // not exist yet, create it. - if (name.startsWith("planet-") && super.getWindow(name) == null) { - System.out.println("New window " + name); - - String planetName = name.substring("planet-".length()); - - // Create the window object. - Window newWindow = new Window("Window about " + planetName); - - // We must set this explicitly or otherwise an automatically - // generated name is used. - newWindow.setName(name); - - // Put some content in it. - newWindow.addComponent(new Label( - "This window contains details about " + planetName + ".")); - - // Add it to the application as a regular application-level window. - addWindow(newWindow); - - newWindow.addListener(new Window.CloseListener() { - public void windowClose(CloseEvent e) { - System.out.println(e.getWindow().getName() + " was closed"); - getMainWindow().addComponent( - new Label("Window '" + e.getWindow().getName() - + "' was closed.")); - } - }); - - return newWindow; - } - - // Otherwise the Application object manages existing windows by their - // name. - return super.getWindow(name); - } -} diff --git a/tests/src/com/vaadin/tests/book/images/Earth_small.png b/tests/src/com/vaadin/tests/book/images/Earth_small.png Binary files differdeleted file mode 100644 index abe9227914..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Earth_small.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Earth_symbol.png b/tests/src/com/vaadin/tests/book/images/Earth_symbol.png Binary files differdeleted file mode 100644 index 6060358883..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Earth_symbol.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Jupiter_symbol.png b/tests/src/com/vaadin/tests/book/images/Jupiter_symbol.png Binary files differdeleted file mode 100644 index 7a973bec48..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Jupiter_symbol.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Mars_symbol.png b/tests/src/com/vaadin/tests/book/images/Mars_symbol.png Binary files differdeleted file mode 100644 index 7ab7616c75..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Mars_symbol.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Mercury_small.png b/tests/src/com/vaadin/tests/book/images/Mercury_small.png Binary files differdeleted file mode 100644 index ef69931a8f..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Mercury_small.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Mercury_symbol.png b/tests/src/com/vaadin/tests/book/images/Mercury_symbol.png Binary files differdeleted file mode 100644 index 97c09d1b29..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Mercury_symbol.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Neptune_symbol.png b/tests/src/com/vaadin/tests/book/images/Neptune_symbol.png Binary files differdeleted file mode 100644 index 2b84811c80..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Neptune_symbol.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Saturn_symbol.png b/tests/src/com/vaadin/tests/book/images/Saturn_symbol.png Binary files differdeleted file mode 100644 index f4b7e5c6ca..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Saturn_symbol.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Uranus_symbol.png b/tests/src/com/vaadin/tests/book/images/Uranus_symbol.png Binary files differdeleted file mode 100644 index 74f755fb97..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Uranus_symbol.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Venus_small.png b/tests/src/com/vaadin/tests/book/images/Venus_small.png Binary files differdeleted file mode 100644 index 7bcac3fa4f..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Venus_small.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/images/Venus_symbol.png b/tests/src/com/vaadin/tests/book/images/Venus_symbol.png Binary files differdeleted file mode 100644 index 6d08313e5d..0000000000 --- a/tests/src/com/vaadin/tests/book/images/Venus_symbol.png +++ /dev/null diff --git a/tests/src/com/vaadin/tests/book/smiley.jpg b/tests/src/com/vaadin/tests/book/smiley.jpg Binary files differdeleted file mode 100644 index dc1a399c76..0000000000 --- a/tests/src/com/vaadin/tests/book/smiley.jpg +++ /dev/null |