]> source.dussan.org Git - vaadin-framework.git/commitdiff
Sampler search and navigation toggle.
authorMarc Englund <marc.englund@itmill.com>
Fri, 17 Oct 2008 12:43:04 +0000 (12:43 +0000)
committerMarc Englund <marc.englund@itmill.com>
Fri, 17 Oct 2008 12:43:04 +0000 (12:43 +0000)
svn changeset:5657/svn branch:trunk

src/com/itmill/toolkit/demo/sampler/FeatureView.java
src/com/itmill/toolkit/demo/sampler/SamplerApplication.java

index 9aeb4aca86a40b5ac72e76d1379767ca4e5753c8..051bebacf2c6ba3dbbe4083b5f818a1bf7b3508d 100644 (file)
@@ -1,7 +1,10 @@
 package com.itmill.toolkit.demo.sampler;
 
+import java.util.HashMap;
+
 import com.itmill.toolkit.terminal.ExternalResource;
 import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.Component;
 import com.itmill.toolkit.ui.CustomLayout;
 import com.itmill.toolkit.ui.Label;
 import com.itmill.toolkit.ui.Link;
@@ -18,6 +21,8 @@ public class FeatureView extends CustomLayout {
     private Label sourceCode;
     private Button showCode;
 
+    private HashMap exampleCache = new HashMap();
+
     private Feature currentFeature;
 
     public FeatureView() {
@@ -55,7 +60,7 @@ public class FeatureView extends CustomLayout {
 
             addComponent(controls, "feature-controls");
 
-            addComponent(feature.getExample(), "feature-example");
+            addComponent(getExampleFor(feature), "feature-example");
 
             Label l = new Label(feature.getName());
             addComponent(l, "feature-name");
@@ -105,4 +110,14 @@ public class FeatureView extends CustomLayout {
 
     }
 
+    private Component getExampleFor(Feature f) {
+
+        Component ex = (Component) exampleCache.get(f);
+        if (ex == null) {
+            ex = f.getExample();
+            exampleCache.put(f, ex);
+        }
+        return ex;
+    }
+
 }
index 4622ec1743ba42fd6d9664b87ec21513f3716ca9..54a091c100fb3319561d1ea688291823c78a3000 100644 (file)
@@ -22,6 +22,7 @@ import com.itmill.toolkit.terminal.ExternalResource;
 import com.itmill.toolkit.terminal.Resource;
 import com.itmill.toolkit.terminal.ThemeResource;
 import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.ComboBox;
 import com.itmill.toolkit.ui.Component;
 import com.itmill.toolkit.ui.CustomComponent;
 import com.itmill.toolkit.ui.Embedded;
@@ -40,48 +41,22 @@ public class SamplerApplication extends Application {
     private static final FeatureSet features = new FeatureSet("All",
             new Feature[] {
             // Main sets
+
                     new FeatureSet("Patterns", new Feature[] {
                     // Patterns
-                            new DummyFeature(), //
-                            new DummyFeature2(), //
-
-                            new FeatureSet("c", new Feature[] {
-                            // some group of patterns
-                                    new DummyFeature(), //
-                                    new DummyFeature2(), //
-                            }),
 
-                            new FeatureSet("d", new Feature[] {
-                            // another group of patterns
-                                    new DummyFeature(), //
-                                    new DummyFeature2(), //
                             }),
 
-                    }),
-
                     new FeatureSet("Components", new Feature[] {
-                    // Patterns
-                            new FeatureSet("ΓΆΓΆ", new Feature[] {
-                            // some group of patterns
-                                    new DummyFeature(), //
-                                    new DummyFeature2(), //
+                    // Components
+
                             }),
 
+                    new FeatureSet("Unsorted", new Feature[] {
+                    // Patterns
                             new DummyFeature(), //
                             new DummyFeature2(), //
 
-                            new FeatureSet("c", new Feature[] {
-                            // some group of patterns
-                                    new DummyFeature(), //
-                                    new DummyFeature2(), //
-                            }),
-
-                            new FeatureSet("d", new Feature[] {
-                            // another group of patterns
-                                    new DummyFeature(), //
-                                    new DummyFeature2(), //
-                            }),
-
                     }),
 
             });
@@ -186,6 +161,9 @@ public class SamplerApplication extends Application {
 
         private MainArea mainArea = new MainArea();
 
+        private SplitPanel mainSplit;
+        private Tree navigationTree;
+
         SamplerWindow() {
             // Main top/expanded-bottom layout
             ExpandLayout mainExpand = new ExpandLayout();
@@ -220,19 +198,29 @@ public class SamplerApplication extends Application {
             nav.setComponentAlignment(b, ExpandLayout.ALIGNMENT_LEFT,
                     ExpandLayout.ALIGNMENT_VERTICAL_CENTER);
 
+            Component search = createSearch();
+            nav.addComponent(search);
+            nav.setComponentAlignment(search, ExpandLayout.ALIGNMENT_LEFT,
+                    ExpandLayout.ALIGNMENT_VERTICAL_CENTER);
+
             // Main left/right split; hidden menu tree
-            SplitPanel split = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL);
-            split.setSizeFull();
-            split.setSplitPosition(0, SplitPanel.UNITS_PIXELS);
-            mainExpand.addComponent(split);
-            mainExpand.expand(split);
+            mainSplit = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL);
+            mainSplit.setSizeFull();
+            mainExpand.addComponent(mainSplit);
+            mainExpand.expand(mainSplit);
 
             // Menu tree, initially hidden
-            Tree tree = createMenuTree();
-            split.addComponent(tree);
+            navigationTree = createMenuTree();
+            mainSplit.addComponent(navigationTree);
 
             // Main Area
-            split.addComponent(mainArea);
+            mainSplit.addComponent(mainArea);
+
+            // Show / hide tree
+            Component treeSwitch = createTreeSwitch();
+            nav.addComponent(treeSwitch);
+            nav.setComponentAlignment(treeSwitch, ExpandLayout.ALIGNMENT_LEFT,
+                    ExpandLayout.ALIGNMENT_VERTICAL_CENTER);
 
             // List/grid/coverflow
             Component mode = createModeSwitch();
@@ -278,6 +266,27 @@ public class SamplerApplication extends Application {
          * SamplerWindow helpers
          */
 
+        private Component createSearch() {
+            ComboBox search = new ComboBox();
+            search.setWidth("120px");
+            search.setNewItemsAllowed(false);
+            search.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
+            search.setNullSelectionAllowed(true);
+            search.setImmediate(true);
+            search.setContainerDataSource(allFeatures);
+            search.addListener(new ComboBox.ValueChangeListener() {
+                public void valueChange(ValueChangeEvent event) {
+                    Feature f = (Feature) event.getProperty().getValue();
+                    if (f != null) {
+                        SamplerWindow.this.setFeature(f);
+                        event.getProperty().setValue(null);
+                    }
+
+                }
+            });
+            return search;
+        }
+
         private Component createLogo() {
             Button logo = new Button("", new Button.ClickListener() {
                 public void buttonClick(ClickEvent event) {
@@ -321,6 +330,31 @@ public class SamplerApplication extends Application {
             return b;
         }
 
+        private Component createTreeSwitch() {
+            ModeSwitch m = new ModeSwitch();
+            m.addMode(1, "", "Hide navigation", new ThemeResource(
+                    "sampler/hidetree.gif"));
+            m.addMode(2, "", "Show navigation", new ThemeResource(
+                    "sampler/showtree.gif"));
+            m.addListener(new ModeSwitch.ModeSwitchListener() {
+                public void componentEvent(Event event) {
+                    if (event instanceof ModeSwitchEvent) {
+                        if (((ModeSwitchEvent) event).getMode().equals(1)) {
+                            mainSplit.setSplitPosition(0);
+                            navigationTree.setVisible(false);
+                            mainSplit.setLocked(true);
+                        } else {
+                            mainSplit.setSplitPosition(20);
+                            mainSplit.setLocked(false);
+                            navigationTree.setVisible(true);
+                        }
+                    }
+                }
+            });
+            m.setMode(1);
+            return m;
+        }
+
         private Component createModeSwitch() {
             ModeSwitch m = new ModeSwitch();
             m.addMode(currentList, "", "View as Icons", new ThemeResource(