You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Mark Fraser <ma...@mark100.net> on 2010/07/24 00:22:45 UTC

Problem selecting new data object in combo box using DOComboBoxModel

I am using the current snapshot of the org.apache.cayenne.dataview classes
in a swing application with Cayenne 3.x.

I am having a problem that when I add (programmatically) an item to a combo
box I can only select it programmatically.  The object appears to be in the
combo box's drop down list, but it cannot be selected by the user.   When
the user selects the object nothing appears selected and
getSelectedDataObject() returns null.

I do not know if this is a bug or if I am missing something or doing
something wrong.

Here is relevant the code where I am populating the combo box:

DataObjectList playerList = new
DataObjectList(ContextManager.getInstance().getDataContext(performQuery(q));
DOComboBox Model newTournamentResultPlayerModel = new DOComboBoxModel();
cmbNewTournamentResultPlayer.setModel(newTournamentResultPlayerModel);
newTournamentResultPlayerModel.setDataObjects(playerList);
newTournamentResultPlayerModel.setViewField(dataView.getObjEntityView("Players").getFieldForObjAttribute("name"));


Here is the code where I add a new item:

Player newPlayer =
(Player)ContextManager.getInstance().getDataContext().newObject(Player.class);
DOComboBoxModel dm =
(DOComboBoxModel)cmbNewTournamentResultPlayer.getModel();
dm.getDataObjects().add(newPlayer);
ContextManager.getInstance().getDataContext(getClass()).commitChanges();
(if here I call dm.getDataObjects.setSelectedDataObject(newPlayer)..it
works)

Any suggestions on what is wrong would be appreciated.

Thanks,

Mark