I try to create a composition of the class org.eclipse.swt.custom.CCombo (for 'project' reasons, I can't inherit from CCombo).
The goal is to avoid this code everywhere, when I want to retrieve the selected data element:
MyElement selectedElement = (MyElement) myCombo.getData(Integer.toString(selectedIndex));
The combo is filled like this:
combo.setData(Integer.toString(myIndex), myObject);
So here is what is did so far:
public class GenericCCombo {
private CCombo combo;
public GenericCCombo(CCombo c) {
combo = c;
}
public IGenericComboList getSelectedData () {
return (IGenericComboList) combo.getData(String.valueOf(combo.getSelectionIndex()));
}
IGenericComboList is juste this:
public interface IGenericComboList {
public String getDescription();
}
So in my implementation code I can retrieve my selected data like this:
//MyElement is just an enum that implements IGenericComboList.
MyElement selectedElement = (MyElement)dateCombo.getSelectedData();
My question is: can I use 'generic type' to avoid casting here :
(MyElement)dateCombo.getSelectedData();
??