Etc, etc.
svn changeset:3132/svn branch:trunk
public class ButtonExample extends CustomComponent implements\r
Button.ClickListener {\r
\r
- Panel status;\r
-\r
public ButtonExample() {\r
\r
OrderedLayout main = new OrderedLayout();\r
Panel basic = new Panel("Basic buttons");\r
basic.setStyleName(Panel.STYLE_LIGHT);\r
horiz.addComponent(basic);\r
- Panel bells = new Panel("+ bells & whistles");\r
+\r
+ Panel bells = new Panel("w/ bells & whistles");\r
bells.setStyleName(Panel.STYLE_LIGHT);\r
horiz.addComponent(bells);\r
- status = new Panel("Clicked");\r
- status.setStyleName(Panel.STYLE_LIGHT);\r
- horiz.addComponent(status);\r
\r
Button b = new Button("Basic button");\r
b.addListener(this);\r
}\r
\r
public void buttonClick(ClickEvent event) {\r
- Button clicked = event.getButton();\r
- String caption = clicked.getCaption();\r
- if (caption == null) {\r
- caption = "<icon>";\r
- }\r
- status.removeAllComponents();\r
- Label l = new Label("Clicked: " + caption + "<br/>" + "Value: "\r
- + clicked.getValue());\r
- l.setContentMode(Label.CONTENT_XHTML);\r
- status.addComponent(l);\r
+ Button b = event.getButton();\r
+ getWindow().showNotification(\r
+ "Clicked"\r
+ + (b instanceof CheckBox ? ", value: "\r
+ + event.getButton().getValue() : ""));\r
\r
}\r
\r
public EmbeddedBrowserExample() {
this(new String[] { DEFAULT_URL,
- "http:// www.itmill.com/index_developers.htm",
+ "http://www.itmill.com/index_developers.htm",
"http://toolkit.itmill.com/demo/doc/api/",
"http://www.itmill.com/manual/index.html" });
}
public class FeatureBrowser extends com.itmill.toolkit.Application implements
Select.ValueChangeListener {
+ // Property IDs
private static final Object PROPERTY_ID_CATEGORY = "Category";
private static final Object PROPERTY_ID_NAME = "Name";
private static final Object PROPERTY_ID_DESC = "Description";
private static final Object PROPERTY_ID_CLASS = "Class";
private static final Object PROPERTY_ID_VIEWED = "Viewed";
+ // Global components
private Tree tree;
private Table table;
private TabSheet ts;
- private HashMap components = new HashMap();
+ // Example "cache"
+ private HashMap exampleInstances = new HashMap();
+ // List of examples
private static final Object[][] demos = new Object[][] {
// Category, Name, Desc, Class, Viewed
// Getting started: Labels
LabelExample.class },
// Getting started: Buttons
{ "Getting started", "Buttons and links",
- "Some variations of Buttons and Links", ButtonExample.class },
+ "Various Buttons and Links", ButtonExample.class },
// Getting started: Fields
{ "Getting started", "Basic value input",
"TextFields, DateFields, and such", ValueInputExample.class },
ComboBoxExample.class },
// Wrangling data: Table
{ "Wrangling data", "Table",
- "A dynamic Table with bells and whistles", Button.class },
+ "A dynamic Table with bells, whistles and actions",
+ Button.class },
// Wrangling data: Tree
- { "Wrangling data", "Tree", "Some variations of Buttons and Links",
+ { "Wrangling data", "Tree", "A hierarchy of things",
TreeExample.class },
// Misc: Notifications
{ "Misc", "Notifications", "Notifications can improve usability",
NotificationExample.class },
// Misc: Caching
- { "Misc", "Client caching", "A simple demo of client-side caching",
+ { "Misc", "Client caching", "Demonstrating of client-side caching",
ClientCachingExample.class },
// Misc: Embedded
{ "Misc", "Embedding",
- "You can embed resources - another site in this case",
+ "Embedding resources - another site in this case",
EmbeddedBrowserExample.class },
// Windowing
{ "Misc", "Windowing", "About windowing", WindowingExample.class },
ExpandLayout exp = new ExpandLayout();
exp.setMargin(true);
split2.addComponent(exp);
+
OrderedLayout wbLayout = new OrderedLayout(
OrderedLayout.ORIENTATION_HORIZONTAL);
-
- 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);
+ Button b = new Button("Open in sub-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);
+ w.setWidth(640);
+ if (Layout.class.isAssignableFrom(component.getClass())) {
+ w.setLayout((Layout) component);
+ } else {
+ w.getLayout().setSizeFull();
+ w.addComponent(component);
+ }
+ getMainWindow().addWindow(w);
+ }
+ });
+ b.setStyleName(Button.STYLE_LINK);
+ wbLayout.addComponent(b);
+ b = 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;
}
- }));
- 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);
+ 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);
+ }
+ });
+ b.setStyleName(Button.STYLE_LINK);
+ wbLayout.addComponent(b);
exp.addComponent(wbLayout);
exp.setComponentAlignment(wbLayout, ExpandLayout.ALIGNMENT_RIGHT,
ts = new TabSheet();
ts.setSizeFull();
- ts.addTab(new Label(
- "Choose demo (Only Notification and CliensSideCaching yet"),
- "Demo", null);
+ ts.addTab(new Label(""), "Choose example", null);
exp.addComponent(ts);
exp.expand(ts);
}
private Component getComponent(Class componentClass) {
- if (!components.containsKey(componentClass)) {
+ if (!exampleInstances.containsKey(componentClass)) {
try {
Component c = (Component) componentClass.newInstance();
- components.put(componentClass, c);
+ exampleInstances.put(componentClass, c);
} catch (Exception e) {
return null;
}
}
- return (Component) components.get(componentClass);
+ return (Component) exampleInstances.get(componentClass);
}
}
package com.itmill.toolkit.demo.featurebrowser;\r
\r
+import com.itmill.toolkit.data.Property.ValueChangeEvent;\r
import com.itmill.toolkit.ui.AbstractSelect;\r
import com.itmill.toolkit.ui.ComboBox;\r
import com.itmill.toolkit.ui.CustomComponent;\r
-import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.Field;\r
import com.itmill.toolkit.ui.ListSelect;\r
import com.itmill.toolkit.ui.NativeSelect;\r
import com.itmill.toolkit.ui.OptionGroup;\r
*/\r
public class SelectExample extends CustomComponent {\r
\r
- // used to show the last entered value in the textfields\r
- Label selectedValue;\r
+ // listener that shows a value change notification\r
+ private Field.ValueChangeListener listener = new Field.ValueChangeListener() {\r
+ public void valueChange(ValueChangeEvent event) {\r
+ getWindow().showNotification("" + event.getProperty().getValue());\r
+ }\r
+ };\r
\r
public SelectExample() {\r
OrderedLayout main = new OrderedLayout();\r
Panel multi = new Panel("Multi selects");\r
multi.setStyleName(Panel.STYLE_LIGHT);\r
horiz.addComponent(multi);\r
- // "last selected" -label\r
- selectedValue = new Label();\r
\r
+ // radio button group\r
AbstractSelect sel = new OptionGroup("OptionGroup");\r
initSelect(sel);\r
single.addComponent(sel);\r
-\r
+ // checkbox group\r
sel = new OptionGroup("OptionGroup");\r
- sel.setMultiSelect(true);\r
+ sel.setMultiSelect(true); // TODO: throws if set after listener - why?\r
initSelect(sel);\r
multi.addComponent(sel);\r
-\r
+ // single-select list\r
sel = new ListSelect("ListSelect");\r
+ ((ListSelect) sel).setColumns(15);\r
initSelect(sel);\r
single.addComponent(sel);\r
-\r
+ // multi-select list\r
sel = new ListSelect("ListSelect");\r
+ ((ListSelect) sel).setColumns(15);\r
sel.setMultiSelect(true);\r
initSelect(sel);\r
multi.addComponent(sel);\r
-\r
+ // native-style dropdows\r
sel = new NativeSelect("NativeSelect");\r
+ ((NativeSelect) sel).setColumns(15);\r
initSelect(sel);\r
single.addComponent(sel);\r
-\r
+ // combobox\r
sel = new ComboBox("ComboBox");\r
+ ((ComboBox) sel).setColumns(15);\r
initSelect(sel);\r
single.addComponent(sel);\r
-\r
+ // "twin column" select\r
sel = new TwinColSelect("TwinColSelect");\r
+ ((TwinColSelect) sel).setColumns(15);\r
initSelect(sel);\r
multi.addComponent(sel);\r
}\r
\r
- private static void initSelect(AbstractSelect sel) {\r
+ /*\r
+ * Initialize select with some values, make immediate and add listener.\r
+ */\r
+ private void initSelect(AbstractSelect sel) {\r
for (int i = 1; i <= 5; i++) {\r
sel.addItem("Item " + i);\r
}\r
- sel.setValue(null);\r
+ // select one item\r
+ sel.select("Item 1");\r
+\r
+ // make immediate, add listener\r
+ sel.setImmediate(true);\r
+ sel.addListener(listener);\r
}\r
\r
}\r
import com.itmill.toolkit.ui.DateField;\r
import com.itmill.toolkit.ui.Field;\r
import com.itmill.toolkit.ui.InlineDateField;\r
-import com.itmill.toolkit.ui.Label;\r
import com.itmill.toolkit.ui.OrderedLayout;\r
import com.itmill.toolkit.ui.Panel;\r
import com.itmill.toolkit.ui.Slider;\r
import com.itmill.toolkit.ui.TextField;\r
+import com.itmill.toolkit.ui.Window.Notification;\r
\r
/**\r
* Shows some basic fields for value input; TextField, DateField, Slider...\r
*/\r
public class ValueInputExample extends CustomComponent {\r
\r
- // used to show the last entered value in the textfields\r
- Label textfieldValue;\r
-\r
public ValueInputExample() {\r
OrderedLayout main = new OrderedLayout();\r
main.setMargin(true);\r
setCompositionRoot(main);\r
\r
+ // listener that shows a value change notification\r
+ Field.ValueChangeListener listener = new Field.ValueChangeListener() {\r
+ public void valueChange(ValueChangeEvent event) {\r
+ getWindow().showNotification("Received",\r
+ "<pre>" + event.getProperty().getValue() + "</pre>",\r
+ Notification.TYPE_WARNING_MESSAGE);\r
+ }\r
+ };\r
+\r
// TextField\r
OrderedLayout horiz = new OrderedLayout(\r
OrderedLayout.ORIENTATION_HORIZONTAL);\r
Panel left = new Panel("TextField");\r
left.setStyleName(Panel.STYLE_LIGHT);\r
horiz.addComponent(left);\r
- Panel right = new Panel("Last input");\r
+ Panel right = new Panel("multiline");\r
right.setStyleName(Panel.STYLE_LIGHT);\r
horiz.addComponent(right);\r
- // "last entered" -label\r
- textfieldValue = new Label();\r
- textfieldValue.setContentMode(Label.CONTENT_PREFORMATTED);\r
- right.addComponent(textfieldValue);\r
- // listener that will update the last entered value for the TextFields\r
- Field.ValueChangeListener listener = new Field.ValueChangeListener() {\r
- public void valueChange(ValueChangeEvent event) {\r
- textfieldValue.setValue(event.getProperty().getValue());\r
- }\r
- };\r
// basic TextField\r
TextField tf = new TextField("Basic");\r
tf.setColumns(15);\r
tf.setRows(5);\r
tf.setImmediate(true);\r
tf.addListener(listener);\r
- left.addComponent(tf);\r
+ right.addComponent(tf);\r
\r
// DateFields\r
horiz = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);\r
left = new Panel("DateField");\r
left.setStyleName(Panel.STYLE_LIGHT);\r
horiz.addComponent(left);\r
- right = new Panel("Inline ");\r
+ right = new Panel("inline");\r
right.setStyleName(Panel.STYLE_LIGHT);\r
horiz.addComponent(right);\r
// default\r
- DateField df = new DateField("Default (day) resolution");\r
+ DateField df = new DateField("Day resolution");\r
+ df.addListener(listener);\r
+ df.setImmediate(true);\r
+ df.setResolution(DateField.RESOLUTION_DAY);\r
left.addComponent(df);\r
// minute\r
df = new DateField("Minute resolution");\r
+ df.addListener(listener);\r
+ df.setImmediate(true);\r
df.setResolution(DateField.RESOLUTION_MIN);\r
left.addComponent(df);\r
// year\r
df = new DateField("Year resolution");\r
+ df.addListener(listener);\r
+ df.setImmediate(true);\r
df.setResolution(DateField.RESOLUTION_YEAR);\r
left.addComponent(df);\r
// msec\r
df = new DateField("Millisecond resolution");\r
+ df.addListener(listener);\r
+ df.setImmediate(true);\r
df.setResolution(DateField.RESOLUTION_MSEC);\r
left.addComponent(df);\r
// Inline\r
df = new InlineDateField();\r
+ df.addListener(listener);\r
+ df.setImmediate(true);\r
right.addComponent(df);\r
\r
// Slider\r
public void buttonClick(ClickEvent event) {\r
Window w = new Window("Subwindow");\r
getApplication().addWindow(w);\r
- Label l = new Label(w.getName());\r
- l\r
- .setCaption("Each opened window has a separate value:");\r
+ Label l = new Label("Each opened window has its own"\r
+ + " name, and is accessed trough its own uri.");\r
+ l.setCaption("Window " + w.getName());\r
w.addComponent(l);\r
getApplication().getMainWindow().open(\r
new ExternalResource(w.getURL()), "_new");\r