Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » MVC question
MVC question [message #458542] Fri, 15 July 2005 08:20 Go to next message
Eclipse UserFriend
Originally posted by: hisdudenessabides.gmail.com

Hi all,

I have a problem. I have a TextViewier, and I want to update its text
continously in a separate thread.

My current solution is this: I have used a custom ITextStore
implementation which has a private StringBuffer. The StringBuffer (since
it has synchronized methods) is updated by the thread. Logically, the
TextViewer should be able to see the text that is being appended to
StringBuffer, but it doesn't !

Therefore, the StringBuffer is the model, the TextViewer is the view, and
the thread is the controller...

Any ideas on how to do this in a proper way ? Somehow I feel this is not
the way MVC apps are dont is SWT, but I just _can't_ find any
documentation/help regarding this. I went through the Manning/Scarpino
book on SWT & JFace, but it is very sketchy about this topic.

Any help is appreciated, I'm really desperate for an answer.....

Regards, DL
Re: MVC question [message #458551 is a reply to message #458542] Fri, 15 July 2005 18:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"DL" <hisdudenessabides@gmail.com> wrote in message
news:976d5478f49e2432ec0c6621f087d6c6$1@www.eclipse.org...
> Hi all,
>
> I have a problem. I have a TextViewier, and I want to update its text
> continously in a separate thread.
> My current solution is this: I have used a custom ITextStore
> implementation which has a private StringBuffer. The StringBuffer (since
> it has synchronized methods) is updated by the thread. Logically, the
> TextViewer should be able to see the text that is being appended to
> StringBuffer, but it doesn't !
>
> Therefore, the StringBuffer is the model, the TextViewer is the view, and
> the thread is the controller...
> Any ideas on how to do this in a proper way ? Somehow I feel this is not
> the way MVC apps are dont is SWT, but I just _can't_ find any
> documentation/help regarding this. I went through the Manning/Scarpino
> book on SWT & JFace, but it is very sketchy about this topic.
>
> Any help is appreciated, I'm really desperate for an answer.....
>
> Regards, DL
>
The TextViewer won't automatically see the changes. You need to call
refresh() on it (probably using Display asyncExec() since you are updating
the buffer in a separate thread).
---
Sunil
Re: MVC question [message #458559 is a reply to message #458551] Fri, 15 July 2005 19:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hisdudenessabides.gmail.com

Thanks for the reply.

What if I use a Document implementation as the model, and I pass that to
the thread ? Wouldn't the textviewer be listening to changes in 'Document'
??

Is asyncExec() the most efficient way to do it ?

Thanks,

DL
Re: MVC question [message #458577 is a reply to message #458559] Fri, 15 July 2005 20:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"DL" <hisdudenessabides@gmail.com> wrote in message
news:b89f483eafb527a188a8f816bf44e29a$1@www.eclipse.org...
> Thanks for the reply.
>
> What if I use a Document implementation as the model, and I pass that to
> the thread ? Wouldn't the textviewer be listening to changes in 'Document'
> ??
>
> Is asyncExec() the most efficient way to do it ?
> Thanks,
>
> DL
>
Using a Document would be a better idea since document content changes fire
a documentChanged Event which will be intercepted by the TextViewer.
Regarding whether asyncExec() is the most efficient way- if you want to
update the UI from a non-UI thread it is pretty much the only way to do it.
Or you can do a syncExec if you wish. Otherwise you will get an non-UI
thread exception.
Another alternative is to schedule a UIJob and do it that way.
---
Sunil
Re: MVC question [message #458594 is a reply to message #458577] Sat, 16 July 2005 18:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hisdudenessabides.gmail.com

Thanks for the reply, Sunil.

If I use Document, then I guess I don't need to use syncExec. But the
document's methods don't seem to be synchronized... would it be practical
to reimplement the AbstractDocument with synchronized methods ?

Basically, what I'm writing is sort of a telnet client... so the server is
reading the output in a seperate thread....

Thanks again,

Regards, DL
Re: MVC question [message #458622 is a reply to message #458594] Sat, 16 July 2005 22:52 Go to previous message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"DL" <hisdudenessabides@gmail.com> wrote in message
news:153e0f6e66821dc76db92387c07f62d4$1@www.eclipse.org...
> Thanks for the reply, Sunil.
>
> If I use Document, then I guess I don't need to use syncExec. But the
> document's methods don't seem to be synchronized... would it be practical
> to reimplement the AbstractDocument with synchronized methods ?
>
You could do that if you want. Remember that even though the methods are not
synchronized, all UI updates happen in the single UI thread, which processes
events on a first come first served basis.

> Basically, what I'm writing is sort of a telnet client... so the server is
> reading the output in a seperate thread....
>

---
Sunil
Previous Topic:Where is source and JavaDoc for SWT & JFace
Next Topic:How to close a shell after an allowing from a dialog?
Goto Forum:
  


Current Time: Sat Oct 24 23:53:05 GMT 2020

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

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

Back to the top