]> source.dussan.org Git - vaadin-framework.git/commitdiff
Documented more, APIResource resolves inner classes.
authorMarc Englund <marc.englund@itmill.com>
Thu, 16 Oct 2008 07:30:25 +0000 (07:30 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 16 Oct 2008 07:30:25 +0000 (07:30 +0000)
svn changeset:5646/svn branch:trunk

src/com/itmill/toolkit/demo/sampler/APIResource.java
src/com/itmill/toolkit/demo/sampler/Feature.java
src/com/itmill/toolkit/demo/sampler/FeatureView.java
src/com/itmill/toolkit/demo/sampler/features/DummyFeature2.java

index 565f53b8a79e2347ba56651903de0a32119608e1..183c9c3a525eb3e710f3e045186f48520fa483ea 100644 (file)
@@ -18,7 +18,7 @@ public class APIResource extends NamedExternalResource {
     }
 
     public APIResource(String baseUrl, Class clazz) {
-        super(clazz.getSimpleName(), getJavadocUrl(baseUrl, clazz));
+        super(resolveName(clazz), getJavadocUrl(baseUrl, clazz));
     }
 
     private static String getJavadocUrl(String baseUrl, Class clazz) {
@@ -26,6 +26,7 @@ public class APIResource extends NamedExternalResource {
             baseUrl += "/";
         }
         String path = clazz.getName().replaceAll("\\.", "/");
+        path = path.replaceAll("\\$", ".");
         return baseUrl + path + ".html";
     }
 
@@ -48,4 +49,9 @@ public class APIResource extends NamedExternalResource {
         return ITMILL_BASE;
     }
 
+    private static String resolveName(Class clazz) {
+        Class ec = clazz.getEnclosingClass();
+        return (ec != null ? ec.getSimpleName() + "." : "")
+                + clazz.getSimpleName();
+    }
 }
