aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo/SelectDemo.java
blob: e8a76d168679ee4c50c966f124997c522f36a12c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.itmill.toolkit.demo;

import java.sql.SQLException;
import com.itmill.toolkit.data.util.QueryContainer;
import com.itmill.toolkit.demo.util.SampleDatabase;
import com.itmill.toolkit.ui.*;

/**
 * This example demonstrates what is lazy loading feature on Select component.
 * Demo Uses similar concepts to QueryContainerDemo.
 * 
 * @author IT Mill Ltd.
 * @since 4.0.0
 * 
 */
public class SelectDemo extends com.itmill.toolkit.Application {

	// Select component where SQL rows are attached (using QueryContainer)
	private Select select = new Select();

	private Select lazySelect = new Select();

	// Database provided with sample data
	private SampleDatabase sampleDatabase;

	/**
	 * Initialize Application. Demo components are added to main window.
	 */
	public void init() {
		Window main = new Window("Select demo");
		setMainWindow(main);

		// set the application to use Corporate -theme
		setTheme("corporate");

		// Main window contains heading, table, select and tree
		Panel panel = new Panel("Select demo (a.k.a Google Suggests)");
		panel.addComponent(lazySelect);
		panel.addComponent(new Label("<hr />", Label.CONTENT_XHTML));
		panel.addComponent(select);
		main.addComponent(panel);

		// create demo database
		sampleDatabase = new SampleDatabase();

		initSelects();
	}

	private void initSelects() {
		// init select
		select.setCaption("All employees default functionality.");
		select.setItemCaptionPropertyId("WORKER");
		// populate Toolkit select component with test SQL table rows
		try {
			QueryContainer qc = new QueryContainer(
					"SELECT ID, UNIT||', '||LASTNAME||' '||FIRSTNAME"
							+ " AS WORKER FROM employee ORDER BY WORKER",
					sampleDatabase.getConnection());
			select.setContainerDataSource(qc);
		} catch (SQLException e) {
			e.printStackTrace();
		}

		// init lazySelect
		lazySelect.setCaption("All employees with lazy loading "
				+ "(a.k.a Google Suggests) activated.");
		lazySelect.setItemCaptionPropertyId("WORKER");
		// use lazy loading (a.k.a Google Suggest)
		lazySelect.setLazyLoading(true);
		// use same datasource as select object uses
		lazySelect.setContainerDataSource(select.getContainerDataSource());
	}

}