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 org.apache.commons.jelly.JellyException;
19 import org.apache.commons.jelly.Tag;
20 import org.apache.commons.jelly.impl.TagFactory;
21 import org.apache.commons.jelly.tags.jface.preference.FieldEditorTag;
22 import org.apache.commons.jelly.tags.jface.preference.PreferenceDialogTag;
23 import org.apache.commons.jelly.tags.jface.preference.PreferencePageTag;
24 import org.apache.commons.jelly.tags.jface.window.ApplicationWindowTag;
25 import org.apache.commons.jelly.tags.jface.wizard.WizardDialogTag;
26 import org.apache.commons.jelly.tags.jface.wizard.WizardPageTag;
27 import org.apache.commons.jelly.tags.swt.SwtTagLibrary;
28 import org.eclipse.jface.action.Separator;
29 import org.eclipse.jface.preference.BooleanFieldEditor;
30 import org.eclipse.jface.preference.ColorFieldEditor;
31 import org.eclipse.jface.preference.DirectoryFieldEditor;
32 import org.eclipse.jface.preference.FileFieldEditor;
33 import org.eclipse.jface.preference.FontFieldEditor;
34 import org.eclipse.jface.preference.IntegerFieldEditor;
35 import org.eclipse.jface.preference.StringFieldEditor;
36 import org.eclipse.jface.viewers.CheckboxTreeViewer;
37 import org.eclipse.jface.viewers.TableTreeViewer;
38 import org.eclipse.jface.viewers.TableViewer;
39 import org.eclipse.jface.viewers.TreeViewer;
40 import org.eclipse.jface.window.ApplicationWindow;
41 import org.eclipse.swt.SWT;
42 import org.xml.sax.Attributes;
43
44 /***
45 * A Jelly custom tag library that creates JFace user interfaces
46 * This taglib extends the SWT tag lib
47 *
48 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
49 */
50 public class JFaceTagLibrary extends SwtTagLibrary {
51
52 public JFaceTagLibrary() {
53
54
55 registerViewerTag("tableViewer", TableViewer.class);
56 registerViewerTag("tableTreeViewer", TableTreeViewer.class);
57 registerViewerTag("treeViewer", TreeViewer.class);
58 registerViewerTag("checkboxTreeViewer", CheckboxTreeViewer.class);
59
60
61 registerTag("doubleClickListener", DoubleClickListenerTag.class);
62 registerTag("selectionChangedListener", SelectionChangedListenerTag.class);
63
64
65 registerWindowTag("applicationWindow", ApplicationWindow.class);
66
67
68 registerMenuManager("menuManager", MenuManagerTag.class);
69
70
71 registerActionTag("action", ActionTag.class);
72
73
74 registerContributionItemTag("separator", Separator.class);
75
76
77 registerWizardDialogTag("wizardDialog", WizardDialogTag.class);
78 registerWizardPageTag("wizardPage", WizardPageTag.class);
79
80
81 registerPreferenceDialogTag("preferenceDialog", PreferenceDialogTag.class);
82 registerTag("preferencePage", PreferencePageTag.class);
83 registerFieldEditorTag("booleanFieldEditor", BooleanFieldEditor.class);
84 registerFieldEditorTag("colorFieldEditor", ColorFieldEditor.class);
85 registerFieldEditorTag("directoryFieldEditor", DirectoryFieldEditor.class);
86 registerFieldEditorTag("fileFieldEditor", FileFieldEditor.class);
87 registerFieldEditorTag("fontFieldEditor", FontFieldEditor.class);
88 registerFieldEditorTag("integerFieldEditor", IntegerFieldEditor.class);
89
90
91 registerFieldEditorTag("stringFieldEditor", StringFieldEditor.class);
92
93 }
94
95 /***
96 * @param string
97 * @param class1
98 */
99 private void registerMenuManager(String name, final Class theClass) {
100 registerTagFactory(name, new TagFactory() {
101 /***
102 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
103 */
104 public Tag createTag(String name, Attributes attributes) throws JellyException {
105 return new MenuManagerTag();
106 }
107 });
108
109 }
110
111 /***
112 * Register a widget tag for the given name
113 *
114 * @param name
115 * @param widgetClass
116 */
117 protected void registerViewerTag(String name, Class widgetClass) {
118 registerViewerTag(name, widgetClass, SWT.NULL);
119 }
120
121 /***
122 * Register a widget tag for the given name
123 *
124 * @param name
125 * @param widgetClass
126 * @param style
127 */
128 protected void registerViewerTag(String name, final Class theClass, final int style) {
129 registerTagFactory(name, new TagFactory() {
130 /***
131 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
132 */
133 public Tag createTag(String name, Attributes attributes) throws JellyException {
134 return new ViewerTag(theClass, style);
135 }
136 });
137 }
138
139 /***
140 * Register a widget tag for the given name
141 *
142 * @param name
143 * @param widgetClass
144 * @param style
145 */
146 protected void registerWindowTag(String name, final Class theClass) {
147 registerTagFactory(name, new TagFactory() {
148 /***
149 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
150 */
151 public Tag createTag(String name, Attributes attributes) throws JellyException {
152 return new ApplicationWindowTag(theClass);
153 }
154 });
155 }
156
157 /***
158 * Register an action tag for the given name
159 */
160 protected void registerActionTag(String name, final Class theClass) {
161 registerTagFactory(name, new TagFactory() {
162 /***
163 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
164 */
165 public Tag createTag(String name, Attributes attributes) throws JellyException {
166 return new ActionTag(theClass);
167 }
168 });
169 }
170
171 /***
172 * Register a contribution item tag for the given name
173 */
174 protected void registerContributionItemTag(String name, final Class theClass) {
175 registerTagFactory(name, new TagFactory() {
176 /***
177 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
178 */
179 public Tag createTag(String name, Attributes attributes) throws JellyException {
180 return new ContributionItemTag(theClass);
181 }
182 });
183 }
184
185 /***
186 * @param name
187 * @param theClass
188 */
189 protected void registerPreferenceDialogTag(String name, final Class theClass) {
190 registerTagFactory(name, new TagFactory() {
191 /***
192 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
193 */
194 public Tag createTag(String name, Attributes attributes) throws JellyException {
195 return new PreferenceDialogTag(theClass);
196 }
197 });
198 }
199
200 /***
201 * @param name
202 * @param theClass
203 */
204 protected void registerFieldEditorTag(String name, final Class theClass) {
205 registerTagFactory(name, new TagFactory() {
206 /***
207 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
208 */
209 public Tag createTag(String name, Attributes attributes) throws JellyException {
210 return new FieldEditorTag(theClass);
211 }
212 });
213 }
214
215 /***
216 * @param name
217 * @param theClass
218 */
219 protected void registerWizardDialogTag(String name, final Class theClass) {
220 registerTagFactory(name, new TagFactory() {
221 /***
222 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
223 */
224 public Tag createTag(String name, Attributes attributes) throws JellyException {
225 return new WizardDialogTag(theClass);
226 }
227 });
228 }
229
230 protected void registerWizardPageTag(String name, final Class theClass) {
231 registerTagFactory(name, new TagFactory() {
232 /***
233 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
234 */
235 public Tag createTag(String name, Attributes attributes) throws JellyException {
236 return new WizardPageTag(theClass);
237 }
238 });
239 }
240
241 /***
242 * Register a widget tag for the given name
243 */
244 protected void registerWidgetTag(String name, Class widgetClass) {
245 registerWidgetTag(name, widgetClass, SWT.NULL);
246 }
247
248 /***
249 * Register a widget tag for the given name
250 */
251 protected void registerWidgetTag(String name, final Class widgetClass, final int style) {
252 registerTagFactory(name, new TagFactory() {
253 /***
254 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
255 */
256 public Tag createTag(String name, Attributes attributes) throws JellyException {
257 return new JFaceWidgetTag(widgetClass, style);
258 }
259 });
260 }
261
262 /***
263 * Register a layout tag for the given name
264 */
265 protected void registerLayoutTag(String name, final Class layoutClass) {
266 registerTagFactory(name, new TagFactory() {
267 /***
268 * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
269 */
270 public Tag createTag(String name, Attributes attributes) throws JellyException {
271 return new JFaceLayoutTag(layoutClass);
272 }
273 });
274 }
275
276 }