« Return to Thread: Master/Details scenario: how to update the details table without loosing the selection in SWT?
Kevin Day wrote:
I'm not sure if this gets at the crux of your question or not:
The approach that I use for master/detail views is to bind a calculation on the source list to the filter/whatever on the child list. Often, in our systems, the child list will be backed by a pluggable list, so we bind the selected value from the master list to the source of the pluggable list. It all depends on the data structure you are presenting, of course.
We use BeansBinding for binding, but you could hand code it using a property change listener on the calculation...
For the child list, construct a list pipleline that starts with a PluggableList, then just set PluggableList.setSource() when the calculation's value changes. This is a bit cleaner if you use a binding framework, but even if you just use PCLs, it'll still be a lot cleaner than trying to manually update the contents of a list like in the code below...
Cheerio,
- K
Here's the calculation we use to determine the last selected element in the master:
/* * Created on Mar 4, 2009 * */ package com.trumpetinc.glazedlistsext;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener;
import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.calculation.AbstractCalculation; import ca.odell.glazedlists.swing.EventSelectionModel;
/** * @author kevin */ public class LastSelectedElementCalculation<E> extends AbstractCalculation<E> implements ListSelectionListener{
private final EventSelectionModel<E> eventSelectionModel; private final EventList<E> source; private final E defaultValue; public LastSelectedElementCalculation(EventSelectionModel<E> eventSelectionModel, EventList<E> source, E defaultValue) { super(defaultValue); this.eventSelectionModel = eventSelectionModel; this.eventSelectionModel.addListSelectionListener(this); this.source = source; this.defaultValue = defaultValue; recalculate(); }
public void dispose() { eventSelectionModel.removeListSelectionListener(this); }
private void recalculate(){ final E oldValue = getValue(); boolean selected = eventSelectionModel.isSelectedIndex(eventSelectionModel.getAnchorSelectionIndex()); setValue(selected ? source.get(eventSelectionModel.getAnchorSelectionIndex()) : defaultValue); final E newValue = getValue(); fireValueChange(oldValue, newValue); } public void valueChanged(ListSelectionEvent e) { recalculate(); }
}
- K
----------------------- Original Message -----------------------
From: philk <phil.kursawe@gmail.com>
To: users@glazedlists.dev.java.net
Cc:
Date: Wed, 24 Jun 2009 04:27:19 -0700 (PDT)
Subject: 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; } } } -- View this message in context: http://www.nabble.com/Master-Details-scenario%3A-how-to-update-the-details-table-without-loosing-the-selection-in-SWT--tp24183003p24183003.html Sent from the GlazedLists - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glazedlists.dev.java.net For additional commands, e-mail: users-help@glazedlists.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glazedlists.dev.java.net
For additional commands, e-mail: users-help@glazedlists.dev.java.net
« Return to Thread: Master/Details scenario: how to update the details table without loosing the selection in SWT?
| Free embeddable forum powered by Nabble | Forum Help |