Announcement Announcement Module
Collapse
No announcement yet.
Simplest Spring-RC application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simplest Spring-RC application

    Hi all!
    Recently I've started learning Spring-RC, so I've faced with some start-up problems. So problems are resoleved, and I want to share the simplest Spring-RC application possible.
    It's
    Hope it will help somebody.

    It consists of 3 java classes, 3-XML config files, 2 properties files and some image resources.

    The bare advisor.
    Code:
    package org.springframework.richclient.samples.simplest;
    
    import org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
    
    public class ApplicationAdvisor extends DefaultApplicationLifecycleAdvisor{
    }
    Main class. It starts the application.
    Code:
    package org.springframework.richclient.samples.simplest;
    
    import org.springframework.richclient.application.ApplicationLauncher;
    
    public class Main {
      public static void main(String[] args) {
        new ApplicationLauncher(
          "/org/springframework/richclient/samples/simplest/config/simplest-splash.xml",
          "/org/springframework/richclient/samples/simplest/config/simplest-application.xml"
        );
      }
    }
    This is the main view. The single overrided method returns the view itself.
    Code:
    package org.springframework.richclient.samples.simplest;
    
    import org.springframework.richclient.application.support.AbstractView;
    
    import javax.swing.*;
    import java.awt.*;
    
    public class MainView extends AbstractView{
      protected JComponent createControl() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(new JLabel("Hello, world!"));
        return panel;
      }
    }
    Next thing is XML-configs. It is nothing, but spring managed beans.
    Splash screen configuration. It's mentioned in launcher class (Main). This is not essential, but it looks cool, when splash screen is shown while whole program is being loaded.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
            "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
      <bean id="splashScreen"
              class="org.springframework.richclient.application.SplashScreen"
              singleton="false">
              <property name="imageResourcePath">
                      <value>/images/splash.png</value>
              </property>
      </bean>
    </beans>
    This is application configuration, it's also mentioned in Main.java and defines the application itself. Mainly it's designated for defining resources such as messages, icons, images and so on. Also it defines views, available in application. Here defined starting view - MainView.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
            "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
      <bean id="application"
        class="org.springframework.richclient.application.Application">
        <constructor-arg index="0">
          <ref bean="simplestAdvisor"/>
        </constructor-arg>
      </bean>
    
      <bean id="simplestAdvisor" class="org.springframework.richclient.samples.simplest.ApplicationAdvisor">
        <property name="windowCommandBarDefinitions">
          <value>/org/springframework/richclient/samples/simplest/config/simplest-commands.xml</value>
        </property>
        <property name="startingPageId">
          <value>mainView</value>
        </property>
      </bean>
    
      <bean id="mainView"
        class="org.springframework.richclient.application.support.DefaultViewDescriptor">
        <property name="viewClass">
          <value>org.springframework.richclient.samples.simplest.MainView</value>
        </property>
      </bean>
    
    
      <bean id="imageResourcesFactory"
        class="org.springframework.context.support.ResourceMapFactoryBean">
        <property name="locations">
          <list>
            <value>classpath&#58;/org/springframework/richclient/samples/simplest/config/images.properties</value>
          </list>
        </property>
        <property name="resourceBasePath">
          <value>images/</value>
        </property>
      </bean>
    
      <bean id="imageSource"
        class="org.springframework.richclient.image.DefaultImageSource">
        <constructor-arg index="0">
          <ref bean="imageResourcesFactory"/>
        </constructor-arg>
      </bean>
    
      <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
          <list>
            <value>org.springframework.richclient.samples.simplest.config.messages</value>
          </list>
        </property>
      </bean>
    </beans>
    Defininion of menu bar. Consists of one command: EXIT.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    	"http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
      <bean id="windowCommandManager"
        class="org.springframework.richclient.application.support.ApplicationWindowCommandManager">
      </bean>
    
      <bean id="menuBar"
        class="org.springframework.richclient.command.CommandGroupFactoryBean">
        <property name="members">
          <list>
            <ref bean="fileMenu"/>
          </list>
        </property>
      </bean>
    
      <bean id="fileMenu"
        class="org.springframework.richclient.command.CommandGroupFactoryBean">
        <property name="members">
          <list>
            <bean class="org.springframework.richclient.command.support.ExitCommand"/>
          </list>
        </property>
      </bean>
    
    </beans>
    At last the resource files:
    images.properties
    Code:
    applicationInfo.image=small-icon.png
    messages.properties
    Code:
    fileMenu.caption=File
    fileMenu.label=File
    
    exitCommand.label=Exit
    That's all.

  • #2
    Thank you for this post.

    BTW, do we still have to get the Spring-RC from CVS?
    zeron

    Comment


    • #3
      thank you for this sample dedicated to newbies (I didn't know where to start - the petstore was to complex for me -).

      What do you (the community) think if this sample moves to the user documentation (maybe in a tutorial section) (http://opensource.atlassian.com/conf...+Documentation) ?

      Comment


      • #4
        If you have an accout in our Jira you should be able to create new pages edit etc. the wiki. Please feel free to do so! There's realy no need to ask ;-)

        Comment


        • #5
          Originally posted by zeron
          BTW, do we still have to get the Spring-RC from CVS?
          zeron
          yes, we do.
          becasuse there is no release version yet from sourceforge.net

          Comment


          • #6
            Fill free to place this sample in user documentation. Fill free to ask me the whole tar.bz2 to ease the process.

            PS. I'm very glad if this sample helps anybody to start-up.

            Comment


            • #7
              When I run the sample, the splash screen and then the main view come up, but I do not get a menu bar in the main view. What I do see is "displayName" near the top of the view and "Hello, world!" in the middle, but no menu bar. Any ideas as to what I am overlooking?

              Comment


              • #8
                Originally posted by MCarlin
                When I run the sample, the splash screen and then the main view come up, but I do not get a menu bar in the main view. What I do see is "displayName" near the top of the view and "Hello, world!" in the middle, but no menu bar. Any ideas as to what I am overlooking?
                The most likely you have not configured message source properly, so RC don't know how to label your menu bar items.

                Check the messages.properties file placed correctly, contains fileMenu.* items and rightly described in bean definition
                Code:
                ...
                  <bean id="messageSource"
                    class="org.springframework.context.support.ResourceBundleMessageSource">
                    <property name="basenames">
                      <list>
                        <value>org.springframework.richclient.samples.simplest.config.messages</value>
                      </list>
                    </property>
                  </bean>
                ...

                Comment


                • #9
                  Thank you for posting this example. I am using it as a starting point to understand Spring RCP.

                  A few beginner questions:

                  1. How do I change the "displayName" text to my own value?

                  2. If I wanted to remove the titlebar containing the "displayName" how would I do that?

                  3. How do I specifiy a different look and feel with the example?

                  Comment


                  • #10
                    There is also a sample RCP application in the last chapter of "Spring, A Developer's Notebook" from O'Reilly.

                    Comment


                    • #11
                      Originally posted by jfcloutier
                      There is also a sample RCP application in the last chapter of "Spring, A Developer's Notebook" from O'Reilly.
                      I have this book and find the example in the last chapter a bit wanting. The last chapter does not address most of the nitty gritty details involved with creating a rich client app using Spring RCP, and certainly does not address the questions in my previous post. The companion web site includes sample code for the book, but not for the example in the last chapter. Basically the book raises more questions about using Spring RCP than it answers.

                      Comment


                      • #12
                        Basically the book raises more questions about using Spring RCP than it answers.
                        True, yet it is the only tutorial material available on RCP. That counts for something.

                        Comment


                        • #13
                          Please Help!!!

                          I have done exactly the same thing that was given in the Simplest Spring RCP example. But i get an error like this:

                          [ERROR,ApplicationLauncher,main] Exception occured initializing Application bean
                          java.lang.IllegalStateException: The application services locator instance has not yet been initialized.
                          at org.springframework.util.Assert.state(Assert.java: 354)
                          at org.springframework.richclient.application.Applica tionServicesLocator.instance(ApplicationServicesLo cator.java:47)
                          at org.springframework.richclient.application.Applica tionServicesLocator.services(ApplicationServicesLo cator.java:69)
                          at org.springframework.richclient.application.Applica tion.services(Application.java:84)
                          at org.springframework.richclient.application.Applica tion.createNewWindow(Application.java:157)
                          at org.springframework.richclient.application.Applica tion.openWindow(Application.java:147)
                          at org.springframework.richclient.application.Applica tion.start(Application.java:210)
                          at org.springframework.richclient.application.Applica tionLauncher.launchMyRichClient(ApplicationLaunche r.java:223)
                          at org.springframework.richclient.application.Applica tionLauncher.<init>(ApplicationLauncher.java:103)
                          at org.springframework.richclient.samples.simplest.Ma in.main(Main.java:7)

                          please can one let me know what's the exact problem and how to resolve it...

                          Comment


                          • #14
                            I would recommend checking out the latest .3 snapshot in SVN accordining to the instructions here:
                            http://spring-rich-c.sourceforge.net...mentSetup.html

                            Once you have the projects imported into your favorite IDE, I would recommend running the "Simple" sample and studying it. With .3, "simple" is even simpler--the simplest possible Spring Rich app you'll come across. A good starting point.

                            Keith

                            Comment


                            • #15
                              Originally posted by MCarlin View Post
                              Thank you for posting this example. I am using it as a starting point to understand Spring RCP.

                              1. How do I change the "displayName" text to my own value?
                              2. If I wanted to eliminate the title bar in the view, how would I do that?
                              3. How do I specifiy a different look and feel with the example?
                              I suspect the original poster of these questions is no longer interested in the answers (since the date was more than a year ago). However, since I found this thread while trying to answer the same questions, I wanted to post the answers I found.

                              Originally posted by MCarlin View Post
                              Thank you for posting this example. I am using it as a starting point to understand Spring RCP.

                              1. How do I change the "displayName" text to my own value?
                              Working with the 0.2.1 snapshot, you'll need a few more beans in the application context:
                              Code:
                                <bean id="applicationServices"
                                     class="org.springframework.richclient.application.support.DefaultApplicationServices">
                                  <property name="applicationObjectConfigurerId"><idref bean="applicationObjectConfigurer" /></property>
                                  <property name="imageSourceId"><idref bean="imageSource"/></property>
                                  <property name="messageSourceId"><idref bean="messageSource"/></property>
                                </bean>
                              
                                <bean id="applicationServicesLocator"
                                  class="org.springframework.richclient.application.ApplicationServicesLocator">
                                  <property name="applicationServices"><ref bean="applicationServices"/></property>
                                </bean>
                                
                                <bean id="applicationObjectConfigurer" depends-on="applicationServicesLocator"
                              		class="org.springframework.richclient.application.config.DefaultApplicationObjectConfigurer"/>
                              The first couple of beans are new to snapshot 0.2.1. Previously, magic bean names (like "messageSource") were used by the framework. Now, the ApplicationServices and ApplicationServicesLocator bean collaborate to accomplish the same thing.

                              The applicationObjectConfigurer is particularly important in this context, since it appears to form the wiring between message properties of components in the UI and the messages.properties file.

                              With these additional beans defined, you can set the label for the mainView UI component in the messages.properties file, like this:
                              Code:
                              mainView.title=Hello, World



                              Originally posted by MCarlin View Post
                              3. How do I specify a different look and feel with the example?
                              Add a look and feel bean to the application context:

                              Code:
                                <bean id="lookAndFeelConfigurer"
                              		class="org.springframework.richclient.application.config.JGoodiesLooksConfigurer">
                                  <property name="popupDropShadowEnabled" value="false" />
                                  <property name="theme">	
                                    <bean class="com.jgoodies.looks.plastic.theme.ExperienceBlue"/>
                                  </property>
                                </bean>

                              Comment

                              Working...
                              X