View Javadoc

1   package net.wotonomy.test;
2   
3   import java.awt.event.ActionEvent;
4   import java.awt.event.ActionListener;
5   import java.awt.event.MouseAdapter;
6   import java.awt.event.MouseEvent;
7   import java.awt.event.WindowAdapter;
8   import java.awt.event.WindowEvent;
9   
10  import javax.swing.AbstractButton;
11  import javax.swing.JDialog;
12  
13  import net.wotonomy.foundation.NSArray;
14  import net.wotonomy.ui.EOAssociation;
15  import net.wotonomy.ui.EODisplayGroup;
16  import net.wotonomy.ui.MasterDetailAssociation;
17  import net.wotonomy.ui.swing.DisplayGroupActionAssociation;
18  import net.wotonomy.ui.swing.ListAssociation;
19  import net.wotonomy.ui.swing.RadioPanelAssociation;
20  import net.wotonomy.ui.swing.TextAssociation;
21  import net.wotonomy.ui.swing.util.WindowUtilities;
22  
23  /***
24  * A simple editor panel with a few textfields.
25  */
26  public class InspectorController 
27  {    
28      public InspectorController( Object o )
29      {
30  		EditPanel editPanel = new EditPanel();
31  		
32  		EODisplayGroup group = new EODisplayGroup();
33          group.setDataSource( new TestDataSource() );
34  		group.setObjectArray( new NSArray( o ) );
35  		group.selectNext();
36  		
37  		// text associations
38  		
39  		EOAssociation ta;
40  		
41  		ta = new TextAssociation( editPanel.firstNameField );
42  		ta.bindAspect( EOAssociation.ValueAspect, group, "firstName" );
43  		ta.establishConnection();
44  		
45  		ta = new TextAssociation( editPanel.middleNameField );
46  		ta.bindAspect( EOAssociation.ValueAspect, group, "middleName" );
47  		ta.establishConnection();
48  		
49  		ta = new TextAssociation( editPanel.lastNameField );
50  		ta.bindAspect( EOAssociation.ValueAspect, group, "lastName" );
51  		ta.establishConnection();
52  		
53  		// radio panels
54  		
55  		ta = new RadioPanelAssociation( editPanel.yearRadioPanel );
56  		ta.bindAspect( EOAssociation.ValueAspect, group, "createDate.year" );
57  		
58  		EODisplayGroup yearTitles = new EODisplayGroup();
59  		yearTitles.setObjectArray( new NSArray( 
60  			new Object[] { "1999", "2000", "2001" } ) );
61  		ta.bindAspect( EOAssociation.TitlesAspect, yearTitles, "" );
62  	
63  		EODisplayGroup yearObjects = new EODisplayGroup();
64  		yearObjects.setObjectArray( new NSArray( 
65  			new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) );
66  		ta.bindAspect( EOAssociation.ObjectsAspect, yearObjects, "" );
67  		
68  		ta.establishConnection();
69  		
70  		// detail group
71  		
72  		final EODisplayGroup detailGroup = new EODisplayGroup();
73  		
74  		ta = new MasterDetailAssociation( detailGroup );
75  		ta.bindAspect( EOAssociation.ParentAspect, group, "childList" );
76  		ta.establishConnection();
77  		
78  		ta = new ListAssociation( editPanel.list );
79  		ta.bindAspect( EOAssociation.TitlesAspect, detailGroup, "fullName" );
80  		ta.establishConnection();
81  		
82  		// display group action associations
83  
84  		AbstractButton button = (AbstractButton)
85  			editPanel.addPanel.getButton( "Add" );
86  		button.addActionListener( new ActionListener()
87  		{
88  			public void actionPerformed( ActionEvent evt )
89  			{
90  				detailGroup.insertNewObjectAtIndex( 0 );	
91  			}
92  		} );
93  		
94  		ta = new DisplayGroupActionAssociation( 
95              editPanel.addPanel.getButton( "Remove" ) );
96  		ta.bindAspect( EOAssociation.ActionAspect, detailGroup, "deleteSelection" );
97  		ta.establishConnection();
98  
99  		// add mouse listener for list
100 		
101 		editPanel.list.addMouseListener( new MouseAdapter() 
102 		{
103 			public void mouseClicked(MouseEvent e)
104 			{
105 				if ( e.getClickCount() == 2 )
106 				{
107 					Object item = detailGroup.selectedObject();
108 					if ( item != null )
109 					{
110 						new InspectorController( item );
111 					}		
112 				}
113 			}
114 		});
115 		
116 		// launch
117 								
118 		JDialog dialog = new JDialog();
119 		dialog.getContentPane().add( editPanel );
120 		dialog.setTitle( "Inspector Panel" );
121 		dialog.pack();
122 		dialog.setSize( 300, dialog.getSize().height );
123         WindowUtilities.cascade( dialog );
124 		dialog.show();
125 
126         // workaround for memory issues on jdk1.2.2
127 		dialog.addWindowListener( new WindowAdapter()
128 		{
129 			// exit on close
130 			public void windowClosing(WindowEvent e)
131 			{	
132 				((JDialog)e.getWindow()).getContentPane().removeAll();
133 			}
134 		});
135 	}
136     
137 }