index 78882fd3973ef88517cde601e30a45e6773856c6..d78b7afd8b68382bf64316abb5b6ae9947d52115 100644 (file)
@@ -12,6 +12,8 @@ abstract public class Feature {
     public static final Object PROPERTY_NAME = "Name";
     public static final Object PROPERTY_DESCRIPTION = "Description";
 
+    private String javaSource = null;
+
     /**
      * Gets the name of this feature. Defaults to class simplename, override if
      * needed.
@@ -38,27 +40,49 @@ abstract public class Feature {
      * pattern description, usability discussion).
      * </p>
      * <p>
-     * Can return null, if the example has no related resources.
+     * May return null, if the example has no related resources.
      * </p>
      * <p>
      * The name of the NamedExternalResource will be shown in the UI. <br/> Note
      * that Javadoc should be referenced via {@link #getRelatedAPI()}.
      * </p>
      * 
+     * @see #getThemeBase()
      * @return related external stuff
      */
     abstract public NamedExternalResource[] getRelatedResources();
 
     /**
-     * Gets related API resources, i.e
+     * Gets related API resources, i.e links to javadoc of used classes.
+     * <p>
+     * Good candidates are IT Mill classes being demoed in the example, or other
+     * classes playing an important role in the example.
+     * </p>
+     * <p>
+     * May return null, if the example uses no interesting classes.
+     * <p>
      * 
      * @return
      */
     abstract public APIResource[] getRelatedAPI();
 
+    /**
+     * Gets related Features; the classes returned should extend Feature.
+     * <p>
+     * Good candidates are Features similar to this one, Features using the
+     * functionality demoed in this one, and Features being used in this one.
+     * </p>
+     * <p>
+     * May return null, if no other Features are related to this one.
+     * <p>
+     * 
+     * @return
+     */
     abstract public Class[] getRelatedFeatures();
 
     /**
+     * Gets the name of the icon for this feature, usually simpleName +
+     * extension.
      * 
      * @return
      */
@@ -67,7 +91,11 @@ abstract public class Feature {
         return icon;
     }
 
-    /** Get the example instance. Override if instantiation needs parameters. */
+    /**
+     * Get the example instance. Override if instantiation needs parameters.
+     * 
+     * @return
+     */
     public Component getExample() {
 
         String className = this.getClass().getName() + "Example";
@@ -85,33 +113,59 @@ abstract public class Feature {
 
     }
 
-    public BufferedReader getSource() {
+    public String getSource() {
 
         // TODO get's .txt for now, change to .java!
-        try {
-            InputStream is = getClass().getResourceAsStream(
-                    getClass().getSimpleName() + "Example.txt");
-            return new BufferedReader(new InputStreamReader(is));
-        } catch (Exception e) {
-            System.err.println("Could not read source for " + getPathName());
+        synchronized (this) {
+            if (javaSource == null) {
+                StringBuffer src = new StringBuffer();
+                try {
+                    InputStream is = getClass().getResourceAsStream(
+                            getClass().getSimpleName() + "Example.txt");
+                    BufferedReader bis = new BufferedReader(
+                            new InputStreamReader(is));
+                    for (String line = bis.readLine(); null != line; line = bis
+                            .readLine()) {
+                        src.append(line);
+                        src.append("\n");
+                    }
+                    javaSource = src.toString();
+                } catch (Exception e) {
+                    System.err.println("Could not read source for "
+                            + getPathName());
+                    javaSource = "Sorry, no source available right now.";
+                }
+            }
         }
-        return null;
-    }
+        return javaSource;
 
-    public BufferedReader getSourceHTML() {
-        return getSource();
     }
 
-    public String toString() {
-        return getName();
+    public String getSourceHTML() {
+        return getSource();
     }
 
+    /**
+     * Gets the name used when resolving the path for this feature. Usually no
+     * need to overrride.
+     * 
+     * @return
+     */
     public String getPathName() {
         return getClass().getSimpleName();
     }
 
+    /**
+     * Gets the base url used to reference theme resources.
+     * 
+     * @return
+     */
     protected static final String getThemeBase() {
         return SamplerApplication.THEME_BASE;
     }
 
+    public String toString() {
+        return getName();
+    }
+
 }
\ No newline at end of file
index bc960abc7b5875cfb8e3ef77cf572245b9055b01..9aeb4aca86a40b5ac72e76d1379767ca4e5753c8 100644 (file)
@@ -1,7 +1,5 @@
 package com.itmill.toolkit.demo.sampler;
 
-import java.io.BufferedReader;
-
 import com.itmill.toolkit.terminal.ExternalResource;
 import com.itmill.toolkit.ui.Button;
 import com.itmill.toolkit.ui.CustomLayout;
@@ -66,18 +64,7 @@ public class FeatureView extends CustomLayout {
             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");
-                }
-            } catch (Exception e) {
-                src = new StringBuffer("Sorry, no source available right now.");
-            }
-            sourceCode.setValue(src.toString());
+            sourceCode.setValue(feature.getSource());
 
             NamedExternalResource[] resources = feature.getRelatedResources();
             if (resources != null) {
index 8250e84a180916014707b05b604f5d1ae52d163a..a5410ccad6faff6f76bf94bfd03995d1002c1405 100644 (file)
@@ -6,6 +6,7 @@ import javax.servlet.ServletContext;
 import com.itmill.toolkit.demo.sampler.APIResource;
 import com.itmill.toolkit.demo.sampler.Feature;
 import com.itmill.toolkit.demo.sampler.NamedExternalResource;
+import com.itmill.toolkit.ui.Button;
 import com.itmill.toolkit.ui.Component;
 
 public class DummyFeature2 extends Feature {
@@ -22,7 +23,8 @@ public class DummyFeature2 extends Feature {
     public APIResource[] getRelatedAPI() {
         return new APIResource[] { new APIResource(String.class),
                 new APIResource(PortletContext.class),
-                new APIResource(ServletContext.class) };
+                new APIResource(ServletContext.class),
+                new APIResource(Button.ClickListener.class) };
     }
 
     @Override