]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updated TabSheet Book example. For #2914.
authorMarko Grönroos <magi@iki.fi>
Thu, 28 May 2009 08:41:59 +0000 (08:41 +0000)
committerMarko Grönroos <magi@iki.fi>
Thu, 28 May 2009 08:41:59 +0000 (08:41 +0000)
svn changeset:8049/svn branch:6.0

src/com/vaadin/tests/book/BookTestApplication.java
src/com/vaadin/tests/book/TabSheetExample.java

index 9d116edbcdbbc94b178a34c749fa7419f2c7f925..a4c423e82f3dfdabb0491b9afd8a0a3176bffb39 100644 (file)
@@ -1022,90 +1022,92 @@ public class BookTestApplication extends com.vaadin.Application {
        }
 
        void example_TabSheet(Window main, String param) {
-        if (param.equals("simple")) {
-            // Create an empty tab sheet.
-            TabSheet tabsheet = new TabSheet();
-            
-            // Create a component to put in a tab and put
-            // some content in it.
-            VerticalLayout myTab = new VerticalLayout();
-            myTab.addComponent(new Label("Hello, I am a Tab!"));
-            
-            // Add the component to the tab sheet as a new tab.
-            tabsheet.addTab(myTab);
-            
-            // Get the Tab holding the component and set its caption.
-            tabsheet.getTab(myTab).setCaption("My Tab");
-
-        } else if (param.equals("icon")) {
-                       final TabSheet tabsheet = new TabSheet();
-
-                       tabsheet.addTab(new Label("Contents of the first tab"),
-                                       "First Tab", new ClassResource("images/Mercury_small.png",
-                                                       main.getApplication()));
-                       tabsheet.addTab(new Label("Contents of the second tab"),
-                                       "Second Tab", new ClassResource("images/Venus_small.png",
-                                                       this));
-                       tabsheet.addTab(new Label("Contents of the third tab"),
-                                       "Third tab", new ClassResource("images/Earth_small.png",
-                                                       this));
-
-                       main.addComponent(tabsheet);
-                       // main.addComponent(new Embedded("Emb", new ClassResource
-                       // ("images/Mercury_small.png", this)));
-               } else if (param.equals("expanding")) {
-                       // Create the layout
-                       VerticalLayout expanding = new VerticalLayout();
-
-                       // It is important to set the expanding layout as the root layout
-                       // of the containing window, in this case the main window, and not
-                       // use addComponent(), which would place the layout inside the
-                       // default root layout.
-                       main.setLayout(expanding);
-
-                       // Create a tab sheet that fills the expanding layout
-                       final TabSheet tabsheet = new TabSheet();
-                       tabsheet.addTab(new Label("Contents of the first tab"),
-                                       "First Tab", null);
-                       tabsheet.addTab(new Label("Contents of the second tab"),
-                                       "Second Tab", null);
-                       tabsheet.addTab(new Label("Contents of the third tab"),
-                                       "Third tab", null);
-
-                       // Set the tabsheet to scale to full size inside its container
-                       tabsheet.setWidth(100, Sizeable.UNITS_PERCENTAGE);
-                       tabsheet.setHeight(100, Sizeable.UNITS_PERCENTAGE);
-
-                       // Add the tab sheet to the layout as usual
-                       expanding.addComponent(tabsheet);
-
-                       // Set the tab sheet to be the expanding component
-                       expanding.setExpandRatio(tabsheet, 1);
-               } else if (param.equals("ordered")) {
-                       // Create the layout
-                       VerticalLayout layout = new VerticalLayout();
-
-                       // It is important to set the expanding layout as the root layout
-                       // of the containing window, in this case the main window, and not
-                       // use addComponent(), which would place the layout inside the
-                       // default root layout.
-                       main.setLayout(layout);
-
-                       // Create a tab sheet that fills the expanding layout
-                       final TabSheet tabsheet = new TabSheet();
-                       tabsheet.addTab(new Label("Contents of the first tab"),
-                                       "First Tab", null);
-                       tabsheet.addTab(new Label("Contents of the second tab"),
-                                       "Second Tab", null);
-                       tabsheet.addTab(new Label("Contents of the third tab"),
-                                       "Third tab", null);
-
-                       // Set the tabsheet to scale to full size inside its container
-                       tabsheet.setWidth(100, Sizeable.UNITS_PERCENTAGE);
-                       // tabsheet().setHeight(100, Sizeable.UNITS_PERCENTAGE);
-
-                       // Add the tab sheet to the layout as usual
-                       layout.addComponent(tabsheet);
+               if (param != null) {
+               if (param.equals("simple")) {
+                   // Create an empty tab sheet.
+                   TabSheet tabsheet = new TabSheet();
+                   
+                   // Create a component to put in a tab and put
+                   // some content in it.
+                   VerticalLayout myTab = new VerticalLayout();
+                   myTab.addComponent(new Label("Hello, I am a Tab!"));
+                   
+                   // Add the component to the tab sheet as a new tab.
+                   tabsheet.addTab(myTab);
+                   
+                   // Get the Tab holding the component and set its caption.
+                   tabsheet.getTab(myTab).setCaption("My Tab");
+
+               } else if (param.equals("icon")) {
+                               final TabSheet tabsheet = new TabSheet();
+       
+                               tabsheet.addTab(new Label("Contents of the first tab"),
+                                               "First Tab", new ClassResource("images/Mercury_small.png",
+                                                               main.getApplication()));
+                               tabsheet.addTab(new Label("Contents of the second tab"),
+                                               "Second Tab", new ClassResource("images/Venus_small.png",
+                                                               this));
+                               tabsheet.addTab(new Label("Contents of the third tab"),
+                                               "Third tab", new ClassResource("images/Earth_small.png",
+                                                               this));
+       
+                               main.addComponent(tabsheet);
+                               // main.addComponent(new Embedded("Emb", new ClassResource
+                               // ("images/Mercury_small.png", this)));
+                       } else if (param.equals("expanding")) {
+                               // Create the layout
+                               VerticalLayout layout = new VerticalLayout();
+       
+                               // It is important to set the expanding layout as the root layout
+                               // of the containing window, in this case the main window, and not
+                               // use addComponent(), which would place the layout inside the
+                               // default root layout.
+                               main.setLayout(layout);
+       
+                               // Create a tab sheet that fills the expanding layout
+                               final TabSheet tabsheet = new TabSheet();
+                               tabsheet.addTab(new Label("Contents of the first tab"),
+                                               "First Tab", null);
+                               tabsheet.addTab(new Label("Contents of the second tab"),
+                                               "Second Tab", null);
+                               tabsheet.addTab(new Label("Contents of the third tab"),
+                                               "Third tab", null);
+       
+                               // Set the tabsheet to scale to full size inside its container
+                               tabsheet.setWidth(100, Sizeable.UNITS_PERCENTAGE);
+                               tabsheet.setHeight(100, Sizeable.UNITS_PERCENTAGE);
+       
+                               // Add the tab sheet to the layout as usual
+                               layout.addComponent(tabsheet);
+       
+                               // Set the tab sheet to be the expanding component
+                               layout.setExpandRatio(tabsheet, 1);
+                       } else if (param.equals("ordered")) {
+                               // Create the layout
+                               VerticalLayout layout = new VerticalLayout();
+       
+                               // It is important to set the expanding layout as the root layout
+                               // of the containing window, in this case the main window, and not
+                               // use addComponent(), which would place the layout inside the
+                               // default root layout.
+                               main.setLayout(layout);
+       
+                               // Create a tab sheet that fills the expanding layout
+                               final TabSheet tabsheet = new TabSheet();
+                               tabsheet.addTab(new Label("Contents of the first tab"),
+                                               "First Tab", null);
+                               tabsheet.addTab(new Label("Contents of the second tab"),
+                                               "Second Tab", null);
+                               tabsheet.addTab(new Label("Contents of the third tab"),
+                                               "Third tab", null);
+       
+                               // Set the tabsheet to scale to full size inside its container
+                               tabsheet.setWidth(100, Sizeable.UNITS_PERCENTAGE);
+                               // tabsheet().setHeight(100, Sizeable.UNITS_PERCENTAGE);
+       
+                               // Add the tab sheet to the layout as usual
+                               layout.addComponent(tabsheet);
+                       }
                } else {
                        main.addComponent(new TabSheetExample());
                }
index cd70143ce6339865beb64ad77890a2e3c1a6e900..9bc3c798238c51a8bed94f15a0dbfe1bc302407a 100644 (file)
@@ -21,43 +21,49 @@ public class TabSheetExample extends CustomComponent implements
     TabSheetExample() {
         setCompositionRoot(tabsheet);
 
-        /* Listen for changes in tab selection. */
+        // Listen for changes in tab selection.
         tabsheet.addListener(this);
 
-        /* First tab contains a button, for which we listen button click events. */
+        // First tab contains a button, for which we
+        // listen button click events.
         tab1.addListener(this);
+        
+        // This will cause a selectedTabChange() call.
         tabsheet.addTab(tab1, "First Tab", null);
 
-        /* A tab that is initially invisible. */
-        tab2.setVisible(false);
+        // A tab that is initially invisible.
         tabsheet.addTab(tab2, "Second Tab", null);
+        tabsheet.getTab(tab2).setVisible(false);
 
-        /* A tab that is initially disabled. */
-        tab3.setEnabled(false);
+        // A tab that is initially disabled.
         tabsheet.addTab(tab3, "Third tab", null);
+        tabsheet.getTab(tab3).setEnabled(false);
     }
 
     public void buttonClick(ClickEvent event) {
-        /* Enable the invisible and disabled tabs. */
-        tab2.setVisible(true);
-        tab3.setEnabled(true);
+        // Enable the invisible and disabled tabs.
+       tabsheet.getTab(tab2).setVisible(true);
+       tabsheet.getTab(tab3).setEnabled(true);
 
-        /* Change selection automatically to second tab. */
+        // Change selection automatically to second tab.
         tabsheet.setSelectedTab(tab2);
     }
 
     public void selectedTabChange(SelectedTabChangeEvent event) {
-        /*
-         * Cast to a TabSheet. This isn't really necessary in this example, as
-         * we have only one TabSheet component, but would be useful if there
-         * were multiple TabSheets.
-         */
+        // Cast to a TabSheet. This isn't really necessary in
+       // this example, as we have only one TabSheet component,
+       // but would be useful if there were multiple TabSheets.
         final TabSheet source = (TabSheet) event.getSource();
+
         if (source == tabsheet) {
-            /* If the first tab was selected. */
+            // If the first tab was selected.
             if (source.getSelectedTab() == tab1) {
-                tab2.setVisible(false);
-                tab3.setEnabled(false);
+               // The 2. and 3. tabs may not have been set yet.
+               if (tabsheet.getTab(tab2) != null
+                       && tabsheet.getTab(tab3) != null) {
+                       tabsheet.getTab(tab2).setVisible(false);
+                       tabsheet.getTab(tab3).setEnabled(false);
+               }
             }
         }
     }