/plugins/SVNPlugin/tags/0.9.2/src/ise/plugin/svn/gui/AddRepositoryDialog.java

# · Java · 193 lines · 125 code · 28 blank · 40 comment · 21 complexity · 446136e4904da0eed914faa083d46329 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;
  26. import java.util.*;
  27. import java.awt.event.*;
  28. import javax.swing.*;
  29. import javax.swing.border.EmptyBorder;
  30. import org.gjt.sp.jedit.GUIUtilities;
  31. import org.gjt.sp.jedit.jEdit;
  32. import org.gjt.sp.jedit.View;
  33. import org.gjt.sp.util.*;
  34. import org.gjt.sp.jedit.browser.VFSBrowser;
  35. import projectviewer.ProjectViewer;
  36. import projectviewer.config.ProjectOptions;
  37. import projectviewer.vpt.VPTNode;
  38. import projectviewer.vpt.VPTProject;
  39. import ise.java.awt.KappaLayout;
  40. import ise.plugin.svn.pv.SVNAction;
  41. import ise.plugin.svn.data.*;
  42. import ise.plugin.svn.command.*;
  43. import ise.plugin.svn.library.PasswordHandler;
  44. import ise.plugin.svn.library.PasswordHandlerException;
  45. import org.tmatesoft.svn.core.wc.SVNInfo;
  46. /**
  47. * Dialog for obtaining/editing the url and credentials to browse a repository.
  48. */
  49. public class AddRepositoryDialog extends JDialog {
  50. private View view = null;
  51. private RepositoryData data = null;
  52. private JTextField name = null;
  53. private JTextField url = null;
  54. private JTextField username = null;
  55. private JPasswordField password = null;
  56. private boolean canceled = false;
  57. public AddRepositoryDialog( View view ) {
  58. super( ( JFrame ) view, "Add Repository Location", true );
  59. this.view = view;
  60. _init();
  61. }
  62. public AddRepositoryDialog( View view, RepositoryData data ) {
  63. super( ( JFrame ) view, "Edit Repository Location", true );
  64. this.view = view;
  65. this.data = data;
  66. _init();
  67. }
  68. /** Initialises the option pane. */
  69. protected void _init() {
  70. JPanel panel = new JPanel( new KappaLayout() );
  71. panel.setBorder( new EmptyBorder( 6, 6, 6, 6 ) );
  72. // name field
  73. JLabel name_label = new JLabel( jEdit.getProperty( SVNAction.PREFIX + "name.label" ) );
  74. String name_value = data != null && data.getName() != null ? data.getName() : "";
  75. name = new JTextField( name_value, 30 );
  76. // subversion repository url field
  77. JLabel url_label = new JLabel( jEdit.getProperty( SVNAction.PREFIX + "url.label" ) );
  78. String url_value = data != null ? data.getURL() : "";
  79. url = new JTextField( url_value, 30 );
  80. // username field
  81. JLabel username_label = new JLabel( jEdit.getProperty( SVNAction.PREFIX + "username.label" ) );
  82. String username_value = data != null && data.getUsername() != null ? data.getUsername() : "";
  83. username = new JTextField( username_value, 30 );
  84. // password field
  85. JLabel password_label = new JLabel( jEdit.getProperty( SVNAction.PREFIX + "password.label" ) );
  86. String password_value = data != null && data.getPassword() != null ? data.getPassword() : "";
  87. // if there is a password, it should be encrypted, so attempt to decrypt
  88. if ( password_value != null && password_value.length() > 0 ) {
  89. try {
  90. PasswordHandler ph = new PasswordHandler();
  91. password_value = ph.decrypt( password_value );
  92. }
  93. catch ( Exception e ) {
  94. password_value = "";
  95. }
  96. }
  97. password = new JPasswordField( password_value, 30 );
  98. // buttons
  99. KappaLayout kl = new KappaLayout();
  100. JPanel btn_panel = new JPanel( kl );
  101. JButton ok_btn = new JButton( "Ok" );
  102. JButton cancel_btn = new JButton( "Cancel" );
  103. btn_panel.add( "0, 0, 1, 1, 0, w, 3", ok_btn );
  104. btn_panel.add( "1, 0, 1, 1, 0, w, 3", cancel_btn );
  105. kl.makeColumnsSameWidth( 0, 1 );
  106. ok_btn.addActionListener( new ActionListener() {
  107. public void actionPerformed( ActionEvent ae ) {
  108. if ( url == null || url.getText().length() == 0 ) {
  109. JOptionPane.showMessageDialog( AddRepositoryDialog.this, "URL is required.", "Error", JOptionPane.ERROR_MESSAGE );
  110. return ;
  111. }
  112. canceled = false;
  113. AddRepositoryDialog.this.setVisible( false );
  114. AddRepositoryDialog.this.dispose();
  115. }
  116. }
  117. );
  118. cancel_btn.addActionListener( new ActionListener() {
  119. public void actionPerformed( ActionEvent ae ) {
  120. canceled = true;
  121. AddRepositoryDialog.this.setVisible( false );
  122. AddRepositoryDialog.this.dispose();
  123. }
  124. }
  125. );
  126. // add the components to the option panel
  127. panel.add( "0, 0, 1, 1, E, , 3", name_label );
  128. panel.add( "1, 0, 2, 1, 0, w, 3", name );
  129. panel.add( "0, 1, 1, 1, E, , 3", url_label );
  130. panel.add( "1, 1, 2, 1, 0, w, 3", url );
  131. panel.add( "0, 2, 1, 1, E, , 3", username_label );
  132. panel.add( "1, 2, 2, 1, 0, w, 3", username );
  133. panel.add( "0, 3, 1, 1, E, , 3", password_label );
  134. panel.add( "1, 3, 2, 1, 0, w, 3", password );
  135. panel.add( "0, 4, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 10, true ) );
  136. panel.add( "0, 5, 3, 1, E, , 0", btn_panel );
  137. setContentPane( panel );
  138. pack();
  139. }
  140. public RepositoryData getValues() {
  141. if ( canceled ) {
  142. return null;
  143. }
  144. RepositoryData data = new RepositoryData();
  145. data.setName( name.getText() );
  146. data.setURL( url.getText() );
  147. data.setUsername( username.getText() );
  148. // encrypt the password if there is one
  149. String pwd = new String( password.getPassword() );
  150. if ( pwd != null && pwd.length() > 0 ) {
  151. try {
  152. PasswordHandler ph = new PasswordHandler();
  153. pwd = ph.encrypt( pwd );
  154. }
  155. catch ( Exception e ) {
  156. // ignore?
  157. }
  158. }
  159. data.setPassword( pwd );
  160. return data;
  161. }
  162. }