/plugins/SVNPlugin/trunk/src/ise/plugin/svn/gui/br/Checkout.java

# · Java · 86 lines · 45 code · 8 blank · 33 comment · 9 complexity · 997da77bfbcac2c695919cfc5b4b7b95 MD5 · raw file

  1. /*
  2. Copyright (c) 2007, Dale Anson
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without modification,
  5. are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. * Neither the name of the author nor the names of its contributors
  12. may be used to endorse or promote products derived from this software without
  13. specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package ise.plugin.svn.gui.br;
  26. import java.awt.event.ActionEvent;
  27. import javax.swing.JOptionPane;
  28. import javax.swing.tree.TreePath;
  29. import ise.plugin.svn.action.*;
  30. import ise.plugin.svn.data.RepositoryData;
  31. public class Checkout extends BRAction {
  32. public void actionPerformed( ActionEvent ae ) {
  33. TreePath[] paths = tree.getSelectionPaths();
  34. if ( paths.length == 0 ) {
  35. return ;
  36. }
  37. if ( paths.length > 1 ) {
  38. JOptionPane.showMessageDialog( view, "Please select a single entry.", "Too many selections", JOptionPane.ERROR_MESSAGE );
  39. return ;
  40. }
  41. String url = null;
  42. for ( TreePath path : paths ) {
  43. if ( path != null ) {
  44. // combine the tree path parts into a string. A tree path has
  45. // it's parts separated by / already. The initial path may or
  46. // may not have a trailing /, remove it if it is there.
  47. Object[] parts = path.getPath();
  48. StringBuilder sb = new StringBuilder();
  49. String part = parts[0].toString();
  50. if (part.endsWith("/")) {
  51. part = part.substring(0, part.length() - 1);
  52. }
  53. sb.append( part );
  54. // append the remaining tree path parts, inserting / if necessary
  55. // to separate the parts
  56. for ( int i = 1; i < parts.length; i++ ) {
  57. part = parts[i].toString();
  58. if (!part.startsWith("/")) {
  59. sb.append("/");
  60. }
  61. sb.append( parts[ i ].toString() );
  62. }
  63. // url is complete, done with loop
  64. url = sb.toString();
  65. break;
  66. }
  67. }
  68. RepositoryData data = new RepositoryData();
  69. data.setURL( url );
  70. data.setUsername( username );
  71. data.setPassword( password );
  72. CheckoutAction action = new CheckoutAction( view, data );
  73. action.actionPerformed( ae );
  74. }
  75. }