Coverage Report - net.wotonomy.test.TreeInspectorController
 
Classes in this File Line Coverage Branch Coverage Complexity
TreeInspectorController
0% 
0% 
1.6
 
 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.ListAssociation;
 18  
 import net.wotonomy.ui.swing.RadioPanelAssociation;
 19  
 import net.wotonomy.ui.swing.TextAssociation;
 20  
 import net.wotonomy.ui.swing.TreeAssociation;
 21  
 import net.wotonomy.ui.swing.util.WindowUtilities;
 22  
 
 23  
 /**
 24  
 * A simple editor panel with a few textfields.
 25  
 */
 26  
 public class TreeInspectorController 
 27  
 {    
 28  0
     public TreeInspectorController( EODisplayGroup titlesGroup, EODisplayGroup childrenGroup )
 29  0
     {
 30  0
         final EODisplayGroup group = childrenGroup;
 31  
 //        final EODisplayGroup group = titlesGroup;
 32  0
                 final TreePanel treePanel = new TreePanel();
 33  
                 
 34  
                 // text associations
 35  
                 
 36  
                 EOAssociation ta;
 37  
                 
 38  0
                 ta = new TreeAssociation( treePanel.tree, "People" );
 39  0
                 ta.bindAspect( EOAssociation.TitlesAspect, titlesGroup, "lastName" );
 40  0
                 ta.bindAspect( EOAssociation.ChildrenAspect, group, "childList" );
 41  0
                 ta.bindAspect( EOAssociation.IsLeafAspect, titlesGroup, "childCount" );
 42  
 //                ta.bindAspect( EOAssociation.IsLeafAspect, null, "false" );
 43  0
                 ta.establishConnection();
 44  0
                 treePanel.tree.setEditable( true );
 45  
                 
 46  0
         ta = new TextAssociation( treePanel.editPanel.firstNameField );
 47  0
         ta.bindAspect( EOAssociation.ValueAspect, group, "firstName" );
 48  0
                 ta.establishConnection();
 49  
         
 50  0
         ta = new TextAssociation( treePanel.editPanel.middleNameField );
 51  0
         ta.bindAspect( EOAssociation.ValueAspect, group, "middleName" );
 52  0
                 ta.establishConnection();
 53  
         
 54  0
         ta = new TextAssociation( treePanel.editPanel.lastNameField );
 55  0
         ta.bindAspect( EOAssociation.ValueAspect, group, "lastName" );
 56  0
                 ta.establishConnection();
 57  
 
 58  0
                 ta = new RadioPanelAssociation( treePanel.editPanel.yearRadioPanel );
 59  0
                 ta.bindAspect( EOAssociation.ValueAspect, group, "createDate.year" );
 60  
                 
 61  0
                 EODisplayGroup yearTitles = new EODisplayGroup();
 62  0
                 yearTitles.setObjectArray( new NSArray( 
 63  0
                         new Object[] { "1999", "2000", "2001" } ) );
 64  0
                 ta.bindAspect( EOAssociation.TitlesAspect, yearTitles, "" );
 65  
         
 66  0
                 EODisplayGroup yearObjects = new EODisplayGroup();
 67  0
                 yearObjects.setObjectArray( new NSArray( 
 68  0
                         new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) );
 69  0
                 ta.bindAspect( EOAssociation.ObjectsAspect, yearObjects, "" );
 70  
                 
 71  0
                 ta.establishConnection();
 72  
 
 73  
                 // detail group
 74  
                 
 75  0
                 final EODisplayGroup detailGroup = new EODisplayGroup();
 76  
                 
 77  0
                 ta = new MasterDetailAssociation( detailGroup );
 78  0
                 ta.bindAspect( EOAssociation.ParentAspect, group, "childList" );
 79  0
                 ta.establishConnection();
 80  
                 
 81  0
                 ta = new ListAssociation( treePanel.editPanel.list );
 82  0
                 ta.bindAspect( EOAssociation.TitlesAspect, detailGroup, "fullName" );
 83  0
                 ta.establishConnection();
 84  
                 
 85  
                 // display group action associations
 86  
 
 87  0
                 AbstractButton addButton = (AbstractButton)
 88  0
                         treePanel.editPanel.addPanel.getButton( "Add" );
 89  0
                 addButton.addActionListener( new ActionListener()
 90  
                 {
 91  0
                         public void actionPerformed( ActionEvent evt )
 92  
                         {
 93  0
                                 detailGroup.insertObjectAtIndex( new TestObject(), 0 );        
 94  0
                         }
 95  
                 } );
 96  
 
 97  0
                 AbstractButton removeButton = (AbstractButton)
 98  0
                         treePanel.editPanel.addPanel.getButton( "Remove" );
 99  0
                 removeButton.addActionListener( new ActionListener()
 100  
                 {
 101  0
                         public void actionPerformed( ActionEvent evt )
 102  
                         {
 103  0
                 if ( detailGroup.selectedObject() != null )
 104  0
                                     detailGroup.deleteSelection();        
 105  0
                         }
 106  
                 } );
 107  
 /*
 108  
                 AbstractButton refreshButton = (AbstractButton)
 109  
                         treePanel.editPanel.addPanel.getButton( "Refresh" );
 110  
                 refreshButton.addActionListener( new ActionListener()
 111  
                 {
 112  
             int count = 0;
 113  
                         public void actionPerformed( ActionEvent evt )
 114  
                         {                
 115  
                 EODisplayGroup displayGroup = (EODisplayGroup)
 116  
                    treePanel.tree.getSelectionPath().getLastPathComponent();
 117  
 //                displayGroup.insertObjectAtIndex( new TestObject(), 0 );
 118  
 //                displayGroup.deleteObjectAtIndex( 0 );
 119  
                List sortOrderings = new LinkedList();
 120  
                if ( count++ % 2 == 0 )
 121  
                {
 122  
                    sortOrderings.add( new EOSortOrdering( 
 123  
                         "lastName", EOSortOrdering.CompareAscending ) );
 124  
                }
 125  
                else
 126  
                {
 127  
                    sortOrderings.add( new EOSortOrdering( 
 128  
                         "lastName", EOSortOrdering.CompareDescending ) );
 129  
                }
 130  
                displayGroup.setSortOrderings( sortOrderings );
 131  
                displayGroup.updateDisplayedObjects();
 132  
                         }
 133  
                 } );
 134  
 */        
 135  
 /*                
 136  
                 ta = new DisplayGroupActionAssociation( 
 137  
             treePanel.editPanel.addPanel.getButton( "Remove" ) );
 138  
                 ta.bindAspect( EOAssociation.ActionAspect, detailGroup, "deleteSelection" );
 139  
                 ta.establishConnection();
 140  
         
 141  
                 ta = new DisplayGroupActionAssociation( 
 142  
             treePanel.editPanel.addPanel.getButton( "Refresh" ) );
 143  
                 ta.bindAspect( EOAssociation.ActionAspect, group, "updateDisplayedObjects" );
 144  
                 ta.establishConnection();
 145  
 */
 146  
 
 147  
                 // add mouse listener for list
 148  
                 
 149  0
                 treePanel.editPanel.list.addMouseListener( new MouseAdapter() 
 150  
                 {
 151  0
                         public void mouseClicked(MouseEvent e)
 152  
                         {
 153  0
                                 if ( e.getClickCount() == 2 )
 154  
                                 {
 155  0
                                         Object item = detailGroup.selectedObject();
 156  0
                                         if ( item != null )
 157  
                                         {
 158  0
                                                 new InspectorController( item );
 159  
                                         }                
 160  
                                 }
 161  0
                         }
 162  
                 });
 163  
 
 164  
                 // launch
 165  
                 
 166  0
                 JDialog d = new JDialog();
 167  0
                 d.getContentPane().add( treePanel );
 168  0
                 d.setTitle( "Tree Panel" );
 169  0
                 d.pack();
 170  0
         WindowUtilities.cascade( d );
 171  0
                 d.show();
 172  
 
 173  
         // workaround for memory issues on jdk1.2.2
 174  0
                 d.addWindowListener( new WindowAdapter()
 175  
                 {
 176  
                         // exit on close
 177  0
                         public void windowClosing(WindowEvent e)
 178  
                         {        
 179  0
                                 ((JDialog)e.getWindow()).getContentPane().removeAll();
 180  0
                         }
 181  
                 });
 182  0
         }
 183  
     
 184  
 }