setSelection in TableViewer unable to select row from non-UI thread. [message #528826] |
Wed, 21 April 2010 23:48 |
PM Messages: 14 Registered: July 2009 |
Junior Member |
|
|
Hi,
I have trying to select/highlight a row in JFace TableViewer from a non-ui thread using setSelection method. Somehow i am not able to get it working. I am using setSelection method. Somehow my viewer gets completely messed up. I am able to see all the rows above the "selected" row. I dont see anything below the "selected" row and only 1st column of the selected row is visible.
I want to retain "selection" of a row after some updates have taken place. TableViewer is VIRTUAL.
Not sure what i am doing wrong. Any suggestions/pointers will be a great help.
Here is a snippet, i can provide more details.
private void subscribeToJMS()
{
Runnable r = new Runnable () {
public void run() {
display.syncExec (new Runnable () {
public void run () {
if( display != null && !display.isDisposed() )
updateViewer();
}
});
}
};
public synchronized void updateViewer()
{
int index = model.indexOf(ot);
if(index != -1) {
model.remove(ot);
if (brrOrder.getTopicName().equals(IBrrConstants.ETS_BRR_FOR_LO CK) ||
brrOrder.getTopicName().equals(IBrrConstants.ETS_BRR_FOR_UNL OCK)){
model.add(index, ot);
}
grid.updateModel(model, false, true); // does a tableViewer.refresh
// sets the selection back.
StructuredSelection sel = new StructuredSelection(tableViewer.getElementAt(index));
tableViewer.setSelection(sel, true);
}
}
Thanx
Priyanka
[Updated on: Wed, 21 April 2010 23:57] Report message to a moderator
|
|
|
Re: setSelection in TableViewer unable to select row from non-UI thread. [message #528841 is a reply to message #528826] |
Thu, 22 April 2010 06:16 |
Daniel Krügler Messages: 853 Registered: July 2009 |
Senior Member |
|
|
On 22.04.2010 01:48, PM wrote:
> Hi,
>
> I have trying to select/highlight a row in JFace TableViewer from a
> non-ui thread using setSelection method. Somehow i am not able to get it
> working. I am using setSelection method. Somehow my viewer gets
> completely messed up. I am able to see all the rows above the "selected"
> row. I dont see anything below the "selected" row and only 1st column of
> the selected row is visible. I want to retain "selection" of a row after
> some updates have taken place.
> Not sure what i am doing wrong. Any suggestions/pointers will be a great
> help.
> Here is a snippet, i can provide more details.
>
> private void subscribeToJMS()
> {
> Runnable r = new Runnable () {
> public void run() {
> display.syncExec (new Runnable () {
> public void run () {
> if( display != null && !display.isDisposed() )
> updateViewer();
> }
> });
> }
> };
It does not make much sense to combine syncExec with a query for
display != null && !display.isDisposed(). To prevent a potential
deadlock problem, use asyncExec *with* above test.
> public synchronized void updateViewer()
> {
> int index = model.indexOf(ot);
> if(index != -1) {
> model.remove(ot);
> if (brrOrder.getTopicName().equals(IBrrConstants.ETS_BRR_FOR_LO CK) ||
> brrOrder.getTopicName().equals(IBrrConstants.ETS_BRR_FOR_UNL OCK)){
> model.add(index, ot);
> }
> grid.updateModel(model, false, true);
> // sets the selection back.
> StructuredSelection sel = new
> StructuredSelection(tableViewer.getElementAt(index));
> tableViewer.setSelection(sel, true);
> }
> }
This looks more like a jface problem (based on TableViewer
API) than a pure SWT problem. Some hints:
1) Don't use TableViewer.getElementAt, this is no official
API ("This method is internal to the framework").
2) You don't inform the Table(Viewer) about your changes
(I do only see that you change your model). Based on jface
API you should call Viewer.refresh();
There could still be problems with your code, but that
is hard to diagnose without a concrete simple program
snippet that demonstrate the unexpected behaviour.
HTH & Greetings from Bremen,
Daniel Krügler
|
|
|
Re: setSelection in TableViewer unable to select row from non-UI thread. [message #528844 is a reply to message #528841] |
Thu, 22 April 2010 06:24 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Am 22.04.10 08:16, schrieb Daniel Krügler:
> On 22.04.2010 01:48, PM wrote:
>> Hi,
>>
>> I have trying to select/highlight a row in JFace TableViewer from a
>> non-ui thread using setSelection method. Somehow i am not able to get it
>> working. I am using setSelection method. Somehow my viewer gets
>> completely messed up. I am able to see all the rows above the "selected"
>> row. I dont see anything below the "selected" row and only 1st column of
>> the selected row is visible. I want to retain "selection" of a row after
>> some updates have taken place.
>> Not sure what i am doing wrong. Any suggestions/pointers will be a great
>> help.
>> Here is a snippet, i can provide more details.
>>
>> private void subscribeToJMS()
>> {
>> Runnable r = new Runnable () {
>> public void run() {
>> display.syncExec (new Runnable () {
>> public void run () {
>> if( display != null && !display.isDisposed() )
>> updateViewer();
>> }
>> });
>> }
>> };
>
> It does not make much sense to combine syncExec with a query for
> display != null && !display.isDisposed(). To prevent a potential
> deadlock problem, use asyncExec *with* above test.
>
>> public synchronized void updateViewer()
>> {
>> int index = model.indexOf(ot);
>> if(index != -1) {
>> model.remove(ot);
>> if (brrOrder.getTopicName().equals(IBrrConstants.ETS_BRR_FOR_LO CK) ||
>> brrOrder.getTopicName().equals(IBrrConstants.ETS_BRR_FOR_UNL OCK)){
>> model.add(index, ot);
>> }
>> grid.updateModel(model, false, true);
>> // sets the selection back.
>> StructuredSelection sel = new
>> StructuredSelection(tableViewer.getElementAt(index));
>> tableViewer.setSelection(sel, true);
>> }
>> }
>
What is grid.updateModel() doing? Where is ot coming from? Why are you
not calling new StructuredSelection(ot)? It looks like there's a check
missing which tests for -1 (the remove case)?
> This looks more like a jface problem (based on TableViewer
> API) than a pure SWT problem. Some hints:
>
> 1) Don't use TableViewer.getElementAt, this is no official
> API ("This method is internal to the framework").
>
> 2) You don't inform the Table(Viewer) about your changes
> (I do only see that you change your model). Based on jface
> API you should call Viewer.refresh();
>
or Viewer#remove/add.
Tom
|
|
|
|
Powered by
FUDForum. Page generated in 0.03133 seconds