1 11 package org.eclipse.pde.ui.templates; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.events.SelectionAdapter; 15 import org.eclipse.swt.events.SelectionEvent; 16 import org.eclipse.swt.widgets.Combo; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Label; 19 20 26 public class ComboChoiceOption extends AbstractChoiceOption { 27 28 private Combo fCombo; 29 private Label fLabel; 30 31 46 public ComboChoiceOption(BaseOptionTemplateSection section, String name, String label, String [][] choices) { 47 super(section, name, label, choices); 48 } 49 50 public void createControl(Composite parent, int span) { 51 fLabel = createLabel(parent, 1); 52 fLabel.setEnabled(isEnabled()); 53 fill(fLabel, 1); 54 55 fCombo = new Combo(parent, SWT.READ_ONLY); 56 fill(fCombo, 1); 57 for (int i = 0; i < fChoices.length; i++) { 58 String [] choice = fChoices[i]; 59 fCombo.add(choice[1], i); 60 fCombo.setEnabled(isEnabled()); 61 } 62 fCombo.addSelectionListener(new SelectionAdapter() { 63 public void widgetSelected(SelectionEvent e) { 64 if (isBlocked()) 65 return; 66 if (fCombo.getSelectionIndex() != -1) { 67 String [] choice = fChoices[fCombo.getSelectionIndex()]; 68 setValue(choice[0]); 69 getSection().validateOptions(ComboChoiceOption.this); 70 } 71 } 72 }); 73 74 if (getChoice() != null) 75 selectChoice(getChoice()); 76 } 77 78 protected void setOptionValue(Object value) { 79 if (fCombo != null && value != null) { 80 selectChoice(value.toString()); 81 } 82 } 83 84 protected void setOptionEnabled(boolean enabled) { 85 if (fLabel != null) { 86 fLabel.setEnabled(enabled); 87 fCombo.setEnabled(enabled); 88 } 89 } 90 91 protected void selectOptionChoice(String choice) { 92 fCombo.setText(choice); 93 if (fCombo.getSelectionIndex() == -1) 94 fCombo.select(0); 95 } 96 } 97 | Popular Tags |