ListTableListEventListener in ObjectListTable

1 view
Skip to first unread message

Nick Nadgauda

unread,
Jul 31, 2007, 8:13:27 AM7/31/07
to GWT-Stuff
Hi,

I am working on a SelectEventList which wraps an EventList and keeps
track of which items in the list are selected. There are a series of
setSelection( ) methods which fire ListEvent.Other events to
listeners. I can contribute the code when I am done.

I am trying to have the ObjectListTable listen for these events and
automatically update the style when they fire. But it looks like the
ListTableEventListener in ObjectListTable swallows ListEvent.Other
events. I can't use ListEvent.Changed events because
ListTableEventListener looks for actual object changes.

Any chance of propagating ListEvent.Other events to the Renderers?

Thanks,
--Nick

Sandy McArthur

unread,
Aug 4, 2007, 12:10:23 AM8/4/07
to gwt-...@googlegroups.com
Umm, I'm a little concerned that would introduce a level of coupling
between the Renderer and the EventList that isn't currently required.

The way I'm tracking a selected set is I have a separate EventList
that is the selected set that keeps track of when elements are removed
from the real list. This works well with pagination and is rather
simple to implement. eg:

EventList realElements = ....;
EventList selectedElements = EventLists.eventList();

// When an element is selected
selectedElements.add(element);

// When an element is unselected
selectedElements.remove(element);

// and then to keep the lists in sync, when elements are removed from
the real list then they are implicitly unselected

private class SelectedElementListEventLisener implements ListEventListener {
private final EventList selectedElements;
public SelectedMessagesListEventLisener(EventList selectedElements) {
this.selectedElements = selectedElements;
}

public void listChanged(final ListEvent listEvent) {
// XXX: I'm not sure I need to check listEvent.isChanged()
if (listEvent.isRemoved() || listEvent.isChanged()) {
selectedElements.retainAll(listEvent.getSource());
}
}
}

realElements.addListEventListener(new
SelectedElementListEventLisener(selectedElements));

// To enable/disable buttons when there is a selection
selectedElements.addListEventListener(new ListEventListener() {
public void listChanged(final ListEvent listEvent) {
deleteSelectedButton.setEnabled(!selectedEements.isEmpty());
}
});

HTH, sorry for not responding sooner, I became a daddy a few days ago.


--
Sandy McArthur

"He who dares not offend cannot be honest."
- Thomas Paine

Nick Nadgauda

unread,
Aug 6, 2007, 9:14:55 PM8/6/07
to GWT-Stuff
Congrats on becoming a father!

My original post may been a little unclear. I've written an
interface (and corresponding implementation) that wraps an EventList
and provides selection capability .....

public interface SelectableEventList extends EventList {
public void select(int index);

public void unselect(int index);

public boolean isSelected(int index);

public void clearSelections();

public void setSelectionInterval(int minIndex, int maxIndex);

//...... more methods to help with selection and intervals

// return an EventList backed by this list containing only
selections
public EventList getSelected();
}

and then

public interface SelectableEventListImpl extends DelegateEventList
implements SelectableEventList {

public SelectableEventListImpl(EventList eventList) {
super(eventList);
// .... some other initializations
}

public void select(int index) {
// ... keep track of selected item
fireListEvent(new ListEvent(this,ListEvent.OTHER,index));
}


// ..... rest of SelectableEventList implementation

}


I've tried to capture the functionality in the
ca.odell.glazedlists.swing.EventSelectionModel class.

The reason I was requesting the change in ObjectListTable was that I
have two views listening in on a SelectableEventList class (which
wraps another EventList). Each view can trigger a selection event and
I would like changes to be propagated to the other view
automatically. I was thinking that if one of the views calls
SelectableEventList.select(index) then the other view (an
ObjectListTable in this case) could catch the ListEvent.Other event
and then highlight the newly selected row.

Hope this clears things regarding the original request re:
ObjectListTable and congratulations again on becoming a dad.

Thanks,
--Nick

> On 7/31/07, Nick Nadgauda <nadga...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I am working on a SelectEventList which wraps an EventList and keeps
> > track of which items in the list are selected. There are a series of
> > setSelection( ) methods which fire ListEvent.Other events to
> > listeners. I can contribute the code when I am done.
>
> > I am trying to have the ObjectListTable listen for these events and
> > automatically update the style when they fire. But it looks like the
> > ListTableEventListener in ObjectListTable swallows ListEvent.Other
> > events. I can't use ListEvent.Changed events because
> > ListTableEventListener looks for actual object changes.
>
> > Any chance of propagating ListEvent.Other events to the Renderers?
>
> > Thanks,
> > --Nick
>
> --
> Sandy McArthur
>
> "He who dares not offend cannot be honest."

> - Thomas Paine- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages