1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.jface.window;
17
18 import java.util.Map;
19
20 import org.apache.commons.jelly.JellyTagException;
21 import org.apache.commons.jelly.MissingAttributeException;
22 import org.apache.commons.jelly.XMLOutput;
23 import org.apache.commons.jelly.tags.core.UseBeanTag;
24 import org.apache.commons.jelly.tags.swt.converters.PointConverter;
25 import org.eclipse.jface.window.Window;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.graphics.Point;
28 import org.eclipse.swt.widgets.Shell;
29
30 /***
31 * This tag creates an JFace ApplicationWindow
32 *
33 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
34 */
35 public class ApplicationWindowTag extends UseBeanTag {
36
37 private Shell parent;
38 private int style = SWT.NULL;
39
40 /***
41 * @param widgetClass
42 */
43 public ApplicationWindowTag(Class tagClass) {
44 super(tagClass);
45 }
46
47
48
49
50 public void doTag(XMLOutput output)
51 throws MissingAttributeException, JellyTagException {
52 Map attributes = getAttributes();
53 Object parent = attributes.remove("parent");
54 if (parent != null) {
55 if (parent instanceof Shell) {
56 this.parent = (Shell) parent;
57 } else {
58 throw new JellyTagException(
59 "The parent attribute is not a Shell, it is of type: "
60 + parent.getClass().getName()
61 + " value: "
62 + parent);
63 }
64 }
65
66 super.doTag(output);
67
68
69 Object title = attributes.remove("title");
70 if (title != null) {
71 getWindow().getShell().setText((String)title);
72 }
73
74
75 Object size = attributes.remove("size");
76 if (size != null) {
77 Point point = new PointConverter().parse((String) size);
78 getWindow().getShell().setSize(point);
79 }
80 }
81
82
83
84
85 protected Object newInstance(
86 Class theClass,
87 Map attributes,
88 XMLOutput output)
89 throws JellyTagException {
90
91 return new ApplicationWindowImpl(parent);
92 }
93
94
95 /***
96 * @return the visible window, if there is one.
97 */
98 public Window getWindow() {
99 Object bean = getBean();
100 if (bean instanceof Window) {
101 return (Window) bean;
102 }
103 return null;
104 }
105
106 }