package com.itmill.toolkit.demo;
import java.util.HashMap;
-import java.util.Iterator;
import com.itmill.toolkit.data.Item;
import com.itmill.toolkit.data.Property;
import com.itmill.toolkit.data.Property.ValueChangeEvent;
import com.itmill.toolkit.data.util.HierarchicalContainer;
import com.itmill.toolkit.data.util.IndexedContainer;
+import com.itmill.toolkit.demo.featurebrowser.ClientCachingExample;
+import com.itmill.toolkit.demo.featurebrowser.EmbeddedBrowserExample;
+import com.itmill.toolkit.demo.featurebrowser.NotificationExample;
+import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.terminal.Sizeable;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.Component;
import com.itmill.toolkit.ui.ExpandLayout;
import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Layout;
+import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Select;
import com.itmill.toolkit.ui.SplitPanel;
import com.itmill.toolkit.ui.TabSheet;
import com.itmill.toolkit.ui.Table;
import com.itmill.toolkit.ui.Tree;
import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Button.ClickEvent;
/**
*
private Tree tree;
private Table table;
+ private TabSheet ts;
+
+ private HashMap components = new HashMap();
// category, name, desc, class, viewed
private static final Object[][] demos = new Object[][] {
// START
// Intro
- { "Intro", "About", "About this demo", HelloWorld.class,
- Boolean.FALSE },
+ { "Intro", "About", "About this demo", Button.class, Boolean.FALSE },
// Windowing
- { "Intro", "Windowing", "About windowing", HelloWorld.class,
+ { "Intro", "Windowing", "About windowing", Button.class,
Boolean.FALSE },
// Basic: Labels
- { "Basic", "Labels", "Some variations of Labels", HelloWorld.class,
+ { "Basic", "Labels", "Some variations of Labels", Button.class,
Boolean.FALSE },
// Basic: Buttons
{ "Basic", "Buttons and links",
- "Some variations of Buttons and Links", HelloWorld.class,
+ "Some variations of Buttons and Links", Button.class,
Boolean.FALSE },
// Basic: Fields
{ "Basic", "User input", "TextFields, DateFields, and such",
- HelloWorld.class, Boolean.FALSE },
+ Button.class, Boolean.FALSE },
// Basic: Selects
{ "Basic", "Choices, choices", "Some variations of simple selects",
- HelloWorld.class, Boolean.FALSE },
+ Button.class, Boolean.FALSE },
// Organizing: ComboBox
{ "Organizing", "ComboBox", "ComboBox - the swiss army select",
- HelloWorld.class, Boolean.FALSE },
+ Button.class, Boolean.FALSE },
// Organizing: Table
{ "Organizing", "Table", "A dynamic Table with bells and whistles",
- HelloWorld.class, Boolean.FALSE },
+ Button.class, Boolean.FALSE },
// Organizing: Tree
{ "Organizing", "Tree", "Some variations of Buttons and Links",
- HelloWorld.class, Boolean.FALSE },
+ Button.class, Boolean.FALSE },
// Misc: Notifications
{ "Misc", "Notifications", "Notifications can improve usability",
- HelloWorld.class, Boolean.FALSE },
+ NotificationExample.class, Boolean.FALSE },
// Misc: Caching
{ "Misc", "Client caching", "A simple demo of client-side caching",
- HelloWorld.class, Boolean.FALSE },
+ ClientCachingExample.class, Boolean.FALSE },
// Misc: Embedded
{ "Misc", "Embedding",
"You can embed resources - another site in this case",
- HelloWorld.class, Boolean.FALSE },
+ EmbeddedBrowserExample.class, Boolean.FALSE },
// END
};
HashMap sectionIds = new HashMap();
HierarchicalContainer container = createContainer();
+ Object rootId = container.addItem();
+ Item item = container.getItem(rootId);
+ Property p = item.getItemProperty(PROPERTY_ID_NAME);
+ p.setValue("All");
for (int i = 0; i < demos.length; i++) {
Object[] demo = demos[i];
String section = (String) demo[0];
} else {
sectionId = container.addItem();
sectionIds.put(section, sectionId);
- Item item = container.getItem(sectionId);
- Property p = item.getItemProperty(PROPERTY_ID_NAME);
+ container.setParent(sectionId, rootId);
+ item = container.getItem(sectionId);
+ p = item.getItemProperty(PROPERTY_ID_NAME);
p.setValue(section);
}
Object id = container.addItem();
tree.setItemCaptionPropertyId(PROPERTY_ID_NAME);
tree.addListener(this);
tree.setImmediate(true);
- for (Iterator it = sectionIds.values().iterator(); it.hasNext();) {
- // expand all sections
- tree.expandItemsRecursively(it.next());
- }
+ tree.expandItemsRecursively(rootId);
+
split.addComponent(tree);
SplitPanel split2 = new SplitPanel();
ExpandLayout exp = new ExpandLayout();
exp.setMargin(true);
split2.addComponent(exp);
- exp.addComponent(new Label("Short desc + open in window (+native)"));
+ OrderedLayout wbLayout = new OrderedLayout(
+ OrderedLayout.ORIENTATION_HORIZONTAL);
- TabSheet ts = new TabSheet();
+ wbLayout.addComponent(new Button("Open in popup window",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ Component component = (Component) ts
+ .getComponentIterator().next();
+ String caption = ts.getTabCaption(component);
+ try {
+ component = (Component) component.getClass()
+ .newInstance();
+ } catch (Exception e) {
+ // Could not create
+ return;
+ }
+ Window w = new Window(caption);
+ if (Layout.class.isAssignableFrom(component.getClass())) {
+ w.setLayout((Layout) component);
+ } else {
+ w.getLayout().setSizeFull();
+ w.addComponent(component);
+ }
+ getMainWindow().addWindow(w);
+ }
+ }));
+ wbLayout.addComponent(new Button("Open in native window",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ Component component = (Component) ts
+ .getComponentIterator().next();
+ String caption = ts.getTabCaption(component);
+ Window w = getWindow(caption);
+ if (w == null) {
+ try {
+ component = (Component) component.getClass()
+ .newInstance();
+ } catch (Exception e) {
+ // Could not create
+ return;
+ }
+ w = new Window(caption);
+ w.setName(caption);
+ if (Layout.class.isAssignableFrom(component
+ .getClass())) {
+ w.setLayout((Layout) component);
+ } else {
+ w.getLayout().setSizeFull();
+ w.addComponent(component);
+ }
+ addWindow(w);
+ }
+ getMainWindow().open(new ExternalResource(w.getURL()),
+ caption);
+ }
+ }));
+
+ exp.addComponent(wbLayout);
+ exp.setComponentAlignment(wbLayout, exp.ALIGNMENT_RIGHT,
+ exp.ALIGNMENT_TOP);
+
+ ts = new TabSheet();
ts.setSizeFull();
- ts.addTab(new Label("asd"), "Demo", null);
- ts.addTab(new Label("asd"), "Source", null);
+ ts.addTab(new Label(
+ "Choose demo (Only Notification and CliensSideCaching yet"),
+ "Demo", null);
exp.addComponent(ts);
exp.expand(ts);
exp.setComponentAlignment(status, exp.ALIGNMENT_RIGHT,
exp.ALIGNMENT_VERTICAL_CENTER);
+ // select initial section ("All")
+ tree.setValue(rootId);
}
private void initItem(Item item, Object[] data) {
c.addContainerProperty(PROPERTY_ID_CATEGORY, String.class, null);
c.addContainerProperty(PROPERTY_ID_NAME, String.class, "");
c.addContainerProperty(PROPERTY_ID_DESC, String.class, "");
- c
- .addContainerProperty(PROPERTY_ID_CLASS, Class.class,
- HelloWorld.class);
+ c.addContainerProperty(PROPERTY_ID_CLASS, Class.class, Button.class);
c
.addContainerProperty(PROPERTY_ID_VIEWED, Boolean.class,
Boolean.FALSE);
Object id = tree.getValue();
Item item = tree.getItem(id);
String section;
- if (tree.hasChildren(id)) {
+ if (tree.isRoot(id)) {
+ section = ""; // show all sections
+ } else if (tree.hasChildren(id)) {
section = (String) item.getItemProperty(PROPERTY_ID_NAME)
.getValue();
} else {
IndexedContainer c = (IndexedContainer) table
.getContainerDataSource();
c.removeAllContainerFilters();
- c.addContainerFilter(PROPERTY_ID_CATEGORY, section, false, true);
+ if (section != null) {
+ c
+ .addContainerFilter(PROPERTY_ID_CATEGORY, section,
+ false, true);
+ }
if (!tree.hasChildren(id)) {
table.setValue(id);
}
table.removeListener(this);
tree.setValue(table.getValue());
table.addListener(this);
+ Item item = table.getItem(table.getValue());
+ Class c = (Class) item.getItemProperty(PROPERTY_ID_CLASS)
+ .getValue();
+ Component component = getComponent(c);
+ if (component != null) {
+ String caption = (String) item.getItemProperty(
+ PROPERTY_ID_NAME).getValue();
+ ts.removeAllComponents();
+ ts.addTab(component, caption, null);
+ }
}
}
}
+ private Component getComponent(Class componentClass) {
+ if (!components.containsKey(componentClass)) {
+ try {
+ Component c = (Component) componentClass.newInstance();
+ components.put(componentClass, c);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ return (Component) components.get(componentClass);
+ }
+
+ public class Dummy extends Label {
+ public Dummy() {
+ super("Dummy component");
+ }
+ }
}
--- /dev/null
+package com.itmill.toolkit.demo.featurebrowser;\r
+\r
+import com.itmill.toolkit.terminal.PaintException;\r
+import com.itmill.toolkit.terminal.PaintTarget;\r
+import com.itmill.toolkit.ui.CustomComponent;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.Layout;\r
+import com.itmill.toolkit.ui.OrderedLayout;\r
+import com.itmill.toolkit.ui.TabSheet;\r
+\r
+/**\r
+ * This example is a (simple) demonstration of client-side caching. The content\r
+ * in one tab is intentionally made very slow to produce server-side. When the\r
+ * user changes to this tab for the first time, there will be a 3 second wait\r
+ * before the content shows up, but the second time it shows up immediately\r
+ * since the content has not changed and is cached client-side.\r
+ * \r
+ * @author IT Mill Ltd.\r
+ */\r
+public class ClientCachingExample extends CustomComponent {\r
+\r
+ private static final String msg = "This example is a (simple) demonstration of client-side caching."\r
+ + " The content in one tab is intentionally made very slow to"\r
+ + " 'produce' server-side. When you changes to this tab for the"\r
+ + " first time, there will be a 3 second wait before the content"\r
+ + " shows up, but the second time it shows up immediately since the"\r
+ + " content has not changed and is cached client-side.";\r
+\r
+ public ClientCachingExample() {\r
+\r
+ OrderedLayout main = new OrderedLayout();\r
+ main.setMargin(true);\r
+ setCompositionRoot(main);\r
+\r
+ main.addComponent(new Label(msg));\r
+\r
+ TabSheet ts = new TabSheet();\r
+ main.addComponent(ts);\r
+\r
+ Layout layout = new OrderedLayout();\r
+ layout.setMargin(true);\r
+ Label l = new Label("This is a normal label, quick to render.");\r
+ l.setCaption("A normal label");\r
+ layout.addComponent(l);\r
+\r
+ ts.addTab(layout, "Normal", null);\r
+\r
+ layout = new OrderedLayout();\r
+ layout.setMargin(true);\r
+ l = new Label("Slow label - until cached client side.") {\r
+ public void paintContent(PaintTarget target) throws PaintException {\r
+ try {\r
+ Thread.sleep(3000);\r
+ } catch (Exception e) {\r
+ // IGNORED\r
+ }\r
+ super.paintContent(target);\r
+ }\r
+\r
+ };\r
+ l.setCaption("A slow label");\r
+ layout.addComponent(l);\r
+ ts.addTab(layout, "Slow", null);\r
+\r
+ }\r
+}\r
--- /dev/null
+package com.itmill.toolkit.demo.featurebrowser;
+
+import java.util.Date;
+
+import com.itmill.toolkit.data.Item;
+import com.itmill.toolkit.ui.AbstractSelect;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.NativeSelect;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.RichTextArea;
+import com.itmill.toolkit.ui.TextField;
+import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+import com.itmill.toolkit.ui.Button.ClickListener;
+
+/**
+ * Demonstrates the use of Notifications.
+ *
+ * @author IT Mill Ltd.
+ * @see com.itmill.toolkit.ui.Window
+ */
+public class NotificationExample extends CustomComponent {
+
+ // Dropdown select for notification type, using the native dropdown
+ NativeSelect type;
+ // Textfield for the notification caption
+ TextField caption;
+ // Textfield for the notification content
+ TextField message;
+
+ /**
+ * Default constructor; We're subclassing CustomComponent, so we need to
+ * choose a root component and set it as composition root.
+ */
+ public NotificationExample() {
+ // Main layout
+ OrderedLayout main = new OrderedLayout();
+ main.setMargin(true); // use theme-specific margin
+ setCompositionRoot(main);
+
+ // Create the 'type' dropdown select.
+ type = new NativeSelect("Notification type");
+ main.addComponent(type);
+ // no empty selection allowed
+ type.setNullSelectionAllowed(false);
+ // we want a different caption than the value
+ type.addContainerProperty("caption", String.class, null);
+ type.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
+ type.setItemCaptionPropertyId("caption");
+ // add some content (items) using the Container API
+ Item i = type.addItem(new Integer(
+ Window.Notification.TYPE_HUMANIZED_MESSAGE));
+ i.getItemProperty("caption").setValue("Humanized message");
+ i = type.addItem(new Integer(Window.Notification.TYPE_WARNING_MESSAGE));
+ i.getItemProperty("caption").setValue("Warning message");
+ i = type.addItem(new Integer(Window.Notification.TYPE_ERROR_MESSAGE));
+ i.getItemProperty("caption").setValue("Error message");
+ i = type
+ .addItem(new Integer(Window.Notification.TYPE_TRAY_NOTIFICATION));
+ i.getItemProperty("caption").setValue("Tray notification");
+ // set the initially selected item
+ type.setValue(new Integer(Window.Notification.TYPE_HUMANIZED_MESSAGE));
+
+ // Notification caption
+ caption = new TextField("Caption");
+ main.addComponent(caption);
+ caption.setColumns(20);
+ caption.setValue("Brown Fox!");
+
+ // Notification message
+ message = new RichTextArea();
+ main.addComponent(message);
+ message.setCaption("Message");
+ message.setValue("A quick one jumped over the lazy dog.");
+
+ // Button to show the notification
+ Button b = new Button("Show notification", new ClickListener() {
+ // this is an inline ClickListener
+ public void buttonClick(ClickEvent event) {
+ // show the notification
+ getWindow().showNotification((String) caption.getValue(),
+ (String) message.getValue(),
+ ((Integer) type.getValue()).intValue());
+ getWindow().setCaption(new Date().toString());
+ }
+ });
+ main.addComponent(b);
+ }
+}