|
From: Keith D. <kd...@cs...> - 2004-07-11 08:53:27
|
Spring rich client now has support for instantiating a single logical =
view as needed, for display in applications with multiple windows open =
at the same time.
In a previous e-mail I mentioned that the cardinality of the View object =
was wrong, where a "View" in our case is a panel like component =
displayed on a page within a window in a spring rich client application =
(and a component that typically supports some navigation / browsing use =
case).
Specifically, what was wrong was the following:
View instances -- which encapsulate the creation and configuration of =
the underlying GUI control, and also register commands (controllers) =
that interact with a business/domain layer in response to user events -- =
were treated as singletons, instantiated directly in a spring =
application context. This was bad, as we must provide support for =
displaying multiple instances of the same view per application, for =
example, in an application that supports multiple windows open at the =
same time.
I've corrected this by introducing the concept of a ViewDescriptor. The =
descriptor is a singleton, defining metadata about a single view. This =
metadata consists of the view's visual properties (display name, =
caption/tooltip, icon, etc.), the classname of the actual View =
implementation, and any properties that should be injected when a new =
view instance is asked to be instantiated by the application. So in =
essence the descriptor acts as a factory for producing and configuring a =
view prototype, when asked on behalf of a requesting client (typically =
an applicaiton page) in order to display the view on an area of a page =
within a particular window.
So if we take a look at the petclinic sample, which I've updated to =
reflect the above, the process of view definition now looks like this in =
a spring application context:
=20
<bean id=3D"vetManagerView"
=
class=3D"org.springframework.richclient.application.ViewDescriptor">
<property name=3D"viewClass">
=
<value>org.springframework.richclient.samples.petclinic.ui.VetManagerView=
</value>
</property>
<property name=3D"viewProperties">
<map>
<entry key=3D"clinic">
<ref bean=3D"clinic"/>
</entry>
</map>
</property>
</bean>
So essentially what happens is, when a rich client application starts, =
the opening application window consults the application lifecycle =
delegate for a inital "perspective" -- or page configuration -- to open. =
The perspective knows how to create and layout an application page, =
where a page can consist of zero to many views, each located at a =
specific area (for example, left, top right, bottom right.) (I should =
point out that currently we only support one view per page, but that =
will be changing soon.) The page delegates to the appropriate view =
descriptor to produce a new view instance, which triggers the =
instantiation & initialization of the viewClass, including injection of =
any viewProperties. The control produced by the view's getControl() =
factory method is then added to the page's display in the right spot. =
This same process basically happens again when a new application window =
is opened, allowing for the same logical view to be displayed in =
multiple windows within the same application instance.
Notice in the above sample there is no specification of locale-sensitive =
properties like the view's name, icon, and tooltip; this is because the =
application object configurer bean post processor handles injecting =
those properties when the descriptor is instantiated, pulling property =
values from a configured message and image source.
Keith |