Getting Further with Spring RCP
Creating the Domain Objects
We begin with our domain objects, two of them, so as not to make life too simple, nor too complex. We have an Address POJO and a Customer POJO, in a new package called "domain":
package domain;
public class Address {
private String street;
private String city;
private String state;
private String zip;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
}
Notice that our next domain object, Customer, makes use of a nested object. The nested object is the Address object, defined above. By using this nesting mechanism, we can use nested property paths in forms. So, for example, we can refer to "firstname" and "lastname", because these are not nested, while when dealing with the Address object, we can refer to "address.street" and "address.city". Later you will see how that can come in handy, as an easy way of seeing how the fields relate to each other.
package domain;
public class Customer {
private int id;
private String firstName;
private String lastName;
private Address address;
public Customer() {
setAddress(new Address());
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Finally, let's create an in-memory data store to hook our two domain objects together and provide some dummy data:
package domain;
import java.util.HashSet;
public class CustomerDataStore {
private static int nextId = 1;
private HashSet customers = new HashSet();
public CustomerDataStore() {
loadData();
}
public Customer[] getAllCustomers() {
return (Customer[]) customers.toArray(new Customer[0]);
}
private void loadData() {
customers.add(makeCustomer(
"Larry", "Streepy", "123 Some St.", "New York", "NY", "10010"));
customers.add(makeCustomer(
"Keith", "Donald", "456 WebFlow Rd.", "Cooltown", "NY", "10001"));
customers.add(makeCustomer(
"Steve", "Brothers", "10921 The Other Street", "Denver", "CO", "81234-2121"));
customers.add(makeCustomer(
"Carlos", "Mencia", "4321 Comedy Central", "Hollywood", "CA", "91020"));
customers.add(makeCustomer(
"Jim", "Jones", "1001 Another Place", "Dallas", "TX", "71212"));
customers.add(makeCustomer(
"Jenny", "Jones", "1001 Another Place", "Dallas", "TX", "75201"));
customers.add(makeCustomer(
"Greg", "Jones", "9 Some Other Place", "Chicago", "IL", "60601"));
}
private Customer makeCustomer(
String first, String last, String street,
String city, String state, String zip) {
Customer customer = new Customer();
customer.setId(nextId++);
customer.setFirstName(first);
customer.setLastName(last);
Address address = customer.getAddress();
address.setStreet(street);
address.setCity(city);
address.setState(state);
address.setZip(zip);
return customer;
}
}
As can plainly be seen, there's nothing here that's specific to Spring RCP. We've simply set up our domain and provided a simple way of accessing the data it represents, via CustomerDataStore.getAllCustomers(). However, here's the special twist that brings us into the world of Spring RCP—in our richclient-application-context.xml we need to register our store of data as a property of our CustomerView, so that we can make use of it there, via a getter and setter that we will create later in our CustomerView. So, open the richclient-application-context.xml and add the "viewProperties" below to the CustomerView bean, as well as creating a new bean called "customerDataStore", which references the class above that defines the data store:
<bean id="CustomerView" class="org.springframework.richclient.application.support.DefaultViewDescriptor">
<property name="viewClass" value="simple.CustomerView" />
<property name="viewProperties">
<map>
<entry key="customerDataStore" value-ref="customerDataStore" />
</map>
</property>
</bean>
<bean id="customerDataStore" class="domain.CustomerDataStore" />
| Attachment | Size |
|---|---|
| figure-1.png | 44.04 KB |
| figure-1-src.png | 35.16 KB |
| figure-2-src.png | 41.8 KB |
| figure-3-src.png | 50.43 KB |
| figure-4-src.png | 44.05 KB |
| figure-5-src.png | 44.83 KB |
| figure-6-src.png | 41.06 KB |
- Login or register to post comments
- 32532 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
Matthew Schmidt replied on Thu, 2008/07/03 - 3:25pm
Jonny Wray replied on Thu, 2008/07/03 - 11:02pm
Great article and introduction to Spring RCP. I just wanted to comment that while version 1.0 has only recently been released the code has been useful for a lot longer. Personally, I have a couple of internal applications at work based on the framework, one of which is about three years old.
As an example of a full application, albeit quite simple, people might be interested in Bio Browser, a program to search and browse instances of a domain model from the National Cancer Institute exposed via their web services. The project page, with a web start launch is http://www.assembla.com/wiki/show/biobrowser. There is a child page on the wiki, instructions, which gives basic instructions and screenshots.
Jonny
Peter Karich replied on Fri, 2008/07/04 - 4:29pm
Some more pointers that I have found for this topic (or quite similar):
I even found a full open source app (I didn't try it):
http://pegadi.underdusken.no/browser/trunk
Peter Karich replied on Fri, 2008/07/04 - 4:30pm
Even more
ge0ffrey replied on Sun, 2008/07/06 - 9:21am
I've added links to these articles in svn revision 2051, so they will be published on the next publish of the official spring-richclient website (which contains links to all available documentation):
http://spring-rich-c.sourceforge.net/
Geertjan Wielenga replied on Sun, 2008/07/06 - 9:57am
in response to: ge0ffrey
I've added links to these articles in svn revision 2051, so they will be published on the next publish of the official spring-richclient website (which contains links to all available documentation):
http://spring-rich-c.sourceforge.net/
[/quote]
Great to hear! And there are more parts to this series that I am currently working on and that will be published over the coming weeks.
doclolieven replied on Mon, 2008/07/07 - 2:18am
I've also written a article on how to write a custom binder: http://www.doclo.be/lieven/articles/creatingbinderrcp.html
Geertjan Wielenga replied on Mon, 2008/07/07 - 3:11am
Jonny Wray replied on Mon, 2008/07/07 - 10:39am
in response to: geertjan
Geertjan,
Not a problem, hope you find it useful. The 'instructions' page on the wiki has an example of running a query and then browsing through the results, including viewing pathway diagrams.
Short version, choose Gene from the search menu and enter say, EPO, in the 'Gene Symbol' field. That'll produce a navigable tree in the tree view. Double clicking on entities with a green arrow icon will then fetch those back. Right click on a pathway entity will bring up a context sensitive menu allow diagram to be displayed.
Hope that's enough to get you going
Jonny
Geertjan Wielenga replied on Mon, 2008/07/07 - 11:30am
Gregg Bolinger replied on Mon, 2008/08/11 - 12:49am
clermont38 replied on Fri, 2008/08/15 - 9:25am
in response to: geertjan
Great series! should turn it to a book.
Would appreciate some help with the following problem pleae :
In the PropertiesExecutor class I am Importing the following Jars
import org.springframework.richclient.command.support.AbstractActionCommandExecutor;
import org.springframework.richclient.dialog.CloseAction;
import org.springframework.richclient.dialog.CompositeDialogPage;
import org.springframework.richclient.dialog.TabbedDialogPage;
import org.springframework.richclient.dialog.TitledPageApplicationDialog;
However I am unable to resolve getWindowControl()
Would you know what I am lacking.
Thanks a lot
japan_733 replied on Thu, 2009/07/16 - 5:44am
I'm new to Spring RCP and I'm trying some demo projects to know more about it. But I want to know that how to build a single executable JAR file for the Spring RCP project. I have tried to execute the test JAR file that is been created in the dist folder of the Net Beans RCP project but it didn't run properly it only shows me the splash screen and then the program ends. Please help me out in this matter.
One more thing I want to know is can we integrate a Spring RCP developed in Net Beans with an applet. Because I need to develop one application in RCP but that needs to be run as a client side applet. Or you can show me some other way.
I regularly refers your tutorial on Spring RCP for NetBeans. And it helps me a lot.
Thanks in advance.
Japan Trivedi,
japan_733@yahoo.co.in