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