Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table/TableViewer row-selection changed
Table/TableViewer row-selection changed [message #440655] Thu, 05 August 2004 10:18 Go to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I'm running into problems when trying to catch if the selected row has
been changed. The event is catched apropiately but I can not cast the
Object retrieved from the evt.getSelectionProvider().getSelection().

I definitly sure that the ISelection is a TableRow which can be seen
from the output below. I'm not sure what the [-brackets mean, can
anybody help me out here, I must be doing something fundametly wrong.

If not has anybody another idea how to retrieve the actually selected
row in the table and an event I could listen to if it changes?

--------------8<---------------
viewer_.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged( SelectionChangedEvent evt ) {
ISelection selection = evt.getSelectionProvider().getSelection();
System.out.println("SELECTION CHANGED!!!!");
System.out.println( evt.getSelectionProvider().getSelection() );
System.out.println( evt.getSelectionProvider());

try {
TableRow row = (TableRow)selection // THROWS CLASS-CAST EXCEPTION;
} catch( ClassCastException e ) {
System.out.println( "E-Message: " + e.getMessage() );
}
}
});
--------------8<---------------

Output:
--------------8<---------------
SELECTION CHANGED!!!!
[at.bestsolution.swtforms.provider.tableutils.TableRow@dc6a77]
org.eclipse.jface.viewers.TableViewer@d1e89e
E-Message: null
--------------8<---------------

Tom
Re: Table/TableViewer row-selection changed [message #440657 is a reply to message #440655] Thu, 05 August 2004 12:17 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Ok. Resolved it myself:

----------------8<----------------
public void selectionChanged( SelectionChangedEvent evt ) {
StructuredSelection selection
=(StructuredSelection)evt.getSelectionProvider().getSelectio n();

((TableRow)selection.toList().get(0)).adjustRowset();
}
----------------8<----------------

Tom

Tom Schindl wrote:
> Hi,
>
> I'm running into problems when trying to catch if the selected row has
> been changed. The event is catched apropiately but I can not cast the
> Object retrieved from the evt.getSelectionProvider().getSelection().
>
> I definitly sure that the ISelection is a TableRow which can be seen
> from the output below. I'm not sure what the [-brackets mean, can
> anybody help me out here, I must be doing something fundametly wrong.
>
> If not has anybody another idea how to retrieve the actually selected
> row in the table and an event I could listen to if it changes?
>
> --------------8<---------------
> viewer_.addSelectionChangedListener(new ISelectionChangedListener() {
> public void selectionChanged( SelectionChangedEvent evt ) {
> ISelection selection = evt.getSelectionProvider().getSelection();
> System.out.println("SELECTION CHANGED!!!!");
> System.out.println( evt.getSelectionProvider().getSelection() );
> System.out.println( evt.getSelectionProvider());
>
> try {
> TableRow row = (TableRow)selection // THROWS CLASS-CAST EXCEPTION;
> } catch( ClassCastException e ) {
> System.out.println( "E-Message: " + e.getMessage() );
> }
> }
> });
> --------------8<---------------
>
> Output:
> --------------8<---------------
> SELECTION CHANGED!!!!
> [at.bestsolution.swtforms.provider.tableutils.TableRow@dc6a77]
> org.eclipse.jface.viewers.TableViewer@d1e89e
> E-Message: null
> --------------8<---------------
>
> Tom
Re: Table/TableViewer row-selection changed [message #440658 is a reply to message #440655] Thu, 05 August 2004 12:25 Go to previous message
Michael Keppler is currently offline Michael KepplerFriend
Messages: 164
Registered: July 2009
Senior Member
Tom Schindl schrieb:

> I definitly sure that the ISelection is a TableRow which can be seen
> from the output below.

That can't be seen by the output. Normally the selection should be an
IStructuredSelection, so do something like

if (selection instanceof IStructuredSelection) {
Object obj=((IStructuredSelection)selection).getFirstElement();
if (obj instanceof TableRow) {
...
}
}

Ciao, Michael.
Previous Topic:Running Crystal Reports in SWT using ActiveX
Next Topic:MoveMemory Variant question...
Goto Forum:
  


Current Time: Thu Apr 25 03:45:23 GMT 2024

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

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

Back to the top