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

#
Java | 269 lines | 198 code | 29 blank | 42 comment | 24 complexity | 68a8dd9646ac6b8e208e5364b0cd150d MD5 | raw file

✨ Summary
  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.io.File;
  28. import java.util.*;
  29. import java.awt.event.*;
  30. import javax.swing.*;
  31. import javax.swing.border.EmptyBorder;
  32. import org.gjt.sp.jedit.GUIUtilities;
  33. import org.gjt.sp.jedit.jEdit;
  34. import org.gjt.sp.jedit.View;
  35. import org.gjt.sp.util.*;
  36. import org.gjt.sp.jedit.browser.VFSBrowser;
  37. import org.gjt.sp.jedit.gui.HistoryTextField;
  38. import ise.java.awt.KappaLayout;
  39. import ise.java.awt.LambdaLayout;
  40. import ise.plugin.svn.PVHelper;
  41. import ise.plugin.svn.pv.SVNAction;
  42. import ise.plugin.svn.data.*;
  43. import ise.plugin.svn.command.*;
  44. import ise.plugin.svn.library.GUIUtils;
  45. import ise.plugin.svn.library.PasswordHandler;
  46. import static ise.plugin.svn.gui.HistoryModelNames.*;
  47. import org.tmatesoft.svn.core.wc.SVNInfo;
  48. import org.tmatesoft.svn.core.SVNURL;
  49. /**
  50. * Dialog for obtaining the url and local directory for an import and optionally
  51. * a username, and password.
  52. */
  53. public class ImportDialog extends JDialog {
  54. // instance fields
  55. private View view = null;
  56. private HistoryTextField url = null;
  57. private HistoryTextField path = null;
  58. private HistoryTextField username = null;
  59. private JPasswordField password = null;
  60. private boolean canceled = false;
  61. public ImportDialog( View view ) {
  62. super( ( JFrame ) view, jEdit.getProperty("ips.Import", "Import"), true );
  63. this.view = view;
  64. _init();
  65. }
  66. /** Initialises the option pane. */
  67. protected void _init() {
  68. JPanel panel = new JPanel( new KappaLayout() );
  69. panel.setBorder( new EmptyBorder( 6, 6, 6, 6 ) );
  70. String project_name = PVHelper.getProjectName(view);
  71. // subversion repository url field
  72. JLabel url_label = new JLabel( jEdit.getProperty("ips.To_this_repository_URL>", "To this repository URL:") );
  73. url = new HistoryTextField(URL);
  74. url.setText("");
  75. url.setColumns(30);
  76. // populate url field from existing svn info, if available
  77. List<String> info_path = new ArrayList<String>();
  78. info_path.add(PVHelper.getProjectRoot(view));
  79. SVNData info_data = new SVNData();
  80. info_data.setPaths(info_path);
  81. String url_text = null;
  82. List<SVNInfo> info_results = null;
  83. try {
  84. info_results = new Info().getInfo(info_data);
  85. }
  86. catch(Exception e) {
  87. info_results = null;
  88. }
  89. if (info_results != null && info_results.size() > 0) {
  90. SVNInfo svn_info = info_results.get(0);
  91. if (svn_info != null && svn_info.getURL() != null) {
  92. url_text = svn_info.getURL().toString();
  93. }
  94. }
  95. if ( url_text != null ) {
  96. url.setText( url_text );
  97. }
  98. // browse for url
  99. JButton browse_remote_btn = new JButton( jEdit.getProperty("ips.Browse...", "Browse...") );
  100. browse_remote_btn.addActionListener(
  101. new ActionListener() {
  102. public void actionPerformed( ActionEvent ae ) {
  103. final JDialog dialog = new JDialog( view, jEdit.getProperty("ips.Select_Repository", "Select Repository") );
  104. dialog.setModal( true );
  105. JPanel panel = new JPanel( new LambdaLayout() );
  106. panel.setBorder( BorderFactory.createEmptyBorder( 6, 6, 6, 6 ) );
  107. final BrowseRepositoryPanel burp = new BrowseRepositoryPanel( view, false );
  108. panel.add( "0, 0, 1, 1, 0, wh, 3", burp );
  109. KappaLayout btn_layout = new KappaLayout();
  110. JPanel button_panel = new JPanel( btn_layout );
  111. JButton ok_btn = new JButton( jEdit.getProperty("ips.Ok", "Ok") );
  112. ok_btn.addActionListener(
  113. new ActionListener() {
  114. public void actionPerformed( ActionEvent ae ) {
  115. String selection = burp.getSelectionPath();
  116. dialog.setVisible( false );
  117. dialog.dispose();
  118. if ( selection != null && selection.length() > 0 ) {
  119. url.setText( selection );
  120. }
  121. }
  122. }
  123. );
  124. JButton cancel_btn = new JButton( jEdit.getProperty("ips.Cancel", "Cancel") );
  125. cancel_btn.addActionListener(
  126. new ActionListener() {
  127. public void actionPerformed( ActionEvent ae ) {
  128. dialog.setVisible( false );
  129. dialog.dispose();
  130. }
  131. }
  132. );
  133. button_panel.add( "0, 0, 1, 1, 0, w, 3", ok_btn );
  134. button_panel.add( "1, 0, 1, 1, 0, w, 3", cancel_btn );
  135. btn_layout.makeColumnsSameWidth( 0, 1 );
  136. panel.add( "0, 1, 1, 1", KappaLayout.createStrut( 350, 11, false ) );
  137. panel.add( "0, 2, 1, 1, E, , 3", button_panel );
  138. dialog.setContentPane( panel );
  139. dialog.pack();
  140. GUIUtils.center( view, dialog );
  141. dialog.setVisible( true );
  142. }
  143. }
  144. );
  145. // local destination directory
  146. JLabel path_label = new JLabel( jEdit.getProperty("ips.Import_files_from_this_directory>", "Import files from this directory:") );
  147. path = new HistoryTextField(PATH);
  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( ImportDialog.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( ImportDialog.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. ImportDialog.this.setVisible( false );
  190. ImportDialog.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. ImportDialog.this.setVisible( false );
  201. ImportDialog.this.dispose();
  202. }
  203. }
  204. );
  205. // add the components to the option panel
  206. panel.add( "0, 0, 1, 1, E, , 3", path_label );
  207. panel.add( "1, 0, 2, 1, 0, w, 3", path );
  208. panel.add( "3, 0, 1, 1, 0, w, 3", browse_btn );
  209. panel.add( "0, 1, 1, 1, E, , 3", url_label );
  210. panel.add( "1, 1, 2, 1, 0, w, 3", url );
  211. panel.add( "3, 1, 1, 1, 0, w, 3", browse_remote_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 CopyData getData() {
  222. if ( canceled ) {
  223. return null;
  224. }
  225. CopyData cd = new CopyData();
  226. try {
  227. cd.setSourceFile(new File(path.getText()));
  228. cd.setDestinationURL(SVNURL.parseURIDecoded(url.getText()));
  229. cd.setUsername(username.getText());
  230. cd.setPassword(PasswordHandler.encryptPassword(new String(password.getPassword())));
  231. }
  232. catch(Exception e) {
  233. e.printStackTrace();
  234. }
  235. return cd;
  236. }
  237. }