1 56 package org.objectstyle.cayenne.dataview; 57 58 import javax.swing.ComboBoxModel ; 59 60 import org.objectstyle.cayenne.DataObject; 61 62 68 public class DOComboBoxModel extends DOListModel implements ComboBoxModel { 69 70 protected DataObject selectedObject; 71 72 public DOComboBoxModel() { 73 } 74 75 public void setSelectedDataObject(DataObject dataObject) { 76 if ((selectedObject != null && !selectedObject.equals(dataObject)) 77 || selectedObject == null 78 && dataObject != null) { 79 selectedObject = dataObject; 80 fireContentsChanged(this, -1, -1); 81 } 82 } 83 84 public DataObject getSelectedDataObject() { 85 return selectedObject; 86 } 87 88 public void setSelectedItem(Object selectedValue) { 89 if (viewField == null) { 90 if (selectedValue instanceof DataObject) 91 setSelectedDataObject((DataObject) selectedValue); 92 else 93 setSelectedDataObject(null); 94 } 95 else { 96 LookupCache cache = viewField.getOwner().getOwner().getLookupCache(); 97 setSelectedDataObject(cache.getDataObject(viewField, selectedValue)); 98 } 99 } 100 101 public Object getSelectedItem() { 102 if (viewField == null) 103 return getSelectedDataObject(); 104 return viewField.getValue(getSelectedDataObject()); 105 } 106 } | Popular Tags |