]> source.dussan.org Git - vaadin-framework.git/commitdiff
Status labels -> Notifications.
authorMarc Englund <marc.englund@itmill.com>
Tue, 4 Dec 2007 07:23:37 +0000 (07:23 +0000)
committerMarc Englund <marc.englund@itmill.com>
Tue, 4 Dec 2007 07:23:37 +0000 (07:23 +0000)
Etc, etc.

svn changeset:3132/svn branch:trunk

src/com/itmill/toolkit/demo/featurebrowser/ButtonExample.java
src/com/itmill/toolkit/demo/featurebrowser/EmbeddedBrowserExample.java
src/com/itmill/toolkit/demo/featurebrowser/FeatureBrowser.java
src/com/itmill/toolkit/demo/featurebrowser/SelectExample.java
src/com/itmill/toolkit/demo/featurebrowser/ValueInputExample.java
src/com/itmill/toolkit/demo/featurebrowser/WindowingExample.java

index 2fdcb135ca4c396c1c2bfa42f2cdf06a3900fa66..b4406da7b4f7962ebbb94deebbf8a154c948cf32 100644 (file)
@@ -19,8 +19,6 @@ import com.itmill.toolkit.ui.Button.ClickEvent;
 public class ButtonExample extends CustomComponent implements\r
         Button.ClickListener {\r
 \r
-    Panel status;\r
-\r
     public ButtonExample() {\r
 \r
         OrderedLayout main = new OrderedLayout();\r
@@ -33,12 +31,10 @@ public class ButtonExample extends CustomComponent implements
         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
@@ -127,16 +123,11 @@ public class ButtonExample extends CustomComponent implements
     }\r
 \r
     public void buttonClick(ClickEvent event) {\r
-        Button clicked = event.getButton();\r
-        String caption = clicked.getCaption();\r
-        if (caption == null) {\r
-            caption = "&lt;icon&gt;";\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
index 7bebaf38c38a7ab605d314aeb7b91967fa66150d..5ff1a9d79e7cb76b1fbed10d0f9944fab79332cf 100644 (file)
@@ -24,7 +24,7 @@ public class EmbeddedBrowserExample extends ExpandLayout implements
 
     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" });
     }
index 3b27ebc70b0259126c6a3dfb33d98b418f69a7c6..5999f9445923511c713b08af05a0b6b559f356c3 100644 (file)
@@ -33,18 +33,22 @@ import com.itmill.toolkit.ui.Button.ClickEvent;
 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
@@ -52,7 +56,7 @@ public class FeatureBrowser extends com.itmill.toolkit.Application implements
                     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 },
@@ -67,19 +71,20 @@ public class FeatureBrowser extends com.itmill.toolkit.Application implements
                     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 },
@@ -164,62 +169,62 @@ public class FeatureBrowser extends com.itmill.toolkit.Application implements
         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,
@@ -227,9 +232,7 @@ public class FeatureBrowser extends com.itmill.toolkit.Application implements
 
         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);
 
@@ -323,15 +326,15 @@ public class FeatureBrowser extends com.itmill.toolkit.Application implements
     }
 
     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);
     }
 
 }
index 4ad91a9a28c4143b2141c4f570b638db766346ce..46baf23fd7195e0c85b5751044fa03877944ad26 100644 (file)
@@ -1,9 +1,10 @@
 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
@@ -18,8 +19,12 @@ import com.itmill.toolkit.ui.TwinColSelect;
  */\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
@@ -35,45 +40,57 @@ public class SelectExample extends CustomComponent {
         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
index e0c21dd77847b5cec6bdb0c957847e43e1a970cf..cc07d4c0d59c1954e481582f27c1539ae6cd96a8 100644 (file)
@@ -5,11 +5,11 @@ import com.itmill.toolkit.ui.CustomComponent;
 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
@@ -18,14 +18,20 @@ import com.itmill.toolkit.ui.TextField;
  */\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
@@ -33,19 +39,9 @@ public class ValueInputExample extends CustomComponent {
         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
@@ -58,7 +54,7 @@ public class ValueInputExample extends CustomComponent {
         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
@@ -66,26 +62,37 @@ public class ValueInputExample extends CustomComponent {
         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
index c7ab103ad41a06341de3a1f19086ccd849f6276e..8ae6021db128210d817ba3e20dd6634d7fec1973 100644 (file)
@@ -88,9 +88,9 @@ public class WindowingExample extends CustomComponent {
                     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