Here is a bit of a nasty problem I was having with combo boxes (pop up menus) when editing an existing record. This had previously worked with adding records, but I found the problem was in copying an object into the local editing context. My code was as follows:
public void edit_thing () { ThingInterfaceController asset_controller = new ThingInterfaceController (); Group_Thing ga = (Group_Thing)thing_display_group.selectedObject ();
if (ga != null) { Thing edit_thing = (Thing)thing_controller.editingContext ().faultForGlobalID (ga.thing ().editingContext ().globalIDForObject (ga.thing ()), thing_controller.editingContext ()); thing_controller.displayGroup ().setSelectedObject (edit_thing);
EOFrameController.runControllerInNewFrame (thing_controller, null); } }
This worked perfectly, except for pop ups associated with the thing object, but resulted in:
apple.awt.EventQueueExceptionHandler Caught Throwable : java.lang.IllegalArgumentException: Array is empty java.lang.IllegalArgumentException: Array is empty at com.webobjects.foundation.NSArray.objectAtIndex(NSArray.java:488) at com.webobjects.eointerface.EODisplayGroup._manipulateRelationship(EODisplayGroup.java:3207) at com.webobjects.eointerface.EODisplayGroup._addObjectToBothSidesOfRelationshipWithKeyAtIndex(EODisplayGroup.java:3265) at com.webobjects.eointerface.EODisplayGroup._addObjectToBothSidesOfSelectedObjectRelationshipWithKey(EODisplayGroup.java:3248) at com.webobjects.eointerface.EOAssociation._addObjectToBothSidesOfSelectedObjectRelationshipWithAspect(EOAssociation.java:805) at com.webobjects.eointerface.EOValueSelectionAssociation._storeSelectionValue(EOValueSelectionAssociation.java:395) at com.webobjects.eointerface.EOValueSelectionAssociation.widgetSelectionDidChange(EOValueSelectionAssociation.java:435) at com.webobjects.eointerface.swing.EOSwingComboBoxPlugin.actionPerformed(EOSwingComboBoxPlugin.java:222) at com.webobjects.eointerface.swing.EOSwingComboBoxPlugin$_ComboBoxModel.setSelectedItem(EOSwingComboBoxPlugin.java:284) at javax.swing.JComboBox.setSelectedItem(JComboBox.java:551) at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:597) at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseReleased(BasicComboPopup.java:749) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:232) at java.awt.Component.processMouseEvent(Component.java:5166) at javax.swing.plaf.basic.BasicComboPopup$2.processMouseEvent(BasicComboPopup.java:452) at java.awt.Component.processEvent(Component.java:4963)
After much pain of scouring the EO model and setup in Interface Builder and thinking there must have been something wrong in this code, I discovered an example with a simpler line to get objects into an editing context and set up the display group:
public void edit_thing () { ThingInterfaceController asset_controller = new ThingInterfaceController (); Group_Thing ga = (Group_Thing)thing_display_group.selectedObject ();
if (ga != null) { thing_controller.setObjectWithGlobalID (ga.thing ().editingContext ().globalIDForObject (ga.thing ())); EOFrameController.runControllerInNewFrame (thing_controller, null); } }
and this works, but I'm still not sure as to why 'faultForGlobalID' was not sufficient to make this work and how I could have better tracked down this rather obscure problem. Still, if anyone else stumbles across it in future years, that is a solution that works. Or have I missed something else?
Ian Joyner Sportstec |