Here is a simple ItemEventListener that can give you the previous selected item.
For me the item is a String so I cast to it.
ItemEventListener listener = e -> {
if (e.getStateChange() == ItemEvent.DESELECTED) {
previousItem = (String) e.getItem();
}
};