| 1 |
0 |
package net.wotonomy.test; |
| 2 |
|
|
| 3 |
|
import java.awt.BorderLayout; |
| 4 |
|
import java.awt.event.ActionEvent; |
| 5 |
|
import java.awt.event.ActionListener; |
| 6 |
|
import java.awt.event.MouseAdapter; |
| 7 |
|
import java.awt.event.MouseEvent; |
| 8 |
|
import java.awt.event.WindowAdapter; |
| 9 |
|
import java.awt.event.WindowEvent; |
| 10 |
|
|
| 11 |
|
import javax.swing.AbstractButton; |
| 12 |
|
import javax.swing.BorderFactory; |
| 13 |
|
import javax.swing.JDialog; |
| 14 |
|
|
| 15 |
|
import net.wotonomy.control.EODataSource; |
| 16 |
|
import net.wotonomy.control.EOEditingContext; |
| 17 |
|
import net.wotonomy.foundation.NSArray; |
| 18 |
|
import net.wotonomy.ui.EOAssociation; |
| 19 |
|
import net.wotonomy.ui.EODisplayGroup; |
| 20 |
|
import net.wotonomy.ui.MasterDetailAssociation; |
| 21 |
|
import net.wotonomy.ui.swing.ListAssociation; |
| 22 |
|
import net.wotonomy.ui.swing.RadioPanelAssociation; |
| 23 |
|
import net.wotonomy.ui.swing.TextAssociation; |
| 24 |
|
import net.wotonomy.ui.swing.TreeAssociation; |
| 25 |
|
import net.wotonomy.ui.swing.components.ButtonPanel; |
| 26 |
|
import net.wotonomy.ui.swing.util.ObjectInspector; |
| 27 |
|
import net.wotonomy.ui.swing.util.WindowUtilities; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
public class TreeController implements ActionListener |
| 33 |
|
{ |
| 34 |
|
final EODisplayGroup group; |
| 35 |
|
final EODisplayGroup titlesGroup; |
| 36 |
|
final EODisplayGroup detailGroup; |
| 37 |
|
final EOEditingContext editingContext; |
| 38 |
|
|
| 39 |
0 |
public TreeController( EODataSource aDataSource ) |
| 40 |
0 |
{ |
| 41 |
0 |
titlesGroup = new EODisplayGroup(); |
| 42 |
0 |
group = new EODisplayGroup(); |
| 43 |
0 |
detailGroup = new EODisplayGroup(); |
| 44 |
0 |
titlesGroup.setDataSource( aDataSource ); |
| 45 |
0 |
editingContext = aDataSource.editingContext(); |
| 46 |
0 |
init(); |
| 47 |
0 |
} |
| 48 |
|
|
| 49 |
0 |
public TreeController( EOEditingContext aContext, |
| 50 |
|
EODisplayGroup aTitlesGroup, EODisplayGroup aChildGroup ) |
| 51 |
0 |
{ |
| 52 |
0 |
titlesGroup = aTitlesGroup; |
| 53 |
0 |
group = aChildGroup; |
| 54 |
0 |
detailGroup = new EODisplayGroup(); |
| 55 |
0 |
editingContext = aContext; |
| 56 |
0 |
init(); |
| 57 |
0 |
} |
| 58 |
|
|
| 59 |
|
public void init() |
| 60 |
|
{ |
| 61 |
0 |
final TreePanel treePanel = new TreePanel(); |
| 62 |
0 |
treePanel.panel.setBorder( |
| 63 |
0 |
BorderFactory.createCompoundBorder( |
| 64 |
0 |
BorderFactory.createRaisedBevelBorder(), |
| 65 |
0 |
BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ) ); |
| 66 |
0 |
treePanel.setBorder( |
| 67 |
0 |
BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) ); |
| 68 |
0 |
ButtonPanel okPanel = new ButtonPanel( |
| 69 |
0 |
new String[] { "Refresh", "Commit" } ); |
| 70 |
0 |
treePanel.add( okPanel, BorderLayout.SOUTH ); |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
0 |
treePanel.tree.setEditable( true ); |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
0 |
titlesGroup.fetch(); |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
EOAssociation ta; |
| 101 |
|
|
| 102 |
0 |
ta = new TreeAssociation( treePanel.tree, "People" ); |
| 103 |
0 |
ta.bindAspect( EOAssociation.TitlesAspect, titlesGroup, "fullName" ); |
| 104 |
0 |
ta.bindAspect( EOAssociation.ChildrenAspect, group, "childList" ); |
| 105 |
0 |
ta.bindAspect( EOAssociation.IsLeafAspect, titlesGroup, "childCount" ); |
| 106 |
|
|
| 107 |
0 |
ta.establishConnection(); |
| 108 |
0 |
treePanel.tree.setEditable( true ); |
| 109 |
|
|
| 110 |
0 |
ta = new TextAssociation( treePanel.editPanel.firstNameField ); |
| 111 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "firstName" ); |
| 112 |
0 |
ta.establishConnection(); |
| 113 |
|
|
| 114 |
0 |
ta = new TextAssociation( treePanel.editPanel.middleNameField ); |
| 115 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "middleName" ); |
| 116 |
0 |
ta.establishConnection(); |
| 117 |
|
|
| 118 |
0 |
ta = new TextAssociation( treePanel.editPanel.lastNameField ); |
| 119 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "lastName" ); |
| 120 |
0 |
ta.establishConnection(); |
| 121 |
|
|
| 122 |
0 |
ta = new RadioPanelAssociation( treePanel.editPanel.yearRadioPanel ); |
| 123 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "createDate.year" ); |
| 124 |
|
|
| 125 |
0 |
EODisplayGroup yearTitles = new EODisplayGroup(); |
| 126 |
0 |
yearTitles.setObjectArray( new NSArray( |
| 127 |
0 |
new Object[] { "1999", "2000", "2001" } ) ); |
| 128 |
0 |
ta.bindAspect( EOAssociation.TitlesAspect, yearTitles, "" ); |
| 129 |
|
|
| 130 |
0 |
EODisplayGroup yearObjects = new EODisplayGroup(); |
| 131 |
0 |
yearObjects.setObjectArray( new NSArray( |
| 132 |
0 |
new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) ); |
| 133 |
0 |
ta.bindAspect( EOAssociation.ObjectsAspect, yearObjects, "" ); |
| 134 |
|
|
| 135 |
0 |
ta.establishConnection(); |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
0 |
ta = new MasterDetailAssociation( detailGroup ); |
| 140 |
0 |
ta.bindAspect( EOAssociation.ParentAspect, group, "childList" ); |
| 141 |
0 |
ta.establishConnection(); |
| 142 |
|
|
| 143 |
0 |
ta = new ListAssociation( treePanel.editPanel.list ); |
| 144 |
0 |
ta.bindAspect( EOAssociation.TitlesAspect, detailGroup, "fullName" ); |
| 145 |
0 |
ta.establishConnection(); |
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
0 |
AbstractButton addButton = (AbstractButton) |
| 150 |
0 |
treePanel.editPanel.addPanel.getButton( "Add" ); |
| 151 |
0 |
addButton.addActionListener( new ActionListener() |
| 152 |
|
{ |
| 153 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 154 |
|
{ |
| 155 |
0 |
Object testObject = new TestObject(); |
| 156 |
0 |
editingContext.insertObject( testObject ); |
| 157 |
0 |
detailGroup.insertObjectAtIndex( testObject, 0 ); |
| 158 |
0 |
} |
| 159 |
|
} ); |
| 160 |
|
|
| 161 |
0 |
AbstractButton removeButton = (AbstractButton) |
| 162 |
0 |
treePanel.editPanel.addPanel.getButton( "Remove" ); |
| 163 |
0 |
removeButton.addActionListener( new ActionListener() |
| 164 |
|
{ |
| 165 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 166 |
|
{ |
| 167 |
0 |
if ( detailGroup.selectedObject() != null ) |
| 168 |
0 |
detailGroup.deleteSelection(); |
| 169 |
0 |
} |
| 170 |
|
} ); |
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
AbstractButton button; |
| 175 |
|
|
| 176 |
0 |
button = (AbstractButton) |
| 177 |
0 |
okPanel.getButton( "Commit" ); |
| 178 |
0 |
button.addActionListener( new ActionListener() |
| 179 |
|
{ |
| 180 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 181 |
|
{ |
| 182 |
0 |
editingContext.saveChanges(); |
| 183 |
0 |
} |
| 184 |
|
} ); |
| 185 |
|
|
| 186 |
0 |
button = (AbstractButton) |
| 187 |
0 |
okPanel.getButton( "Refresh" ); |
| 188 |
0 |
button.addActionListener( new ActionListener() |
| 189 |
|
{ |
| 190 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 191 |
|
{ |
| 192 |
0 |
editingContext.revert(); |
| 193 |
|
|
| 194 |
0 |
} |
| 195 |
|
} ); |
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 234 |
|
|
| 235 |
|
|
| 236 |
|
|
| 237 |
|
|
| 238 |
|
|
| 239 |
|
|
| 240 |
0 |
treePanel.editPanel.list.addMouseListener( new MouseAdapter() |
| 241 |
|
{ |
| 242 |
0 |
public void mouseClicked(MouseEvent e) |
| 243 |
|
{ |
| 244 |
0 |
if ( e.getClickCount() == 2 ) |
| 245 |
|
{ |
| 246 |
0 |
Object item = detailGroup.selectedObject(); |
| 247 |
0 |
if ( item != null ) |
| 248 |
|
{ |
| 249 |
0 |
new InspectorController( item ); |
| 250 |
|
} |
| 251 |
|
} |
| 252 |
0 |
} |
| 253 |
|
}); |
| 254 |
|
|
| 255 |
|
|
| 256 |
|
|
| 257 |
0 |
JDialog d = new JDialog(); |
| 258 |
0 |
d.getContentPane().add( treePanel ); |
| 259 |
0 |
d.setTitle( "Tree Panel" ); |
| 260 |
0 |
d.pack(); |
| 261 |
0 |
WindowUtilities.cascade( d ); |
| 262 |
0 |
d.show(); |
| 263 |
|
|
| 264 |
|
|
| 265 |
0 |
d.addWindowListener( new WindowAdapter() |
| 266 |
|
{ |
| 267 |
|
|
| 268 |
0 |
public void windowClosing(WindowEvent e) |
| 269 |
|
{ |
| 270 |
0 |
((JDialog)e.getWindow()).getContentPane().removeAll(); |
| 271 |
0 |
} |
| 272 |
|
}); |
| 273 |
0 |
} |
| 274 |
|
|
| 275 |
|
public void actionPerformed( ActionEvent evt ) |
| 276 |
|
{ |
| 277 |
0 |
Object item = group.selectedObject(); |
| 278 |
0 |
if ( item != null ) |
| 279 |
|
{ |
| 280 |
|
|
| 281 |
0 |
new ObjectInspector( item ); |
| 282 |
|
} |
| 283 |
0 |
} |
| 284 |
|
|
| 285 |
|
} |