1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.ui.swing;
20
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23
24 import net.wotonomy.foundation.NSArray;
25 import net.wotonomy.foundation.NSSelector;
26 import net.wotonomy.foundation.internal.WotonomyException;
27 import net.wotonomy.ui.EODisplayGroup;
28
29 /***
30 * ActionAssociation binds any ActionEvent broadcaster
31 * (typically Buttons and the like) to a display group,
32 * but invokes actions directly on the bound display
33 * group rather than the selected objects.
34 * Bindings are:
35 * <ul>
36 * <li>action: a method to be invoked on the bound display group.
37 * If the argument aspect is bound, the method must take
38 * one argument. Otherwise, the method must take no arguments.</li>
39 * <li>argument: the attribute of the selected object(s) (possibly
40 * from a different display group) that will be used as an argument
41 * to the action method</li>
42 * <li>enabled: a boolean property that determines whether
43 * the controlled component is enabled</li>
44 * <li>visible: a boolean property that determines whether
45 * the controlled component is visible</li>
46 * </ul>
47 *
48 * @author michael@mpowers.net
49 * @author $Author: cgruber $
50 * @version $Revision: 904 $
51 */
52 public class DisplayGroupActionAssociation extends ActionAssociation
53 {
54 static final NSArray aspects =
55 new NSArray( new Object[] {
56 ActionAspect, ArgumentAspect, EnabledAspect, VisibleAspect
57 } );
58 static final NSArray aspectSignatures =
59 new NSArray( new Object[] {
60 AttributeToOneAspectSignature,
61 AttributeToOneAspectSignature,
62 AttributeToOneAspectSignature,
63 AttributeToOneAspectSignature
64 } );
65 static final NSArray objectKeysTaken =
66 new NSArray( new Object[] {
67 "target"
68 } );
69
70 static NSSelector addActionListener =
71 new NSSelector( "addActionListener",
72 new Class[] { ActionListener.class } );
73 static NSSelector removeActionListener =
74 new NSSelector( "removeActionListener",
75 new Class[] { ActionListener.class } );
76
77 /***
78 * Constructor specifying the object to be controlled by this
79 * association. Does not establish connection.
80 */
81 public DisplayGroupActionAssociation ( Object anObject )
82 {
83 super( anObject );
84 }
85
86
87
88 public void actionPerformed( ActionEvent evt )
89 {
90 EODisplayGroup actionDisplayGroup = null;
91 String actionKey = null;
92
93
94 actionDisplayGroup = displayGroupForAspect( ActionAspect );
95 if ( actionDisplayGroup != null )
96 {
97 actionKey = displayGroupKeyForAspect( ActionAspect );
98
99
100
101 try
102 {
103 NSSelector.invoke( actionKey, actionDisplayGroup );
104 }
105 catch ( Exception exc )
106 {
107 throw new WotonomyException( "DisplayGroupActionAssociation: "
108 + "error invoking action: " + actionKey, exc );
109 }
110 }
111 }
112
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134