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.TagSupport;
21 import org.apache.commons.jelly.XMLOutput;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.eclipse.jface.viewers.DoubleClickEvent;
25 import org.eclipse.jface.viewers.IDoubleClickListener;
26 import org.eclipse.jface.viewers.StructuredViewer;
27 import org.eclipse.jface.viewers.Viewer;
28
29 /***
30 * This tag adds a listener for double-clicks in this viewer.
31 *
32 * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
33 */
34 public class DoubleClickListenerTag
35 extends TagSupport
36 implements IDoubleClickListener {
37
38 /*** The Log to which logging calls will be made. */
39 private static final Log log = LogFactory.getLog(DoubleClickListenerTag.class);
40
41 private String var = "event";
42 private XMLOutput output;
43
44
45
46
47 public void doTag(XMLOutput output)
48 throws MissingAttributeException, JellyTagException {
49 if (var == null) {
50 throw new MissingAttributeException("var");
51 }
52
53 StructuredViewer viewer = getParentViewer();
54 if (viewer == null) {
55 throw new JellyTagException("This tag must be nested within a viewer tag");
56 }
57
58 viewer.addDoubleClickListener(this);
59 this.output = output;
60 }
61
62 public StructuredViewer getParentViewer() {
63 ViewerTag tag = (ViewerTag) findAncestorWithClass(ViewerTag.class);
64 if (tag != null) {
65 Viewer viewer = tag.getViewer();
66 if (viewer instanceof StructuredViewer) {
67 return (StructuredViewer) viewer;
68 }
69 }
70 return null;
71 }
72
73 /***
74 * @return String
75 */
76 public String getVar() {
77 return var;
78 }
79
80 /***
81 * Sets the var.
82 * @param var The var to set
83 */
84 public void setVar(String var) {
85 this.var = var;
86 }
87
88
89
90
91
92
93 public void doubleClick(DoubleClickEvent event) {
94 try {
95 context.setVariable(var, event);
96 invokeBody(output);
97 } catch (Exception e) {
98 log.error(
99 "Caught exception: " + e + " while processing event: " + event,
100 e);
101 }
102 }
103
104 }