diff options
Diffstat (limited to 'projects/net.wotonomy.test/src/main/java/net/wotonomy/test/InspectorController.java')
| -rw-r--r-- | projects/net.wotonomy.test/src/main/java/net/wotonomy/test/InspectorController.java | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/InspectorController.java b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/InspectorController.java new file mode 100644 index 0000000..58e2d9a --- /dev/null +++ b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/InspectorController.java @@ -0,0 +1,137 @@ +package net.wotonomy.test; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.AbstractButton; +import javax.swing.JDialog; + +import net.wotonomy.foundation.NSArray; +import net.wotonomy.ui.EOAssociation; +import net.wotonomy.ui.EODisplayGroup; +import net.wotonomy.ui.MasterDetailAssociation; +import net.wotonomy.ui.swing.DisplayGroupActionAssociation; +import net.wotonomy.ui.swing.ListAssociation; +import net.wotonomy.ui.swing.RadioPanelAssociation; +import net.wotonomy.ui.swing.TextAssociation; +import net.wotonomy.ui.swing.util.WindowUtilities; + +/** +* A simple editor panel with a few textfields. +*/ +public class InspectorController +{ + public InspectorController( Object o ) + { + EditPanel editPanel = new EditPanel(); + + EODisplayGroup group = new EODisplayGroup(); + group.setDataSource( new TestDataSource() ); + group.setObjectArray( new NSArray( o ) ); + group.selectNext(); + + // text associations + + EOAssociation ta; + + ta = new TextAssociation( editPanel.firstNameField ); + ta.bindAspect( EOAssociation.ValueAspect, group, "firstName" ); + ta.establishConnection(); + + ta = new TextAssociation( editPanel.middleNameField ); + ta.bindAspect( EOAssociation.ValueAspect, group, "middleName" ); + ta.establishConnection(); + + ta = new TextAssociation( editPanel.lastNameField ); + ta.bindAspect( EOAssociation.ValueAspect, group, "lastName" ); + ta.establishConnection(); + + // radio panels + + ta = new RadioPanelAssociation( editPanel.yearRadioPanel ); + ta.bindAspect( EOAssociation.ValueAspect, group, "createDate.year" ); + + EODisplayGroup yearTitles = new EODisplayGroup(); + yearTitles.setObjectArray( new NSArray( + new Object[] { "1999", "2000", "2001" } ) ); + ta.bindAspect( EOAssociation.TitlesAspect, yearTitles, "" ); + + EODisplayGroup yearObjects = new EODisplayGroup(); + yearObjects.setObjectArray( new NSArray( + new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) ); + ta.bindAspect( EOAssociation.ObjectsAspect, yearObjects, "" ); + + ta.establishConnection(); + + // detail group + + final EODisplayGroup detailGroup = new EODisplayGroup(); + + ta = new MasterDetailAssociation( detailGroup ); + ta.bindAspect( EOAssociation.ParentAspect, group, "childList" ); + ta.establishConnection(); + + ta = new ListAssociation( editPanel.list ); + ta.bindAspect( EOAssociation.TitlesAspect, detailGroup, "fullName" ); + ta.establishConnection(); + + // display group action associations + + AbstractButton button = (AbstractButton) + editPanel.addPanel.getButton( "Add" ); + button.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent evt ) + { + detailGroup.insertNewObjectAtIndex( 0 ); + } + } ); + + ta = new DisplayGroupActionAssociation( + editPanel.addPanel.getButton( "Remove" ) ); + ta.bindAspect( EOAssociation.ActionAspect, detailGroup, "deleteSelection" ); + ta.establishConnection(); + + // add mouse listener for list + + editPanel.list.addMouseListener( new MouseAdapter() + { + public void mouseClicked(MouseEvent e) + { + if ( e.getClickCount() == 2 ) + { + Object item = detailGroup.selectedObject(); + if ( item != null ) + { + new InspectorController( item ); + } + } + } + }); + + // launch + + JDialog dialog = new JDialog(); + dialog.getContentPane().add( editPanel ); + dialog.setTitle( "Inspector Panel" ); + dialog.pack(); + dialog.setSize( 300, dialog.getSize().height ); + WindowUtilities.cascade( dialog ); + dialog.show(); + + // workaround for memory issues on jdk1.2.2 + dialog.addWindowListener( new WindowAdapter() + { + // exit on close + public void windowClosing(WindowEvent e) + { + ((JDialog)e.getWindow()).getContentPane().removeAll(); + } + }); + } + +} |
