From: Henri Sara com.vaadin.data.Container
and set it as datasource to UI
- * components com.vaadin.ui.Component.Tree
, how to receive
- * ExpandEvent and implement com.vaadin.ui.Tree.ExpandListener
, how
- * to use com.vaadin.event.Action
.
- *
- * @author IT Mill Ltd.
- * @since 4.0.0
- *
- */
-public class QueryContainerDemo extends com.vaadin.Application implements
- Action.Handler {
-
- private static final String ACTION_DESCRIPTION = "Try right mouse button to initiate "
- + "actions menu.
Note: on Opera you use meta key "
- + "and left mouse button.";
-
- private static final String TABLE_CAPTION = SampleDatabase.ROWCOUNT
- + " dynamically loaded rows from example SQL table";
-
- // Table component where SQL rows are attached (using QueryContainer)
- private final Table table = new Table();
-
- private final Label tableLastAction = new Label(
- "No action selected for table.");
-
- // Select component where SQL rows are attached (using QueryContainer)
- private final Select select = new Select();
-
- // Tree component that uses select as datasource
- private final Tree tree = new Tree();
-
- private final Label treeLastAction = new Label(
- "No action selected for tree.");
-
- // Database provided with sample data
- private SampleDatabase sampleDatabase;
-
- // Example Actions for table
- private final Action ACTION1 = new Action("Upload");
-
- private final Action ACTION2 = new Action("Download");
-
- private final Action ACTION3 = new Action("Show history");
-
- private final Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 };
-
- /**
- * Initialize Application. Demo components are added to main window.
- */
- @Override
- public void init() {
- final Window main = new Window("QueryContainer demo");
- setMainWindow(main);
-
- // Main window contains heading, table, select and tree
- main
- .addComponent(new Label(
- "QueryContainer demo
"
- + "Rows are loaded from the server as they are needed.
"
- + "Try scrolling the table to see it in action.
"
- + ACTION_DESCRIPTION, Label.CONTENT_XHTML));
- main.addComponent(table);
- main.addComponent(tableLastAction);
- main.addComponent(new Label("
", Label.CONTENT_XHTML));
- main.addComponent(select);
- main.addComponent(new Label("
", Label.CONTENT_XHTML));
- main.addComponent(tree);
- main.addComponent(treeLastAction);
-
- // create demo database
- sampleDatabase = new SampleDatabase();
-
- // initialize demo components
- initTable();
- initSelect();
- initTree();
- }
-
- /**
- * Populates table component with all rows from employee table.
- *
- */
- private void initTable() {
- // init table
- table.setCaption(TABLE_CAPTION);
- table.setPageLength(10);
- table.setSelectable(true);
- table.setRowHeaderMode(Table.ROW_HEADER_MODE_INDEX);
- table.setColumnCollapsingAllowed(true);
- table.setColumnReorderingAllowed(true);
- table.setSelectable(true);
- // this class handles table actions (see handleActions method below)
- table.addActionHandler(this);
- table.setDescription(ACTION_DESCRIPTION);
-
- // populate Vaadin table component with test SQL table rows
- try {
- final QueryContainer qc = new QueryContainer(
- "SELECT * FROM employee", sampleDatabase.getConnection());
- table.setContainerDataSource(qc);
- } catch (final SQLException e) {
- e.printStackTrace();
- }
- // define which columns should be visible on Table component
- table.setVisibleColumns(new Object[] { "FIRSTNAME", "LASTNAME",
- "TITLE", "UNIT" });
- table.setItemCaptionPropertyId("ID");
- }
-
- /**
- * Populates select component with distinct unit values from employee table.
- *
- */
- private void initSelect() {
- // init select
- select.setCaption("All distinct units from employee table.");
- select.setItemCaptionPropertyId("UNIT");
-
- // populate Vaadin select component with test SQL table rows
- try {
- final QueryContainer qc = new QueryContainer(
- "SELECT DISTINCT UNIT FROM employee", sampleDatabase
- .getConnection());
- select.setContainerDataSource(qc);
- } catch (final SQLException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Populates tree component using select component as data source for root
- * nodes, child nodes are queried from database. Implementation is done for
- * example purposes only.
- *
- */
- private void initTree() {
- // init tree
- tree.setCaption("All distinct units from employee table.");
- tree.setItemCaptionPropertyId("UNIT");
- tree.setSelectable(true);
- // this class handles tree actions (see handleActions method below)
- tree.addActionHandler(this);
- tree.setDescription("Try right mouse button to initiate "
- + "actions menu. Note: on Opera you use meta key "
- + "and left mouse button.");
-
- // Populate Vaadin Tree using select component as data source
- tree.setContainerDataSource(select.getContainerDataSource());
- }
-
- /**
- * Return example actions
- */
- public Action[] getActions(Object target, Object sender) {
- return actions;
- }
-
- /**
- * Executed by right mouse button on table or tree component.
- */
- public void handleAction(Action action, Object sender, Object target) {
- if (sender == table) {
- tableLastAction.setValue("Last action clicked was '"
- + action.getCaption() + "' on item " + target);
- } else if (sender == tree) {
- treeLastAction.setValue("Last action clicked was '"
- + action.getCaption() + "' on item " + target);
- }
- }
-
-}
diff --git a/tests/src/com/vaadin/tests/TestBench.java b/tests/src/com/vaadin/tests/TestBench.java
index be3471c02d..1e71c6fa91 100644
--- a/tests/src/com/vaadin/tests/TestBench.java
+++ b/tests/src/com/vaadin/tests/TestBench.java
@@ -44,9 +44,8 @@ public class TestBench extends com.vaadin.Application implements
// Add here packages which are used for finding testable classes
String[] testablePackages = { "com.vaadin.tests", "com.vaadin.demo",
- "com.vaadin.demo.colorpicker", "com.vaadin.demo.reservation",
- "com.vaadin.demo.features", "com.vaadin.tests.tickets",
- "com.vaadin.tests.book" };
+ "com.vaadin.demo.colorpicker", "com.vaadin.demo.features",
+ "com.vaadin.tests.tickets", "com.vaadin.tests.book" };
HierarchicalContainer testables = new HierarchicalContainer();
diff --git a/tests/src/com/vaadin/tests/TestComponentsAndLayouts.java b/tests/src/com/vaadin/tests/TestComponentsAndLayouts.java
deleted file mode 100644
index ba9fbe86d0..0000000000
--- a/tests/src/com/vaadin/tests/TestComponentsAndLayouts.java
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
-@ITMillApache2LicenseForJavaFiles@
- */
-
-package com.vaadin.tests;
-
-import java.io.File;
-import java.sql.SQLException;
-
-import com.vaadin.Application;
-import com.vaadin.data.Container;
-import com.vaadin.data.util.FilesystemContainer;
-import com.vaadin.data.util.QueryContainer;
-import com.vaadin.demo.util.SampleDatabase;
-import com.vaadin.demo.util.SampleDirectory;
-import com.vaadin.event.Action;
-import com.vaadin.terminal.ClassResource;
-import com.vaadin.terminal.ErrorMessage;
-import com.vaadin.terminal.ExternalResource;
-import com.vaadin.terminal.UserError;
-import com.vaadin.ui.AbstractComponent;
-import com.vaadin.ui.Accordion;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.CheckBox;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.CustomComponent;
-import com.vaadin.ui.DateField;
-import com.vaadin.ui.Embedded;
-import com.vaadin.ui.GridLayout;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.Layout;
-import com.vaadin.ui.Link;
-import com.vaadin.ui.NativeSelect;
-import com.vaadin.ui.OptionGroup;
-import com.vaadin.ui.OrderedLayout;
-import com.vaadin.ui.Panel;
-import com.vaadin.ui.RichTextArea;
-import com.vaadin.ui.Select;
-import com.vaadin.ui.Slider;
-import com.vaadin.ui.SplitPanel;
-import com.vaadin.ui.TabSheet;
-import com.vaadin.ui.Table;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.Tree;
-import com.vaadin.ui.TwinColSelect;
-import com.vaadin.ui.Upload;
-import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.Window;
-import com.vaadin.ui.Component.Event;
-import com.vaadin.ui.Component.Listener;
-
-/**
- * Search for "TWEAK these" keyword and configure Custom/AbstractComponents to
- * various states and see how they work inside different Layouts.
- *
- */
-public class TestComponentsAndLayouts extends Application implements Listener,
- Action.Handler {
-
- // event listener feedback (see console)
- Label eventListenerFeedback = new Label(
- "See console for event listener log.");
- int eventCount = 0;
-
- Window window;
-
- // component counter
- int count = 0;
-
- SampleDatabase sampleDatabase;
-
- // Example Actions for table
- private final Action ACTION1 = new Action("Upload");
- private final Action ACTION2 = new Action("Download");
- private final Action ACTION3 = new Action("Show history");
- private final Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 };
-
- @Override
- public void init() {
- sampleDatabase = new SampleDatabase();
- createNewView();
- }
-
- public void createNewView() {
- final Window main = new Window("Main window");
- setMainWindow(main);
-
- // By default push all containers inside main window
- Layout target = main.getLayout();
-
- 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. See source how to tweak this test."));
- main.addComponent(eventListenerFeedback);
-
- // //////////////////////////////////////////////////////////////////////
- // ////
- if (false) {
- window = new Window("Components inside Window (TEST: Window)");
-
- if (false) {
- // push every container and their components inside window
- target = window.getLayout();
- } else {
- // window is just one container to be tested
- populateLayout(window.getLayout());
- }
- getMainWindow().addWindow(window);
- }
-
- // //////////////////////////////////////////////////////////////////////
- // ////
- if (false) {
- target
- .addComponent(new Label(
- "Components inside horizontal OrderedLayout",
- Label.CONTENT_XHTML));
- final OrderedLayout ol = new OrderedLayout(
- OrderedLayout.ORIENTATION_HORIZONTAL);
- populateLayout(ol);
- target.addComponent(ol);
- }
-
- // //////////////////////////////////////////////////////////////////////
- // ////
- if (false) {
- target
- .addComponent(new Label(
- "
Components inside vertical OrderedLayout",
- Label.CONTENT_XHTML));
- final OrderedLayout ol2 = new OrderedLayout(
- OrderedLayout.ORIENTATION_VERTICAL);
- populateLayout(ol2);
- target.addComponent(ol2);
- }
-
- // //////////////////////////////////////////////////////////////////////
- // ////
- if (false) {
- target.addComponent(new Label(
- "
Components inside TabSheet",
- Label.CONTENT_XHTML));
- final TabSheet tabsheet = new TabSheet();
- final OrderedLayout tab1 = new OrderedLayout();
- tab1.addComponent(new Label("try tab2"));
- final OrderedLayout tab2 = new OrderedLayout();
- populateLayout(tab2);
- tabsheet.addTab(tab1, "TabSheet tab1", new ClassResource("m.gif",
- this));
- tabsheet.addTab(tab2, "TabSheet tab2", new ClassResource("m.gif",
- this));
- target.addComponent(tabsheet);
- // test(tabsheet);
- // test(tab1);
- // test(tab2);
- // test(expandLayout);
- }
-
- // //////////////////////////////////////////////////////////////////////
- // ////
- if (true) {
- target.addComponent(new Label(
- "
Components inside Accordion",
- Label.CONTENT_XHTML));
- final Accordion accordion = new Accordion();
- accordion.setHeight(500);
- final OrderedLayout acc1 = new OrderedLayout();
- acc1.addComponent(new Label("try acc2"));
- final OrderedLayout acc2 = new OrderedLayout();
- populateLayout(acc2);
- accordion.addTab(acc1, "Accordion acc1", new ClassResource("m.gif",
- this));
- accordion.addTab(acc2, "Accordion acc2", new ClassResource("m.gif",
- this));
- target.addComponent(accordion);
- // test(accordion);
- // test(acc1);
- // test(acc2);
- // test(expandLayout);
- }
-
- // //////////////////////////////////////////////////////////////////////
- // ////
- if (false) {
- target.addComponent(new Label(
- "
Components inside GridLayout",
- Label.CONTENT_XHTML));
- final GridLayout gridLayout = new GridLayout(4, 100);
- populateLayout(gridLayout);
- target.addComponent(gridLayout);
- // test(gridLayout);
- }
-
- // //////////////////////////////////////////////////////////////////////
- // ////
- if (false) {
- target.addComponent(new Label(
- "
Components inside Panel",
- Label.CONTENT_XHTML));
- final Panel panel = new Panel("Panel");
- populateLayout(panel.getLayout());
- target.addComponent(panel);
- }
-
- // //////////////////////////////////////////////////////////////////////
- // ////
- if (false) {
- target
- .addComponent(new Label(
- "
Components inside horizontal SplitPanel (splitpanel is under 250px height ExpandLayout)",
- Label.CONTENT_XHTML));
- final VerticalLayout sp2l = new VerticalLayout();
- sp2l.setHeight(250, SplitPanel.UNITS_PIXELS);
- final SplitPanel sp2 = new SplitPanel(
- SplitPanel.ORIENTATION_HORIZONTAL);
- sp2l.addComponent(sp2);
- final VerticalLayout sp2first = new VerticalLayout();
- final VerticalLayout sp2second = new VerticalLayout();
- sp2.setFirstComponent(sp2first);
- populateLayout(sp2first);
- populateLayout(sp2second);
- sp2.setSecondComponent(sp2second);
- target.addComponent(sp2l);
- }
-
- }
-
- void populateLayout(Layout layout) {
- final Button button = new Button("Button " + count++);
- test(layout, button);
-
- final DateField df = new DateField("DateField " + count++);
- test(layout, df);
-
- final CheckBox cb = new CheckBox("Checkbox " + count++);
- test(layout, cb);
-
- final ClassResource flashResource = new ClassResource(
- "vaadin_spin.swf", this);
- final Embedded emb = new Embedded("Embedded " + count++, flashResource);
- emb.setType(Embedded.TYPE_OBJECT);
- emb.setMimeType("application/x-shockwave-flash");
- emb.setWidth("250px");
- emb.setHeight("100px");
- test(layout, emb);
-
- final Panel panel = new Panel("Panel " + count++);
- test(layout, panel);
-
- final Label label = new Label("Label " + count++);
- test(layout, label);
-
- final Link link = new Link("Link " + count++, new ExternalResource(
- "www.vaadin.com"));
- test(layout, link);
-
- final NativeSelect nativeSelect = new NativeSelect("NativeSelect "
- + count++);
- nativeSelect.setContainerDataSource(getContainer());
- test(layout, nativeSelect);
-
- final OptionGroup optionGroup = new OptionGroup("OptionGroup "
- + count++);
- optionGroup.setContainerDataSource(getSmallContainer());
- optionGroup.setItemCaptionPropertyId("UNIT");
- test(layout, optionGroup);
-
- // final ProgressIndicator pi = new ProgressIndicator();
- // pi.setCaption("ProgressIndicator");
- // test(layout, pi);
-
- final RichTextArea rta = new RichTextArea();
- test(layout, rta);
-
- final Select select = new Select("Select " + count++);
- select.setContainerDataSource(getSmallContainer());
- select.setItemCaptionPropertyId("UNIT");
- test(layout, select);
-
- final Slider slider = new Slider("Slider " + count++);
- test(layout, slider);
-
- final Table table = new Table("Table " + count++);
- 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");
- test(layout, table);
-
- final TabSheet tabsheet = new TabSheet();
- final VerticalLayout tab1 = new VerticalLayout();
- tab1.addComponent(new Label("tab1 " + count++));
- final VerticalLayout tab2 = new VerticalLayout();
- tab2.addComponent(new Label("tab2 " + count++));
- tabsheet.addTab(tab1, "Default (not configured) TabSheet tab1",
- new ClassResource("m.gif", this));
- tabsheet.addTab(tab2, "Configured TabSheet tab2", new ClassResource(
- "m.gif", this));
- test(layout, tabsheet);
-
- final Accordion accordion = new Accordion();
- final VerticalLayout acc1 = new VerticalLayout();
- acc1.addComponent(new Label("acc1 " + count++));
- final VerticalLayout acc2 = new VerticalLayout();
- acc2.addComponent(new Label("acc2 " + count++));
- accordion.addTab(acc1, "Default (not configured) Accordion acc1",
- new ClassResource("m.gif", this));
- accordion.addTab(acc2, "Configured Accordion acc2", new ClassResource(
- "m.gif", this));
- test(layout, accordion);
-
- final TextField tf = new TextField("Textfield " + count++);
- test(layout, tf);
- // do not configure acc1
- // test(acc1);
- test(acc2);
-
- final Tree tree = new Tree("Tree " + count++);
- final File sampleDir = SampleDirectory.getDirectory(this);
- final FilesystemContainer fsc = new FilesystemContainer(sampleDir, true);
- tree.setContainerDataSource(fsc);
- test(layout, tree);
-
- final TwinColSelect twinColSelect = new TwinColSelect("TwinColSelect "
- + count++);
- twinColSelect.setContainerDataSource(getSmallContainer());
- twinColSelect.setItemCaptionPropertyId("UNIT");
- test(layout, twinColSelect);
-
- final 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));
- final TestForUpload tfu = new TestForUpload();
- layout.addComponent(tfu);
- layout.addComponent(new Label("
----------