void () { ServiceViewItem lastSelection = myLastSelection; WeakReference<ServiceViewItem> itemRef = new WeakReference<>(lastSelection == null ? null : getModel().findItemSafe(lastSelection)); AppUIExecutor.onUiThread().expireWith(this).submit(() -> { List<ServiceViewItem> selected = getSelectedItems(); if (selected.isEmpty()) { ServiceViewItem item = ContainerUtil.getFirstItem(getModel().getRoots()); if (item != null) { selectSafe(item.getValue(), item.getRootContributor().getClass()); return; } } ServiceViewItem updatedItem = itemRef.get(); ServiceViewItem newSelection = ContainerUtil.getOnlyItem(selected); if (Comparing.equal(newSelection, updatedItem)) { newSelection = updatedItem; } if (Comparing.equal(newSelection, myLastSelection)) { myLastSelection = newSelection; // Skip updating details component if updatedItem has been already marked as removed, // thus details component will be updated in the next already submitted update runnable. if (mySelected && (updatedItem == null || !updatedItem.isRemoved())) { ServiceViewDescriptor descriptor = newSelection == null || (newSelection.isRemoved() && updatedItem == null) ? null : newSelection.getViewDescriptor(); myUi.setDetailsComponent(descriptor == null ? null : descriptor.getContentComponent()); } } }); }