diff options
Diffstat (limited to 'projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestController.java')
| -rw-r--r-- | projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestController.java | 490 |
1 files changed, 222 insertions, 268 deletions
diff --git a/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestController.java b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestController.java index 8bbb452..83fe97c 100644 --- a/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestController.java +++ b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestController.java @@ -39,357 +39,311 @@ import net.wotonomy.ui.swing.components.IconCellRenderer; import net.wotonomy.ui.swing.components.KeyableCellEditor; /** -* Controller for the TestPanel. -*/ -public class TestController implements ActionListener -{ + * Controller for the TestPanel. + */ +public class TestController implements ActionListener { EODisplayGroup displayGroup; TestPanel panel; - public TestController( TestPanel aPanel ) - { + public TestController(TestPanel aPanel) { panel = aPanel; - - // setup display group - displayGroup = new EODisplayGroup(); - displayGroup.setSortOrderings( new NSArray( new Object[] - { "firstName", "middleName", "lastName" } ) ); + // setup display group + + displayGroup = new EODisplayGroup(); + displayGroup.setSortOrderings(new NSArray(new Object[] { "firstName", "middleName", "lastName" })); // fetch the data // displayGroup.setUsesOptimisticRefresh( true ); - displayGroup.setDataSource( new TestDataSource() ); + displayGroup.setDataSource(new TestDataSource()); // displayGroup.setSelectsFirstObjectAfterFetch( true ); - displayGroup.fetch(); - displayGroup.selectNext(); + displayGroup.fetch(); + displayGroup.selectNext(); -displayGroup.setDelegate( this ); + displayGroup.setDelegate(this); // set up associations - EOAssociation assoc; - + EOAssociation assoc; + // table association - + TableColumn column; - + column = new TableColumn(); - column.setHeaderValue( "First" ); - IconCellRenderer iconRenderer = new IconCellRenderer() - { - private Icon icon = UIManager.getIcon("FileChooser.homeFolderIcon"); - public Icon getIconForContext( - JComponent container, Object value, - int row, int col, - boolean isSelected, boolean hasFocus, - boolean isExpanded, boolean isLeaf ) - { - return icon; - } - }; - iconRenderer.addActionListener( this ); - column.setCellRenderer( new AlternatingRowCellRenderer( iconRenderer ) ); + column.setHeaderValue("First"); + IconCellRenderer iconRenderer = new IconCellRenderer() { + private Icon icon = UIManager.getIcon("FileChooser.homeFolderIcon"); + + public Icon getIconForContext(JComponent container, Object value, int row, int col, boolean isSelected, + boolean hasFocus, boolean isExpanded, boolean isLeaf) { + return icon; + } + }; + iconRenderer.addActionListener(this); + column.setCellRenderer(new AlternatingRowCellRenderer(iconRenderer)); // column.setCellEditor( iconRenderer ); // assoc = new TableColumnAssociation( column ); - assoc = new TreeColumnAssociation( column ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "firstName" ); + assoc = new TreeColumnAssociation(column); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "firstName"); //new net.wotonomy.ui.swing.DisplayGroupInspector( displayGroup ); //displayGroup = new EODisplayGroup(); // assoc.bindAspect( EOAssociation.ChildrenAspect, displayGroup, "childList" ); - assoc.bindAspect( EOAssociation.EditableAspect, null, "true" ); - assoc.bindAspect( EOAssociation.IsLeafAspect, null, "childCount" ); - ((TableColumnAssociation)assoc).setTable( panel.table ); + assoc.bindAspect(EOAssociation.EditableAspect, null, "true"); + assoc.bindAspect(EOAssociation.IsLeafAspect, null, "childCount"); + ((TableColumnAssociation) assoc).setTable(panel.table); assoc.establishConnection(); - ((TreeColumnAssociation)assoc).getTreeModelAssociation().setInsertingAfter( false ); - ((TreeColumnAssociation)assoc).getTreeModelAssociation().setInsertingChild( false ); + ((TreeColumnAssociation) assoc).getTreeModelAssociation().setInsertingAfter(false); + ((TreeColumnAssociation) assoc).getTreeModelAssociation().setInsertingChild(false); // column.setCellRenderer( new AlternatingRowCellRenderer( column.getCellRenderer() ) ); -/* - // test the standalone mode of the icon cell renderer - panel.add( iconRenderer, java.awt.BorderLayout.SOUTH ); - iconRenderer.setText( "Hello World!" ); - iconRenderer.setIcon( UIManager.getIcon("FileChooser.homeFolderIcon") ); -*/ - + /* + * // test the standalone mode of the icon cell renderer panel.add( + * iconRenderer, java.awt.BorderLayout.SOUTH ); iconRenderer.setText( + * "Hello World!" ); iconRenderer.setIcon( + * UIManager.getIcon("FileChooser.homeFolderIcon") ); + */ + column = new TableColumn(); - column.setHeaderValue( "Middle" ); - column.setCellRenderer( new AlternatingRowCellRenderer() ); - assoc = new TableColumnAssociation( column ); - ((TableColumnAssociation)assoc).setSortCaseSensitive( true ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "middleName" ); - ((TableColumnAssociation)assoc).setTable( panel.table ); + column.setHeaderValue("Middle"); + column.setCellRenderer(new AlternatingRowCellRenderer()); + assoc = new TableColumnAssociation(column); + ((TableColumnAssociation) assoc).setSortCaseSensitive(true); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "middleName"); + ((TableColumnAssociation) assoc).setTable(panel.table); assoc.establishConnection(); - + column = new TableColumn(); - column.setHeaderValue( "Last" ); - column.setCellRenderer( new AlternatingRowCellRenderer() ); - column.setCellEditor( new KeyableCellEditor() ); - assoc = new TableColumnAssociation( column ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "lastName" ); - assoc.bindAspect( EOAssociation.EditableAspect, null, "true" ); - ((TableColumnAssociation)assoc).setTable( panel.table ); + column.setHeaderValue("Last"); + column.setCellRenderer(new AlternatingRowCellRenderer()); + column.setCellEditor(new KeyableCellEditor()); + assoc = new TableColumnAssociation(column); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "lastName"); + assoc.bindAspect(EOAssociation.EditableAspect, null, "true"); + ((TableColumnAssociation) assoc).setTable(panel.table); assoc.establishConnection(); - + column = new TableColumn(); - column.setHeaderValue( "Created" ); + column.setHeaderValue("Created"); FormattedCellRenderer renderer = new FormattedCellRenderer(); - renderer.setFormat( DateFormat.getDateInstance() ); - column.setCellRenderer( new AlternatingRowCellRenderer( renderer ) ); - assoc = new TableColumnAssociation( column ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate" ); - ((TableColumnAssociation)assoc).setTable( panel.table ); + renderer.setFormat(DateFormat.getDateInstance()); + column.setCellRenderer(new AlternatingRowCellRenderer(renderer)); + assoc = new TableColumnAssociation(column); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "createDate"); + ((TableColumnAssociation) assoc).setTable(panel.table); assoc.establishConnection(); - + column = new TableColumn(); - column.setHeaderValue( "Special" ); - column.setCellRenderer( new AlternatingRowCellRenderer( - panel.table.getDefaultRenderer( Boolean.class ) ) ); - assoc = new TableColumnAssociation( column ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "special" ); - assoc.bindAspect( EOAssociation.EditableAspect, null, "true" ); - ((TableColumnAssociation)assoc).setTable( panel.table ); + column.setHeaderValue("Special"); + column.setCellRenderer(new AlternatingRowCellRenderer(panel.table.getDefaultRenderer(Boolean.class))); + assoc = new TableColumnAssociation(column); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "special"); + assoc.bindAspect(EOAssociation.EditableAspect, null, "true"); + ((TableColumnAssociation) assoc).setTable(panel.table); assoc.establishConnection(); - - // text associations - assoc = new TextAssociation( panel.firstNameField ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "firstName" ); + // text associations + + assoc = new TextAssociation(panel.firstNameField); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "firstName"); //EODisplayGroup controllerDisplayGroup = new EODisplayGroup(); //controllerDisplayGroup.setObjectArray( new NSArray( this ) ); //controllerDisplayGroup.selectNext(); //assoc.bindAspect( EOAssociation.ValueAspect, controllerDisplayGroup, "filter" ); assoc.establishConnection(); - assoc = new TextAssociation( panel.middleNameField ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "middleName" ); + assoc = new TextAssociation(panel.middleNameField); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "middleName"); assoc.establishConnection(); - - assoc = new TextAssociation( panel.lastNameField ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "lastName" ); - assoc.bindAspect( EOAssociation.LabelAspect, displayGroup, "special" ); + + assoc = new TextAssociation(panel.lastNameField); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "lastName"); + assoc.bindAspect(EOAssociation.LabelAspect, displayGroup, "special"); assoc.establishConnection(); - - assoc = new ButtonAssociation( panel.checkbox ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "special" ); + + assoc = new ButtonAssociation(panel.checkbox); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "special"); // assoc.bindAspect( EOAssociation.EnabledAspect, displayGroup, "special" ); // assoc.bindAspect( EOAssociation.VisibleAspect, displayGroup, "special" ); assoc.establishConnection(); - + // combo associations - - assoc = new ComboBoxAssociation( panel.dateBox ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate.date" ); - // no titles aspect: uses existing combobox options + + assoc = new ComboBoxAssociation(panel.dateBox); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "createDate.date"); + // no titles aspect: uses existing combobox options assoc.establishConnection(); - - assoc = new ComboBoxAssociation( panel.monthBox ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate.month" ); + + assoc = new ComboBoxAssociation(panel.monthBox); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "createDate.month"); EODisplayGroup monthTitlesGroup = new EODisplayGroup(); - monthTitlesGroup.setObjectArray( new NSArray( - new Object[] { "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" } ) ); - assoc.bindAspect( EOAssociation.TitlesAspect, monthTitlesGroup, "" ); + monthTitlesGroup.setObjectArray(new NSArray(new Object[] { "January", "February", "March", "April", "May", + "June", "July", "August", "September", "October", "November", "December" })); + assoc.bindAspect(EOAssociation.TitlesAspect, monthTitlesGroup, ""); EODisplayGroup monthObjectsGroup = new EODisplayGroup(); - monthObjectsGroup.setObjectArray( new NSArray( - new Object[] { new Integer( 0 ), - new Integer( 1 ), new Integer( 2 ), new Integer( 3 ), - new Integer( 4 ), new Integer( 5 ), new Integer( 6 ), - new Integer( 7 ), new Integer( 8 ), new Integer( 9 ), - new Integer( 10 ), new Integer( 11 ) } ) ); - assoc.bindAspect( EOAssociation.ObjectsAspect, monthObjectsGroup, "" ); - + monthObjectsGroup.setObjectArray(new NSArray(new Object[] { new Integer(0), new Integer(1), new Integer(2), + new Integer(3), new Integer(4), new Integer(5), new Integer(6), new Integer(7), new Integer(8), + new Integer(9), new Integer(10), new Integer(11) })); + assoc.bindAspect(EOAssociation.ObjectsAspect, monthObjectsGroup, ""); + assoc.establishConnection(); - - assoc = new ComboBoxAssociation( panel.yearBox ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate.year" ); - + assoc = new ComboBoxAssociation(panel.yearBox); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "createDate.year"); + EODisplayGroup yearTitlesGroup = new EODisplayGroup(); - yearTitlesGroup.setObjectArray( new NSArray( - new Object[] { "1999", "2000", "2001" } ) ); - assoc.bindAspect( EOAssociation.TitlesAspect, yearTitlesGroup, "" ); + yearTitlesGroup.setObjectArray(new NSArray(new Object[] { "1999", "2000", "2001" })); + assoc.bindAspect(EOAssociation.TitlesAspect, yearTitlesGroup, ""); EODisplayGroup yearObjectsGroup = new EODisplayGroup(); - yearObjectsGroup.setObjectArray( new NSArray( - new Object[] { new Integer( 99 ), new Integer( 100 ), new Integer( 101 ) } ) ); - assoc.bindAspect( EOAssociation.ObjectsAspect, yearObjectsGroup, "" ); - + yearObjectsGroup + .setObjectArray(new NSArray(new Object[] { new Integer(99), new Integer(100), new Integer(101) })); + assoc.bindAspect(EOAssociation.ObjectsAspect, yearObjectsGroup, ""); + assoc.establishConnection(); - - assoc = new SliderAssociation( panel.slider ); - assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "createDate.date" ); - assoc.bindAspect( EOAssociation.VisibleAspect, displayGroup, "special" ); + + assoc = new SliderAssociation(panel.slider); + assoc.bindAspect(EOAssociation.ValueAspect, displayGroup, "createDate.date"); + assoc.bindAspect(EOAssociation.VisibleAspect, displayGroup, "special"); assoc.establishConnection(); - - assoc = new TextAssociation( panel.infoPanel.getLabelForKey( "Day of Month" ) ); - assoc.bindAspect( EOAssociation.VisibleAspect, displayGroup, "special" ); + + assoc = new TextAssociation(panel.infoPanel.getLabelForKey("Day of Month")); + assoc.bindAspect(EOAssociation.VisibleAspect, displayGroup, "special"); assoc.establishConnection(); - + // display group action associations - AbstractButton button; - - button = (AbstractButton) - panel.savePanel.getButton( "Refresh All" ); - button.addActionListener( new ActionListener() - { - public void actionPerformed( ActionEvent evt ) - { // panel.lastNameField.setText( panel.lastNameField.getText().trim() ); - - // test all three ways - - displayGroup.dataSource().editingContext().invalidateAllObjects(); + AbstractButton button; + + button = (AbstractButton) panel.savePanel.getButton("Refresh All"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { // panel.lastNameField.setText( + // panel.lastNameField.getText().trim() ); + + // test all three ways + + displayGroup.dataSource().editingContext().invalidateAllObjects(); // displayGroup.dataSource().editingContext().parentObjectStore().invalidateAllObjects(); // displayGroup.dataSource().editingContext().revert(); } - } ); - - button = (AbstractButton) - panel.savePanel.getButton( "Commit" ); - button.addActionListener( new ActionListener() - { - public void actionPerformed( ActionEvent evt ) - { - try - { - displayGroup.dataSource().editingContext().saveChanges(); - } - catch ( RuntimeException exc ) - { - JOptionPane.showMessageDialog( - (java.awt.Component)evt.getSource(), exc.getMessage() ); - exc.printStackTrace(); - } + }); + + button = (AbstractButton) panel.savePanel.getButton("Commit"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + try { + displayGroup.dataSource().editingContext().saveChanges(); + } catch (RuntimeException exc) { + JOptionPane.showMessageDialog((java.awt.Component) evt.getSource(), exc.getMessage()); + exc.printStackTrace(); + } } - } ); - - button = (AbstractButton) - panel.buttonPanel.getButton( "Add" ); - button.addActionListener( new ActionListener() - { - public void actionPerformed( ActionEvent evt ) - { - displayGroup.insertNewObjectAtIndex( 0 ); + }); + + button = (AbstractButton) panel.buttonPanel.getButton("Add"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + displayGroup.insertNewObjectAtIndex(0); } - } ); - - assoc = new DisplayGroupActionAssociation( - panel.buttonPanel.getButton( "Remove" ) ); - assoc.bindAspect( EOAssociation.ActionAspect, displayGroup, "deleteSelection" ); - assoc.establishConnection(); -/* - assoc = new DisplayGroupActionAssociation( - panel.infoPanel.getButtonPanel().getButton( "Refresh" ) ); - assoc.bindAspect( EOAssociation.ActionAspect, displayGroup, "updateDisplayedObjects" ); - assoc.establishConnection(); + }); - assoc = new DisplayGroupActionAssociation( - panel.infoPanel.getButtonPanel().getButton( "Commit" ) ); - assoc.bindAspect( EOAssociation.ActionAspect, displayGroup, "updateDisplayedObjects" ); + assoc = new DisplayGroupActionAssociation(panel.buttonPanel.getButton("Remove")); + assoc.bindAspect(EOAssociation.ActionAspect, displayGroup, "deleteSelection"); assoc.establishConnection(); -*/ + /* + * assoc = new DisplayGroupActionAssociation( + * panel.infoPanel.getButtonPanel().getButton( "Refresh" ) ); assoc.bindAspect( + * EOAssociation.ActionAspect, displayGroup, "updateDisplayedObjects" ); + * assoc.establishConnection(); + * + * assoc = new DisplayGroupActionAssociation( + * panel.infoPanel.getButtonPanel().getButton( "Commit" ) ); assoc.bindAspect( + * EOAssociation.ActionAspect, displayGroup, "updateDisplayedObjects" ); + * assoc.establishConnection(); + */ // add MouseListener for table - panel.table.addMouseListener( new MouseAdapter() - { - public void mouseClicked(MouseEvent e) - { - if ( e.getClickCount() == 2 ) - { + panel.table.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { Object o = displayGroup.selectedObject(); - if ( o != null ) - { + if (o != null) { // new InspectorController( o ); - new EditController( - new ChildDataSource( - displayGroup.dataSource(), o ) ); - } + new EditController(new ChildDataSource(displayGroup.dataSource(), o)); + } } } }); - + // add ActionListener for tree button - ((JButton) panel.buttonPanel.getButton( - "Tree View" ) ).addActionListener( new ActionListener() - { - public void actionPerformed( ActionEvent evt ) - { - EOEditingContext parentContext = Test.editingContext; - EOEditingContext childContext = new EOEditingContext( parentContext ); - - // transpose objects to ids to faults - List ids = new LinkedList(); - Iterator i = displayGroup.selectedObjects().iterator(); - while ( i.hasNext() ) - { - ids.add( parentContext.globalIDForObject( i.next() ) ); - } - List objects = new LinkedList(); - i = ids.iterator(); - while( i.hasNext() ) - { - objects.add( childContext.faultForGlobalID( (EOGlobalID) i.next(), childContext ) ); - } - + ((JButton) panel.buttonPanel.getButton("Tree View")).addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + EOEditingContext parentContext = Test.editingContext; + EOEditingContext childContext = new EOEditingContext(parentContext); + + // transpose objects to ids to faults + List ids = new LinkedList(); + Iterator i = displayGroup.selectedObjects().iterator(); + while (i.hasNext()) { + ids.add(parentContext.globalIDForObject(i.next())); + } + List objects = new LinkedList(); + i = ids.iterator(); + while (i.hasNext()) { + objects.add(childContext.faultForGlobalID((EOGlobalID) i.next(), childContext)); + } + EODisplayGroup treeGroup = new EODisplayGroup(); - treeGroup.setSortOrderings( new NSArray( "lastName" ) ); - treeGroup.setObjectArray( objects ); + treeGroup.setSortOrderings(new NSArray("lastName")); + treeGroup.setObjectArray(objects); - EODisplayGroup childGroup = new EODisplayGroup(); - - //childGroup.setDelegate( new DebuggingDelegate() ); - //new TreeInspectorController( treeGroup, childGroup ); - //new BindingController( treeGroup, childGroup ); + EODisplayGroup childGroup = new EODisplayGroup(); - new TreeController( childContext, treeGroup, childGroup ); + // childGroup.setDelegate( new DebuggingDelegate() ); + // new TreeInspectorController( treeGroup, childGroup ); + // new BindingController( treeGroup, childGroup ); - //NOTE: ChildDataSource is fundamentally broken + new TreeController(childContext, treeGroup, childGroup); + + // NOTE: ChildDataSource is fundamentally broken // new TreeController( new ChildDataSource( // displayGroup.dataSource(), displayGroup.selectedObjects() ) ); } }); -/* - NSNotificationCenter.defaultCenter().addObserver( - this, - new NSSelector( "hitMe", new Class[] { NSNotification.class } ), - null, null ); -*/ + /* + * NSNotificationCenter.defaultCenter().addObserver( this, new NSSelector( + * "hitMe", new Class[] { NSNotification.class } ), null, null ); + */ + } + + private String filter; + + public String getFilter() { + return filter; + } + + public void setFilter(String aFilter) { + filter = aFilter; + + EOQualifier qualifier = null; + if (!"".equals(aFilter)) { + qualifier = new EOKeyValueQualifier("firstName", EOQualifier.QualifierOperatorContains, filter); + } + displayGroup.setQualifier(qualifier); + displayGroup.updateDisplayedObjects(); + } + + public void hitMe(NSNotification aNote) { + System.out.println(aNote); } - - private String filter; - public String getFilter() - { - return filter; - } - - public void setFilter( String aFilter ) - { - filter = aFilter; - - EOQualifier qualifier = null; - if ( ! "".equals( aFilter ) ) - { - qualifier = new EOKeyValueQualifier( - "firstName", EOQualifier.QualifierOperatorContains, filter ); - } - displayGroup.setQualifier( qualifier ); - displayGroup.updateDisplayedObjects(); - } - - public void hitMe( NSNotification aNote ) - { - System.out.println( aNote ); - } - - public void actionPerformed( ActionEvent evt ) - { - Object o = displayGroup.selectedObject(); - if ( o != null ) - { + + public void actionPerformed(ActionEvent evt) { + Object o = displayGroup.selectedObject(); + if (o != null) { // new ObjectInspector( o ); - new InspectorController( o ); - } - } - + new InspectorController(o); + } + } + } |
