public enum Vulnerability {
NONE, NORTH_SOUTH, EAST_WEST, BOTH;
}
Now I have a combo, where someone can choose one of these values.
Because I don't want to use the toString() method, I have a String
array, holding the values for the combo. But I don't have an idea how
to create a good mapping, because it must work in both directions. At
the moment I am using switch statements for the mapping. But this
seems error prone, when changing something. There must be a better way.
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new FillLayout());
vulCombo = new Combo(container,SWT.DROP_DOWN);
vulCombo.setItems(vulnerability);
if(rule.getVul() == null) {
vulCombo.setText(vulnerability[4]);
} else {
switch(rule.getVul()) {
case NORTH_SOUTH: vulCombo.setText(vulnerability[0]); break;
case EAST_WEST: vulCombo.setText(vulnerability[1]); break;
case BOTH: vulCombo.setText(vulnerability[2]); break;
case NONE: vulCombo.setText(vulnerability[3]); break;
}
}
vulCombo.setVisible(true);
vulCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent se) {
int index = vulCombo.getSelectionIndex();
switch(index){
case 0: vul = Vulnerability.NONE; break;
case 1: vul = Vulnerability.NORTH_SOUTH; break;
case 2: vul = Vulnerability.EAST_WEST; break;
case 3: vul = Vulnerability.NONE; break;
case 4: vul = null;
}
}
});
container.pack();
//
setControl(container);
}
Thanks
Helge
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden