« Return to Thread: reading table selected items after filter changed - SWT

re[3]: reading table selected items after filter changed - 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.
Cool.
 
As an FYI, there is already a Calculation implementation that will get you the first element of any list (see Calculations.elementAt() ).
 
That works great if your list is single selection.
 
My funky code is useful for providing an intuitive experience in the multi-select case - but, as you say, it does rely on the list selection model.  I suppose another (diametrically opposite) option would be to include Calculations.oneElement() in the mix and not show any detail view if multiple items are selected.
 
- K
 
----------------------- Original Message -----------------------
  
From: Matt P blyefd@...
To: users@...
Cc: 
Date: Fri, 22 May 2009 13:14:02 -0700 (PDT)
Subject: Re: re: reading table selected items after filter changed - SWT
  

Thanks Kevin,

For SWT there was a bit of difference with the SWT EventTableViewer (there
was no EventSelectionModel type of class).  But eventTableViewer does have a
getSelected() method which returns an Event list of selected items.  I
created a similar Calculation class which gives the first selected item in
the list, as follows:

import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.calculation.AbstractCalculation;
import ca.odell.glazedlists.event.ListEvent;
import ca.odell.glazedlists.event.ListEventListener;

public class FirstSelectedElementCalculation<E> extends
AbstractCalculation<E> implements ListEventListener<E> {

    private final EventList<E> source;

    public FirstSelectedElementCalculation(EventList<E> source) {
        super( source.size() > 0 ? source.get( 0) : null);

        this.source = source;
        this.source.addListEventListener(this);
    }

    public void dispose() {
        this.source.removeListEventListener(this);
    }

    public void listChanged(ListEvent<E> listChanges) {
        final E oldValue = getValue();
        setValue(listChanges.getSourceList().size() > 0 ?
listChanges.getSourceList().get(0) : null);
        final E newValue = getValue();
        fireValueChange(oldValue, newValue);
    }

}

Then, I added the following code to link the eventTableViewer sel ected
eventList to this calculation:

new FirstSelectedElementCalculation<Employee>
(eventTableViewer.getSelected())
    .addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            //here I bind ((Employee)event.getNewValue()) to my detail view model.
        }
    }
);






Kevin Day wrote:

>
>
>
> I use a Calculation against the EventSelectionModel (I know that's the
> Swing world, but there's probably an analog for&nbsp;EventSelectionModel
> in SWT).&nbsp; I then bind the calculation result to the model that drives
> the detail&nbsp;view.&nbsp; This approach is a lot more declaritive than
> processin g list events - it makes the view and model&nbsp;code nice and
> clean.
> You could use a Calculation that returns the first value in the list
> selection, but I find that I often want to base my concept of the current
> selected individual item based on the last element of the list selected
> (that way if more than one item is picked, the last one actually
> selected&nbsp;will be used to drive the detail view).&nbsp; Our users find
> that to be more intuitive.
> &nbsp;
> Here's a calculation that will give the last selected element (or a
> default value if there is no selected element).&nbsp; This is specific to
> EventSelectModel, so you'll need to adapt it to SWT:
> &nbsp;
>
>

--
View this message in context: http://w ww.nabble.com/reading-table-selected-items-after-filter-changed---SWT-tp23675106p23676652.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: reading table selected items after filter changed - SWT