From 4431425fcf72cb34048f35a9aa7ea012b986cd4b Mon Sep 17 00:00:00 2001 From: Jani Laakso Date: Sun, 21 Oct 2007 13:11:48 +0000 Subject: [PATCH] Added few test classes. svn changeset:2566/svn branch:trunk --- .../toolkit/tests/TestCaptionWrapper.java | 43 +++++++ .../toolkit/tests/UsingObjectsInSelect.java | 108 ++++++++++++++++++ src/com/itmill/toolkit/tests/m.gif | Bin 0 -> 1036 bytes 3 files changed, 151 insertions(+) create mode 100644 src/com/itmill/toolkit/tests/TestCaptionWrapper.java create mode 100644 src/com/itmill/toolkit/tests/UsingObjectsInSelect.java create mode 100644 src/com/itmill/toolkit/tests/m.gif diff --git a/src/com/itmill/toolkit/tests/TestCaptionWrapper.java b/src/com/itmill/toolkit/tests/TestCaptionWrapper.java new file mode 100644 index 0000000000..675ab7e534 --- /dev/null +++ b/src/com/itmill/toolkit/tests/TestCaptionWrapper.java @@ -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 index 0000000000..565c2dbe98 --- /dev/null +++ b/src/com/itmill/toolkit/tests/UsingObjectsInSelect.java @@ -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("Type: " + task.getType() + + "
Assigned to: " + task.getAssignedTo() + + "
Estimated hours: " + 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 index 0000000000000000000000000000000000000000..2201bdfc1c682621408b64bca12464c095c1c4d4 GIT binary patch literal 1036 zcmZ?wbhEHb1l*H0ifP$hK%3|rNKye^fEJIZ+Lq$AORXjsgJX1|PLmfy;WT{JJt4U^R zNM>nBWob$SQMRUZj+S(`hD?r@Opdl(j*eWej$EFeLcX42zCH*Q=qnW%fKZ{na)F^z zp^ApYV@?!n5k(%6gxFLVMcc1%%ZHhMOpKTa^{xh zEhx`lR9n2PzI=Io#qx&A6)jb(dz#nxw{M!*wPi~Gws}+c%%8Py(VYD&79U={{P?=% z$2P1vxpl+otsBm6+jw@{rZc;@UD&hz;=z4aj~%*x_SD^rXYXIV{OH=1$M^5PczEyC zv#0M~JbVA*`TIAoKE8eZ>Ft}(@7{g>^7;GMFF$_#`1SM0@1H+^|M~?)e}4b|^M4dj z5CV!nSs1w({xj$>00AgZFmSwN_|N%AytS*7L3Npf;8Ws|OrntMr^ju6 z{H(f#G8z*OxXXLi^sU**?DD!_TS!jDqcDw6*q~RWw@`uc^nS?-*`5g#Qw5gVI;va{ zc(Js(k(HNiLE@L?Ct3K-*uqXecyNG8BDRF%M#9siZgH6`?;iq-j~;DI-6nA{=~