Spring RCP Application Initialized From Griffon

To get them to co-exist, somehow Spring RCP's application class should replace the Griffon application class, or the other way round. Maybe I need to create an ApplicationBuilder for Spring RCP? There's also threading issues to figure out. Anyway, right now I'm able to show both applications: the Griffon application and the Spring RCP application (at least, their main windows):

Here's the application context, containing one single bean only, for the application class:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="application" class="org.springframework.richclient.application.Application">
    </bean>

</beans>

Now the question is from where to initialize the above. In "Startup.groovy", I have this:

def rootController = app.controllers.root
rootController.startApplication()

...which points to this in the above referenced controller:

def appContextPath = "richclient-application-context.xml"

def startApplication = { evt = null ->
    edt {
        withWorker( start: true ) {
            onInit {
            }
            work {
                try {
                    new ApplicationLauncher(appContextPath)
                } catch (RuntimeException e) {
                    println 'Failure'
                }
            }
            onDone {
            }
        }
    }
}

Without SwingWorker, I couldn't get it to work. Then when the application is run, first the Griffon view is shown, then you see Spring RCP output (all about initialization of Spring RCP internals), and then the application class is initialized and displayed. Whether the above is a step forward or not I don't know. But at least it shows the Spring RCP application, which is nice to see in this context.

Comments:

Geertjan, a couple of notes. Startup.groovy already runs inside the EDT, so calling edt{} inside startApplication() is not needed. withworker() is a thin abstraction layer over SwingWorker (jdk6/swingx depending on your running jvm), which only requires you to write code for the work{} and onDone{} blocks. onInit{} works like a constructor/initializer, in your case you don't need it :-)

If your controller does not need to reference the Spring RCP Application bean, the you could safely put all the code in Initialize.groovy, which will run inside EDT also, so make sure to wrap your code with SwingBuilder.doOutside{} (doLater/doOutside are conveniently defined as static methods), or even Thread.start{ /\*your code\*/ }

Posted by Andres Almiray on September 29, 2008 at 08:47 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today