1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.jface;
17
18 import java.util.Map;
19
20 import org.apache.commons.jelly.JellyTagException;
21 import org.apache.commons.jelly.XMLOutput;
22 import org.apache.commons.jelly.tags.swt.WidgetTag;
23 import org.eclipse.jface.viewers.Viewer;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Widget;
27
28 /***
29 * This tag creates an JFace Viewer
30 *
31 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
32 */
33 public class ViewerTag extends WidgetTag {
34
35 private Composite parent;
36 private int style = SWT.NULL;
37
38 /***
39 * @param widgetClass
40 */
41 public ViewerTag(Class tagClass) {
42 super(tagClass);
43 }
44
45 /***
46 * @param widgetClass
47 * @param style
48 */
49 public ViewerTag(Class tagClass, int style) {
50 super(tagClass);
51 this.style = style;
52 }
53
54
55
56
57 protected Object newInstance(
58 Class theClass,
59 Map attributes,
60 XMLOutput output)
61 throws JellyTagException {
62
63 int style = getStyle(attributes);
64
65
66 Widget parent = getParentWidget();
67 Viewer viewer = (Viewer) createWidget(theClass, parent, style);
68
69 return viewer;
70 }
71
72 /***
73 * @return the visible viewer, if there is one.
74 */
75 public Viewer getViewer() {
76 Object bean = getBean();
77 if (bean instanceof Viewer) {
78 return (Viewer) bean;
79 }
80 return null;
81 }
82
83 }