Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT_AWT in commercial projects?
SWT_AWT in commercial projects? [message #448481] Tue, 11 January 2005 01:16 Go to next message
Ravi is currently offline RaviFriend
Messages: 19
Registered: July 2009
Junior Member
Hi,

I have a few questions on mixing SWT and Swing controls:
1. Are there commercial products (or projects) which use Swing and SWT
together, using the SWT_AWT bridge ?
2. Is there any recommendation for synchronizing data between SWT and
Swing controls (components), since they run in different threads?
3. Shouldn't we (eclipse) come up with a framework which allows easy
mixing of Swing and SWT components, so that the framework handles in a
transparent way the threading issues involved (i.e. updating SWT controls
in SWT thread and Swing components in Swing thread). If we don't do this,
then every user will have to build his/her own synchronization framework
leading to bugs and high maintanence costs.

thanks,
-Ravi
Re: SWT_AWT in commercial projects? [message #448527 is a reply to message #448481] Tue, 11 January 2005 16:22 Go to previous messageGo to next message
Philip Borlin is currently offline Philip BorlinFriend
Messages: 17
Registered: July 2009
Junior Member
1. We are experimenting with SWT_AWT right now in our app right now. We
are writing credit union software so this is definately a large scope
complex rich client. I am currently having a focus problem, but I will
try to keep you up to date on what is happening.

2.3. These are pretty broad questions. Can you give me a specific
scenario we can work through?

-Phil


Ravi wrote:

> Hi,

> I have a few questions on mixing SWT and Swing controls:
> 1. Are there commercial products (or projects) which use Swing and SWT
> together, using the SWT_AWT bridge ?
> 2. Is there any recommendation for synchronizing data between SWT and
> Swing controls (components), since they run in different threads?
> 3. Shouldn't we (eclipse) come up with a framework which allows easy
> mixing of Swing and SWT components, so that the framework handles in a
> transparent way the threading issues involved (i.e. updating SWT controls
> in SWT thread and Swing components in Swing thread). If we don't do this,
> then every user will have to build his/her own synchronization framework
> leading to bugs and high maintanence costs.

> thanks,
> -Ravi
Re: SWT_AWT in commercial projects? [message #448536 is a reply to message #448527] Tue, 11 January 2005 18:31 Go to previous messageGo to next message
Ravi is currently offline RaviFriend
Messages: 19
Registered: July 2009
Junior Member
Thanks Philip for the response.

Here's an example: I have a Swing component in my main View. When the user
types in data in a text field or selects an item in the como box of the
Swing component, i would like to update 1 or more views (like property
sheets etc.) containing SWT controls with the same data. This update has
to be done in the SWT UI thread. It is easier to imagine the data going in
the other direction too, in this case we have to update the swing
components in the Swing thread.

This will be a common pattern whenever we need to keep swing and SWT
controls in Sync. I was wondering if it makes sense for SWT to have some
helper classes to update swing components transparently and vice-versa
(i.e. deal with the UI thread issues)

thanks,
-Ravi

Philip Borlin wrote:

> 1. We are experimenting with SWT_AWT right now in our app right now. We
> are writing credit union software so this is definately a large scope
> complex rich client. I am currently having a focus problem, but I will
> try to keep you up to date on what is happening.

> 2.3. These are pretty broad questions. Can you give me a specific
> scenario we can work through?

> -Phil


> Ravi wrote:

>> Hi,

>> I have a few questions on mixing SWT and Swing controls:
>> 1. Are there commercial products (or projects) which use Swing and SWT
>> together, using the SWT_AWT bridge ?
>> 2. Is there any recommendation for synchronizing data between SWT and
>> Swing controls (components), since they run in different threads?
>> 3. Shouldn't we (eclipse) come up with a framework which allows easy
>> mixing of Swing and SWT components, so that the framework handles in a
>> transparent way the threading issues involved (i.e. updating SWT controls
>> in SWT thread and Swing components in Swing thread). If we don't do this,
>> then every user will have to build his/her own synchronization framework
>> leading to bugs and high maintanence costs.

>> thanks,
>> -Ravi
Re: SWT_AWT in commercial projects? [message #448606 is a reply to message #448536] Tue, 11 January 2005 21:27 Go to previous messageGo to next message
Jim Adams is currently offline Jim AdamsFriend
Messages: 160
Registered: July 2009
Senior Member
I would do this with listeners if you need to keep the Swing and SWT stuff
separate. Have things that need to be kept in sync set themselves as
listeners to some central repository. Then the Swing stuff can fire changes
into that repository.

"Ravi" <rshankark@hotmail.com> wrote in message
news:cs161t$37e$1@www.eclipse.org...
> Thanks Philip for the response.
>
> Here's an example: I have a Swing component in my main View. When the user
> types in data in a text field or selects an item in the como box of the
> Swing component, i would like to update 1 or more views (like property
> sheets etc.) containing SWT controls with the same data. This update has
> to be done in the SWT UI thread. It is easier to imagine the data going in
> the other direction too, in this case we have to update the swing
> components in the Swing thread.
>
> This will be a common pattern whenever we need to keep swing and SWT
> controls in Sync. I was wondering if it makes sense for SWT to have some
> helper classes to update swing components transparently and vice-versa
> (i.e. deal with the UI thread issues)
>
> thanks,
> -Ravi
>
> Philip Borlin wrote:
>
> > 1. We are experimenting with SWT_AWT right now in our app right now. We
> > are writing credit union software so this is definately a large scope
> > complex rich client. I am currently having a focus problem, but I will
> > try to keep you up to date on what is happening.
>
> > 2.3. These are pretty broad questions. Can you give me a specific
> > scenario we can work through?
>
> > -Phil
>
>
> > Ravi wrote:
>
> >> Hi,
>
> >> I have a few questions on mixing SWT and Swing controls:
> >> 1. Are there commercial products (or projects) which use Swing and SWT
> >> together, using the SWT_AWT bridge ?
> >> 2. Is there any recommendation for synchronizing data between SWT and
> >> Swing controls (components), since they run in different threads?
> >> 3. Shouldn't we (eclipse) come up with a framework which allows easy
> >> mixing of Swing and SWT components, so that the framework handles in a
> >> transparent way the threading issues involved (i.e. updating SWT
controls
> >> in SWT thread and Swing components in Swing thread). If we don't do
this,
> >> then every user will have to build his/her own synchronization
framework
> >> leading to bugs and high maintanence costs.
>
> >> thanks,
> >> -Ravi
>
>
Re: SWT_AWT in commercial projects? [message #448630 is a reply to message #448536] Wed, 12 January 2005 15:44 Go to previous messageGo to next message
Philip Borlin is currently offline Philip BorlinFriend
Messages: 17
Registered: July 2009
Junior Member
I work on an open source business framework called core
(core-framework.dev.java.net) and in that framework we have business
objects that hold all of our logic/data which we bind to custom UI
components (by installing listeners in the background). Sounds exactly
like what you want to do. In our framework the business objects fire an
event everytime a setter is called and whomever is interested in those
events listens. Our UI components are one of the things we register to
listen to those events.

These events are general framework events and can come in from any thread
so we need to do something in order to get it on the UI event thread.
What we do is wrap all logic in our UI component listener within an
EventQueue.invokeLater() (We are mainly Swing right now). In your case
you would just have two components listen to your business object, one the
Swing component and one the SWT component. The Swing component would wrap
the logic in an EventQueue.invokeLater() and the SWT component would wrap
the logic in its version (my SWT is pretty weak).

-Phil

Ravi wrote:

> Thanks Philip for the response.

> Here's an example: I have a Swing component in my main View. When the user
> types in data in a text field or selects an item in the como box of the
> Swing component, i would like to update 1 or more views (like property
> sheets etc.) containing SWT controls with the same data. This update has
> to be done in the SWT UI thread. It is easier to imagine the data going in
> the other direction too, in this case we have to update the swing
> components in the Swing thread.

> This will be a common pattern whenever we need to keep swing and SWT
> controls in Sync. I was wondering if it makes sense for SWT to have some
> helper classes to update swing components transparently and vice-versa
> (i.e. deal with the UI thread issues)

> thanks,
> -Ravi

> Philip Borlin wrote:

>> 1. We are experimenting with SWT_AWT right now in our app right now. We
>> are writing credit union software so this is definately a large scope
>> complex rich client. I am currently having a focus problem, but I will
>> try to keep you up to date on what is happening.

>> 2.3. These are pretty broad questions. Can you give me a specific
>> scenario we can work through?

>> -Phil


>> Ravi wrote:

>>> Hi,

>>> I have a few questions on mixing SWT and Swing controls:
>>> 1. Are there commercial products (or projects) which use Swing and SWT
>>> together, using the SWT_AWT bridge ?
>>> 2. Is there any recommendation for synchronizing data between SWT and
>>> Swing controls (components), since they run in different threads?
>>> 3. Shouldn't we (eclipse) come up with a framework which allows easy
>>> mixing of Swing and SWT components, so that the framework handles in a
>>> transparent way the threading issues involved (i.e. updating SWT controls
>>> in SWT thread and Swing components in Swing thread). If we don't do this,
>>> then every user will have to build his/her own synchronization framework
>>> leading to bugs and high maintanence costs.

>>> thanks,
>>> -Ravi
Re: SWT_AWT in commercial projects? [message #448648 is a reply to message #448630] Wed, 12 January 2005 19:44 Go to previous messageGo to next message
Ravi is currently offline RaviFriend
Messages: 19
Registered: July 2009
Junior Member
Thanks. We have built a framework similar to what you have described. The
listener code will get executed in the appropriate UI thread. However we
need to be careful about 2 things: 1. Not to use a lot of aSyncExec
Runnables since they have the lowest priority compared to other UI events.
If there are many such runnables this may lead to unresponsive UI.(
although our tests have indicated that it's not so bad) 2. The data may
have changed before the runnables are executed. So, we may have to
synchronize the model and ensure that listeners are executed before
allowing to change the model data.

Looking at this link:
http://www.eclipse.org/org/councils/20041215EclipseTPFinalDr aft.pdf

There seems to be some work going on to allow Swing applications to
seemlessly work within SWT. I wonder about the specifics of this topic.


-Ravi

Philip Borlin wrote:

> I work on an open source business framework called core
> (core-framework.dev.java.net) and in that framework we have business
> objects that hold all of our logic/data which we bind to custom UI
> components (by installing listeners in the background). Sounds exactly
> like what you want to do. In our framework the business objects fire an
> event everytime a setter is called and whomever is interested in those
> events listens. Our UI components are one of the things we register to
> listen to those events.

> These events are general framework events and can come in from any thread
> so we need to do something in order to get it on the UI event thread.
> What we do is wrap all logic in our UI component listener within an
> EventQueue.invokeLater() (We are mainly Swing right now). In your case
> you would just have two components listen to your business object, one the
> Swing component and one the SWT component. The Swing component would wrap
> the logic in an EventQueue.invokeLater() and the SWT component would wrap
> the logic in its version (my SWT is pretty weak).

> -Phil

> Ravi wrote:

>> Thanks Philip for the response.

>> Here's an example: I have a Swing component in my main View. When the user
>> types in data in a text field or selects an item in the como box of the
>> Swing component, i would like to update 1 or more views (like property
>> sheets etc.) containing SWT controls with the same data. This update has
>> to be done in the SWT UI thread. It is easier to imagine the data going in
>> the other direction too, in this case we have to update the swing
>> components in the Swing thread.

>> This will be a common pattern whenever we need to keep swing and SWT
>> controls in Sync. I was wondering if it makes sense for SWT to have some
>> helper classes to update swing components transparently and vice-versa
>> (i.e. deal with the UI thread issues)

>> thanks,
>> -Ravi

>> Philip Borlin wrote:

>>> 1. We are experimenting with SWT_AWT right now in our app right now. We
>>> are writing credit union software so this is definately a large scope
>>> complex rich client. I am currently having a focus problem, but I will
>>> try to keep you up to date on what is happening.

>>> 2.3. These are pretty broad questions. Can you give me a specific
>>> scenario we can work through?

>>> -Phil


>>> Ravi wrote:

>>>> Hi,

>>>> I have a few questions on mixing SWT and Swing controls:
>>>> 1. Are there commercial products (or projects) which use Swing and SWT
>>>> together, using the SWT_AWT bridge ?
>>>> 2. Is there any recommendation for synchronizing data between SWT and
>>>> Swing controls (components), since they run in different threads?
>>>> 3. Shouldn't we (eclipse) come up with a framework which allows easy
>>>> mixing of Swing and SWT components, so that the framework handles in a
>>>> transparent way the threading issues involved (i.e. updating SWT controls
>>>> in SWT thread and Swing components in Swing thread). If we don't do this,
>>>> then every user will have to build his/her own synchronization framework
>>>> leading to bugs and high maintanence costs.

>>>> thanks,
>>>> -Ravi
Re: SWT_AWT in commercial projects? [message #448654 is a reply to message #448648] Wed, 12 January 2005 20:41 Go to previous messageGo to next message
Philip Borlin is currently offline Philip BorlinFriend
Messages: 17
Registered: July 2009
Junior Member
Ravi wrote:

> 1. Not to use a lot of aSyncExec
> Runnables since they have the lowest priority compared to other UI events.
> If there are many such runnables this may lead to unresponsive UI.(
> although our tests have indicated that it's not so bad)

I don't know how SWT handles this, but Swing has a thread optimizing the
EventQueue that deletes a paint request if a second one comes in that will
paint over what would have been painted by the second one. Anyways, we
have never had problems since the main bottlenecks tend to be data access
and business logic, but of which are happening on separate threads.

> 2. The data may
> have changed before the runnables are executed. So, we may have to
> synchronize the model and ensure that listeners are executed before
> allowing to change the model data.

Who cares? If the data has changed then two events will get fired. If
the first paint command doesn't get optimized out then the two paint
commands will execute so fast that your users won't be able to tell. The
UI doesn't need to reflect the first change, only the current change. I
have not seen a use case where it was important to block my event firing
in order to wait for a screen to paint.

It seems like we are going in the same direction.

-Phil
Re: SWT_AWT in commercial projects? [message #448689 is a reply to message #448654] Thu, 13 January 2005 08:32 Go to previous messageGo to next message
Ivan Markov is currently offline Ivan MarkovFriend
Messages: 61
Registered: July 2009
Member
"Philip Borlin" <pborlin@cmcflex.com> wrote in message
news:cs421a$mmc$1@www.eclipse.org...
> Ravi wrote:
>
> > 1. Not to use a lot of aSyncExec
> > Runnables since they have the lowest priority compared to other UI
events.
> > If there are many such runnables this may lead to unresponsive UI.(
> > although our tests have indicated that it's not so bad)
>
> I don't know how SWT handles this, but Swing has a thread optimizing the
> EventQueue that deletes a paint request if a second one comes in that will
> paint over what would have been painted by the second one. Anyways, we
> have never had problems since the main bottlenecks tend to be data access
> and business logic, but of which are happening on separate threads.

SWT doesn't have to go in such complications. Paint events' collapsing is
done for free by the OS.
As far as I remember, Swing needs these equilibristics, because it runs the
native peers in a separate thread, and it moves messages from the "native
peers" thread to the AWT UI thread. Hope I'm correct on this.

-Ivan
Re: SWT_AWT in commercial projects? [message #448770 is a reply to message #448654] Thu, 13 January 2005 20:52 Go to previous message
Nick Lerissa is currently offline Nick LerissaFriend
Messages: 6
Registered: July 2009
Junior Member
"Philip Borlin" <pborlin@cmcflex.com> wrote in message
news:cs421a$mmc$1@www.eclipse.org...
>> Ravi wrote: 2. The data may have changed before the runnables are
>> executed. So, we may have to synchronize the model and ensure that
>> listeners are executed before allowing to change the model data.
>
> Philip wrote:
> Who cares? If the data has changed then two events will get fired. If
> the first paint command doesn't get optimized out then the two paint
> commands will execute so fast that your users won't be able to tell. The
> UI doesn't need to reflect the first change, only the current change. I
> have not seen a use case where it was important to block my event firing
> in order to wait for a screen to paint.
>
Philip, for simple property change events, I agree: "Who cares?". When
reading a model that is
a graph in an event handler, it is ususally important that the model not be
in the middle of an edit (self consistent).
I am playing around with this now and have come to the conclusion that you
need to use
a read-write lock to implement this correctly. To update the model, follow
this pattern:

try {
model.getReadWriteLock().writeLock().lock();
// update the model
}
finally {
model.getReadWriteLock().writeLock().unlock();
}
fireModelChangedEvents(); //make sure the lock has been released

To handle an event follow this:

public void modelChanged(ModelChangedEvent e) {
Model model = e.getModel();
try {
model.getReadWriteLock().readLock().lock();
// update the UI
}
finally {
model.getReadWriteLock().readLock().unlock();
}
}

Since the event was fired asynchronously (SWT->Swing), its important to
assume that the state
of the model will be consistent with the info inside of the event.
Previous Topic:Programmatic selection of TreeView nodes?
Next Topic:Create Dialog in seperate thread?
Goto Forum:
  


Current Time: Thu Apr 25 09:05:40 GMT 2024

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

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

Back to the top