capint
1/12/2016 - 3:20 PM

Eclipse >> SWT >> Combo box

Eclipse >> SWT >> Combo box

final Combo combo = new Combo(propagateComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
    combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    combo.addModifyListener(new ModifyListener() {

      @Override
      public void modifyText(ModifyEvent e) {
        //*** Get data out of combo box based on the index of selected item
        selectedEnumLiteral = (EnumerationPropertyLiteral) combo.getData(String.valueOf(combo.getSelectionIndex()));
        // Use selectedEnumLiteral
      }
    });

//*** Add label and set data for combobox
//*** We can use the setData and getData methods on any SWT widget to associate data
combo.add("");
combo.setData(String.valueOf(0), null);

// Add list of labels and data for combobox
int i = 1;
for (EnumerationPropertyLiteral enumLiteral : ept.getOwnedLiterals()) {
  combo.add(enumLiteral.getLabel());
  combo.setData(String.valueOf(i), enumLiteral);
  i++;
}