1 12 13 package org.eclipse.jface.viewers; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.custom.CCombo; 18 import org.eclipse.swt.widgets.Combo; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Control; 21 22 36 public final class ComboViewer extends AbstractListViewer { 37 38 44 private Combo combo; 45 46 53 private CCombo ccombo; 54 55 62 public ComboViewer(Composite parent) { 63 this(parent, SWT.READ_ONLY | SWT.BORDER); 64 } 65 66 75 public ComboViewer(Composite parent, int style) { 76 this(new Combo(parent, style)); 77 } 78 79 86 public ComboViewer(Combo list) { 87 this.combo = list; 88 hookControl(list); 89 } 90 91 99 public ComboViewer(CCombo list) { 100 this.ccombo = list; 101 hookControl(list); 102 } 103 104 protected void listAdd(String string, int index) { 105 if (combo == null) { 106 ccombo.add(string, index); 107 } else { 108 combo.add(string, index); 109 } 110 } 111 112 protected void listSetItem(int index, String string) { 113 if (combo == null) { 114 ccombo.setItem(index, string); 115 } else { 116 combo.setItem(index, string); 117 } 118 } 119 120 protected int[] listGetSelectionIndices() { 121 if (combo == null) { 122 return new int[] { ccombo.getSelectionIndex() }; 123 } else { 124 return new int[] { combo.getSelectionIndex() }; 125 } 126 } 127 128 protected int listGetItemCount() { 129 if (combo == null) { 130 return ccombo.getItemCount(); 131 } else { 132 return combo.getItemCount(); 133 } 134 } 135 136 protected void listSetItems(String [] labels) { 137 if (combo == null) { 138 ccombo.setItems(labels); 139 } else { 140 combo.setItems(labels); 141 } 142 } 143 144 protected void listRemoveAll() { 145 if (combo == null) { 146 ccombo.removeAll(); 147 } else { 148 combo.removeAll(); 149 } 150 } 151 152 protected void listRemove(int index) { 153 if (combo == null) { 154 ccombo.remove(index); 155 } else { 156 combo.remove(index); 157 } 158 } 159 160 163 public Control getControl() { 164 if (combo == null) { 165 return ccombo; 166 } else { 167 return combo; 168 } 169 } 170 171 178 public CCombo getCCombo() { 179 Assert.isNotNull(ccombo); 180 return ccombo; 181 } 182 183 189 public Combo getCombo() { 190 Assert.isNotNull(combo); 191 return combo; 192 } 193 194 199 public void reveal(Object element) { 200 } 201 202 205 protected void listSetSelection(int[] ixs) { 206 if (combo == null) { 207 for (int idx = 0; idx < ixs.length; idx++) { 208 ccombo.select(ixs[idx]); 209 } 210 } else { 211 for (int idx = 0; idx < ixs.length; idx++) { 212 combo.select(ixs[idx]); 213 } 214 } 215 } 216 217 220 protected void listDeselectAll() { 221 if (combo == null) { 222 ccombo.deselectAll(); 223 ccombo.clearSelection(); 224 } else { 225 combo.deselectAll(); 226 combo.clearSelection(); 227 } 228 } 229 230 233 protected void listShowSelection() { 234 } 235 } | Popular Tags |