import com.itmill.toolkit.ui.Component;
+/**
+ * Represents one feature or sample, with associated example.
+ * <p>
+ *
+ * </p>
+ *
+ */
abstract public class Feature {
public static final Object PROPERTY_ICON = "Icon";
public static final Object PROPERTY_NAME = "Name";
public static final Object PROPERTY_DESCRIPTION = "Description";
+ private static final Object MUTEX = new Object();
private String javaSource = null;
/**
* Gets the name of this feature. Defaults to class simplename, override if
- * needed.
+ * needed. Try not to exceed 25 characters too much.
*
* @return
*/
/**
* Gets the description for this feature. Should describe what the example
- * intends to showcase. May contain HTML.
+ * intends to showcase. May contain HTML. 100 words should be enough, and
+ * about 7 rows...
*
* @return the description
*/
public String getSource() {
// TODO get's .txt for now, change to .java!
- synchronized (this) {
+ synchronized (MUTEX) {
if (javaSource == null) {
StringBuffer src = new StringBuffer();
try {
* @return
*/
protected static final String getThemeBase() {
- return SamplerApplication.THEME_BASE;
+ return SamplerApplication.getThemeBase();
}
public String toString() {
package com.itmill.toolkit.demo.sampler;
+import java.net.URI;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
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",
new Feature[] {
private static final HierarchicalContainer allFeatures = features
.getContainer(true);
+ // init() inits
+ private static final String THEME_NAME = "sampler";
+
+ // used when trying to guess theme location
+ private static String APP_URL = null;
+
public void init() {
setTheme("sampler");
setMainWindow(new SamplerWindow());
+ if (APP_URL == null) {
+ APP_URL = getURL().toString();
+ }
+ }
+
+ /**
+ * Tries to guess theme location.
+ *
+ * @return
+ */
+ public static String getThemeBase() {
+ try {
+ URI uri = new URI(APP_URL + "../ITMILL/themes/" + THEME_NAME + "/");
+ return uri.normalize().toString();
+ } catch (Exception e) {
+ System.err.println("Theme location could not be resolved:" + e);
+ }
+ return "/ITMILL/themes/" + THEME_NAME + "/";
}
// Supports multiple browser windows
return null;
}
+ /**
+ * Gets the instance for the given Feature class, e.g DummyFeature.class.
+ *
+ * @param clazz
+ * @return
+ */
public static Feature getFeatureFor(Class clazz) {
for (Iterator it = allFeatures.getItemIds().iterator(); it.hasNext();) {
Feature f = (Feature) it.next();