| 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.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 |
|
|
| 25 |
|
|
| 26 |
|
public class InspectorController |
| 27 |
|
{ |
| 28 |
0 |
public InspectorController( Object o ) |
| 29 |
0 |
{ |
| 30 |
0 |
EditPanel editPanel = new EditPanel(); |
| 31 |
|
|
| 32 |
0 |
EODisplayGroup group = new EODisplayGroup(); |
| 33 |
0 |
group.setDataSource( new TestDataSource() ); |
| 34 |
0 |
group.setObjectArray( new NSArray( o ) ); |
| 35 |
0 |
group.selectNext(); |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
EOAssociation ta; |
| 40 |
|
|
| 41 |
0 |
ta = new TextAssociation( editPanel.firstNameField ); |
| 42 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "firstName" ); |
| 43 |
0 |
ta.establishConnection(); |
| 44 |
|
|
| 45 |
0 |
ta = new TextAssociation( editPanel.middleNameField ); |
| 46 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "middleName" ); |
| 47 |
0 |
ta.establishConnection(); |
| 48 |
|
|
| 49 |
0 |
ta = new TextAssociation( editPanel.lastNameField ); |
| 50 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "lastName" ); |
| 51 |
0 |
ta.establishConnection(); |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
0 |
ta = new RadioPanelAssociation( editPanel.yearRadioPanel ); |
| 56 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "createDate.year" ); |
| 57 |
|
|
| 58 |
0 |
EODisplayGroup yearTitles = new EODisplayGroup(); |
| 59 |
0 |
yearTitles.setObjectArray( new NSArray( |
| 60 |
0 |
new Object[] { "1999", "2000", "2001" } ) ); |
| 61 |
0 |
ta.bindAspect( EOAssociation.TitlesAspect, yearTitles, "" ); |
| 62 |
|
|
| 63 |
0 |
EODisplayGroup yearObjects = new EODisplayGroup(); |
| 64 |
0 |
yearObjects.setObjectArray( new NSArray( |
| 65 |
0 |
new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) ); |
| 66 |
0 |
ta.bindAspect( EOAssociation.ObjectsAspect, yearObjects, "" ); |
| 67 |
|
|
| 68 |
0 |
ta.establishConnection(); |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
0 |
final EODisplayGroup detailGroup = new EODisplayGroup(); |
| 73 |
|
|
| 74 |
0 |
ta = new MasterDetailAssociation( detailGroup ); |
| 75 |
0 |
ta.bindAspect( EOAssociation.ParentAspect, group, "childList" ); |
| 76 |
0 |
ta.establishConnection(); |
| 77 |
|
|
| 78 |
0 |
ta = new ListAssociation( editPanel.list ); |
| 79 |
0 |
ta.bindAspect( EOAssociation.TitlesAspect, detailGroup, "fullName" ); |
| 80 |
0 |
ta.establishConnection(); |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
0 |
AbstractButton button = (AbstractButton) |
| 85 |
0 |
editPanel.addPanel.getButton( "Add" ); |
| 86 |
0 |
button.addActionListener( new ActionListener() |
| 87 |
|
{ |
| 88 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 89 |
|
{ |
| 90 |
0 |
detailGroup.insertNewObjectAtIndex( 0 ); |
| 91 |
0 |
} |
| 92 |
|
} ); |
| 93 |
|
|
| 94 |
0 |
ta = new DisplayGroupActionAssociation( |
| 95 |
0 |
editPanel.addPanel.getButton( "Remove" ) ); |
| 96 |
0 |
ta.bindAspect( EOAssociation.ActionAspect, detailGroup, "deleteSelection" ); |
| 97 |
0 |
ta.establishConnection(); |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
0 |
editPanel.list.addMouseListener( new MouseAdapter() |
| 102 |
|
{ |
| 103 |
0 |
public void mouseClicked(MouseEvent e) |
| 104 |
|
{ |
| 105 |
0 |
if ( e.getClickCount() == 2 ) |
| 106 |
|
{ |
| 107 |
0 |
Object item = detailGroup.selectedObject(); |
| 108 |
0 |
if ( item != null ) |
| 109 |
|
{ |
| 110 |
0 |
new InspectorController( item ); |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
0 |
} |
| 114 |
|
}); |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
0 |
JDialog dialog = new JDialog(); |
| 119 |
0 |
dialog.getContentPane().add( editPanel ); |
| 120 |
0 |
dialog.setTitle( "Inspector Panel" ); |
| 121 |
0 |
dialog.pack(); |
| 122 |
0 |
dialog.setSize( 300, dialog.getSize().height ); |
| 123 |
0 |
WindowUtilities.cascade( dialog ); |
| 124 |
0 |
dialog.show(); |
| 125 |
|
|
| 126 |
|
|
| 127 |
0 |
dialog.addWindowListener( new WindowAdapter() |
| 128 |
|
{ |
| 129 |
|
|
| 130 |
0 |
public void windowClosing(WindowEvent e) |
| 131 |
|
{ |
| 132 |
0 |
((JDialog)e.getWindow()).getContentPane().removeAll(); |
| 133 |
0 |
} |
| 134 |
|
}); |
| 135 |
0 |
} |
| 136 |
|
|
| 137 |
|
} |