]> source.dussan.org Git - vaadin-framework.git/commitdiff
Sampler feature resource linking stuff.
authorMarc Englund <marc.englund@itmill.com>
Wed, 15 Oct 2008 13:35:22 +0000 (13:35 +0000)
committerMarc Englund <marc.englund@itmill.com>
Wed, 15 Oct 2008 13:35:22 +0000 (13:35 +0000)
svn changeset:5643/svn branch:trunk

src/com/itmill/toolkit/demo/sampler/Feature.java
src/com/itmill/toolkit/demo/sampler/FeatureView.java
src/com/itmill/toolkit/demo/sampler/SamplerApplication.java
src/com/itmill/toolkit/demo/sampler/features/DummyFeature.java
src/com/itmill/toolkit/demo/sampler/features/DummyFeature2.java
src/com/itmill/toolkit/demo/sampler/features/DummyFeatureExample.java

index d2be3a0310170840552f399b30e3ac1695bdebcf..00fc43a8314f9294ee123d0a7c4ab47a89545b73 100644 (file)
@@ -87,4 +87,8 @@ abstract public class Feature {
         return getClass().getSimpleName();
     }
 
+    protected static final String getThemeBase() {
+        return SamplerApplication.THEME_BASE;
+    }
+
 }
\ No newline at end of file
index b8287c590db432163cecf170674008427f05e79c..bc960abc7b5875cfb8e3ef77cf572245b9055b01 100644 (file)
@@ -12,28 +12,28 @@ import com.itmill.toolkit.ui.Button.ClickEvent;
 
 public class FeatureView extends CustomLayout {
 
-    OrderedLayout controls;
+    private static final String MSG_SHOW_SRC = "Show java source";
+    private static final String MSG_HIDE_SRC = "Hide java source";
 
-    Label sourceCode;
+    private OrderedLayout controls;
+
+    private Label sourceCode;
+    private Button showCode;
+
+    private Feature currentFeature;
 
     public FeatureView() {
-        super("sampler/featureview");
+        super("featureview");
 
         controls = new OrderedLayout();
-
-        controls.addComponent(new Label("Live example"));
-        Button b = new Button("Show java source", new Button.ClickListener() {
+        controls.setCaption("Live example");
+        showCode = new Button(MSG_SHOW_SRC, new Button.ClickListener() {
             public void buttonClick(ClickEvent event) {
-                // toggle source code
-                sourceCode.setVisible(!sourceCode.isVisible());
-                event.getButton().setCaption(
-                        (sourceCode.isVisible() ? "Hide java source"
-                                : "Show java source"));
-
+                toggleSource();
             }
         });
-        b.setStyleName(Button.STYLE_LINK);
-        controls.addComponent(b);
+        showCode.setStyleName(Button.STYLE_LINK);
+        controls.addComponent(showCode);
 
         sourceCode = new Label();
         sourceCode.setVisible(false);
@@ -41,67 +41,79 @@ public class FeatureView extends CustomLayout {
         controls.addComponent(sourceCode);
     }
 
+    private void toggleSource() {
+        showSource(!sourceCode.isVisible());
+    }
+
+    private void showSource(boolean show) {
+        showCode.setCaption((show ? MSG_HIDE_SRC : MSG_SHOW_SRC));
+        sourceCode.setVisible(show);
+    }
+
     public void setFeature(Feature feature) {
-        removeAllComponents();
+        if (feature != currentFeature) {
+            removeAllComponents();
+            showSource(false);
 
-        addComponent(controls, "feature-controls");
+            addComponent(controls, "feature-controls");
 
-        addComponent(feature.getExample(), "feature-example");
+            addComponent(feature.getExample(), "feature-example");
 
-        Label l = new Label(feature.getName());
-        addComponent(l, "feature-name");
+            Label l = new Label(feature.getName());
+            addComponent(l, "feature-name");
 
-        l = new Label(feature.getDescription());
-        l.setContentMode(Label.CONTENT_XHTML);
-        addComponent(l, "feature-desc");
+            l = new Label(feature.getDescription());
+            l.setContentMode(Label.CONTENT_XHTML);
+            addComponent(l, "feature-desc");
 
-        StringBuffer src = new StringBuffer();
-        BufferedReader srcbr = feature.getSource();
-        try {
-            for (String line = srcbr.readLine(); null != line; line = srcbr
-                    .readLine()) {
-                src.append(line);
-                src.append("\n");
+            StringBuffer src = new StringBuffer();
+            BufferedReader srcbr = feature.getSource();
+            try {
+                for (String line = srcbr.readLine(); null != line; line = srcbr
+                        .readLine()) {
+                    src.append(line);
+                    src.append("\n");
+                }
+            } catch (Exception e) {
+                src = new StringBuffer("Sorry, no source available right now.");
             }
-        } catch (Exception e) {
-            src = new StringBuffer("Sorry, no source available right now.");
-        }
-        sourceCode.setValue(src.toString());
-
-        NamedExternalResource[] resources = feature.getRelatedResources();
-        if (resources != null) {
-            OrderedLayout res = new OrderedLayout();
-            res.setCaption("Resources");
-            for (NamedExternalResource r : resources) {
-                res.addComponent(new Link(r.getName(), r));
+            sourceCode.setValue(src.toString());
+
+            NamedExternalResource[] resources = feature.getRelatedResources();
+            if (resources != null) {
+                OrderedLayout res = new OrderedLayout();
+                res.setCaption("Additional resources");
+                for (NamedExternalResource r : resources) {
+                    res.addComponent(new Link(r.getName(), r));
+                }
+                addComponent(res, "feature-res");
             }
-            addComponent(res, "feature-res");
-        }
 
-        APIResource[] apis = feature.getRelatedAPI();
-        if (apis != null) {
-            OrderedLayout api = new OrderedLayout();
-            api.setCaption("Related Samples");
-            addComponent(api, "feature-api");
-            for (APIResource r : apis) {
-                api.addComponent(new Link(r.getName(), r));
+            APIResource[] apis = feature.getRelatedAPI();
+            if (apis != null) {
+                OrderedLayout api = new OrderedLayout();
+                api.setCaption("API documentation");
+                addComponent(api, "feature-api");
+                for (APIResource r : apis) {
+                    api.addComponent(new Link(r.getName(), r));
+                }
             }
-        }
 
-        Class[] features = feature.getRelatedFeatures();
-        if (features != null) {
-            OrderedLayout rel = new OrderedLayout();
-            rel.setCaption("Related Samples");
-            for (Class c : features) {
-                Feature f = SamplerApplication.getFeatureFor(c);
-                if (f != null) {
-                    String path = SamplerApplication.getPathFor(f);
-                    rel.addComponent(new Link(f.getName(),
-                            new ExternalResource(getApplication().getURL()
-                                    + path)));
+            Class[] features = feature.getRelatedFeatures();
+            if (features != null) {
+                OrderedLayout rel = new OrderedLayout();
+                rel.setCaption("Related Samples");
+                for (Class c : features) {
+                    Feature f = SamplerApplication.getFeatureFor(c);
+                    if (f != null) {
+                        String path = SamplerApplication.getPathFor(f);
+                        rel.addComponent(new Link(f.getName(),
+                                new ExternalResource(getApplication().getURL()
+                                        + path)));
+                    }
                 }
+                addComponent(rel, "feature-rel");
             }
-            addComponent(rel, "feature-rel");
         }
 
     }
index c63869f22601d8035f43b43a76295797d58ce569..1959780ef746457ea44cd63feebffe0ac6d0f1f5 100644 (file)
@@ -35,6 +35,7 @@ import com.itmill.toolkit.ui.Button.ClickEvent;
 import com.itmill.toolkit.ui.Button.ClickListener;
 
 public class SamplerApplication extends Application {
+    public static final String THEME_BASE = "/ITMILL/themes/sampler/";
 
     // Main structure, root is always a FeatureSet that is not shown
     private static final FeatureSet features = new FeatureSet("All",
@@ -91,7 +92,7 @@ public class SamplerApplication extends Application {
             .getContainer(true);
 
     public void init() {
-        setTheme("example");
+        setTheme("sampler");
         setMainWindow(new SamplerWindow());
     }
 
index a753346e7903bea1a381741aaee87592e0150253..cdcd1409457dbb7b9fdd5dd0d3ce8f6a0302495f 100644 (file)
@@ -31,7 +31,7 @@ public class DummyFeature extends Feature {
     public NamedExternalResource[] getRelatedResources() {
         return new NamedExternalResource[] {
         //
-        new NamedExternalResource("CSS", "../ITMILL/themes/example/styles.css")
+        new NamedExternalResource("CSS", getThemeBase() + "dummy/styles.css")
         //
         };
     }
index 13a8b4d1ed3bf2059f48e86665a54c975e63afb3..48afbb9358ed92d6a950d03e69ce8a7f0e85a53d 100644 (file)
@@ -29,7 +29,7 @@ public class DummyFeature2 extends Feature {
     public NamedExternalResource[] getRelatedResources() {
         return new NamedExternalResource[] {
         //
-        new NamedExternalResource("CSS", "../ITMILL/themes/example/styles.css")
+        new NamedExternalResource("CSS", getThemeBase() + "dummy/styles.css")
         //
         };
     }
index cca5a2314365405195e6d95acda999ed753908cc..d7efe1a1e05dd2dfcdee0735d5a0134475dcc89c 100644 (file)
@@ -6,6 +6,7 @@ import com.itmill.toolkit.ui.Panel;
 public class DummyFeatureExample extends Panel {
 
     public DummyFeatureExample() {
+        setStyleName("DummyFeatureExample");
         setCaption("An example example");
         addComponent(new Label("A label"));
     }