From: Marc Englund Date: Wed, 15 Oct 2008 13:35:22 +0000 (+0000) Subject: Sampler feature resource linking stuff. X-Git-Tag: 6.7.0.beta1~3986 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e1f740434702a85c7287fb7abdd5a6d04613732c;p=vaadin-framework.git Sampler feature resource linking stuff. svn changeset:5643/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/sampler/Feature.java b/src/com/itmill/toolkit/demo/sampler/Feature.java index d2be3a0310..00fc43a831 100644 --- a/src/com/itmill/toolkit/demo/sampler/Feature.java +++ b/src/com/itmill/toolkit/demo/sampler/Feature.java @@ -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 diff --git a/src/com/itmill/toolkit/demo/sampler/FeatureView.java b/src/com/itmill/toolkit/demo/sampler/FeatureView.java index b8287c590d..bc960abc7b 100644 --- a/src/com/itmill/toolkit/demo/sampler/FeatureView.java +++ b/src/com/itmill/toolkit/demo/sampler/FeatureView.java @@ -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"); } } diff --git a/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java b/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java index c63869f226..1959780ef7 100644 --- a/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java +++ b/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java @@ -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()); } diff --git a/src/com/itmill/toolkit/demo/sampler/features/DummyFeature.java b/src/com/itmill/toolkit/demo/sampler/features/DummyFeature.java index a753346e79..cdcd140945 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/DummyFeature.java +++ b/src/com/itmill/toolkit/demo/sampler/features/DummyFeature.java @@ -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") // }; } diff --git a/src/com/itmill/toolkit/demo/sampler/features/DummyFeature2.java b/src/com/itmill/toolkit/demo/sampler/features/DummyFeature2.java index 13a8b4d1ed..48afbb9358 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/DummyFeature2.java +++ b/src/com/itmill/toolkit/demo/sampler/features/DummyFeature2.java @@ -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") // }; } diff --git a/src/com/itmill/toolkit/demo/sampler/features/DummyFeatureExample.java b/src/com/itmill/toolkit/demo/sampler/features/DummyFeatureExample.java index cca5a23143..d7efe1a1e0 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/DummyFeatureExample.java +++ b/src/com/itmill/toolkit/demo/sampler/features/DummyFeatureExample.java @@ -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")); }