When I delete a domain object in my app, I check a tab pane to see if it
contains any tabs that edits the deleted object and close them. I find
myself writing code like this (Page is the domain object in this example):
// Delete the page from RDBMS
deletePage(page);
// Put tabs to remove in another list to avoid
ConcurrentModificationException
List<Component> remove = new ArrayList<Component>();
// Search for tabs to remove
for (Component tab : tabs.getTabs()) {
if (tab instanceof DomainObjectHolder) {
DomainObjectHolder holder = (DomainObjectHolder) tab;
if (page.equals(holder.getDomainObject()))
remove.add(tab);
}
}
// Remove the tabs
for (Component tab : remove)
tabs.getTabs().remove(tab);
If tabs.getTabs() could give me a ListIterator, this would be a lot
smoother, by maybe there is another Pivot way of doing this?
-- Edvin