/plugins/SVNPlugin/tags/0.10.0/src/ise/plugin/svn/gui/ExportDialog.java

#
Java | 284 lines | 216 code | 32 blank | 36 comment | 43 complexity | 3e85d92dcff211699738a7075cd47605 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. import java.awt.Dimension;
  27. import java.io.File;
  28. import java.util.*;
  29. import java.awt.event.*;
  30. import javax.swing.*;
  31. import javax.swing.table.*;
  32. import org.gjt.sp.jedit.GUIUtilities;
  33. import org.gjt.sp.jedit.View;
  34. import org.gjt.sp.util.*;
  35. import org.gjt.sp.jedit.browser.VFSBrowser;
  36. import org.gjt.sp.jedit.gui.HistoryTextField;
  37. import ise.java.awt.*;
  38. import ise.plugin.svn.data.*;
  39. import ise.plugin.svn.command.*;
  40. import ise.plugin.svn.gui.component.*;
  41. import ise.plugin.svn.library.*;
  42. import static ise.plugin.svn.gui.HistoryModelNames.*;
  43. import org.tmatesoft.svn.core.SVNURL;
  44. public class ExportDialog extends JDialog {
  45. // instance fields
  46. private View view = null;
  47. private ExportData data = null;
  48. private JTextField path = null;
  49. private JCheckBox recursive_cb = null;
  50. private RevisionSelectionPanel revision_panel = null;
  51. private RevisionSelectionPanel peg_revision_panel = null;
  52. private JComboBox eol = null;
  53. private JCheckBox force = null;
  54. private boolean canceled = false;
  55. public ExportDialog( View view, ExportData data ) {
  56. super( ( JFrame ) view, "Export", true );
  57. this.view = view;
  58. if ( data == null ) {
  59. throw new IllegalArgumentException( "data cannot be null" );
  60. }
  61. if ( data.getSourceFiles() == null && data.getSourceURLs() == null ) {
  62. throw new IllegalArgumentException( "no source file(s) to copy" );
  63. }
  64. this.data = data;
  65. init();
  66. }
  67. protected void init() {
  68. KappaLayout layout = new KappaLayout();
  69. JPanel panel = new JPanel( layout );
  70. panel.setBorder( BorderFactory.createEmptyBorder( 6, 6, 6, 6 ) );
  71. // source for export
  72. List paths;
  73. if ( data.getSourceFiles() != null ) {
  74. paths = data.getSourceFiles();
  75. }
  76. else {
  77. paths = data.getSourceURLs();
  78. }
  79. JLabel file_label = new JLabel( "Export " + ( paths.size() == 1 ? "this file:" : "these files:" ) );
  80. BestRowTable file_table = new BestRowTable();
  81. final DefaultTableModel file_table_model = new DefaultTableModel(
  82. new String[] {
  83. "", "File"
  84. }, paths.size() ) {
  85. public Class getColumnClass( int index ) {
  86. if ( index == 0 ) {
  87. return Boolean.class;
  88. }
  89. else {
  90. return super.getColumnClass( index );
  91. }
  92. }
  93. };
  94. file_table.setModel( file_table_model );
  95. // load the table model
  96. int i = 0;
  97. for ( Object path : paths ) {
  98. if ( path != null ) {
  99. file_table_model.setValueAt( true, i, 0 );
  100. file_table_model.setValueAt( path, i, 1 );
  101. ++i;
  102. }
  103. }
  104. file_table.getColumnModel().getColumn( 0 ).setMaxWidth( 25 );
  105. file_table.getColumnModel().getColumn( 1 ).setPreferredWidth( 625 );
  106. file_table.packRows();
  107. recursive_cb = new JCheckBox( "Recursive?" );
  108. recursive_cb.setSelected( true );
  109. // revision selection panels
  110. revision_panel = new RevisionSelectionPanel( "Export from this revision:", SwingConstants.VERTICAL, data.getSourceURLs() == null );
  111. peg_revision_panel = new RevisionSelectionPanel( "Using this peg revision:", SwingConstants.VERTICAL, false, false, true, false, false );
  112. // destination
  113. JLabel path_label = new JLabel( "Export to this directory:" );
  114. path = new HistoryTextField(PATH);
  115. path.setText("");
  116. path.setColumns(30);
  117. JButton browse_local_btn = new JButton( "Browse Local..." );
  118. browse_local_btn.addActionListener( new ActionListener() {
  119. public void actionPerformed( ActionEvent ae ) {
  120. String[] dirs = GUIUtilities.showVFSFileDialog( view, System.getProperty( "user.home" ), VFSBrowser.CHOOSE_DIRECTORY_DIALOG, false );
  121. if ( dirs != null && dirs.length > 0 ) {
  122. String filename = dirs[ 0 ];
  123. File f = new File( filename );
  124. path.setText( f.getAbsolutePath() );
  125. }
  126. }
  127. }
  128. );
  129. eol = new JComboBox( new String[] {"native", "CRLF (Windows)", "LF (Unix)", "CR (Old Mac)"} );
  130. eol.setEditable( false );
  131. eol.setSelectedItem( "native" );
  132. force = new JCheckBox("Overwrite existing files?");
  133. // ok and cancel buttons
  134. KappaLayout kl = new KappaLayout();
  135. JPanel btn_panel = new JPanel( kl );
  136. JButton ok_btn = new JButton( "Ok" );
  137. JButton cancel_btn = new JButton( "Cancel" );
  138. btn_panel.add( "0, 0, 1, 1, 0, w, 3", ok_btn );
  139. btn_panel.add( "1, 0, 1, 1, 0, w, 3", cancel_btn );
  140. kl.makeColumnsSameWidth( 0, 1 );
  141. ok_btn.addActionListener( new ActionListener() {
  142. public void actionPerformed( ActionEvent ae ) {
  143. if ( path.getText() == null || path.getText().length() == 0 ) {
  144. JOptionPane.showMessageDialog( view, "Please select a destination directory for the export.", "Error", JOptionPane.ERROR_MESSAGE );
  145. return ;
  146. }
  147. if ( data.getSourceFiles() != null ) {
  148. List<File> paths = new ArrayList<File>();
  149. for ( int row = 0; row < file_table_model.getRowCount(); row++ ) {
  150. Boolean selected = ( Boolean ) file_table_model.getValueAt( row, 0 );
  151. if ( selected ) {
  152. paths.add( ( File ) file_table_model.getValueAt( row, 1 ) );
  153. }
  154. }
  155. if ( paths.size() == 0 ) {
  156. // nothing to add, bail out
  157. canceled = true;
  158. }
  159. else {
  160. data.setSourceFiles( paths );
  161. canceled = false;
  162. }
  163. }
  164. else if ( data.getSourceURLs() != null ) {
  165. List<SVNURL> paths = new ArrayList<SVNURL>();
  166. for ( int row = 0; row < file_table_model.getRowCount(); row++ ) {
  167. Boolean selected = ( Boolean ) file_table_model.getValueAt( row, 0 );
  168. if ( selected ) {
  169. paths.add( ( SVNURL ) file_table_model.getValueAt( row, 1 ) );
  170. }
  171. }
  172. if ( paths.size() == 0 ) {
  173. // nothing to add, bail out
  174. canceled = true;
  175. }
  176. else {
  177. data.setSourceURLs( paths );
  178. canceled = false;
  179. }
  180. }
  181. else {
  182. canceled = true;
  183. }
  184. if ( canceled ) {
  185. data = null;
  186. }
  187. else {
  188. data.setRecursive( recursive_cb.isSelected() );
  189. data.setRevision( revision_panel.getRevision() );
  190. data.setPegRevision( peg_revision_panel.getRevision() );
  191. data.setDestinationFile( new File( path.getText() ) );
  192. String[] line_ender = eol.getSelectedItem().toString().split( " " );
  193. data.setEOLStyle( line_ender[ 0 ] );
  194. data.setForce(force.isSelected());
  195. }
  196. ExportDialog.this.setVisible( false );
  197. ExportDialog.this.dispose();
  198. }
  199. }
  200. );
  201. cancel_btn.addActionListener( new ActionListener() {
  202. public void actionPerformed( ActionEvent ae ) {
  203. canceled = true;
  204. ExportDialog.this.setVisible( false );
  205. ExportDialog.this.dispose();
  206. }
  207. }
  208. );
  209. // add the components to the option panel
  210. JScrollPane file_scroller = new JScrollPane( file_table );
  211. file_scroller.getViewport().setPreferredSize( new Dimension( 600, Math.min( file_table.getBestHeight(), 250 ) ) );
  212. panel.add( "0, 0, 8, 1, W, w, 3", file_label );
  213. panel.add( "0, 1, 8, 1, W, w, 3", file_scroller );
  214. panel.add( "0, 2, 8, 1, W, w, 3", recursive_cb );
  215. panel.add( "0, 3, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  216. LambdaLayout lam = new LambdaLayout();
  217. JPanel revision_panel_holder = new JPanel(lam);
  218. revision_panel_holder.add( "0, 0, 1, 1, 0, w, 3", revision_panel );
  219. revision_panel_holder.add( "1, 0, 1, 1, 0, wh, 3", peg_revision_panel );
  220. lam.makeColumnsSameWidth(0, 1);
  221. panel.add( "0, 4, 8, 1, 0, w, 0", revision_panel_holder );
  222. panel.add( "0, 5, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  223. panel.add( "0, 6, 8, 1, W, , 3", path_label );
  224. panel.add( "0, 7, 8, 1, w, w, 3", path );
  225. panel.add( "0, 8, 2, 1, W, , 3", browse_local_btn );
  226. panel.add( "4, 8, 2, 1, W, , 0", force );
  227. panel.add( "0, 9, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  228. panel.add( "0, 10, 1, 1, W, , 3", new JLabel( "End-of-line style:" ) );
  229. panel.add( "1, 10, 2, 1, 0, w, 3", eol );
  230. panel.add( "0, 12, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  231. panel.add( "0, 14, 8, 1, E, , 0", btn_panel );
  232. setContentPane( panel );
  233. pack();
  234. }
  235. public ExportData getData() {
  236. if ( canceled ) {
  237. return null;
  238. }
  239. return data;
  240. }
  241. public static void main (String[] args) {
  242. ExportData data = new ExportData();
  243. List<File> files = new ArrayList<File>();
  244. files.add(new File(System.getProperty("user.home")));
  245. data.setSourceFiles(files);
  246. ExportDialog ed = new ExportDialog(null, data);
  247. ed.setVisible(true);
  248. }
  249. }