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.ListAssociation;
18 import net.wotonomy.ui.swing.RadioPanelAssociation;
19 import net.wotonomy.ui.swing.TextAssociation;
20 import net.wotonomy.ui.swing.TreeAssociation;
21 import net.wotonomy.ui.swing.util.WindowUtilities;
22
23 /***
24 * A simple editor panel with a few textfields.
25 */
26 public class TreeInspectorController
27 {
28 public TreeInspectorController( EODisplayGroup titlesGroup, EODisplayGroup childrenGroup )
29 {
30 final EODisplayGroup group = childrenGroup;
31
32 final TreePanel treePanel = new TreePanel();
33
34
35
36 EOAssociation ta;
37
38 ta = new TreeAssociation( treePanel.tree, "People" );
39 ta.bindAspect( EOAssociation.TitlesAspect, titlesGroup, "lastName" );
40 ta.bindAspect( EOAssociation.ChildrenAspect, group, "childList" );
41 ta.bindAspect( EOAssociation.IsLeafAspect, titlesGroup, "childCount" );
42
43 ta.establishConnection();
44 treePanel.tree.setEditable( true );
45
46 ta = new TextAssociation( treePanel.editPanel.firstNameField );
47 ta.bindAspect( EOAssociation.ValueAspect, group, "firstName" );
48 ta.establishConnection();
49
50 ta = new TextAssociation( treePanel.editPanel.middleNameField );
51 ta.bindAspect( EOAssociation.ValueAspect, group, "middleName" );
52 ta.establishConnection();
53
54 ta = new TextAssociation( treePanel.editPanel.lastNameField );
55 ta.bindAspect( EOAssociation.ValueAspect, group, "lastName" );
56 ta.establishConnection();
57
58 ta = new RadioPanelAssociation( treePanel.editPanel.yearRadioPanel );
59 ta.bindAspect( EOAssociation.ValueAspect, group, "createDate.year" );
60
61 EODisplayGroup yearTitles = new EODisplayGroup();
62 yearTitles.setObjectArray( new NSArray(
63 new Object[] { "1999", "2000", "2001" } ) );
64 ta.bindAspect( EOAssociation.TitlesAspect, yearTitles, "" );
65
66 EODisplayGroup yearObjects = new EODisplayGroup();
67 yearObjects.setObjectArray( new NSArray(
68 new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) );
69 ta.bindAspect( EOAssociation.ObjectsAspect, yearObjects, "" );
70
71 ta.establishConnection();
72
73
74
75 final EODisplayGroup detailGroup = new EODisplayGroup();
76
77 ta = new MasterDetailAssociation( detailGroup );
78 ta.bindAspect( EOAssociation.ParentAspect, group, "childList" );
79 ta.establishConnection();
80
81 ta = new ListAssociation( treePanel.editPanel.list );
82 ta.bindAspect( EOAssociation.TitlesAspect, detailGroup, "fullName" );
83 ta.establishConnection();
84
85
86
87 AbstractButton addButton = (AbstractButton)
88 treePanel.editPanel.addPanel.getButton( "Add" );
89 addButton.addActionListener( new ActionListener()
90 {
91 public void actionPerformed( ActionEvent evt )
92 {
93 detailGroup.insertObjectAtIndex( new TestObject(), 0 );
94 }
95 } );
96
97 AbstractButton removeButton = (AbstractButton)
98 treePanel.editPanel.addPanel.getButton( "Remove" );
99 removeButton.addActionListener( new ActionListener()
100 {
101 public void actionPerformed( ActionEvent evt )
102 {
103 if ( detailGroup.selectedObject() != null )
104 detailGroup.deleteSelection();
105 }
106 } );
107
108
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 treePanel.editPanel.list.addMouseListener( new MouseAdapter()
150 {
151 public void mouseClicked(MouseEvent e)
152 {
153 if ( e.getClickCount() == 2 )
154 {
155 Object item = detailGroup.selectedObject();
156 if ( item != null )
157 {
158 new InspectorController( item );
159 }
160 }
161 }
162 });
163
164
165
166 JDialog d = new JDialog();
167 d.getContentPane().add( treePanel );
168 d.setTitle( "Tree Panel" );
169 d.pack();
170 WindowUtilities.cascade( d );
171 d.show();
172
173
174 d.addWindowListener( new WindowAdapter()
175 {
176
177 public void windowClosing(WindowEvent e)
178 {
179 ((JDialog)e.getWindow()).getContentPane().removeAll();
180 }
181 });
182 }
183
184 }