aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/itmill/toolkit/demo')
-rw-r--r--src/com/itmill/toolkit/demo/LayoutDemo.java138
-rw-r--r--src/com/itmill/toolkit/demo/Parameters.java5
-rw-r--r--src/com/itmill/toolkit/demo/QueryContainerDemo.java1
-rw-r--r--src/com/itmill/toolkit/demo/SelectDemo.java74
-rw-r--r--src/com/itmill/toolkit/demo/Shortcut.java9
5 files changed, 219 insertions, 8 deletions
diff --git a/src/com/itmill/toolkit/demo/LayoutDemo.java b/src/com/itmill/toolkit/demo/LayoutDemo.java
new file mode 100644
index 0000000000..cedebf84a7
--- /dev/null
+++ b/src/com/itmill/toolkit/demo/LayoutDemo.java
@@ -0,0 +1,138 @@
+package com.itmill.toolkit.demo;
+
+import com.itmill.toolkit.terminal.ClassResource;
+import com.itmill.toolkit.ui.*;
+
+/**
+ * This example demonstrates layouts. Layouts are populated with sample Toolkit
+ * UI components.
+ *
+ * @author IT Mill Ltd.
+ * @since 4.0.0
+ *
+ */
+public class LayoutDemo extends com.itmill.toolkit.Application {
+
+ /**
+ * Initialize Application. Demo components are added to main window.
+ */
+ public void init() {
+ Window mainWindow = new Window("Layout demo");
+ setMainWindow(mainWindow);
+
+ // set the application to use Corporate -theme
+ setTheme("corporate");
+
+ //
+ // Create horizontal ordered layout
+ //
+ OrderedLayout layoutA = new OrderedLayout(
+ OrderedLayout.ORIENTATION_HORIZONTAL);
+ // Add 4 panels
+ fillLayout(layoutA, 4);
+
+ //
+ // Create vertical ordered layout
+ //
+ OrderedLayout layoutB = new OrderedLayout(
+ OrderedLayout.ORIENTATION_VERTICAL);
+ // Add 4 panels
+ fillLayout(layoutB, 4);
+
+ //
+ // Create grid layout
+ //
+ GridLayout layoutG = new GridLayout(4, 4);
+ // Add 16 panels components
+ fillLayout(layoutG, 16);
+
+ //
+ // Create grid layout
+ //
+ GridLayout layoutG2 = new GridLayout(4, 4);
+ // Add 4 panels with absolute coordinates (diagonally)
+ layoutG2.addComponent(getExampleComponent("x=0, y=0"), 0, 0);
+ layoutG2.addComponent(getExampleComponent("x=1, y=1"), 1, 1);
+ layoutG2.addComponent(getExampleComponent("x=2, y=2"), 2, 2);
+ layoutG2.addComponent(getExampleComponent("x=3, y=3"), 3, 3);
+ // Add 4 pictures with absolute coordinates (diagonally)
+ layoutG2.addComponent(getExamplePicture("x=3, y=0"), 3, 0);
+ layoutG2.addComponent(getExamplePicture("x=2, y=1"), 2, 1);
+ layoutG2.addComponent(getExamplePicture("x=1, y=2"), 1, 2);
+ layoutG2.addComponent(getExamplePicture("x=0, y=3"), 0, 3);
+
+ //
+ // Create TabSheet
+ //
+ TabSheet tabsheet = new TabSheet();
+ tabsheet
+ .setCaption("Tabsheet, above layouts are added to this component");
+ tabsheet.addTab(layoutA, "Horizontal ordered layout", null);
+ tabsheet.addTab(layoutB, "Vertical ordered layout", null);
+ tabsheet.addTab(layoutG, "First grid layout", null);
+ tabsheet.addTab(layoutG2, "Second grid layout", null);
+
+ //
+ // Add demo layouts to main window
+ //
+ mainWindow.addComponent(new Label(
+ "<h3>Horizontal ordered layout</h3>Added four components.",
+ Label.CONTENT_XHTML));
+ mainWindow.addComponent(layoutA);
+ mainWindow.addComponent(new Label(
+ "<br /><h3>Vertical ordered layout</h3>Added four components.",
+ Label.CONTENT_XHTML));
+ mainWindow.addComponent(layoutB);
+ mainWindow.addComponent(new Label(
+ "<br /><h3>Grid Layout (4 x 4)</h3>Added 16 components.",
+ Label.CONTENT_XHTML));
+ mainWindow.addComponent(layoutG);
+ mainWindow
+ .addComponent(new Label("<br /><h3>Grid Layout (4 x 4)</h3>"
+ + "Added four panels and four embedded components "
+ + "diagonally with absolute coordinates.",
+ Label.CONTENT_XHTML));
+ mainWindow.addComponent(layoutG2);
+ mainWindow.addComponent(new Label(
+ "<br /><h3>TabSheet</h3>Added above layouts as tabs.",
+ Label.CONTENT_XHTML));
+ mainWindow.addComponent(tabsheet);
+
+ }
+
+ private Component getExamplePicture(String caption) {
+ ClassResource cr = new ClassResource("features/m-bullet-blue.gif", this);
+ Embedded em = new Embedded("Embedded " + caption, cr);
+ em.setWidth(170);
+ return em;
+ }
+
+ private Component getExampleComponent(String caption) {
+ Panel panel = new Panel();
+ panel.setCaption("Panel component " + caption);
+ panel
+ .addComponent(new Label(
+ "Panel is a container for other components, by default it draws a frame around it's "
+ + "extremities and may have a caption to clarify the nature of the contained components' purpose."
+ + " Panel contains an layout where the actual contained components are added, "
+ + "this layout may be switched on the fly.",
+ Label.CONTENT_XHTML));
+ panel.setWidth(222);
+ return panel;
+ }
+
+ /**
+ * Add multiple demo component to given layout.
+ *
+ * @param layout
+ * where components are added
+ * @param numberOfComponents
+ * to add
+ */
+ private void fillLayout(Layout layout, int numberOfComponents) {
+ for (int i = 1; i <= numberOfComponents; i++) {
+ layout.addComponent(getExampleComponent(Integer.toString(i)));
+ }
+ }
+
+}
diff --git a/src/com/itmill/toolkit/demo/Parameters.java b/src/com/itmill/toolkit/demo/Parameters.java
index 1c6b66457a..d65707900b 100644
--- a/src/com/itmill/toolkit/demo/Parameters.java
+++ b/src/com/itmill/toolkit/demo/Parameters.java
@@ -92,8 +92,8 @@ public class Parameters extends com.itmill.toolkit.Application implements
* communicate with EmbeddedToolkit.jsp
*/
public void handleParameters(Map parameters) {
- // disabled, see bug #550
- //params.removeAllItems();
+ // TODO: disabled, see bug #550
+ // params.removeAllItems();
System.out.println("handleParameters()");
for (Iterator i = parameters.keySet().iterator(); i.hasNext();) {
String name = (String) i.next();
@@ -105,7 +105,6 @@ public class Parameters extends com.itmill.toolkit.Application implements
v += "'" + values[j] + "'";
}
params.addItem(new Object[] { v }, name);
- System.out.println("parameter name="+name+", value="+v);
}
}
}
diff --git a/src/com/itmill/toolkit/demo/QueryContainerDemo.java b/src/com/itmill/toolkit/demo/QueryContainerDemo.java
index 91026e33ac..51cb0c378b 100644
--- a/src/com/itmill/toolkit/demo/QueryContainerDemo.java
+++ b/src/com/itmill/toolkit/demo/QueryContainerDemo.java
@@ -154,6 +154,7 @@ public class QueryContainerDemo extends com.itmill.toolkit.Application
tree.setDescription("Try right mouse button to initiate "
+ "actions menu. Note: on Opera you use meta key "
+ "and left mouse button.");
+ tree.setStyle("menu");
// Populate Toolkit Tree using select component as data source
tree.setContainerDataSource(select.getContainerDataSource());
diff --git a/src/com/itmill/toolkit/demo/SelectDemo.java b/src/com/itmill/toolkit/demo/SelectDemo.java
new file mode 100644
index 0000000000..e8a76d1686
--- /dev/null
+++ b/src/com/itmill/toolkit/demo/SelectDemo.java
@@ -0,0 +1,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());
+ }
+
+}
diff --git a/src/com/itmill/toolkit/demo/Shortcut.java b/src/com/itmill/toolkit/demo/Shortcut.java
index 97f25ce549..32dda20ce0 100644
--- a/src/com/itmill/toolkit/demo/Shortcut.java
+++ b/src/com/itmill/toolkit/demo/Shortcut.java
@@ -106,7 +106,6 @@ public class Shortcut extends com.itmill.toolkit.Application implements Handler
}
public void handleAction(Action action, Object sender, Object target) {
- main.addComponent(new Label("ShortcutAction fired" + action));
if (target == a)
this.buttonAHandler();
if (target == b)
@@ -117,6 +116,10 @@ public class Shortcut extends com.itmill.toolkit.Application implements Handler
this.close();
}
+ public void buttonAHandler() {
+ main.addComponent(new Label("Button A handler fired"));
+ }
+
public void buttonBHandler() {
main.addComponent(new Label("Button B handler fired"));
}
@@ -124,8 +127,4 @@ public class Shortcut extends com.itmill.toolkit.Application implements Handler
public void buttonCHandler() {
main.addComponent(new Label("Button C handler fired"));
}
-
- public void buttonAHandler() {
- main.addComponent(new Label("Button A handler fired"));
- }
}