1 14 package org.compiere.grid.ed; 15 16 import java.math.*; 17 import javax.swing.*; 18 19 import org.compiere.model.*; 20 import org.compiere.util.*; 21 import org.compiere.plaf.*; 22 import org.compiere.swing.*; 23 24 32 public class VComboBox extends CComboBox 33 { 34 37 public VComboBox() 38 { 39 super(); 40 } 42 public VComboBox(Object [] items) 43 { 44 super(items); 45 } 47 public VComboBox(ComboBoxModel model) 48 { 49 super(model); 50 } 53 73 public void setValue(Object key) 74 { 75 if (key == null) 76 { 77 this.setSelectedIndex(-1); 78 return; 79 } 80 81 ComboBoxModel model = getModel(); 82 int size = model.getSize(); 83 for (int i = 0; i < size; i++) 84 { 85 Object element = model.getElementAt(i); 86 String ID = null; 87 if (element instanceof NamePair) 88 ID = ((NamePair)element).getID(); 89 else if (element instanceof MLocator) 90 ID = String.valueOf(((MLocator)element).getM_Locator_ID()); 91 else 92 Log.error("VComboBox.setValue - Element not NamePair - " + element.getClass().toString()); 93 94 if (key == null || ID == null) 95 { 96 if (key == null && ID == null) 97 { 98 setSelectedIndex(i); 99 return; 100 } 101 } 102 else if (ID.equals(key.toString())) 103 { 104 setSelectedIndex(i); 105 return; 106 } 107 } 108 setSelectedIndex(-1); 109 setSelectedItem(null); 110 } 112 116 public void setValue (int key) 117 { 118 setValue(String.valueOf(key)); 119 } 121 125 public Object getValue() 126 { 127 if (getSelectedIndex() == -1) 128 return null; 129 NamePair p = (NamePair)getSelectedItem(); 131 if (p == null) 132 return null; 133 if (p instanceof KeyNamePair) 135 { 136 if (p.getID() == null) 137 return null; 138 return new Integer (p.getID()); 139 } 140 return p.getID(); 141 } 143 147 public String getDisplay() 148 { 149 if (getSelectedIndex() == -1) 150 return ""; 151 NamePair p = (NamePair)getSelectedItem(); 153 if (p == null) 154 return ""; 155 return p.getName(); 156 } 158 } | Popular Tags |