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.MissingAttributeException;
20 import org.apache.commons.jelly.XMLOutput;
21 import org.apache.commons.jelly.tags.core.UseBeanTag;
22 import org.eclipse.jface.action.ContributionItem;
23 import org.eclipse.jface.action.IContributionManager;
24
25 /***
26 * This tag creates an JFace ContributionItem
27 *
28 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
29 */
30 public class ContributionItemTag extends UseBeanTag {
31
32 public ContributionItemTag(Class arg0) {
33 super(arg0);
34 }
35
36 /***
37 * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
38 */
39 public void doTag(XMLOutput output)
40 throws MissingAttributeException, JellyTagException {
41
42 super.doTag(output);
43
44 Object bean = getBean();
45 if (bean != null && bean instanceof ContributionItem) {
46 IContributionManager cm = getParentContributionManager();
47 if (cm != null) {
48 cm.add((ContributionItem) bean);
49 }
50 }
51
52 }
53
54 /***
55 * @return IContributionManager
56 */
57 protected IContributionManager getParentContributionManager() {
58 MenuManagerTag tag =
59 (MenuManagerTag) findAncestorWithClass(MenuManagerTag.class);
60 if (tag != null) {
61 return tag.getMenuManager();
62 }
63 return null;
64 }
65
66 }