]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added few test classes.
authorJani Laakso <jani.laakso@itmill.com>
Sun, 21 Oct 2007 13:11:48 +0000 (13:11 +0000)
committerJani Laakso <jani.laakso@itmill.com>
Sun, 21 Oct 2007 13:11:48 +0000 (13:11 +0000)
svn changeset:2566/svn branch:trunk

src/com/itmill/toolkit/tests/TestCaptionWrapper.java [new file with mode: 0644]
src/com/itmill/toolkit/tests/UsingObjectsInSelect.java [new file with mode: 0644]
src/com/itmill/toolkit/tests/m.gif [new file with mode: 0644]

diff --git a/src/com/itmill/toolkit/tests/TestCaptionWrapper.java b/src/com/itmill/toolkit/tests/TestCaptionWrapper.java
new file mode 100644 (file)
index 0000000..675ab7e
--- /dev/null
@@ -0,0 +1,43 @@
+package com.itmill.toolkit.tests;
+
+import com.itmill.toolkit.terminal.ClassResource;
+import com.itmill.toolkit.terminal.ErrorMessage;
+import com.itmill.toolkit.terminal.UserError;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+
+public class TestCaptionWrapper extends CustomComponent {
+
+       OrderedLayout main = new OrderedLayout();
+       Label label = new Label("iconLabel");
+
+       public TestCaptionWrapper() {
+               setCompositionRoot(main);
+       }
+
+       public void attach() {
+               super.attach();
+               createNewView();
+       }
+
+       public void createNewView() {
+               main.removeAllComponents();
+
+               // Add resource for label (icon)
+               ClassResource res = new ClassResource("m.gif", this.getApplication());
+               label.setIcon(res);
+
+               // Add error message for label
+               ErrorMessage errorMsg = new UserError("User error");
+               label.setComponentError(errorMsg);
+
+               // Set other common properties for label
+               label.setDescription("iconLabel description");
+               label.setCaption("iconLabel caption");
+               label.setValue("iconLabel value");
+
+               main.addComponent(label);
+       }
+
+}
diff --git a/src/com/itmill/toolkit/tests/UsingObjectsInSelect.java b/src/com/itmill/toolkit/tests/UsingObjectsInSelect.java
new file mode 100644 (file)
index 0000000..565c2db
--- /dev/null
@@ -0,0 +1,108 @@
+package com.itmill.toolkit.tests;
+
+import java.util.LinkedList;
+import java.util.Random;
+
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import com.itmill.toolkit.data.Property.ValueChangeListener;
+import com.itmill.toolkit.terminal.ClassResource;
+import com.itmill.toolkit.ui.*;
+
+public class UsingObjectsInSelect extends com.itmill.toolkit.Application
+               implements ValueChangeListener {
+
+       private Select select = new Select();
+       private Label selectedTask = new Label("Selected task", Label.CONTENT_XHTML);
+
+       public LinkedList exampleTasks = new LinkedList();
+
+       public static Random random = new Random(1);
+
+       public void init() {
+               Window main = new Window("Select demo");
+               setMainWindow(main);
+
+               setTheme("corporate");
+
+               Panel panel = new Panel("Select demo");
+               panel.addComponent(select);
+               Panel panel2 = new Panel("Selection");
+               panel2.addComponent(selectedTask);
+
+               select.setCaption("Select component");
+               select.addListener((ValueChangeListener) this);
+               select.setImmediate(true);
+
+               main.addComponent(panel);
+               main.addComponent(panel2);
+
+               createExampleTasks();
+       }
+
+       public void createExampleTasks() {
+               String[] assignedTo = new String[] { "John", "Mary", "Joe", "Sarah",
+                               "Jeff", "Jane", "Peter", "Marc", "Josie", "Linus" };
+               String[] type = new String[] { "Enhancement", "Bugfix", "Testing",
+                               "Task" };
+               for (int j = 0; j < 100; j++) {
+                       Task task = new Task(
+                                       type[(int) (random.nextDouble() * (type.length - 1))],
+                                       assignedTo[(int) (random.nextDouble() * (assignedTo.length - 1))],
+                                       random.nextInt(100));
+                       select.addItem(task);
+               }
+       }
+
+       public void valueChange(ValueChangeEvent event) {
+               Task task = (Task) select.getValue();
+               selectedTask.setValue("<b>Type:</b> " + task.getType()
+                               + "<br /><b>Assigned to:</b> " + task.getAssignedTo()
+                               + "<br /><b>Estimated hours: </b>" + task.getEstimatedHours());
+       }
+
+       /**
+        * Sample class which is bind in Toolkit components
+        * 
+        */
+       public class Task {
+
+               private String type;
+               private String assignedTo;
+               private int estimatedHours;
+
+               public Task(String type, String assignedTo, int estimatedHours) {
+                       this.type = type;
+                       this.assignedTo = assignedTo;
+                       this.estimatedHours = estimatedHours;
+               }
+
+               public String toString() {
+                       return type + ", " + assignedTo;
+               }
+
+               public String getType() {
+                       return type;
+               }
+
+               public void setType(String type) {
+                       this.type = type;
+               }
+
+               public String getAssignedTo() {
+                       return assignedTo;
+               }
+
+               public void setAssignedTo(String assignedTo) {
+                       this.assignedTo = assignedTo;
+               }
+
+               public float getEstimatedHours() {
+                       return estimatedHours;
+               }
+
+               public void setEstimatedHours(int estimatedHours) {
+                       this.estimatedHours = estimatedHours;
+               }
+       }
+
+}
diff --git a/src/com/itmill/toolkit/tests/m.gif b/src/com/itmill/toolkit/tests/m.gif
new file mode 100644 (file)
index 0000000..2201bdf
Binary files /dev/null and b/src/com/itmill/toolkit/tests/m.gif differ