1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.jface.preference;
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.core.UseBeanTag;
23 import org.apache.commons.jelly.tags.jface.window.ApplicationWindowTag;
24 import org.eclipse.jface.preference.PreferenceDialog;
25 import org.eclipse.jface.preference.PreferenceManager;
26 import org.eclipse.swt.widgets.Shell;
27
28 /***
29 * This Tag creates a JFace PreferenceDialog
30 *
31 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
32 */
33 public class PreferenceDialogTag extends UseBeanTag {
34
35 public PreferenceDialogTag(Class arg0) {
36 super(arg0);
37 }
38
39 /***
40 * @return PreferenceDialog
41 */
42 public PreferenceDialog getPreferenceDialog() {
43 Object bean = getBean();
44 if (bean instanceof PreferenceDialog) {
45 return (PreferenceDialog) bean;
46 }
47 return null;
48 }
49
50 /***
51 * @return Shell
52 * @throws JellyTagException
53 */
54 protected Shell getShell() throws JellyTagException {
55 ApplicationWindowTag tag =
56 (ApplicationWindowTag) findAncestorWithClass(ApplicationWindowTag.class);
57
58 if (tag != null) {
59 return tag.getWindow().getShell();
60
61 } else {
62 Map attributes = getAttributes();
63 Object parent = attributes.remove("parent");
64 if (parent instanceof Shell) {
65 return (Shell) parent;
66 } else {
67 throw new JellyTagException("This tag must be nested inside a <applicationWindow> or have a parent of type Shell");
68 }
69 }
70 }
71
72
73
74
75 protected Object newInstance(Class arg0, Map arg1, XMLOutput arg2) throws JellyTagException {
76 PreferenceManager pm = new PreferenceManager();
77 return new PreferenceDialog(getShell(), pm);
78 }
79
80 }