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.JellyTagException;
19 import org.apache.commons.jelly.Tag;
20 import org.apache.commons.jelly.tags.jface.window.ApplicationWindowImpl;
21 import org.apache.commons.jelly.tags.jface.window.ApplicationWindowTag;
22 import org.apache.commons.jelly.tags.jface.wizard.WizardPageTag;
23 import org.apache.commons.jelly.tags.swt.WidgetTag;
24 import org.eclipse.jface.window.Window;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Widget;
27
28 /***
29 * Implementation of SWT WidgetTag
30 *
31 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
32 */
33 public class JFaceWidgetTag extends WidgetTag implements Tag {
34
35 /***
36 * @param widgetClass
37 */
38 public JFaceWidgetTag(Class widgetClass) {
39 super(widgetClass);
40 }
41
42 /***
43 * @param widgetClass
44 * @param style
45 */
46 public JFaceWidgetTag(Class widgetClass, int style) {
47 super(widgetClass, style);
48 }
49
50
51
52
53 protected void attachWidgets(Object parent, Widget widget) throws JellyTagException {
54 super.attachWidgets(parent, widget);
55
56
57 if (getParent() instanceof WizardPageTag) {
58 WizardPageTag tag = (WizardPageTag) getParent();
59 if (tag.getWizardPageImpl().getParentControl() == null) {
60 if (widget instanceof Composite) {
61 tag.getWizardPageImpl().setParentComposite((Composite) widget);
62 } else {
63 throw new JellyTagException("First child of a <wizardPage> must be of type Composite");
64 }
65 }
66 }
67 }
68
69
70
71
72 public Widget getParentWidget() {
73 parent = super.getParentWidget();
74
75 if (parent == null && getParent() instanceof WizardPageTag) {
76 WizardPageTag tag = (WizardPageTag) getParent();
77 if (tag != null) {
78 WizardPageTag.WizardPageImpl page = tag.getWizardPageImpl();
79 return page.getControl();
80 }
81 }
82
83 if (parent == null) {
84 ApplicationWindowTag tag =
85 (ApplicationWindowTag) findAncestorWithClass(ApplicationWindowTag.class);
86 if (tag != null) {
87 Window window = tag.getWindow();
88 if (window != null && window instanceof ApplicationWindowImpl) {
89 return ((ApplicationWindowImpl) window).getContents();
90 }
91 }
92 }
93
94 return parent;
95 }
96
97 }