aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarko Grönroos <magi@iki.fi>2007-11-07 18:56:20 +0000
committerMarko Grönroos <magi@iki.fi>2007-11-07 18:56:20 +0000
commitfa9dc06d321eb2059f533ec5103b907ce8766450 (patch)
tree4a20ea68945a038ee81c6899ecf0d031c6884149
parentba0a10608cfb25c1fbf1cb71a01fad6dc8a81010 (diff)
downloadvaadin-framework-fa9dc06d321eb2059f533ec5103b907ce8766450.tar.gz
vaadin-framework-fa9dc06d321eb2059f533ec5103b907ce8766450.zip
Added personal testbench.
svn changeset:2742/svn branch:trunk
-rw-r--r--WebContent/ITMILL/themes/tests-magi/styles.css3
-rw-r--r--WebContent/WEB-INF/web.xml14
-rw-r--r--src/com/itmill/toolkit/tests/magi/DefaultButtonExample.java84
-rw-r--r--src/com/itmill/toolkit/tests/magi/EmbeddedButton.java30
-rw-r--r--src/com/itmill/toolkit/tests/magi/MagiTestApplication.java347
-rw-r--r--src/com/itmill/toolkit/tests/magi/MyUploader.java69
-rw-r--r--src/com/itmill/toolkit/tests/magi/SSNField.java81
-rw-r--r--src/com/itmill/toolkit/tests/magi/SelectExample.java92
-rw-r--r--src/com/itmill/toolkit/tests/magi/TableExample.java39
-rw-r--r--src/com/itmill/toolkit/tests/magi/TheButton.java21
-rw-r--r--src/com/itmill/toolkit/tests/magi/TheButtons.java26
-rw-r--r--src/com/itmill/toolkit/tests/magi/TheButtons2.java26
12 files changed, 832 insertions, 0 deletions
diff --git a/WebContent/ITMILL/themes/tests-magi/styles.css b/WebContent/ITMILL/themes/tests-magi/styles.css
new file mode 100644
index 0000000000..aea758a435
--- /dev/null
+++ b/WebContent/ITMILL/themes/tests-magi/styles.css
@@ -0,0 +1,3 @@
+#itmill-ajax-window {
+ background: white;
+}
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
index 79de882d05..2d7646ef80 100644
--- a/WebContent/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -305,6 +305,15 @@
<param-value>com.itmill.toolkit.demo.NotificationDemo</param-value>
</init-param>
</servlet>
+
+ <servlet>
+ <servlet-name>MagiTestServlet</servlet-name>
+ <servlet-class>com.itmill.toolkit.terminal.gwt.server.ApplicationServlet</servlet-class>
+ <init-param>
+ <param-name>application</param-name>
+ <param-value>com.itmill.toolkit.tests.magi.MagiTestApplication</param-value>
+ </init-param>
+ </servlet>
<servlet-mapping>
@@ -448,6 +457,11 @@
<url-pattern>/NotificationDemo/*</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>MagiTestServlet</servlet-name>
+ <url-pattern>/testbench2/*</url-pattern>
+ </servlet-mapping>
+
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
diff --git a/src/com/itmill/toolkit/tests/magi/DefaultButtonExample.java b/src/com/itmill/toolkit/tests/magi/DefaultButtonExample.java
new file mode 100644
index 0000000000..991264d206
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/DefaultButtonExample.java
@@ -0,0 +1,84 @@
+package com.itmill.toolkit.tests.magi;
+import com.itmill.toolkit.event.Action;
+import com.itmill.toolkit.event.ShortcutAction;
+import com.itmill.toolkit.event.Action.Handler;
+import com.itmill.toolkit.ui.*;
+
+public class DefaultButtonExample extends CustomComponent implements Handler {
+ // Define and create user interface components
+ Panel panel = new Panel("Login");
+ OrderedLayout formlayout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
+ TextField username = new TextField("Username");
+ TextField password = new TextField("Password");
+ OrderedLayout buttons = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
+
+ // Create buttons and define their listener methods. Here we use parameterless
+ // methods so that we can use same methods for both click events and keyboard
+ // actions.
+ Button ok = new Button("OK", this, "okHandler");
+ Button cancel = new Button("Cancel", this, "cancelHandler");
+
+ public DefaultButtonExample() {
+ // Set up the user interface
+ setCompositionRoot(panel);
+ panel.addComponent(formlayout);
+ formlayout.addComponent(username);
+ formlayout.addComponent(password);
+ formlayout.setStyle("form");
+ formlayout.addComponent(buttons);
+ buttons.addComponent(ok);
+ buttons.addComponent(cancel);
+
+ // Set focus to username
+ username.focus();
+
+ // Set this object as the action handler for actions related to the Ok
+ // and Cancel buttons.
+ // @TODO
+ //ok.addActionHandler(this);
+ //cancel.addActionHandler(this);
+ }
+
+ /**
+ * Retrieve actions for a specific component. This method will be called for each
+ * object that has a handler; in this example the Ok and Cancel buttons.
+ **/
+ public Action[] getActions(Object target, Object sender) {
+ Action[] actions = new Action[1];
+
+ // Set the action for the requested component
+ if (sender == ok) {
+ // Bind the unmodified Enter key to the Ok button.
+ actions[0] = new ShortcutAction("Default key",
+ ShortcutAction.KeyCode.ENTER, null);
+ } else if (sender == cancel) {
+ // Bind "C" key modified with Alt to the Cancel button.
+ actions[0] = new ShortcutAction("Alt+C",
+ ShortcutAction.KeyCode.C, new int[] {
+ ShortcutAction.ModifierKey.ALT});
+ } else
+ return null;
+ return actions;
+ }
+
+ /**
+ * 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 (target == ok)
+ this.okHandler();
+ if (target == cancel)
+ this.cancelHandler();
+ }
+
+ public void okHandler() {
+ // Do something: report the click
+ formlayout.addComponent(new Label("OK clicked"));
+ }
+
+ public void cancelHandler() {
+ // Do something: report the click
+ formlayout.addComponent(new Label("Cancel clicked"));
+ }
+}
diff --git a/src/com/itmill/toolkit/tests/magi/EmbeddedButton.java b/src/com/itmill/toolkit/tests/magi/EmbeddedButton.java
new file mode 100644
index 0000000000..d447f2ba64
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/EmbeddedButton.java
@@ -0,0 +1,30 @@
+package com.itmill.toolkit.tests.magi;
+import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.terminal.*;
+
+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/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java b/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java
new file mode 100644
index 0000000000..88090f927b
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java
@@ -0,0 +1,347 @@
+package com.itmill.toolkit.tests.magi;
+import java.net.URL;
+
+import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.data.Validator;
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import com.itmill.toolkit.data.Property.ValueChangeListener;
+import com.itmill.toolkit.data.validator.StringLengthValidator;
+import com.itmill.toolkit.terminal.*;
+
+public class MagiTestApplication extends com.itmill.toolkit.Application implements URIHandler {
+ Window main = new Window("Application window");
+
+ TheButton butts1;
+ TheButtons butts2;
+ TheButtons2 butts3;
+
+ Label mylabel1;
+ Label mylabel2;
+ Label mylabel3;
+
+ StreamResource strres;
+ OrderedLayout ol;
+
+ public void init() {
+ setTheme("tests-magi");
+
+ setMainWindow(main);
+ }
+
+ public DownloadStream handleURI(URL context, String relativeUri) {
+ /* Ignore ansynchronous request URIs in IT Mill Toolkit 4.0.x. */
+ if (relativeUri.compareTo("UIDL/") == 0)
+ return null;
+
+ main.removeAllComponents();
+
+ String test = relativeUri.substring(5);
+
+ if (test.equals("defaultbutton")) defaultButtonTest(main);
+ else if (test.equals("tree")) treeTest(main);
+ else if (test.equals("embedded")) init_embeddedTest(main);
+ else if (test.equals("textfield")) init_textFieldTest(main);
+ else if (test.equals("textfieldvalidation"))textFieldValidation(main);
+ else if (test.equals("datefield")) init_dateFieldTest(main);
+ else if (test.equals("button")) init_buttonTest(main);
+ else if (test.equals("select")) init_selectTest(main);
+ else if (test.equals("tabsheet")) init_tabSheetTest(main);
+ else if (test.equals("validator")) init_validatorTest(main);
+ else if (test.equals("table")) init_tableTest(main);
+ else if (test.equals("upload")) init_uploadTest(main);
+ else if (test.equals("link")) init_linkTest(main);
+ else if (test.equals("gridlayout")) init_gridLayoutTest(main);
+ else if (test.equals("panellayout")) init_panelLayoutTest(main);
+ else
+ main.addComponent(new Label("Unknown test '"+test+"'."));
+
+ return null;
+ }
+
+ public void handleButton (Button.ClickEvent event) {
+ ol.setStyle("myLayout2");
+ }
+
+ void defaultButtonTest(Window main) {
+ main.addComponent(new DefaultButtonExample());
+ }
+
+ void treeTest(Window main) {
+ 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"}};
+
+ Tree tree = new Tree("The Planets and Major Moons");
+
+ /* Add planets as root items in the tree. */
+ for (int i=0; i<planets.length; i++) {
+ 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++) {
+ 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);
+ }
+ }
+
+
+ main.addComponent(tree);
+ }
+
+ void init_selectTest(Window main) {
+ main.addComponent(new SelectExample(this));
+ }
+
+ void init_textFieldTest(Window main) {
+ /* Add a single-line text field. */
+ TextField subject = new TextField("Subject");
+ subject.setColumns(40);
+ main.addComponent(subject);
+
+ /* Add a multi-line text field. */
+ TextField message = new TextField("Message");
+ message.setRows(7);
+ message.setColumns(40);
+ main.addComponent(message);
+ }
+
+ void textFieldValidation(Window main) {
+ // Create a text field with a label
+ 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
+ TextField username = (TextField)(event.getProperty());
+
+ try {
+ // Validate the field value.
+ username.validate();
+
+ // The value was ok, reset a possible error
+ username.setComponentError(null);
+ } catch (Validator.InvalidValueException e) {
+ // The value was not ok. Set the error.
+ username.setComponentError(new UserError(e.getMessage()));
+ }
+ }
+ });
+ }
+
+ void init_dateFieldTest(Window main) {
+ /* Create a DateField with the calendar style. */
+ DateField date = new DateField("Here is a calendar field");
+ //date.setStyle("calendar");
+
+ /* Set the date and time to present. */
+ date.setValue(new java.util.Date());
+
+ main.addComponent(date);
+
+ //date.setResolution(DateField.RESOLUTION_DAY);
+ }
+ void init_tabSheetTest(Window main) {
+ //main.addComponent(new TabSheetExample());
+
+ 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);
+ */
+
+ 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", main.getApplication()));
+ tabsheet.addTab(new Label("Contents of the third tab"),
+ "Third tab",
+ new ClassResource ("images/Earth_small.png", main.getApplication()));
+
+ main.addComponent(tabsheet);
+ }
+
+ void init_validatorTest(Window main) {
+ main.addComponent(new SSNField());
+ }
+
+ void init_tableTest(Window main) {
+ main.addComponent(new TableExample());
+ }
+
+ void init_uploadTest(Window main) {
+ main.addComponent(new MyUploader());
+ }
+
+ void init_linkTest(Window main) {
+ /* Create a native window object to be opened as a popup window when
+ * the link is clicked. */
+ Window popup = new Window("Open a window");
+ popup.setStyle("native");
+ popup.addComponent(new Button("Some component"));
+ main.getApplication().addWindow(popup);
+
+ /* Create a link that opens the popup window. */
+ Link alink = new Link (popup);
+
+ /* Set the resource to be opened in the window. */
+ alink.setResource(new ExternalResource("http://www.itmill.com/"));
+
+ main.addComponent(alink);
+
+ 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.itmill.com/")));
+ }
+
+ void init_labelTest(Window main) {
+ GridLayout labelgrid = new GridLayout (2,1);
+ labelgrid.setStyle("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);
+
+ ClassResource labelimage = new ClassResource ("smiley.jpg", this);
+ main.addComponent(new Label("Here we have an image <img src=\""
+ + this.getRelativeLocation(labelimage) + "\"/> within some text.",
+ Label.CONTENT_XHTML));
+ }
+
+ void init_buttonTest(Window main) {
+ /*
+ main.addComponent(mylabel1 = new Label ("Laabeli 1"));
+ main.addComponent(mylabel2 = new Label ("Laabeli 2"));
+ main.addComponent(mylabel3 = new Label ("Laabeli 3"));
+ */
+ //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);
+ Button button = new Button("My Button");
+ button.setStyle("link");
+ main.addComponent(button);
+ }
+
+ void init_panelLayoutTest(Window main) {
+ Panel panel = new Panel ("Contact Information");
+ OrderedLayout ordered = new OrderedLayout(
+ OrderedLayout.ORIENTATION_VERTICAL);
+ ordered.addComponent(new TextField("Name"));
+ ordered.addComponent(new TextField("Email"));
+ ordered.setStyle("form");
+ for (int i=0; i<20; i++)
+ ordered.addComponent(new Label("a row"));
+ panel.setIcon(new ClassResource ("smiley.jpg", main.getApplication()));
+ panel.addComponent(ordered);
+ main.addComponent(panel);
+ }
+
+ void init_gridLayoutTest(Window main) {
+ /* Create a 4 by 4 grid layout. */
+ GridLayout gridLO = new GridLayout(4, 4);
+
+ /* Fill out the first row using the cursor. */
+ gridLO.addComponent(new Button("R/C 1"));
+ for (int i=0; i<3; i++) /* Add a few buttons. */
+ gridLO.addComponent(new Button("Col " + (gridLO.getCursorX()+1)));
+
+ /* Fill out the first column using coordinates. */
+ for (int i=1; i<4; i++)
+ gridLO.addComponent(new Button("Row " + i), 0, i);
+
+ /* Add some components of various shapes. */
+ gridLO.addComponent(new Button("3x1 button"), 1, 1, 3, 1);
+ gridLO.addComponent(new Label("1x2 cell"), 1, 2, 1, 3);
+ DateField date = new DateField("A 2x2 date field");
+ date.setStyle("calendar");
+ gridLO.addComponent(date, 2, 2, 3, 3);
+
+ //gridLO.setStyle("example-bordered");
+ main.addComponent(gridLO);
+ }
+
+ void init_orderedLayoutTest(Window main) {
+ OrderedLayout orderedLO = new OrderedLayout(
+ OrderedLayout.ORIENTATION_VERTICAL);
+ orderedLO.addComponent(new TextField("Name"));
+ orderedLO.addComponent(new TextField("Street address"));
+ orderedLO.addComponent(new TextField("Postal code"));
+ /* orderedLO.setStyle("form"); */
+ main.addComponent(orderedLO);
+ }
+
+ void init_windowTest() {
+ Window mydialog = new Window("My Dialog");
+ mydialog.addComponent(new Label("A text label in the window."));
+ Button okbutton = new Button("OK");
+ mydialog.addComponent(okbutton);
+ addWindow(mydialog);
+ }
+
+ void init_embeddedTest(Window main) {
+ //main.addComponent(new Embedded("Image title", new ClassResource("smiley.jpg", this)));
+ Embedded image = new Embedded ("", new ClassResource("smiley.jpg", this));
+ image.setStyle("omaimage");
+ main.addComponent(image);
+
+ EmbeddedButton button = new EmbeddedButton(new ClassResource("smiley.jpg", this));
+ main.addComponent(button);
+
+ }
+
+}
diff --git a/src/com/itmill/toolkit/tests/magi/MyUploader.java b/src/com/itmill/toolkit/tests/magi/MyUploader.java
new file mode 100644
index 0000000000..94a0856a4f
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/MyUploader.java
@@ -0,0 +1,69 @@
+package com.itmill.toolkit.tests.magi;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.terminal.*;
+
+public class MyUploader extends CustomComponent implements Upload.FinishedListener {
+ MyUploadReceiver uploadReceiver; /* Upload receiver object. */
+ Panel root; /* Root element for contained components. */
+ Panel imagePanel; /* Panel that contains the uploaded image. */
+
+ /* Custom upload receiver that has to be implemented for Upload. */
+ class MyUploadReceiver implements Upload.Receiver {
+ java.io.File file; /* File to write to. */
+ java.io.FileOutputStream fos; /* Output stream to write to. */
+
+ public OutputStream receiveUpload(String filename, String MIMEType) {
+ file = new File("/tmp/uploads/"+filename);
+ try {
+ /* Open the file for writing. */
+ fos = new FileOutputStream(file);
+ } catch (java.io.FileNotFoundException e) {
+ return null; /* Error while opening the file. Not reported here. */
+ }
+
+ return fos; /* Return the output stream. */
+ }
+
+ public File getFile () {
+ return file;
+ }
+ }
+
+ MyUploader () {
+ root = new Panel("My Upload Component");
+ setCompositionRoot(root);
+
+ /* Create the upload receiver required by Upload. */
+ uploadReceiver = new MyUploadReceiver();
+
+ /* Create the Upload component. */
+ Upload upload = new Upload ("Upload", uploadReceiver);
+
+ /* Listen for Upload.FinishedEvent events. */
+ upload.addListener(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);
+ }
+
+ /* This is called when the upload is finished. */
+ public void uploadFinished(Upload.FinishedEvent event) {
+ /* Log the upload on screen. */
+ root.addComponent(new Label(String.format("File %s of type '%s' uploaded.",
+ event.getFilename(),
+ event.getMIMEType())));
+
+ /* Display the uploaded file in the image panel. */
+ FileResource imageResource = new FileResource (uploadReceiver.getFile(), getApplication());
+ imagePanel.removeAllComponents();
+ imagePanel.addComponent(new Embedded("", imageResource));
+ }
+}
diff --git a/src/com/itmill/toolkit/tests/magi/SSNField.java b/src/com/itmill/toolkit/tests/magi/SSNField.java
new file mode 100644
index 0000000000..062cebec40
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/SSNField.java
@@ -0,0 +1,81 @@
+package com.itmill.toolkit.tests.magi;
+import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.data.*;
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import java.text.*;
+
+/* Finnish Social Security Number input field that validates the value. */
+public class SSNField extends CustomComponent implements Property.ValueChangeListener {
+ OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
+ 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 (InvalidValueException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /** Validate the given SSN. */
+ public void validate(Object value) throws InvalidValueException {
+ String ssn = (String) value;
+ if (ssn.length() != 11)
+ throw new InvalidValueException("Invalid SSN length");
+
+ String numbers = ssn.substring(0,6) + ssn.substring(7,10);
+ int checksum = new Integer(numbers) % 31;
+ if (!ssn.substring(10).equals("0123456789ABCDEFHJKLMNPRSTUVWXY".substring(checksum,checksum+1)))
+ throw new InvalidValueException("Invalid SSN checksum");
+ }
+ }
+
+ SSNField() {
+ setCompositionRoot(layout);
+ layout.setStyle("form");
+
+ /* Create the text field for the SSN. */
+ myfield = new TextField("Social Security Number");
+ myfield.setColumns(11);
+ myfield.setFormat(new MessageFormat("{0,number,##}"));
+
+ /* Create and set the validator object for the field. */
+ SSNValidator ssnvalidator = new SSNValidator ();
+ myfield.addValidator(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");
+ myfield.setStyle("");
+ } catch (Validator.InvalidValueException e) {
+ /* Report the error message to the user. */
+ myerror.setValue(e.getMessage());
+
+ /* The CSS defines that text field with the "error" class will be colored red. */
+ myfield.setStyle("error");
+ }
+ }
+}
diff --git a/src/com/itmill/toolkit/tests/magi/SelectExample.java b/src/com/itmill/toolkit/tests/magi/SelectExample.java
new file mode 100644
index 0000000000..2603ef6e45
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/SelectExample.java
@@ -0,0 +1,92 @@
+package com.itmill.toolkit.tests.magi;
+import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.data.*;
+import com.itmill.toolkit.*;
+
+/* 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;
+ }
+ public String toString () {
+ return "The Planet " + planetName;
+ }
+ }
+
+ /* Create the Select object with a caption. */
+ Select select = new Select(/*"This is a Select component that allows adding new items"*/);
+
+ OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
+ Label status = new Label("");
+
+ SelectExample (Application application) {
+ setCompositionRoot (layout);
+ layout.addComponent(select);
+
+ /* 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 something --");
+
+ layout.addComponent(status);
+
+ /*
+ status.setValue(String.format("Currently selected item ID: %s<br/>" +
+ "Class of the Item ID: %s<br/>" +
+ "Caption: %s",
+ select.getValue(),
+ select.getValue().getClass().getName(),
+ select.getItemCaption(select.getValue())));
+ status.setContentMode(Label.CONTENT_XHTML);
+ */
+
+ }
+
+ /* 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(true) {
+ status.setValue(String.format("Currently selected item ID: %s<br/>" +
+ "Class of the Item ID: %s<br/>" +
+ "Caption: %s",
+ event.getProperty().getValue(),
+ event.getProperty().getValue().getClass().getName(),
+ select.getItemCaption(event.getProperty().getValue())));
+ status.setContentMode(Label.CONTENT_XHTML);
+ }
+ }
+}
diff --git a/src/com/itmill/toolkit/tests/magi/TableExample.java b/src/com/itmill/toolkit/tests/magi/TableExample.java
new file mode 100644
index 0000000000..d9bba06e96
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/TableExample.java
@@ -0,0 +1,39 @@
+package com.itmill.toolkit.tests.magi;
+import com.itmill.toolkit.ui.*;
+
+public class TableExample extends CustomComponent {
+ /* Create the table with a caption. */
+ Table table = new Table("This is a Table");
+
+ /* A layout needed for the example. */
+ OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
+
+ 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<500; 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))],
+ (int) (1900+Math.random() * 100)}, i);
+ }
+
+ /* Set the number of items visible in the table. */
+ table.setPageLength(10);
+
+ table.setStyle("twincol");
+ table.setColumnReorderingAllowed(true);
+ table.setColumnCollapsingAllowed(true);
+ }
+}
diff --git a/src/com/itmill/toolkit/tests/magi/TheButton.java b/src/com/itmill/toolkit/tests/magi/TheButton.java
new file mode 100644
index 0000000000..d480a503aa
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/TheButton.java
@@ -0,0 +1,21 @@
+package com.itmill.toolkit.tests.magi;
+import com.itmill.toolkit.ui.*;
+
+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/src/com/itmill/toolkit/tests/magi/TheButtons.java b/src/com/itmill/toolkit/tests/magi/TheButtons.java
new file mode 100644
index 0000000000..32eb646452
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/TheButtons.java
@@ -0,0 +1,26 @@
+package com.itmill.toolkit.tests.magi;
+import com.itmill.toolkit.ui.*;
+
+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/src/com/itmill/toolkit/tests/magi/TheButtons2.java b/src/com/itmill/toolkit/tests/magi/TheButtons2.java
new file mode 100644
index 0000000000..ffe84d92bb
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/magi/TheButtons2.java
@@ -0,0 +1,26 @@
+package com.itmill.toolkit.tests.magi;
+import com.itmill.toolkit.ui.*;
+
+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!");
+ }
+}