1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.jface.wizard;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.MissingAttributeException;
20 import org.apache.commons.jelly.XMLOutput;
21 import org.apache.commons.jelly.tags.core.UseBeanTag;
22 import org.apache.commons.jelly.tags.jface.preference.PreferencePageTag;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.eclipse.jface.wizard.Wizard;
26 import org.eclipse.jface.wizard.WizardPage;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29
30 /***
31 * This Tag creates a JFace WizardPage
32 *
33 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
34 */
35 public class WizardPageTag extends UseBeanTag {
36
37 /***
38 * Implementation of a WizardPage
39 * method createControl is called on Dialog.open()
40 */
41 public class WizardPageImpl extends WizardPage {
42 private Composite parentComposite;
43
44 public WizardPageImpl(String title) {
45 super(title);
46 }
47
48 public void createControl(Composite parent) {
49
50 setControl(parent);
51
52
53 try {
54 invokeBody(output);
55 } catch (JellyTagException e) {
56 log.error(e);
57 }
58
59
60 if (parentComposite != null) {
61 setControl(parentComposite);
62 }
63 }
64
65 public Control getParentControl() {
66 return parentComposite;
67 }
68 public void setParentComposite(Composite parentComposite) {
69 this.parentComposite = parentComposite;
70 }
71
72 }
73
74 /*** The Log to which logging calls will be made. */
75 private static final Log log = LogFactory.getLog(PreferencePageTag.class);
76
77 /*** Jelly XMLOutput */
78 private XMLOutput output;
79
80 /***
81 * @param theClass
82 */
83 public WizardPageTag(Class theClass) {
84 super(theClass);
85 }
86
87
88
89
90 public void doTag(XMLOutput output) throws JellyTagException {
91
92 WizardDialogTag wizardTag = (WizardDialogTag) findAncestorWithClass(WizardDialogTag.class);
93 if (wizardTag == null) {
94 throw new JellyTagException("This tag must be nested within a <wizardDialog>");
95 }
96
97
98 String title = (String) getAttributes().get("title");
99 if (title == null) {
100 throw new MissingAttributeException("title");
101 }
102
103
104 WizardPageImpl page = new WizardPageImpl(title);
105 setBean(page);
106 setBeanProperties(page, getAttributes());
107
108 String var = (String) getAttributes().get("var");
109 processBean(var, page);
110
111
112 WizardDialogTag.WizardDialogImpl dialog = wizardTag.getWizardDialogImpl();
113 Wizard wizard = (Wizard) dialog.getWizard();
114
115
116 wizard.addPage(page);
117
118
119 this.output = output;
120 }
121
122 /***
123 * Get the WizardPageImpl
124 * @return WizardPageImpl
125 */
126 public WizardPageImpl getWizardPageImpl() {
127 Object bean = getBean();
128 if (bean instanceof WizardPageImpl) {
129 return (WizardPageImpl) bean;
130 }
131 return null;
132 }
133
134 }