View Javadoc

1   /*
2   Wotonomy: OpenStep design patterns for pure Java applications.
3   Copyright (C) 2000 Intersect Software Corporation
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, see http://www.gnu.org
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      // interface ActionListener
87      
88      public void actionPerformed( ActionEvent evt )
89      {
90  		EODisplayGroup actionDisplayGroup = null;
91  		String actionKey = null;
92  		
93  		// action aspect
94  		actionDisplayGroup = displayGroupForAspect( ActionAspect );
95  		if ( actionDisplayGroup != null )
96  		{
97  			actionKey = displayGroupKeyForAspect( ActionAspect );
98  
99  			//TODO: argument aspect not implemented
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  * $Log$
117  * Revision 1.2  2006/02/18 23:19:05  cgruber
118  * Update imports and maven dependencies.
119  *
120  * Revision 1.1  2006/02/16 13:22:22  cgruber
121  * Check in all sources in eclipse-friendly maven-enabled packages.
122  *
123  * Revision 1.2  2003/08/06 23:07:52  chochos
124  * general code cleanup (mostly, removing unused imports)
125  *
126  * Revision 1.1.1.1  2000/12/21 15:48:46  mpowers
127  * Contributing wotonomy.
128  *
129  * Revision 1.3  2000/12/20 16:25:40  michael
130  * Added log to all files.
131  *
132  *
133  */
134