01: // (c) copyright 2006 by eXXcellent solutions, Ulm. Author: bschmid
02:
03: package foo.bar.plaf;
04:
05: import foo.bar.MyComponent;
06: import org.wings.header.Header;
07: import org.wings.header.SessionHeaders;
08: import org.wings.io.Device;
09: import org.wings.plaf.css.AbstractComponentCG;
10: import org.wings.plaf.css.Utils;
11:
12: import java.io.IOException;
13: import java.util.ArrayList;
14: import java.util.Collections;
15: import java.util.List;
16:
17: /**
18: * Example implementation for a component CG. <p>The mapping component to CG can be achieved using custom <code>default.properties</code>
19: * and <code>default_shortbrowsername.properties</code> in the <code>org.wings.plaf.css</code> package.
20: *
21: * @author Benjamin Schmid <B.Schmid@exxcellent.de>
22: */
23: public class MyComponentCG extends AbstractComponentCG<MyComponent> {
24:
25: /**
26: * A static immutable list of all external resources we need to run our custom component.
27: */
28: protected final static List<Header> headers;
29:
30: static {
31: List<Header> headerList = new ArrayList<Header>();
32: // add and register our custom css stylesheet
33: headerList
34: .add(Utils
35: .createExternalizedCSSHeader("foo/bar/css/customcomponent.css"));
36: // reuse and declare that we utilize some libraries that are already bundled with wingS core.
37: headerList
38: .add(Utils
39: .createExternalizedJSHeaderFromProperty(Utils.JS_YUI_EVENT));
40: // Include our custom javascript
41: headerList
42: .add(Utils
43: .createExternalizedJSHeader("foo/bar/js/customcomponent.js"));
44: headers = Collections.unmodifiableList(headerList);
45: }
46:
47: @Override
48: public void installCG(final MyComponent component) {
49: super .installCG(component);
50: // on any component that is created in our session we register our resources. This makes
51: // sure that it can be used i.e. within cell renderers.
52: // if you want to be resource saving use onParentFrameAdded and onParentFrameRemoved
53: SessionHeaders.getInstance().registerHeaders(headers);
54: }
55:
56: @Override
57: public void writeInternal(final Device device,
58: final MyComponent myComponent) throws IOException {
59: // check javadoc of this method to see what it does
60: writeTablePrefix(device, myComponent);
61:
62: // Here we render our component HTML code as desired.
63: // Many useful helper methods can be found in the Util class.
64: device.print(
65: "<!-- my component code --><div onclick=\"foobar()\">")
66: .print(myComponent.getPayload()).print("</div>");
67:
68: writeTableSuffix(device, myComponent);
69: }
70: }
|