Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » WANTED: Table content changed event
WANTED: Table content changed event [message #809865] Wed, 29 February 2012 11:22 Go to next message
Veselin Markov is currently offline Veselin MarkovFriend
Messages: 3
Registered: February 2012
Junior Member

I have a question about Table and TableViewer. In my case I added a ViewerFilter to my TableViewer. When i set a new filtering condition to my ViewerFilter I also refresh my TableViewer so that the filtered Table is shown. Now comes the point where I want to calculate a sum of a certain column (containing numbers)of all the rows of the table and write it in a Text object. What I've done is that the filter takes care of updateing the Text, but thats not logically correct as it's not the filters job to do this. I searched for an event of Table or TableViewer that tells me if TableItems (rows) are added or removed from the Table but found nothing. Is there such an event?

Re: WANTED: Table content changed event [message #810230 is a reply to message #809865] Wed, 29 February 2012 21:46 Go to previous messageGo to next message
Andreas Hoegger is currently offline Andreas HoeggerFriend
Messages: 179
Registered: February 2010
Senior Member
I run into similar issues few weeks ago. Since there is really no event after refilter/resort a table viewer I came up with the solution to override the table viewer.

  private class MyTableViewer extends TableViewer {
    public MyTableViewer(Composite parent) {

    protected Object[] getSortedChildren(Object parent) {
      Object[] finalElements = super.getSortedChildren(parent);
      // do your calculations on the elements or inform an event handler
      return finalElements;

Any better solution?

Re: WANTED: Table content changed event [message #811582 is a reply to message #810230] Fri, 02 March 2012 14:57 Go to previous message
Veselin Markov is currently offline Veselin MarkovFriend
Messages: 3
Registered: February 2012
Junior Member
Hello Andreas,

I have come up with the following solution:
public class TableViewerSendingContentChangedEvent extends TableViewer {
	protected EventListenerSupport<ChangeListener> eventHandler;
	 * Calls only the super constructor
	 * @param parent
	 * @param style
	 * @see org.eclipse.jface.viewers.TableViewer.TableViewer(Composite parent, int style)
	public TableViewerSendingContentChangedEvent(Composite parent, int style) {
		super(parent, style);
		eventHandler = EventListenerSupport.create(ChangeListener.class);
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object)
	protected void internalRefresh(Object element) {
		super.internalRefresh(element); ChangeEvent(this));
	public void addRefreshListener(ChangeListener aApp) {

What I've done ist override the internalRefresh method, so it sends an event when the table has been refreshed. I find this is a better place to insert the event as getSortedChildren() because it I need an event when the table changes and not when sorted children are required. At the end its the same but I find it more logical this way.
The next step is to check if add() and remove() use internalRefresh().

Thanks for the hint with extending TableViewer. I'm sure I would've come to this eventually but wanted to know if an event isn't implemented already. Maybe it's worth a feature request ticket. What do you think?
Previous Topic:How can I set text limit per byte size on Text widget?
Next Topic:Tree with Multiple Columns - Renderer
Goto Forum:

Current Time: Sat Oct 10 09:09:30 GMT 2015

Powered by FUDForum. Page generated in 0.01770 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software