%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.jface.window.ApplicationWindowTag |
|
|
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.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 | 0 | private int style = SWT.NULL; |
39 | ||
40 | /** |
|
41 | * @param widgetClass |
|
42 | */ |
|
43 | public ApplicationWindowTag(Class tagClass) { |
|
44 | 0 | super(tagClass); |
45 | 0 | } |
46 | ||
47 | /* |
|
48 | * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput) |
|
49 | */ |
|
50 | public void doTag(XMLOutput output) |
|
51 | throws MissingAttributeException, JellyTagException { |
|
52 | 0 | Map attributes = getAttributes(); |
53 | 0 | Object parent = attributes.remove("parent"); |
54 | 0 | if (parent != null) { |
55 | 0 | if (parent instanceof Shell) { |
56 | 0 | this.parent = (Shell) parent; |
57 | } else { |
|
58 | 0 | 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 | 0 | super.doTag(output); |
67 | ||
68 | // set Title of aaplicationWindow |
|
69 | 0 | Object title = attributes.remove("title"); |
70 | 0 | if (title != null) { |
71 | 0 | getWindow().getShell().setText((String)title); |
72 | } |
|
73 | ||
74 | // set size of applicationWindow |
|
75 | 0 | Object size = attributes.remove("size"); |
76 | 0 | if (size != null) { |
77 | 0 | Point point = new PointConverter().parse((String) size); |
78 | 0 | getWindow().getShell().setSize(point); |
79 | } |
|
80 | 0 | } |
81 | ||
82 | /* |
|
83 | * @see org.apache.commons.jelly.tags.core.UseBeanTag#newInstance(java.lang.Class, java.util.Map, org.apache.commons.jelly.XMLOutput) |
|
84 | */ |
|
85 | protected Object newInstance( |
|
86 | Class theClass, |
|
87 | Map attributes, |
|
88 | XMLOutput output) |
|
89 | throws JellyTagException { |
|
90 | ||
91 | 0 | return new ApplicationWindowImpl(parent); |
92 | } |
|
93 | ||
94 | ||
95 | /** |
|
96 | * @return the visible window, if there is one. |
|
97 | */ |
|
98 | public Window getWindow() { |
|
99 | 0 | Object bean = getBean(); |
100 | 0 | if (bean instanceof Window) { |
101 | 0 | return (Window) bean; |
102 | } |
|
103 | 0 | return null; |
104 | } |
|
105 | ||
106 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |