From: Jani Laakso Date: Wed, 7 Nov 2007 19:02:52 +0000 (+0000) Subject: Added test application for most components and layouts. Modify test methods when... X-Git-Tag: 6.7.0.beta1~5641 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2c6500cb56de6abfa60a3823b1c88ff9dff25924;p=vaadin-framework.git Added test application for most components and layouts. Modify test methods when inspecting how components work within various layouts. svn changeset:2743/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/tests/TestComponentsAndLayouts.java b/src/com/itmill/toolkit/tests/TestComponentsAndLayouts.java new file mode 100644 index 0000000000..3f7156ca41 --- /dev/null +++ b/src/com/itmill/toolkit/tests/TestComponentsAndLayouts.java @@ -0,0 +1,279 @@ +package com.itmill.toolkit.tests; + +import java.io.File; +import java.sql.SQLException; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.data.Container; +import com.itmill.toolkit.data.util.FilesystemContainer; +import com.itmill.toolkit.data.util.QueryContainer; +import com.itmill.toolkit.demo.util.SampleDatabase; +import com.itmill.toolkit.demo.util.SampleDirectory; +import com.itmill.toolkit.event.Action; +import com.itmill.toolkit.terminal.ClassResource; +import com.itmill.toolkit.terminal.ErrorMessage; +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.terminal.UserError; + +import com.itmill.toolkit.ui.*; +import com.itmill.toolkit.ui.Component.Event; +import com.itmill.toolkit.ui.Component.Listener; + +public class TestComponentsAndLayouts extends Application implements Listener, + Action.Handler { + + OrderedLayout main = new OrderedLayout(); + + // event listener feedback (see console) + Label eventListenerFeedback = new Label( + "See console for event listener log."); + int eventCount = 0; + + // component counter + int count = 0; + + SampleDatabase sampleDatabase; + + // Example Actions for table + private Action ACTION1 = new Action("Upload"); + private Action ACTION2 = new Action("Download"); + private Action ACTION3 = new Action("Show history"); + private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 }; + + public void init() { + sampleDatabase = new SampleDatabase(); + createNewView(); + } + + public void createNewView() { + Window main = new Window("Main window"); + setMainWindow(main); + + main + .addComponent(new Label( + "Each Layout and their contained components should " + + "have icon, caption, description, user error defined. " + + "Eeach layout should contain similar components. " + + "All components are in immmediate mode.")); + main.addComponent(eventListenerFeedback); + + main.addComponent(new Label("OrderedLayout")); + test(main); + populateLayout(main); + + Panel panel = new Panel("Panel"); + test(panel); + populateLayout(panel); + main.addComponent(panel); + + TabSheet tabsheet = new TabSheet(); + test(tabsheet); + OrderedLayout tab1 = new OrderedLayout(); + tab1.addComponent(new Label("try tab2")); + OrderedLayout tab2 = new OrderedLayout(); + test(tab2); + populateLayout(tab2); + tabsheet + .addTab(tab1, "TabSheet tab1", new ClassResource("m.gif", this)); + tabsheet + .addTab(tab2, "TabSheet tab2", new ClassResource("m.gif", this)); + main.addComponent(tabsheet); + + ExpandLayout expandLayout = new ExpandLayout(); + test(expandLayout); + populateLayout(expandLayout); + main.addComponent(expandLayout); + + GridLayout gridLayout = new GridLayout(); + test(gridLayout); + populateLayout(gridLayout); + main.addComponent(gridLayout); + + Window window = new Window("TEST: Window"); + test(window); + populateLayout(window); + getMainWindow().addWindow(window); + } + + void populateLayout(Layout layout) { + Button button = new Button("Button " + count++); + test(layout, button); + + DateField df = new DateField("DateField " + count++); + test(layout, df); + + CheckBox cb = new CheckBox("Checkbox " + count++); + test(layout, cb); + + ClassResource flashResource = new ClassResource("itmill_spin.swf", this); + Embedded emb = new Embedded("Embedded " + count++, flashResource); + test(layout, emb); + emb.setType(Embedded.TYPE_OBJECT); + emb.setMimeType("application/x-shockwave-flash"); + emb.setWidth(250); + emb.setHeight(100); + + Panel panel = new Panel("Panel " + count++); + test(layout, panel); + + Label label = new Label("Label " + count++); + test(layout, label); + + Link link = new Link("Link " + count++, new ExternalResource( + "www.itmill.com")); + test(layout, link); + + NativeSelect nativeSelect = new NativeSelect("NativeSelect " + count++); + test(layout, nativeSelect); + nativeSelect.setContainerDataSource(getContainer()); + + OptionGroup optionGroup = new OptionGroup("OptionGroup " + count++); + optionGroup.setContainerDataSource(getSmallContainer()); + test(layout, optionGroup); + + ProgressIndicator pi = new ProgressIndicator(50.0f); + test(layout, pi); + + RichTextArea rta = new RichTextArea(); + test(layout, rta); + + Select select = new Select("Select " + count++); + test(layout, select); + select.setContainerDataSource(getSmallContainer()); + + Slider slider = new Slider("Slider " + count++); + test(layout, slider); + + Table table = new Table("Table " + count++); + test(layout, table); + table.setPageLength(10); + table.setSelectable(true); + table.setRowHeaderMode(Table.ROW_HEADER_MODE_INDEX); + table.setColumnCollapsingAllowed(true); + table.setColumnReorderingAllowed(true); + table.setSelectable(true); + table.addActionHandler(this); + table.setContainerDataSource(getContainer()); + table.setVisibleColumns(new Object[] { "FIRSTNAME", "LASTNAME", + "TITLE", "UNIT" }); + table.setItemCaptionPropertyId("ID"); + + TabSheet tabsheet = new TabSheet(); + OrderedLayout tab1 = new OrderedLayout(); + tab1.addComponent(new Label("tab1 " + count++)); + OrderedLayout tab2 = new OrderedLayout(); + tab2.addComponent(new Label("tab2")); + tabsheet + .addTab(tab1, "TabSheet tab1", new ClassResource("m.gif", this)); + tabsheet + .addTab(tab2, "TabSheet tab2", new ClassResource("m.gif", this)); + + TextField tf = new TextField("Textfield " + count++); + test(layout, tf); + + Tree tree = new Tree("Tree " + count++); + test(layout, tree); + File sampleDir = SampleDirectory.getDirectory(this); + FilesystemContainer fsc = new FilesystemContainer(sampleDir, true); + tree.setContainerDataSource(fsc); + + TwinColSelect twinColSelect = new TwinColSelect("TwinColSelect " + + count++); + test(layout, twinColSelect); + twinColSelect.setContainerDataSource(getSmallContainer()); + + Upload upload = new Upload("Upload (non-functional)", null); + test(layout, upload); + + // Custom components + layout.addComponent(new Label("Below are few custom components", + Label.CONTENT_XHTML)); + TestForUpload tfu = new TestForUpload(); + layout.addComponent(tfu); + + } + + Container getContainer() { + // populate container with test SQL table rows + try { + return new QueryContainer("SELECT * FROM employee", sampleDatabase + .getConnection()); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + Container getSmallContainer() { + // populate container with test SQL table rows + try { + return new QueryContainer("SELECT * FROM unit ", sampleDatabase + .getConnection()); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + /** + * Stresses component by configuring it + * + * @param c + */ + void test(AbstractComponent c) { + ClassResource res = new ClassResource("m.gif", this); + ErrorMessage errorMsg = new UserError("User error " + c); + + if ((c.getCaption() == null) || (c.getCaption().length() <= 0)) + c.setCaption("Caption " + c); + c.setDescription("Description " + c); + c.setComponentError(errorMsg); + c.setIcon(res); + c.setImmediate(true); + // c.setEnabled(false); + // c.setVisible(false); + // c.setStyle("testStyle"); + // c.setStyleName("testStyleName"); + // c.setReadOnly(true); + + // try to add listener + try { + c.addListener(this); + } catch (Exception e) { + System.err.println("Could not add listener for component " + c + + ", count was " + count); + } + } + + /** + * Stresses component by configuring it in a given layout + * + * @param c + */ + void test(Layout layout, AbstractComponent c) { + test(c); + layout.addComponent(c); + layout.addComponent(new Label("
", Label.CONTENT_XHTML)); + } + + public void componentEvent(Event event) { + eventCount++; + String feedback = "eventCount=" + eventCount + ", class=" + + event.getClass() + ", source=" + event.getSource() + + ", toString()=" + event.toString(); + System.out.println("eventListenerFeedback: " + feedback); + eventListenerFeedback.setValue("Events: " + eventCount); + } + + // For sample actions + public Action[] getActions(Object target, Object sender) { + return actions; + } + + // For sample actions + public void handleAction(Action action, Object sender, Object target) { + System.out.println("ACTION: " + action.getCaption() + " on item " + + target); + } + +} diff --git a/src/com/itmill/toolkit/tests/itmill_spin.swf b/src/com/itmill/toolkit/tests/itmill_spin.swf new file mode 100644 index 0000000000..9e58ce29c6 Binary files /dev/null and b/src/com/itmill/toolkit/tests/itmill_spin.swf differ