/plugins/SVNPlugin/tags/1.1.0/src/ise/plugin/svn/gui/CheckoutDialog.java

# · Java · 267 lines · 194 code · 30 blank · 43 comment · 25 complexity · 660f200d8732bfd5780676939c048a2a 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. // imports
  27. import java.util.*;
  28. import java.awt.event.*;
  29. import javax.swing.*;
  30. import javax.swing.border.EmptyBorder;
  31. import org.gjt.sp.jedit.GUIUtilities;
  32. import org.gjt.sp.jedit.jEdit;
  33. import org.gjt.sp.jedit.View;
  34. import org.gjt.sp.jedit.browser.VFSBrowser;
  35. import org.gjt.sp.jedit.gui.HistoryTextField;
  36. import ise.java.awt.KappaLayout;
  37. import ise.java.awt.LambdaLayout;
  38. import ise.plugin.svn.PVHelper;
  39. import ise.plugin.svn.pv.SVNAction;
  40. import ise.plugin.svn.data.*;
  41. import ise.plugin.svn.command.*;
  42. import ise.plugin.svn.library.GUIUtils;
  43. import ise.plugin.svn.library.PasswordHandler;
  44. import static ise.plugin.svn.gui.HistoryModelNames.*;
  45. import org.tmatesoft.svn.core.wc.SVNInfo;
  46. /**
  47. * Dialog for obtaining the url and local directory for a checkout from a
  48. * subversion repository, and optionally a username, and password.
  49. */
  50. public class CheckoutDialog extends JDialog {
  51. // instance fields
  52. private View view = null;
  53. private String _url = null;
  54. private HistoryTextField url = null;
  55. private HistoryTextField path = null;
  56. private HistoryTextField username = null;
  57. private JPasswordField password = null;
  58. private boolean canceled = false;
  59. public CheckoutDialog( View view, String url ) {
  60. super( ( JFrame ) view, jEdit.getProperty("ips.Checkout", "Checkout"), true );
  61. this.view = view;
  62. this._url = url;
  63. _init();
  64. }
  65. /** Initialises the option pane. */
  66. protected void _init() {
  67. JPanel panel = new JPanel( new KappaLayout() );
  68. panel.setBorder( new EmptyBorder( 6, 6, 6, 6 ) );
  69. String project_name = PVHelper.getProjectName(view);
  70. // subversion repository url field
  71. JLabel url_label = new JLabel( jEdit.getProperty( SVNAction.PREFIX + "url.label" ) );
  72. url = new HistoryTextField(URL);
  73. url.setText( _url != null ? _url : jEdit.getProperty( SVNAction.PREFIX + project_name + ".url" ));
  74. url.setColumns( 30 );
  75. // populate url field from existing svn info, if available
  76. List<String> info_path = new ArrayList<String>();
  77. info_path.add(PVHelper.getProjectRoot(view));
  78. SVNData info_data = new SVNData();
  79. info_data.setPaths(info_path);
  80. String url_text = null;
  81. List<SVNInfo> info_results = null;
  82. try {
  83. info_results = new Info().getInfo(info_data);
  84. }
  85. catch(Exception e) {
  86. info_results = null;
  87. }
  88. if (info_results != null && info_results.size() > 0) {
  89. SVNInfo svn_info = info_results.get(0);
  90. if (svn_info != null && svn_info.getURL() != null) {
  91. url_text = svn_info.getURL().toString();
  92. }
  93. }
  94. if ( url_text != null ) {
  95. url.setText( url_text );
  96. }
  97. // browse for url
  98. JButton browse_remote_btn = new JButton( jEdit.getProperty("ips.Browse...", "Browse...") );
  99. browse_remote_btn.addActionListener(
  100. new ActionListener() {
  101. public void actionPerformed( ActionEvent ae ) {
  102. final JDialog dialog = new JDialog( view, jEdit.getProperty("ips.Select_Repository", "Select Repository") );
  103. dialog.setModal( true );
  104. JPanel panel = new JPanel( new LambdaLayout() );
  105. panel.setBorder( BorderFactory.createEmptyBorder( 6, 6, 6, 6 ) );
  106. final BrowseRepositoryPanel burp = new BrowseRepositoryPanel( view, false );
  107. panel.add( "0, 0, 1, 1, 0, wh, 3", burp );
  108. KappaLayout btn_layout = new KappaLayout();
  109. JPanel button_panel = new JPanel( btn_layout );
  110. JButton ok_btn = new JButton( jEdit.getProperty("ips.Ok", "Ok") );
  111. ok_btn.addActionListener(
  112. new ActionListener() {
  113. public void actionPerformed( ActionEvent ae ) {
  114. String selection = burp.getSelectionPath();
  115. dialog.setVisible( false );
  116. dialog.dispose();
  117. if ( selection != null && selection.length() > 0 ) {
  118. url.setText( selection );
  119. }
  120. }
  121. }
  122. );
  123. JButton cancel_btn = new JButton( jEdit.getProperty("ips.Cancel", "Cancel") );
  124. cancel_btn.addActionListener(
  125. new ActionListener() {
  126. public void actionPerformed( ActionEvent ae ) {
  127. dialog.setVisible( false );
  128. dialog.dispose();
  129. }
  130. }
  131. );
  132. button_panel.add( "0, 0, 1, 1, 0, w, 3", ok_btn );
  133. button_panel.add( "1, 0, 1, 1, 0, w, 3", cancel_btn );
  134. btn_layout.makeColumnsSameWidth( 0, 1 );
  135. panel.add( "0, 1, 1, 1", KappaLayout.createStrut( 350, 11, false ) );
  136. panel.add( "0, 2, 1, 1, E, , 3", button_panel );
  137. dialog.setContentPane( panel );
  138. dialog.pack();
  139. GUIUtils.center( view, dialog );
  140. dialog.setVisible( true );
  141. }
  142. }
  143. );
  144. // local destination directory
  145. JLabel path_label = new JLabel( jEdit.getProperty( SVNAction.PREFIX + "path.label" ) );
  146. path = new HistoryTextField(PATH);
  147. // TODO: can I do some munging here to get the project name out of the url?
  148. path.setText( PVHelper.getProjectRoot(view));
  149. path.setColumns( 30 );
  150. JButton browse_btn = new JButton( jEdit.getProperty("ips.Browse", "Browse") );
  151. browse_btn.addActionListener( new ActionListener() {
  152. public void actionPerformed( ActionEvent ae ) {
  153. String[] dirs = GUIUtilities.showVFSFileDialog( view, PVHelper.getProjectRoot(view), VFSBrowser.CHOOSE_DIRECTORY_DIALOG, false );
  154. if (dirs != null && dirs.length > 0) {
  155. path.setText(dirs[0]);
  156. }
  157. }
  158. }
  159. );
  160. // username field
  161. JLabel username_label = new JLabel( jEdit.getProperty( SVNAction.PREFIX + "username.label" ) );
  162. username = new HistoryTextField(USERNAME);
  163. username.setText( jEdit.getProperty( SVNAction.PREFIX + project_name + ".username" ));
  164. username.setColumns( 30 );
  165. // password field
  166. JLabel password_label = new JLabel( jEdit.getProperty( SVNAction.PREFIX + "password.label" ) );
  167. String pwd = jEdit.getProperty( SVNAction.PREFIX + project_name + ".password" );
  168. pwd = PasswordHandler.decryptPassword(pwd);
  169. password = new JPasswordField( pwd, 30 );
  170. // buttons
  171. KappaLayout kl = new KappaLayout();
  172. JPanel btn_panel = new JPanel( kl );
  173. JButton ok_btn = new JButton( jEdit.getProperty("ips.Ok", "Ok") );
  174. JButton cancel_btn = new JButton( jEdit.getProperty("ips.Cancel", "Cancel") );
  175. btn_panel.add( "0, 0, 1, 1, 0, w, 3", ok_btn );
  176. btn_panel.add( "1, 0, 1, 1, 0, w, 3", cancel_btn );
  177. kl.makeColumnsSameWidth( 0, 1 );
  178. ok_btn.addActionListener( new ActionListener() {
  179. public void actionPerformed( ActionEvent ae ) {
  180. if ( url == null || url.getText().length() == 0 ) {
  181. JOptionPane.showMessageDialog( CheckoutDialog.this, jEdit.getProperty("ips.URL_is_required.", "URL is required."), jEdit.getProperty("ips.Error", "Error"), JOptionPane.ERROR_MESSAGE );
  182. return ;
  183. }
  184. if ( path == null || path.getText().length() == 0 ) {
  185. JOptionPane.showMessageDialog( CheckoutDialog.this, jEdit.getProperty("ips.Directory_is_required.", "Directory is required."), jEdit.getProperty("ips.Error", "Error"), JOptionPane.ERROR_MESSAGE );
  186. return ;
  187. }
  188. canceled = false;
  189. CheckoutDialog.this.setVisible( false );
  190. CheckoutDialog.this.dispose();
  191. url.addCurrentToHistory();
  192. path.addCurrentToHistory();
  193. username.addCurrentToHistory();
  194. }
  195. }
  196. );
  197. cancel_btn.addActionListener( new ActionListener() {
  198. public void actionPerformed( ActionEvent ae ) {
  199. canceled = true;
  200. CheckoutDialog.this.setVisible( false );
  201. CheckoutDialog.this.dispose();
  202. }
  203. }
  204. );
  205. // add the components to the option panel
  206. panel.add( "0, 0, 1, 1, E, , 3", url_label );
  207. panel.add( "1, 0, 2, 1, 0, w, 3", url );
  208. panel.add( "3, 0, 1, 1, 0, w, 3", browse_remote_btn );
  209. panel.add( "0, 1, 1, 1, E, , 3", path_label );
  210. panel.add( "1, 1, 2, 1, 0, w, 3", path );
  211. panel.add( "3, 1, 1, 1, 0, w, 3", browse_btn );
  212. panel.add( "0, 2, 1, 1, E, , 3", username_label );
  213. panel.add( "1, 2, 2, 1, 0, w, 3", username );
  214. panel.add( "0, 3, 1, 1, E, , 3", password_label );
  215. panel.add( "1, 3, 2, 1, 0, w, 3", password );
  216. panel.add( "0, 4, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 10, true ) );
  217. panel.add( "0, 5, 4, 1, E, , 0", btn_panel );
  218. setContentPane( panel );
  219. pack();
  220. }
  221. public CheckoutData getValues() {
  222. if ( canceled ) {
  223. return null;
  224. }
  225. CheckoutData cd = new CheckoutData();
  226. cd.setURL(url.getText());
  227. cd.setUsername(username.getText());
  228. cd.setPassword(PasswordHandler.encryptPassword(new String(password.getPassword())));
  229. List<String> paths = new ArrayList<String>();
  230. paths.add(path.getText());
  231. cd.setPaths(paths);
  232. return cd;
  233. }
  234. }