Master/Details scenario: how to update the details table without loosing the selection in SWT?
Hello,
I have 2 GL table viewers in SWT. I periodically refresh the master view and the details view. If the master viewer is updated (using replaceAllSorted) it also triggers a refresh of the details view for the currently selected item. The details view then does a clear() and addAll() with its list. This looses the selection of course. Using replaceAllSorted in the details makes it updating weird. Old entries stay in the list for a visible amount of time. The details list items implement Comparable.
please find my update code below:
public void selectionChanged(final IFormPart part, final ISelection selection) {
if (!(selection instanceof StructuredSelection)) {
return;
}
this.positions.getReadWriteLock().writeLock().lock();
try {
this.positions.clear();
} finally {
this.positions.getReadWriteLock().writeLock().unlock();
}
final OrderService orderService = (OrderService) this.orderServiceTracker.getService();
if (orderService != null) {
final Iterator<Order> iterator = ((StructuredSelection) selection).iterator();
while (iterator.hasNext()) {
final Order order = iterator.next();
final Collection<LineItem> newPositions = orderService.getPositions(order.getOrderNumber());
this.positions.getReadWriteLock().writeLock().lock();
try {
this.positions.addAll(newPositions);
this.form.setText(NLS.bind(Messages.OrderDetailsPage_Positions, this.positions.size()));
} finally {
this.positions.getReadWriteLock().writeLock().unlock();
}
// Do not show all orders. This should be later enabled by the user using a toolbar button.
break;
}
}
}