| 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 |
|
import javax.swing.JFrame; |
| 15 |
|
|
| 16 |
|
import net.wotonomy.control.ChildDataSource; |
| 17 |
|
import net.wotonomy.control.EODataSource; |
| 18 |
|
import net.wotonomy.control.PropertyDataSource; |
| 19 |
|
import net.wotonomy.foundation.NSArray; |
| 20 |
|
import net.wotonomy.ui.EOAssociation; |
| 21 |
|
import net.wotonomy.ui.EODisplayGroup; |
| 22 |
|
import net.wotonomy.ui.MasterDetailAssociation; |
| 23 |
|
import net.wotonomy.ui.swing.DisplayGroupActionAssociation; |
| 24 |
|
import net.wotonomy.ui.swing.ListAssociation; |
| 25 |
|
import net.wotonomy.ui.swing.RadioPanelAssociation; |
| 26 |
|
import net.wotonomy.ui.swing.TextAssociation; |
| 27 |
|
import net.wotonomy.ui.swing.components.ButtonPanel; |
| 28 |
|
import net.wotonomy.ui.swing.util.WindowUtilities; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
public class EditController |
| 34 |
|
{ |
| 35 |
|
EODisplayGroup group; |
| 36 |
|
JDialog dialog; |
| 37 |
|
|
| 38 |
0 |
public EditController( EODataSource aDataSource ) |
| 39 |
0 |
{ |
| 40 |
0 |
EditPanel editPanel = new EditPanel(); |
| 41 |
0 |
editPanel.infoPanel.setBorder( |
| 42 |
0 |
BorderFactory.createCompoundBorder( |
| 43 |
0 |
BorderFactory.createRaisedBevelBorder(), |
| 44 |
0 |
BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ) ); |
| 45 |
0 |
editPanel.setBorder( |
| 46 |
0 |
BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) ); |
| 47 |
0 |
ButtonPanel okPanel = new ButtonPanel( |
| 48 |
0 |
new String[] { "Revert", "Refault", "Refresh", "Commit" } ); |
| 49 |
0 |
editPanel.add( okPanel, BorderLayout.SOUTH ); |
| 50 |
|
|
| 51 |
0 |
group = new EODisplayGroup(); |
| 52 |
0 |
group.setDataSource( aDataSource ); |
| 53 |
0 |
group.fetch(); |
| 54 |
0 |
group.selectNext(); |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
EOAssociation ta; |
| 59 |
|
|
| 60 |
0 |
ta = new TextAssociation( editPanel.firstNameField ); |
| 61 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "firstName" ); |
| 62 |
0 |
ta.establishConnection(); |
| 63 |
|
|
| 64 |
0 |
ta = new TextAssociation( editPanel.middleNameField ); |
| 65 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "middleName" ); |
| 66 |
0 |
ta.establishConnection(); |
| 67 |
|
|
| 68 |
0 |
ta = new TextAssociation( editPanel.lastNameField ); |
| 69 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "lastName" ); |
| 70 |
0 |
ta.establishConnection(); |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
0 |
ta = new RadioPanelAssociation( editPanel.yearRadioPanel ); |
| 75 |
0 |
ta.bindAspect( EOAssociation.ValueAspect, group, "createDate.year" ); |
| 76 |
|
|
| 77 |
0 |
EODisplayGroup yearTitles = new EODisplayGroup(); |
| 78 |
0 |
yearTitles.setObjectArray( new NSArray( |
| 79 |
0 |
new Object[] { "1999", "2000", "2001" } ) ); |
| 80 |
0 |
ta.bindAspect( EOAssociation.TitlesAspect, yearTitles, "" ); |
| 81 |
|
|
| 82 |
0 |
EODisplayGroup yearObjects = new EODisplayGroup(); |
| 83 |
0 |
yearObjects.setObjectArray( new NSArray( |
| 84 |
0 |
new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) ); |
| 85 |
0 |
ta.bindAspect( EOAssociation.ObjectsAspect, yearObjects, "" ); |
| 86 |
|
|
| 87 |
0 |
ta.establishConnection(); |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
0 |
final EODisplayGroup detailGroup = new EODisplayGroup(); |
| 92 |
0 |
detailGroup.setDataSource( new PropertyDataSource( |
| 93 |
0 |
aDataSource.editingContext(), TestObject.class ) ); |
| 94 |
|
|
| 95 |
0 |
ta = new MasterDetailAssociation( detailGroup ); |
| 96 |
0 |
ta.bindAspect( EOAssociation.ParentAspect, group, "childList" ); |
| 97 |
0 |
ta.establishConnection(); |
| 98 |
|
|
| 99 |
0 |
ta = new ListAssociation( editPanel.list ); |
| 100 |
0 |
ta.bindAspect( EOAssociation.TitlesAspect, detailGroup, "fullName" ); |
| 101 |
0 |
ta.establishConnection(); |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
0 |
AbstractButton button = (AbstractButton) |
| 106 |
0 |
editPanel.addPanel.getButton( "Add" ); |
| 107 |
0 |
button.addActionListener( new ActionListener() |
| 108 |
|
{ |
| 109 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 110 |
|
{ |
| 111 |
0 |
detailGroup.insertNewObjectAtIndex( 0 ); |
| 112 |
0 |
} |
| 113 |
|
} ); |
| 114 |
|
|
| 115 |
0 |
ta = new DisplayGroupActionAssociation( |
| 116 |
0 |
editPanel.addPanel.getButton( "Remove" ) ); |
| 117 |
0 |
ta.bindAspect( EOAssociation.ActionAspect, detailGroup, "deleteSelection" ); |
| 118 |
0 |
ta.establishConnection(); |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
0 |
button = (AbstractButton) |
| 123 |
0 |
okPanel.getButton( "Commit" ); |
| 124 |
0 |
button.addActionListener( new ActionListener() |
| 125 |
|
{ |
| 126 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 127 |
|
{ |
| 128 |
0 |
group.dataSource().editingContext().saveChanges(); |
| 129 |
0 |
} |
| 130 |
|
} ); |
| 131 |
|
|
| 132 |
0 |
button = (AbstractButton) |
| 133 |
0 |
okPanel.getButton( "Refresh" ); |
| 134 |
0 |
button.addActionListener( new ActionListener() |
| 135 |
|
{ |
| 136 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 137 |
|
{ |
| 138 |
0 |
group.dataSource().editingContext().invalidateAllObjects(); |
| 139 |
0 |
} |
| 140 |
|
} ); |
| 141 |
|
|
| 142 |
0 |
button = (AbstractButton) |
| 143 |
0 |
okPanel.getButton( "Refault" ); |
| 144 |
0 |
button.addActionListener( new ActionListener() |
| 145 |
|
{ |
| 146 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 147 |
|
{ |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
0 |
group.dataSource().editingContext().revert(); |
| 156 |
0 |
group.dataSource().editingContext().refaultObjects(); |
| 157 |
0 |
} |
| 158 |
|
} ); |
| 159 |
|
|
| 160 |
0 |
button = (AbstractButton) |
| 161 |
0 |
okPanel.getButton( "Revert" ); |
| 162 |
0 |
button.addActionListener( new ActionListener() |
| 163 |
|
{ |
| 164 |
0 |
public void actionPerformed( ActionEvent evt ) |
| 165 |
|
{ |
| 166 |
0 |
group.dataSource().editingContext().revert(); |
| 167 |
0 |
} |
| 168 |
|
} ); |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
0 |
editPanel.list.addMouseListener( new MouseAdapter() |
| 173 |
|
{ |
| 174 |
0 |
public void mouseClicked(MouseEvent e) |
| 175 |
|
{ |
| 176 |
0 |
if ( e.getClickCount() == 2 ) |
| 177 |
|
{ |
| 178 |
0 |
Object item = detailGroup.selectedObject(); |
| 179 |
0 |
if ( item != null ) |
| 180 |
|
{ |
| 181 |
|
|
| 182 |
|
|
| 183 |
0 |
new EditController( |
| 184 |
0 |
new ChildDataSource( |
| 185 |
0 |
group.dataSource(), item ) ); |
| 186 |
|
} |
| 187 |
|
} |
| 188 |
0 |
} |
| 189 |
|
}); |
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
0 |
dialog = new JDialog(); |
| 194 |
|
|
| 195 |
0 |
dialog.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); |
| 196 |
0 |
dialog.getContentPane().add( editPanel ); |
| 197 |
0 |
dialog.setTitle( "Edit Panel" ); |
| 198 |
0 |
dialog.pack(); |
| 199 |
|
|
| 200 |
0 |
WindowUtilities.cascade( dialog ); |
| 201 |
0 |
dialog.show(); |
| 202 |
|
|
| 203 |
|
|
| 204 |
0 |
dialog.addWindowListener( new WindowAdapter() |
| 205 |
|
{ |
| 206 |
|
|
| 207 |
0 |
public void windowClosing(WindowEvent e) |
| 208 |
|
{ |
| 209 |
0 |
((JDialog)e.getWindow()).getContentPane().removeAll(); |
| 210 |
0 |
} |
| 211 |
|
}); |
| 212 |
0 |
} |
| 213 |
|
|
| 214 |
|
} |