« Return to Thread: Master/Details scenario: how to update the details table without loosing the selection in SWT?

re[3]: Master/Details scenario: how to update the details table without loosing the selection in SWT?

by Kevin Day-7 :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.
Ahh - I see what you are doing now...  (also, you can ignore my prior selection calculation - that was specific to Swing).
 
I don't think that pluggable list is necessarily going to make the difference on selection being preserved (but if you are using a presentation model to manage the child view, then it is quite handy).
 
You won't be able to use a regular Collection for the source list of a PluggableList - the source has to be an EventList - but I think this is a distraction from your primary question.
 
 
I guess my question is:  If you are replacing the content of the sub-list, then what sort of selection should be preserved?  The selected row number?  If that's the case, then I suspect I am out of me depth (it probably involves some sort of SWT selection model) - sorry, but someone who works with SWT will need to answer that one.
 
- K
 
----------------------- Original Message -----------------------
  
From: philk phil.kursawe@...
To: users@...
Cc: 
Date: Wed, 24 Jun 2009 23:04:58 -0700 (PDT)
Subject: Re: re: Master/Details scenario: how to update the details table without loosing the selection in SWT?
  

Thanks Kevin for your reply.
As I wrote my details are the list of line items to a given order. So I get
the order objects in the selection and query the database for its items. So
basically the pipeline would be something like this?

PluggableList<LineItem> detailList = new PluggableList<Linetem>();


void onUpdate(Collection<Order> orders) {
 Collection<LineItem> lineItems = new ArrayList<LineItem>();
 for (Order order : orders) {
   lineItems.addAll(orderService.getLineItems(order.getId()));
 }
 detailsList.setSource(lineItems);
}

This would preserve the selection, if the detailList is bound to an SWT
viewer?

Thanks,
Phil


Kevin Day wrote:

>
>
>
>
>
>
>
> I'm not sure if this gets at the crux of your question or not:
> &nbsp;
> 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.&nbsp; 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.&nbsp; It all depends on the data structure you are
> presenting, of course.
> &nbsp;
> We use BeansBinding for binding, but you could hand code it using a
> property change listener on the calculation...
> &nbsp;
> For the child list, construct a list pipleline that starts with a
> PluggableList, then just set PluggableList.setSource() when the
> calculation's value changes.&nbsp; 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&nbsp;like in
> the code below...
> &nbsp;
> Cheerio,
> &nbsp;
> - K
> &nbsp;
> &nbsp;
> &nbsp;
> Here's the calculation we use to determine the last selected element in
> the master:
> &nbsp;
> /* &nbsp;* Created on Mar 4, 2009 &nbsp;* &nbsp;*/ 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;
> /** &nbsp;* @author kevin &nbsp;*/ public class
> LastSelectedElementCalculation&lt;E&gt; extends
> AbstractCalculation&lt;E&gt; implements ListSelectionListener{
> &nbsp;&nbsp;&nbsp; private final EventSelectionModel&lt;E&gt;
> eventSelectionModel; &nbsp;&nbsp;&nbsp; private final EventList&lt;E&gt;
> source; &nbsp;&nbsp;&nbsp; private final E defaultValue;
> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public
> LastSelectedElementCalculation(EventSelectionModel&lt;E&gt;
> eventSelectionModel, EventList&lt;E&gt; source, E defaultValue) {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super(defaultValue);
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.eventSelectionModel =
> eventSelectionModel; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> this.eventSelectionModel.addListSelectionListener(this);
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.source = source;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.defaultValue =
> defaultValue; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recalculate();
> &nbsp;&nbsp;&nbsp; }
> &nbsp;&nbsp;&nbsp; public void dispose() {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> eventSelectionModel.removeListSelectionListener(this); &nbsp;&nbsp;&nbsp;
> }
> &nbsp;&nbsp;&nbsp; private void recalculate(){
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final E oldValue = getValue();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boolean selected =
> eventSelectionModel.isSelectedIndex(eventSelectionModel.getAnchorSelectionIndex());
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setValue(selected ?
> source.get(eventSelectionModel.getAnchorSelectionIndex()) : defaultValue);
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final E newValue = getValue();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fireValueChange(oldValue,
> newValue); &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
> public void valueChanged(ListSelectionEvent e) {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recalculate();
> &nbsp;&nbsp;&nbsp; }
> }
> &nbsp;
> - K
> &nbsp;
>
> ----------------------- Original Message -----------------------
> &nbsp;&nbsp;
> From:&nbsp;philk
> To:&nbsp;
users@...
> Cc:&nbsp;
> Date:&nbsp;Wed, 24 Jun 2009 04:27:19 -0700 (PDT)
> Subject:&nbsp;Master/Details scenario: how to update the details table
> without loosing the selection in SWT?
> &nbsp;&nbsp;
> 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) {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!(selection instanceof
> StructuredSelection)) {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.positions.getReadWriteLock().writeLock().lock();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.positions.clear();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} finally {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.positions.getReadWriteLock().writeLock().unlock();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final OrderService
> orderService = (OrderService) this.orderServiceTracker.getService();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (orderService != null)
> {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final
> Iterator&lt;Order&gt; iterator = ((StructuredSelection)
> selection).iterator();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while
> (iterator.hasNext()) {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final
> Order order = iterator.next();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final
> Collection&lt;LineItem&gt; newPositions =
> orderService.getPositions(order.getOrderNumber());
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.positions.getReadWriteLock().writeLock().lock();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try
> {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.positions.addAll(newPositions);
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.form.setText(NLS.bind(Messages.OrderDetailsPage_Positions,
> this.positions.size()));
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> finally {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.positions.getReadWriteLock().writeLock().unlock();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//
> Do not show all orders. This should be later enabled by the user using a
> toolbar button.
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> &nbsp;&nbsp;&nbsp;&nbsp;} -- 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@... For
> additional commands, e-mail: users-help@...
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>
>

--
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--tp24183003p24197489.html
Sent from the GlazedLists - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@...

 « Return to Thread: Master/Details scenario: how to update the details table without loosing the selection in SWT?