%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.jface.wizard.WizardDialogTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | super(theClass); |
107 | 0 | } |
108 | ||
109 | /* |
|
110 | * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput) |
|
111 | */ |
|
112 | public void doTag(XMLOutput output) throws JellyTagException { |
|
113 | 0 | super.doTag(output); |
114 | ||
115 | 0 | if (getAttributes().get("performCancel") != null) { |
116 | 0 | Object script = getAttributes().get("performCancel"); |
117 | 0 | if (script instanceof Script) { |
118 | 0 | performCancel = (Script) getAttributes().get("performCancel"); |
119 | } else { |
|
120 | 0 | throw new JellyTagException("Attributevalue " + script + " must be a Script"); |
121 | } |
|
122 | } |
|
123 | ||
124 | 0 | if (getAttributes().get("performFinish") != null) { |
125 | 0 | Object script = getAttributes().get("performFinish"); |
126 | 0 | if (script instanceof Script) { |
127 | 0 | performFinish = (Script) getAttributes().get("performFinish"); |
128 | } else { |
|
129 | 0 | throw new JellyTagException("Attributevalue " + script + " must be a Script"); |
130 | } |
|
131 | } |
|
132 | ||
133 | 0 | this.output = output; |
134 | 0 | } |
135 | ||
136 | /** |
|
137 | * @return Shell |
|
138 | * @throws JellyTagException |
|
139 | */ |
|
140 | protected Shell getShell() throws JellyTagException { |
|
141 | 0 | ApplicationWindowTag tag = |
142 | (ApplicationWindowTag) findAncestorWithClass(ApplicationWindowTag.class); |
|
143 | 0 | if (tag == null) { |
144 | 0 | throw new JellyTagException("This tag must be nested inside a <applicationWindow>"); |
145 | } else { |
|
146 | 0 | return tag.getWindow().getShell(); |
147 | } |
|
148 | } |
|
149 | ||
150 | /** |
|
151 | * @return WizardDialog |
|
152 | */ |
|
153 | public WizardDialogImpl getWizardDialogImpl() { |
|
154 | 0 | Object bean = getBean(); |
155 | 0 | if (bean instanceof WizardDialog) { |
156 | 0 | return (WizardDialogImpl) bean; |
157 | } |
|
158 | 0 | return null; |
159 | } |
|
160 | ||
161 | /* |
|
162 | * @see org.apache.commons.jelly.tags.core.UseBeanTag#newInstance(java.lang.Class, java.util.Map, org.apache.commons.jelly.XMLOutput) |
|
163 | */ |
|
164 | protected Object newInstance(Class theClass, Map attributes, XMLOutput output) |
|
165 | throws JellyTagException { |
|
166 | 0 | Wizard wizard = new WizardImpl(); |
167 | 0 | 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 | 0 | this.performCancel = performCancel; |
176 | 0 | } |
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 | 0 | this.performFinish = performFinish; |
184 | 0 | } |
185 | ||
186 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |