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