
Some parts of this message have been removed.
Learn more about Nabble's
security policy.
I use a Calculation against the EventSelectionModel (I know that's the Swing world, but there's probably an analog for EventSelectionModel in SWT). I then bind the calculation result to the model that drives the detail view. This approach is a lot more declaritive than processing list events - it makes the view and model 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 will be used to drive the detail view). Our users find that to be more intuitive.
Here's a calculation that will give the last selected element (or a default value if there is no selected element). This is specific to EventSelectModel, so you'll need to adapt it to SWT:
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();
}
}
----------------------- Original Message -----------------------
Cc:
Date: Fri, 22 May 2009 10:41:51 -0700 (PDT)
Subject: reading table selected items after filter changed - SWT
Hi,
I have a FilterList feeding an EventTableViewer for a SWT table. The
filterlist is connected to a TextWidgetMatcherEditor and a Text widget.
Everything works as normal.
I also have a detail area on my UI, so that when there is an item selected
in the table, the details of that item is shown in the detail area.
The problem is when there is an item already selected in the table, and then
I type stuff into the filter text widget, the selected item possibly will
disappear from the table. At this point I would like to then clear the
detail area since the corresponding selected item is no longer visible in
the table.
So I thought I would add a listener to the fitlerList.
filterList.addListEventListener( new ListEventListener<Employee>() {
public void list
Changed(ListEvent<Employee> event) {
//what do I do here to determine if the selected item is now not in this
list?
}
});
However I am getting thoroughly confused on how the listChanged() method
and the ListEvents are supposed to work. I can't find much in the docs or
searching to solve this...
Is there a better way of doing this?
Thanks
--
View this message in context:
http://www.nabble.com/reading-table-selected-items-after-filter-changed---SWT-tp23675106p23675106.htmlSent 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@...