}
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) {
baseUrl += "/";
}
String path = clazz.getName().replaceAll("\\.", "/");
+ path = path.replaceAll("\\$", ".");
return baseUrl + path + ".html";
}
return ITMILL_BASE;
}
+ private static String resolveName(Class clazz) {
+ Class ec = clazz.getEnclosingClass();
+ return (ec != null ? ec.getSimpleName() + "." : "")
+ + clazz.getSimpleName();
+ }
}
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.
* 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
*/
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";
}
- 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
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;
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) {