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 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.jface.window.ApplicationWindowTag;
25 import org.eclipse.jface.action.MenuManager;
26 import org.eclipse.jface.window.ApplicationWindow;
27 import org.eclipse.jface.window.Window;
28
29 /***
30 * This tag creates an JFace MenuManager
31 *
32 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
33 */
34 public class MenuManagerTag extends UseBeanTag {
35
36 private String text;
37 private MenuManager mm;
38
39 /***
40 * @return the parent window which this widget will be added to.
41 */
42 public Window getParentWindow() {
43
44 ApplicationWindowTag tag =
45 (ApplicationWindowTag) findAncestorWithClass(ApplicationWindowTag
46 .class);
47 if (tag != null) {
48 return tag.getWindow();
49 }
50
51 return null;
52 }
53
54
55
56
57 public void doTag(XMLOutput output)
58 throws MissingAttributeException, JellyTagException {
59
60 Map attributes = getAttributes();
61 text = attributes.remove("text").toString();
62
63 if (text == null)
64 throw new MissingAttributeException("text attribute is missing");
65
66 mm = new MenuManager(text);
67
68 ApplicationWindow window = (ApplicationWindow) getParentWindow();
69 if (window != null) {
70 window.getMenuBarManager().add(mm);
71 }
72
73
74 invokeBody(output);
75 }
76
77 /***
78 * @return MenuManager
79 */
80 public MenuManager getMenuManager() {
81 return mm;
82 }
83
84 }