Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Updating selection when removing lines from table
Updating selection when removing lines from table [message #810323] Thu, 01 March 2012 00:53 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 105
Registered: December 2010
Senior Member
When my code has to delete something from the table, it usually is the selected row.
So I have this code to move the selection to the previous row:

 int selIdx = mTableView.getTable().getSelectionIndex();
 mTableView.getTable().setSelection((selIdx > 0) ? (selIdx - 1) : 0);
 mTableView.getTable().notifyListeners(SWT.Selection, new Event());


This works fine - EXCEPT if the currently selected item is row 0.
After the delete, and the above code executes. (reselecting row 0)
the table is left with no selection.

Am I missing something?
Re: Updating selection when removing lines from table [message #810565 is a reply to message #810323] Thu, 01 March 2012 08:56 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
I did not get into details why the selection does not work for selIdx = 0 but I would propose to
place the selection in an asyncExec and it will probably work:

e.g.
deleteButton.addSelectionListener(new SelectionAdapter() {
	@Override
	public void widgetSelected(SelectionEvent e) {
		IStructuredSelection selection = (IStructuredSelection) mTableView.getSelection();
		if (selection!=null && !selection.isEmpty() && selection.size()==1)
		{
			final int selIdx = mTableView.getTable().getSelectionIndex();
			
			List<MyModel> model = (List<MyModel>) mTableView.getInput();
			model.remove(selection.getFirstElement());
			
			mTableView.getTable().getDisplay().asyncExec(new Runnable()
			{
				public void run() {
						 mTableView.getTable().setSelection((selIdx > 0) ? (selIdx - 1) : 0);
						 mTableView.getTable().notifyListeners(SWT.Selection, new Event());
					}
			});
		}
		
		mTableView.refresh();
	}
});
Re: Updating selection when removing lines from table [message #810895 is a reply to message #810565] Thu, 01 March 2012 16:51 Go to previous message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 105
Registered: December 2010
Senior Member
Thanks, that does fix the problem.
Previous Topic:Difference between RCP and E4
Next Topic:Eclipse Templates: Escape < and > ?
Goto Forum:
  


Current Time: Sat Sep 21 02:28:58 GMT 2024

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

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

Back to the top