Swing Breadcrumb Bar for browsing remote SVN repositories

October 2nd, 2007

Early last year, i wrote about an outside contribution to the Flamingo component suite. Back then, Rick Jelliffe of Topologi has graciously donated his Breadcrumb Bar component under the BSD license. You can see breadcrumb bars pretty much everywhere on the web, and Vista explorer uses it as the default representation of your current location in the folder tree:

Vista explorer breadcrumb bar

Since then, i’ve made a few simplifications and improvements to the original code, and the BreadcrumbFileSelector component (now in org.jvnet.flamingo.bcb.core package) provides a Vista-like file navigator bar. In addition, the latest development drop of Flamingo 2.1dev (code-named Deirdre) contains an additional core breadcrumb bar implementation that allows navigating SVN repositories (local and remote).

The implementation itself is available in the BreadcrumbSvnSelector component (in the same package) and uses SVNKit, the pure Java Subversion client library. A sidenote before i proceed – the SVNKit license is copyleft, and if you want to use this component in your closed source, you will either have to buy a commercial SVNKit license, or replace the implementation of BreadcrumbSvnSelector.PathCallback with another SVN library.

Let me show you how simple it is to use this component. First, you can run the demo application that allows you browsing through three remote SVN repositories, SVNKit itself, KDE and Apache:

The initial screen is empty and has a combobox in the left part of the toolbar to select the SVN repository:

Once you select the repository, the application code calls the following method on the BreadcrumbSvnSelector component:

public void setConnectionParams(String url, String userName, String password)

The parameters are self-explanatory, with the first one being the repository URL (can start with svn://, http://, file://), and the last two specifying the authentication information. Once the connection has been established, the breadcrumb bar component will show the first path selector:

From this point, the component will fill the path choices on its own without any additional application code (unless you want to provide custom filtering or sorting). Nevertheless, the application needs to provide some code to react to the path change events on the breadcrumb bar. In order to do this, add a listener to the component by calling the following method:

public void addListener(BreadcrumbBarListener<String> lst)

In the listener, listen to BreadcrumbBarEvent.PATH_CHANGED event type, retrieve the path with the getNewValue() method of the event itself and provide application-specific logic. In the following screenshot, the right panel shows all files under the selected folder:

As i already mentioned, the application doesn’t need to provide any callback to fetch the subfolders of the selected folder – the default implementation does it automatically:

You can also switch the SVN repositories on the fly by calling the setConnectionParams method mentioned above. There is no need to reset the breadcrumb bar path state – the component does so automatically:

To view the complete source for this test application, click here. As you will see, most of the code deals with the layout and memory load / save functionality (another feature of breadcrumb bar that is detailed in the documentation). All the hard work of connecting and browsing the repositories is done by the component itself.