| 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.text.DateFormat; |
| 8 |
|
import java.util.Iterator; |
| 9 |
|
import java.util.LinkedList; |
| 10 |
|
import java.util.List; |
| 11 |
|
|
| 12 |
|
import javax.swing.AbstractButton; |
| 13 |
|
import javax.swing.Icon; |
| 14 |
|
import javax.swing.JButton; |
| 15 |
|
import javax.swing.JComponent; |
| 16 |
|
import javax.swing.JOptionPane; |
| 17 |
|
import javax.swing.UIManager; |
| 18 |
|
import javax.swing.table.TableColumn; |
| 19 |
|
|
| 20 |
|
import net.wotonomy.control.ChildDataSource; |
| 21 |
|
import net.wotonomy.control.EOEditingContext; |
| 22 |
|
import net.wotonomy.control.EOGlobalID; |
| 23 |
|
import net.wotonomy.control.EOKeyValueQualifier; |
| 24 |
|
import net.wotonomy.control.EOQualifier; |
| 25 |
|
import net.wotonomy.foundation.NSArray; |
| 26 |
|
import net.wotonomy.foundation.NSNotification; |
| 27 |
|
import net.wotonomy.ui.EOAssociation; |
| 28 |
|
import net.wotonomy.ui.EODisplayGroup; |
| 29 |
|
import net.wotonomy.ui.swing.ButtonAssociation; |
| 30 |
|
import net.wotonomy.ui.swing.ComboBoxAssociation; |
| 31 |
|
import net.wotonomy.ui.swing.DisplayGroupActionAssociation; |
| 32 |
|
import net.wotonomy.ui.swing.SliderAssociation; |
| 33 |
|
import net.wotonomy.ui.swing.TableColumnAssociation; |
| 34 |
|
import net.wotonomy.ui.swing.TextAssociation; |
| 35 |
|
import net.wotonomy.ui.swing.TreeColumnAssociation; |
| 36 |
|
import net.wotonomy.ui.swing.components.AlternatingRowCellRenderer; |
| 37 |
|
import net.wotonomy.ui.swing.components.FormattedCellRenderer; |
| 38 |
|
import net.wotonomy.ui.swing.components.IconCellRenderer; |
| 39 |
|
import net.wotonomy.ui.swing.components.KeyableCellEditor; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
public class TestController implements ActionListener |
| 45 |
|
{ |
| 46 |
|
EODisplayGroup displayGroup; |
| 47 |
|
TestPanel panel; |
| 48 |
|
|
| 49 |
0 |
public TestController( TestPanel aPanel ) |
| 50 |
0 |
{ |
| 51 |
0 |
panel = aPanel; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
0 |
displayGroup = new EODisplayGroup(); |
| 56 |
0 |
displayGroup.setSortOrderings( new NSArray( new Object[] |
| 57 |
0 |
{ "firstName", "middleName", "lastName" } ) ); |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
0 |
displayGroup.setDataSource( new TestDataSource() ); |
| 62 |
|
|
| 63 |
0 |
displayGroup.fetch(); |
| 64 |
0 |
displayGroup.selectNext(); |
| 65 |
|
|
| 66 |
0 |
displayGroup.setDelegate( this ); |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
EOAssociation assoc; |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
TableColumn column; |
| 75 |
|
|
| 76 |
0 |
column = new TableColumn(); |
| 77 |
0 |
column.setHeaderValue( "First" ); |
| 78 |
0 |
IconCellRenderer iconRenderer = new IconCellRenderer() |
| 79 |
|
{ |
| 80 |
0 |
private Icon icon = UIManager.getIcon("FileChooser.homeFolderIcon"); |
| 81 |
0 |
public Icon getIconForContext( |
| 82 |
|
JComponent container, Object value, |
| 83 |
|
int row, int col, |
| 84 |
|
boolean isSelected, boolean hasFocus, |
| 85 |
|
boolean isExpanded, boolean isLeaf ) |
| 86 |
|
{ |
| 87 |
0 |
return icon; |
| 88 |
|
} |
| 89 |
|
}; |
| 90 |
0 |
iconRenderer.addActionListener( this ); |
| 91 |
0 |
column.setCellRenderer( new AlternatingRowCellRenderer( iconRenderer ) ); |
| 92 |
|
|
| 93 |
|
|
| 94 |
0 |
assoc = new TreeColumnAssociation( column ); |
| 95 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "firstName" ); |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
0 |
assoc.bindAspect( EOAssociation.EditableAspect, null, "true" ); |
| 100 |
0 |
assoc.bindAspect( EOAssociation.IsLeafAspect, null, "childCount" ); |
| 101 |
0 |
((TableColumnAssociation)assoc).setTable( panel.table ); |
| 102 |
0 |
assoc.establishConnection(); |
| 103 |
0 |
((TreeColumnAssociation)assoc).getTreeModelAssociation().setInsertingAfter( false ); |
| 104 |
0 |
((TreeColumnAssociation)assoc).getTreeModelAssociation().setInsertingChild( false ); |
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
0 |
column = new TableColumn(); |
| 116 |
0 |
column.setHeaderValue( "Middle" ); |
| 117 |
0 |
column.setCellRenderer( new AlternatingRowCellRenderer() ); |
| 118 |
0 |
assoc = new TableColumnAssociation( column ); |
| 119 |
0 |
((TableColumnAssociation)assoc).setSortCaseSensitive( true ); |
| 120 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "middleName" ); |
| 121 |
0 |
((TableColumnAssociation)assoc).setTable( panel.table ); |
| 122 |
0 |
assoc.establishConnection(); |
| 123 |
|
|
| 124 |
0 |
column = new TableColumn(); |
| 125 |
0 |
column.setHeaderValue( "Last" ); |
| 126 |
0 |
column.setCellRenderer( new AlternatingRowCellRenderer() ); |
| 127 |
0 |
column.setCellEditor( new KeyableCellEditor() ); |
| 128 |
0 |
assoc = new TableColumnAssociation( column ); |
| 129 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "lastName" ); |
| 130 |
0 |
assoc.bindAspect( EOAssociation.EditableAspect, null, "true" ); |
| 131 |
0 |
((TableColumnAssociation)assoc).setTable( panel.table ); |
| 132 |
0 |
assoc.establishConnection(); |
| 133 |
|
|
| 134 |
0 |
column = new TableColumn(); |
| 135 |
0 |
column.setHeaderValue( "Created" ); |
| 136 |
0 |
FormattedCellRenderer renderer = new FormattedCellRenderer(); |
| 137 |
0 |
renderer.setFormat( DateFormat.getDateInstance() ); |
| 138 |
0 |
column.setCellRenderer( new AlternatingRowCellRenderer( renderer ) ); |
| 139 |
0 |
assoc = new TableColumnAssociation( column ); |
| 140 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate" ); |
| 141 |
0 |
((TableColumnAssociation)assoc).setTable( panel.table ); |
| 142 |
0 |
assoc.establishConnection(); |
| 143 |
|
|
| 144 |
0 |
column = new TableColumn(); |
| 145 |
0 |
column.setHeaderValue( "Special" ); |
| 146 |
0 |
column.setCellRenderer( new AlternatingRowCellRenderer( |
| 147 |
0 |
panel.table.getDefaultRenderer( Boolean.class ) ) ); |
| 148 |
0 |
assoc = new TableColumnAssociation( column ); |
| 149 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "special" ); |
| 150 |
0 |
assoc.bindAspect( EOAssociation.EditableAspect, null, "true" ); |
| 151 |
0 |
((TableColumnAssociation)assoc).setTable( panel.table ); |
| 152 |
0 |
assoc.establishConnection(); |
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
0 |
assoc = new TextAssociation( panel.firstNameField ); |
| 157 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "firstName" ); |
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
0 |
assoc.establishConnection(); |
| 163 |
|
|
| 164 |
0 |
assoc = new TextAssociation( panel.middleNameField ); |
| 165 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "middleName" ); |
| 166 |
0 |
assoc.establishConnection(); |
| 167 |
|
|
| 168 |
0 |
assoc = new TextAssociation( panel.lastNameField ); |
| 169 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "lastName" ); |
| 170 |
0 |
assoc.bindAspect( EOAssociation.LabelAspect, displayGroup, "special" ); |
| 171 |
0 |
assoc.establishConnection(); |
| 172 |
|
|
| 173 |
0 |
assoc = new ButtonAssociation( panel.checkbox ); |
| 174 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "special" ); |
| 175 |
|
|
| 176 |
|
|
| 177 |
0 |
assoc.establishConnection(); |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
0 |
assoc = new ComboBoxAssociation( panel.dateBox ); |
| 182 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate.date" ); |
| 183 |
|
|
| 184 |
0 |
assoc.establishConnection(); |
| 185 |
|
|
| 186 |
0 |
assoc = new ComboBoxAssociation( panel.monthBox ); |
| 187 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate.month" ); |
| 188 |
0 |
EODisplayGroup monthTitlesGroup = new EODisplayGroup(); |
| 189 |
0 |
monthTitlesGroup.setObjectArray( new NSArray( |
| 190 |
0 |
new Object[] { "January", "February", "March", "April", "May", "June", |
| 191 |
0 |
"July", "August", "September", "October", "November", "December" } ) ); |
| 192 |
0 |
assoc.bindAspect( EOAssociation.TitlesAspect, monthTitlesGroup, "" ); |
| 193 |
|
|
| 194 |
0 |
EODisplayGroup monthObjectsGroup = new EODisplayGroup(); |
| 195 |
0 |
monthObjectsGroup.setObjectArray( new NSArray( |
| 196 |
0 |
new Object[] { new Integer( 0 ), |
| 197 |
0 |
new Integer( 1 ), new Integer( 2 ), new Integer( 3 ), |
| 198 |
0 |
new Integer( 4 ), new Integer( 5 ), new Integer( 6 ), |
| 199 |
0 |
new Integer( 7 ), new Integer( 8 ), new Integer( 9 ), |
| 200 |
0 |
new Integer( 10 ), new Integer( 11 ) } ) ); |
| 201 |
0 |
assoc.bindAspect( EOAssociation.ObjectsAspect, monthObjectsGroup, "" ); |
| 202 |
|
|
| 203 |
0 |
assoc.establishConnection(); |
| 204 |
|
|
| 205 |
|
|
| 206 |
0 |
assoc = new ComboBoxAssociation( panel.yearBox ); |
| 207 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate.year" ); |
| 208 |
|
|
| 209 |
0 |
EODisplayGroup yearTitlesGroup = new EODisplayGroup(); |
| 210 |
0 |
yearTitlesGroup.setObjectArray( new NSArray( |
| 211 |
0 |
new Object[] { "1999", "2000", "2001" } ) ); |
| 212 |
0 |
assoc.bindAspect( EOAssociation.TitlesAspect, yearTitlesGroup, "" ); |
| 213 |
|
|
| 214 |
0 |
EODisplayGroup yearObjectsGroup = new EODisplayGroup(); |
| 215 |
0 |
yearObjectsGroup.setObjectArray( new NSArray( |
| 216 |
0 |
new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) ); |
| 217 |
0 |
assoc.bindAspect( EOAssociation.ObjectsAspect, yearObjectsGroup, "" ); |
| 218 |
|
|
| 219 |
0 |
assoc.establishConnection(); |
| 220 |
|
|
| 221 |
0 |
assoc = new SliderAssociation( panel.slider ); |
| 222 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate.date" ); |
| 223 |
0 |
assoc.bindAspect( EOAssociation.VisibleAspect, displayGroup, "special" ); |
| 224 |
0 |
assoc.establishConnection(); |
| 225 |
|
|
| 226 |
0 |
assoc = new TextAssociation( panel.infoPanel.getLabelForKey( "Day of Month" ) ); |
| 227 |
0 |
assoc.bindAspect( EOAssociation.VisibleAspect, displayGroup, "special" ); |
| 228 |
0 |
assoc.establishConnection(); |
| 229 |
|
|
| 230 |
|
|
| 231 |
|
AbstractButton button; |
| 232 |
|
|
| 233 |
0 |
button = (AbstractButton) |
| 234 |
0 |
panel.savePanel.getButton( "Refresh All" ); |
| 235 |
0 |
button.addActionListener( new ActionListener() |
| 236 |
|
{ |
| 237 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 238 |
|
{ |
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
0 |
displayGroup.dataSource().editingContext().invalidateAllObjects(); |
| 243 |
|
|
| 244 |
|
|
| 245 |
0 |
} |
| 246 |
|
} ); |
| 247 |
|
|
| 248 |
0 |
button = (AbstractButton) |
| 249 |
0 |
panel.savePanel.getButton( "Commit" ); |
| 250 |
0 |
button.addActionListener( new ActionListener() |
| 251 |
|
{ |
| 252 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 253 |
|
{ |
| 254 |
|
try |
| 255 |
|
{ |
| 256 |
0 |
displayGroup.dataSource().editingContext().saveChanges(); |
| 257 |
|
} |
| 258 |
0 |
catch ( RuntimeException exc ) |
| 259 |
|
{ |
| 260 |
0 |
JOptionPane.showMessageDialog( |
| 261 |
0 |
(java.awt.Component)evt.getSource(), exc.getMessage() ); |
| 262 |
0 |
exc.printStackTrace(); |
| 263 |
0 |
} |
| 264 |
0 |
} |
| 265 |
|
} ); |
| 266 |
|
|
| 267 |
0 |
button = (AbstractButton) |
| 268 |
0 |
panel.buttonPanel.getButton( "Add" ); |
| 269 |
0 |
button.addActionListener( new ActionListener() |
| 270 |
|
{ |
| 271 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 272 |
|
{ |
| 273 |
0 |
displayGroup.insertNewObjectAtIndex( 0 ); |
| 274 |
0 |
} |
| 275 |
|
} ); |
| 276 |
|
|
| 277 |
0 |
assoc = new DisplayGroupActionAssociation( |
| 278 |
0 |
panel.buttonPanel.getButton( "Remove" ) ); |
| 279 |
0 |
assoc.bindAspect( EOAssociation.ActionAspect, displayGroup, "deleteSelection" ); |
| 280 |
0 |
assoc.establishConnection(); |
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
| 284 |
|
|
| 285 |
|
|
| 286 |
|
|
| 287 |
|
|
| 288 |
|
|
| 289 |
|
|
| 290 |
|
|
| 291 |
|
|
| 292 |
|
|
| 293 |
0 |
panel.table.addMouseListener( new MouseAdapter() |
| 294 |
|
{ |
| 295 |
0 |
public void mouseClicked(MouseEvent e) |
| 296 |
|
{ |
| 297 |
0 |
if ( e.getClickCount() == 2 ) |
| 298 |
|
{ |
| 299 |
0 |
Object o = displayGroup.selectedObject(); |
| 300 |
0 |
if ( o != null ) |
| 301 |
|
{ |
| 302 |
|
|
| 303 |
0 |
new EditController( |
| 304 |
0 |
new ChildDataSource( |
| 305 |
0 |
displayGroup.dataSource(), o ) ); |
| 306 |
|
} |
| 307 |
|
} |
| 308 |
0 |
} |
| 309 |
|
}); |
| 310 |
|
|
| 311 |
|
|
| 312 |
0 |
((JButton) panel.buttonPanel.getButton( |
| 313 |
0 |
"Tree View" ) ).addActionListener( new ActionListener() |
| 314 |
|
{ |
| 315 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 316 |
|
{ |
| 317 |
0 |
EOEditingContext parentContext = Test.editingContext; |
| 318 |
0 |
EOEditingContext childContext = new EOEditingContext( parentContext ); |
| 319 |
|
|
| 320 |
|
|
| 321 |
0 |
List ids = new LinkedList(); |
| 322 |
0 |
Iterator i = displayGroup.selectedObjects().iterator(); |
| 323 |
0 |
while ( i.hasNext() ) |
| 324 |
|
{ |
| 325 |
0 |
ids.add( parentContext.globalIDForObject( i.next() ) ); |
| 326 |
0 |
} |
| 327 |
0 |
List objects = new LinkedList(); |
| 328 |
0 |
i = ids.iterator(); |
| 329 |
0 |
while( i.hasNext() ) |
| 330 |
|
{ |
| 331 |
0 |
objects.add( childContext.faultForGlobalID( (EOGlobalID) i.next(), childContext ) ); |
| 332 |
0 |
} |
| 333 |
|
|
| 334 |
0 |
EODisplayGroup treeGroup = new EODisplayGroup(); |
| 335 |
0 |
treeGroup.setSortOrderings( new NSArray( "lastName" ) ); |
| 336 |
0 |
treeGroup.setObjectArray( objects ); |
| 337 |
|
|
| 338 |
0 |
EODisplayGroup childGroup = new EODisplayGroup(); |
| 339 |
|
|
| 340 |
|
|
| 341 |
|
|
| 342 |
|
|
| 343 |
|
|
| 344 |
0 |
new TreeController( childContext, treeGroup, childGroup ); |
| 345 |
|
|
| 346 |
|
|
| 347 |
|
|
| 348 |
|
|
| 349 |
0 |
} |
| 350 |
|
}); |
| 351 |
|
|
| 352 |
|
|
| 353 |
|
|
| 354 |
|
|
| 355 |
|
|
| 356 |
|
|
| 357 |
|
|
| 358 |
0 |
} |
| 359 |
|
|
| 360 |
|
private String filter; |
| 361 |
|
public String getFilter() |
| 362 |
|
{ |
| 363 |
0 |
return filter; |
| 364 |
|
} |
| 365 |
|
|
| 366 |
|
public void setFilter( String aFilter ) |
| 367 |
|
{ |
| 368 |
0 |
filter = aFilter; |
| 369 |
|
|
| 370 |
0 |
EOQualifier qualifier = null; |
| 371 |
0 |
if ( ! "".equals( aFilter ) ) |
| 372 |
|
{ |
| 373 |
0 |
qualifier = new EOKeyValueQualifier( |
| 374 |
0 |
"firstName", EOQualifier.QualifierOperatorContains, filter ); |
| 375 |
|
} |
| 376 |
0 |
displayGroup.setQualifier( qualifier ); |
| 377 |
0 |
displayGroup.updateDisplayedObjects(); |
| 378 |
0 |
} |
| 379 |
|
|
| 380 |
|
public void hitMe( NSNotification aNote ) |
| 381 |
|
{ |
| 382 |
0 |
System.out.println( aNote ); |
| 383 |
0 |
} |
| 384 |
|
|
| 385 |
|
public void actionPerformed( ActionEvent evt ) |
| 386 |
|
{ |
| 387 |
0 |
Object o = displayGroup.selectedObject(); |
| 388 |
0 |
if ( o != null ) |
| 389 |
|
{ |
| 390 |
|
|
| 391 |
0 |
new InspectorController( o ); |
| 392 |
|
} |
| 393 |
0 |
} |
| 394 |
|
|
| 395 |
|
} |