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 java.util.Map;
19
20 import org.apache.commons.jelly.JellyTagException;
21 import org.apache.commons.jelly.Script;
22 import org.apache.commons.jelly.XMLOutput;
23 import org.apache.commons.jelly.tags.core.UseBeanTag;
24 import org.apache.commons.jelly.tags.jface.window.ApplicationWindowTag;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.eclipse.jface.wizard.IWizard;
28 import org.eclipse.jface.wizard.Wizard;
29 import org.eclipse.jface.wizard.WizardDialog;
30 import org.eclipse.swt.widgets.Shell;
31
32 /***
33 * This Tag creates a JFace WizardDialog
34 *
35 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
36 */
37 public class WizardDialogTag extends UseBeanTag {
38
39 /***
40 * Provide a public method getWizard
41 */
42 class WizardDialogImpl extends WizardDialog {
43 public WizardDialogImpl(Shell parentShell, IWizard newWizard) {
44 super(parentShell, newWizard);
45 }
46
47 public IWizard getWizard() {
48 return super.getWizard();
49 }
50 }
51
52 /***
53 * Provide a Wizard implementation
54 */
55 class WizardImpl extends Wizard {
56 public WizardImpl() {
57 super();
58 setNeedsProgressMonitor(true);
59 }
60
61 public boolean performCancel() {
62 try {
63 if (performCancel != null) {
64 performCancel.run(context, output);
65 } else {
66 invokeBody(output);
67 }
68 } catch (JellyTagException e) {
69 log.error(e);
70 return false;
71 }
72 return true;
73 }
74
75 public boolean performFinish() {
76 try {
77 if (performFinish != null) {
78 performFinish.run(context, output);
79 } else {
80 invokeBody(output);
81 }
82 } catch (JellyTagException e) {
83 log.error(e);
84 return false;
85 }
86 return true;
87 }
88 }
89
90 /*** The Log to which logging calls will be made. */
91 private static final Log log = LogFactory.getLog(WizardDialogTag.class);
92
93 /*** Jelly XMLOutput */
94 private XMLOutput output;
95
96 /*** Script to be executed on performCancel */
97 private Script performCancel;
98
99 /*** Script to be executed on performFinish */
100 private Script performFinish;
101
102 /***
103 * @param theClass
104 */
105 public WizardDialogTag(Class theClass) {
106 super(theClass);
107 }
108
109
110
111
112 public void doTag(XMLOutput output) throws JellyTagException {
113 super.doTag(output);
114
115 if (getAttributes().get("performCancel") != null) {
116 Object script = getAttributes().get("performCancel");
117 if (script instanceof Script) {
118 performCancel = (Script) getAttributes().get("performCancel");
119 } else {
120 throw new JellyTagException("Attributevalue " + script + " must be a Script");
121 }
122 }
123
124 if (getAttributes().get("performFinish") != null) {
125 Object script = getAttributes().get("performFinish");
126 if (script instanceof Script) {
127 performFinish = (Script) getAttributes().get("performFinish");
128 } else {
129 throw new JellyTagException("Attributevalue " + script + " must be a Script");
130 }
131 }
132
133 this.output = output;
134 }
135
136 /***
137 * @return Shell
138 * @throws JellyTagException
139 */
140 protected Shell getShell() throws JellyTagException {
141 ApplicationWindowTag tag =
142 (ApplicationWindowTag) findAncestorWithClass(ApplicationWindowTag.class);
143 if (tag == null) {
144 throw new JellyTagException("This tag must be nested inside a <applicationWindow>");
145 } else {
146 return tag.getWindow().getShell();
147 }
148 }
149
150 /***
151 * @return WizardDialog
152 */
153 public WizardDialogImpl getWizardDialogImpl() {
154 Object bean = getBean();
155 if (bean instanceof WizardDialog) {
156 return (WizardDialogImpl) bean;
157 }
158 return null;
159 }
160
161
162
163
164 protected Object newInstance(Class theClass, Map attributes, XMLOutput output)
165 throws JellyTagException {
166 Wizard wizard = new WizardImpl();
167 return new WizardDialogImpl(getShell(), wizard);
168 }
169
170 /***
171 * Sets the Script to be executed on performCancel.
172 * @param performCancel The performCancel to set
173 */
174 public void setPerformCancel(Script performCancel) {
175 this.performCancel = performCancel;
176 }
177
178 /***
179 * Sets the Script to be executed on performFinish.
180 * @param performFinish The performFinish to set
181 */
182 public void setPerformFinish(Script performFinish) {
183 this.performFinish = performFinish;
184 }
185
186 }