Swing Breadcrumb Bar for browsing remote SVN repositories

October 2nd, 2007 | 12 Comments »

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.


Related posts:

  1. Rainbow 1.1 – SVG browser for remote SVN repositories Those of you who came to the session (PDF link) that Alex and I have...
  2. Flamingo component suite 3.0 – breadcrumb bar The breadcrumb bar component from the Flamingo component suite has been mentioned a few times...
  3. SVN Breadcrumb Bar – feedback from the comments Following the comments from the previous entry that introduced a Swing breadcrumb bar component that...
  4. Syntax coloring for the Swing editor pane Ayman Al-Sairafi has a very useful project called JSyntaxPane which provides syntax highlighting capabilities for...


12 Comments on “Swing Breadcrumb Bar for browsing remote SVN repositories”

  1. 1 Kamil Páral said at 12:24 am on October 3rd, 2007:

    It should make the connections in another thread. When you are changing the directory, whole gui freezes for a short time…

  2. 2 AC said at 4:26 am on October 3rd, 2007:

    Wouldn’t it be easier to just rely on the TreeModel interface, so you could use BreadcrumbBar as a drop-in replacement for a JTree? Or am I missing something? At least it would be nice to have an adapter allowing the use of a TreeModel with BreadcrumbBar.

    Great work none the less!

  3. 3 Kirill Grouchnikov said at 8:23 am on October 3rd, 2007:

    Kamil and AC – thanks for the suggestions. I will work on these in the next few days.

    Kirill

  4. 4 Danno Ferrin said at 9:30 am on October 3rd, 2007:

    Shame on you! Doing network processing in the EDT. Of all people you should know!

    org.tmatesoft.svn.core.SVNException: svn: ‘/repos/asf/!svn/bc/581647/felix/trunk/main/pom.xml/LICENSE/LICENSE’ path not found: 404 Not Found (http://svn.apache.org)
    at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:49)
    at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.getDir(DAVRepository.java:282)
    at org.tmatesoft.svn.core.io.SVNRepository.getDir(SVNRepository.java:916)
    at org.jvnet.flamingo.bcb.core.BreadcrumbSvnSelector$PathCallback.getLeafs(BreadcrumbSvnSelector.java:115)
    at test.bcb.SvnBreadCrumbTest$3.breadcrumbBarEvent(SvnBreadCrumbTest.java:231)
    at org.jvnet.flamingo.bcb.BreadcrumbBar.fireBreadcrumbBarEvent(BreadcrumbBar.java:221)
    at org.jvnet.flamingo.bcb.BreadcrumbBar.pushChoice(BreadcrumbBar.java:590)
    at test.bcb.SvnBreadCrumbTest$4$1.run(SvnBreadCrumbTest.java:287)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  5. 5 Kirill Grouchnikov said at 9:45 am on October 3rd, 2007:

    Danno – over the next few days the internal implementation will be reworked to use a worker thread for working with SVN. Thanks for the comment. Kirill

  6. 6 Eugene Kuleshov said at 1:37 pm on October 3rd, 2007:

    The first drop down look somehow odd. Why didn’t you used same selection arrow like for the following segments?

  7. 7 Kirill Grouchnikov said at 1:40 pm on October 3rd, 2007:

    Eugene – i’m not sure that i follow. What selection arrow are you talking about? The one right next to the combobox, or perhaps something else?

  8. 8 Eugene Kuleshov said at 2:01 pm on October 3rd, 2007:

    Consider this example:

    > SVNkit > trunk > svnkit-eclipse >

    I think it would be more natural if all arrows (“>”) should be clickable and show a dropdown menu, but not the dropdown list around section text like in your examples.

  9. 9 Kirill Grouchnikov said at 2:35 pm on October 3rd, 2007:

    Eugene – i understand now. The current implementation in this specific example uses a combobox to select an SVN repository and a breadcrumb bar to browse that repository. You’re talking about a breadcrumb bar that has a list of SVN repositories as the root selector. It can be easily done, but in this test application i wanted to show the “division of responsibilities” between selecting an SVN repository and browsing through the selected repository.

    I will add a new implementation of SVN-based breadcrumb bar that incorporates your suggestion.

    Thanks
    Kirill

  10. 10 Eugene Kuleshov said at 2:39 pm on October 3rd, 2007:

    I see. You should probably add some vertical separator to show that combobox is not part of the other control. But even then on screenshot with “trunk” and dropdown it is confusing to see “trunk” looking as combobox.

  11. 11 Kirill Grouchnikov said at 2:48 pm on October 3rd, 2007:

    Eugene,

    This is how the Vista renders the active part of the breadcrumb bar, highlighting both the arrow and the item that precedes it. The rendering in this application is done by Substance that follows the Vista design.

  12. 12 SVN Breadcrumb Bar - feedback from the comments said at 11:25 pm on October 4th, 2007:

    [...] Swing Breadcrumb Bar for browsing remote SVN repositories Oct [...]