Getting Further with Spring RCP
Adding Functionality to the Table
Let's now add a popup item to our table. Whenever the user right-clicks in the table, the popup item should appear. The starting point is to override "AbstractView.registerLocalCommandExecutors()", similar to how we did it in the section Adding Context Sensitivity, in "Getting Started with Spring RCP". Here we specify that we want to use our PropertiesExecutor to handle the Properties command. That executor returns a simple JOptionPane as a placeholder for code that we will add later.
Then we use the Spring RCP "CommandGroup" class and the Spring RCP "ValueModel" class to display the popup item within the table. One or more commands can be gathered up together into a "CommandGroup", which has several useful utility methods, such as "setPopupCommandGroup", for creating popups. A "ValueModel", on the other hand, is useful for ensuring that a command is only active when something is selected. We create a new "ListSingleSelectionGuard", which selects a list selection model that is held by the ValueModel. Then the related commands (which are the guarded objects) are either enabled or disabled. You will find that, if you don't set a ValueModel, the command will always be disabled.
It is this interaction, i.e., the fact that changes in the GUI are reflected in ValueModels (and the fact that the values of the ValueModels are committed back to the related form objects, once the values in the ValueModel change), that is called "data binding", in the context of Spring RCP.
So, replace the content of your current CustomerView with the following:
package simple;
import domain.CustomerDataStore;
import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.springframework.binding.value.ValueModel;
import org.springframework.richclient.application.PageComponentContext;
import org.springframework.richclient.application.support.AbstractView;
import org.springframework.richclient.command.ActionCommand;
import org.springframework.richclient.command.CommandGroup;
import org.springframework.richclient.command.GuardedActionCommandExecutor;
import org.springframework.richclient.command.support.AbstractActionCommandExecutor;
import org.springframework.richclient.command.support.GlobalCommandIds;
import org.springframework.richclient.list.ListSelectionValueModelAdapter;
import org.springframework.richclient.list.ListSingleSelectionGuard;
public class CustomerView extends AbstractView {
private CustomerTable customerTable;
private CustomerDataStore customerDataStore;
private GuardedActionCommandExecutor propertiesExecutor = new PropertiesExecutor();
protected CustomerDataStore getCustomerDataStore() {
return customerDataStore;
}
public void setCustomerDataStore(CustomerDataStore customerDataStore) {
this.customerDataStore = customerDataStore;
}
@Override
protected void registerLocalCommandExecutors(PageComponentContext context) {
context.register(GlobalCommandIds.PROPERTIES, propertiesExecutor);
}
@Override
protected JComponent createControl() {
customerTable = new customerTableFactory().createCustomerTable();
JPanel view = new JPanel(new BorderLayout());
JScrollPane sp = getComponentFactory().createScrollPane(customerTable.getControl());
view.add(sp, BorderLayout.CENTER);
return view;
}
private class customerTableFactory {
public CustomerTable createCustomerTable() {
CustomerTable customerTable = new CustomerTable(customerDataStore);
CommandGroup popup = new CommandGroup();
popup.add((ActionCommand) getWindowCommandManager().getCommand(GlobalCommandIds.PROPERTIES, ActionCommand.class));
customerTable.setPopupCommandGroup(popup);
ValueModel selectionHolder = new ListSelectionValueModelAdapter(customerTable.getSelectionModel());
new ListSingleSelectionGuard(selectionHolder, propertiesExecutor);
return customerTable;
}
}
private class PropertiesExecutor extends AbstractActionCommandExecutor {
@Override
public void execute() {
JOptionPane.showMessageDialog(null, "Placeholder for showing TitledPageApplicationDialog...");
}
}
}
Now when you right-click in the table, you should see your new popup item:
When you select the item, a JOptionPane appears, as a placeholder for the code you will add in the next section.
And now you might be wondering how to set a double-click event, so that the PropertiesExecutor will be invoked when the user double-clicks on the table. Here it is, simply add this to the createCustomerTable() method, somewhere between lines 56 and 63 above:
customerTable.setDoubleClickHandler(propertiesExecutor);
Then run the application again and double-click in the table and you will have the same result as when you right-clicked the table and then invoked the popup item.
| 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 |





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 ___ 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 ___ replied on Fri, 2008/07/04 - 4:30pm
Even more
Geoffrey De Smet 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:
Geoffrey De Smet
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.
Lieven Doclo 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 Wielenga
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
Pierre Teddy replied on Fri, 2008/08/15 - 9:25am
in response to:
Geertjan Wielenga
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 Trivedi 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
Matt Coleman replied on Mon, 2012/01/16 - 4:41am
Mateo Gomez replied on Tue, 2012/01/17 - 1:32am
Steve Sdas replied on Thu, 2012/11/01 - 11:21am
Steve Sdas replied on Fri, 2012/11/30 - 7:23am
Uilly Tocky replied on Tue, 2012/12/04 - 11:34am
Uilly Tocky replied on Wed, 2012/12/05 - 3:06am
Uilly Tocky replied on Fri, 2012/12/07 - 6:59am
Uilly Tocky replied on Tue, 2012/12/11 - 2:57am
Uilly Tocky replied on Tue, 2012/12/11 - 11:30am
Uilly Tocky replied on Thu, 2012/12/13 - 6:19am
Uilly Tocky replied on Thu, 2012/12/13 - 8:43am
Uilly Tocky replied on Fri, 2012/12/14 - 4:15am
Uilly Tocky replied on Fri, 2012/12/14 - 6:35am
Uilly Tocky replied on Mon, 2012/12/17 - 11:15am
Uilly Tocky replied on Mon, 2012/12/24 - 9:45am
Uilly Tocky replied on Wed, 2012/12/26 - 10:27am
Uilly Tocky replied on Sat, 2012/12/29 - 9:48am