]> source.dussan.org Git - vaadin-framework.git/commitdiff
Better window handing for Sampler, so that samples can open subwindows.
authorMarc Englund <marc.englund@itmill.com>
Thu, 19 Feb 2009 09:15:08 +0000 (09:15 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 19 Feb 2009 09:15:08 +0000 (09:15 +0000)
svn changeset:6902/svn branch:trunk

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

index 797b336720c9b203acae8c7b31dc3b43d900aff1..f32e122d51672b508d1493818540951c3015703d 100644 (file)
@@ -14,6 +14,7 @@ import com.itmill.toolkit.ui.Label;
 import com.itmill.toolkit.ui.Link;
 import com.itmill.toolkit.ui.Panel;
 import com.itmill.toolkit.ui.VerticalLayout;
+import com.itmill.toolkit.ui.Window;
 import com.itmill.toolkit.ui.Button.ClickEvent;
 
 public class FeatureView extends HorizontalLayout {
@@ -25,12 +26,14 @@ public class FeatureView extends HorizontalLayout {
 
     private VerticalLayout controls;
 
-    private ActiveLink srcWin;
+    private ActiveLink showSrc;
 
     private HashMap<Feature, Component> exampleCache = new HashMap<Feature, Component>();
 
     private Feature currentFeature;
 
+    private Window srcWindow;
+
     public FeatureView() {
 
         setWidth("100%");
@@ -71,25 +74,41 @@ public class FeatureView extends HorizontalLayout {
 
         controlButtons.addComponent(new Label("|"));
 
-        srcWin = new ActiveLink();
-        srcWin
+        showSrc = new ActiveLink();
+        showSrc
                 .setDescription("Right / middle / ctrl / shift -click for browser window/tab");
-        srcWin.addListener(new LinkActivatedListener() {
+        showSrc.addListener(new LinkActivatedListener() {
 
             public void linkActivated(LinkActivatedEvent event) {
                 if (!event.isLinkOpened()) {
-                    ((SamplerWindow) getWindow()).showSource(currentFeature
-                            .getSource());
+                    showSource(currentFeature.getSource());
                 }
 
             }
 
         });
-        srcWin.setCaption(MSG_SHOW_SRC);
-        srcWin.addStyleName("showcode");
-        srcWin.setTargetBorder(Link.TARGET_BORDER_NONE);
-        controlButtons.addComponent(srcWin);
+        showSrc.setCaption(MSG_SHOW_SRC);
+        showSrc.addStyleName("showcode");
+        showSrc.setTargetBorder(Link.TARGET_BORDER_NONE);
+        controlButtons.addComponent(showSrc);
+
+    }
 
+    public void showSource(String source) {
+        if (srcWindow == null) {
+            srcWindow = new Window("Java™ source");
+            ((VerticalLayout) srcWindow.getLayout()).setSizeUndefined();
+            srcWindow.setWidth("70%");
+            srcWindow.setHeight("60%");
+            srcWindow.setPositionX(100);
+            srcWindow.setPositionY(100);
+        }
+        srcWindow.removeAllComponents();
+        srcWindow.addComponent(new CodeLabel(source));
+
+        if (srcWindow.getParent() == null) {
+            getWindow().addWindow(srcWindow);
+        }
     }
 
     private void resetExample() {
@@ -143,8 +162,8 @@ public class FeatureView extends HorizontalLayout {
 
             { // open src in new window -link
                 String path = SamplerApplication.getPathFor(currentFeature);
-                srcWin.setTargetName(path);
-                srcWin.setResource(new ExternalResource(getApplication()
+                showSrc.setTargetName(path);
+                showSrc.setResource(new ExternalResource(getApplication()
                         .getURL()
                         + "src/" + path));
             }
index fbd87748ad7e7cdac2d11f74673676ddf2249d0f..7ce97ffadeda3f6dd26f748f41322f68f4761d93 100644 (file)
@@ -161,8 +161,6 @@ public class SamplerApplication extends Application {
         Button previousSample;
         Button nextSample;
 
-        private Window srcWindow = null;
-
         SamplerWindow() {
             // Main top/expanded-bottom layout
             VerticalLayout mainExpand = new VerticalLayout();
@@ -253,23 +251,13 @@ public class SamplerApplication extends Application {
             });
         }
 
-        public void showSource(String source) {
-            hideSource();
-            Window w = new Window("Java™ source");
-            ((VerticalLayout) w.getLayout()).setSizeUndefined();
-            w.setWidth("70%");
-            w.setHeight("60%");
-            w.setPositionX(100);
-            w.setPositionY(100);
-            w.addComponent(new CodeLabel(source));
-            addWindow(w);
-            srcWindow = w;
-        }
-
-        public void hideSource() {
-            if (srcWindow != null) {
-                removeWindow(srcWindow);
-                srcWindow = null;
+        @SuppressWarnings("unchecked")
+        public void removeSubwindows() {
+            Collection<Window> wins = getChildWindows();
+            if (null != wins) {
+                for (Window w : wins) {
+                    removeWindow(w);
+                }
             }
         }
 
@@ -280,7 +268,7 @@ public class SamplerApplication extends Application {
          *            the Feature(Set) to show
          */
         public void setFeature(Feature f) {
-            hideSource();
+            removeSubwindows();
             currentFeature.setValue(f);
             String path = getPathFor(f);
             webAnalytics.trackPageview(path);