/plugins/SVNPlugin/tags/1.6.0/src/ise/plugin/svn/gui/AddDialog.java

# · Java · 231 lines · 151 code · 38 blank · 42 comment · 20 complexity · 0695f73a4a678d19dbba6cb48db650bc 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.awt.Dimension;
  28. import java.awt.event.*;
  29. import java.io.File;
  30. import java.util.*;
  31. import javax.swing.*;
  32. import javax.swing.table.*;
  33. import javax.swing.border.EmptyBorder;
  34. import org.gjt.sp.jedit.View;
  35. import org.gjt.sp.jedit.jEdit;
  36. import ise.java.awt.KappaLayout;
  37. import ise.plugin.svn.data.SVNData;
  38. /**
  39. * Dialog for adding files and directories.
  40. */
  41. public class AddDialog extends JDialog {
  42. public final static String PREFIX = "ise.plugin.svn.pv.";
  43. private List<String> nodes = null;
  44. private boolean canceled = false;
  45. private SVNData addData = null;
  46. public AddDialog( View view, List<String> nodes ) {
  47. this( view, nodes, false );
  48. }
  49. public AddDialog( View view, List<String> nodes, boolean showLogin ) {
  50. super( ( JFrame ) view, "Add", true );
  51. if ( nodes == null ) {
  52. throw new IllegalArgumentException( "nodes may not be null" );
  53. }
  54. this.nodes = nodes;
  55. _init( showLogin );
  56. }
  57. /** Initialises the option pane. */
  58. protected void _init( boolean showLogin ) {
  59. addData = new SVNData();
  60. JPanel panel = new JPanel( new KappaLayout() );
  61. panel.setBorder( new EmptyBorder( 6, 6, 6, 6 ) );
  62. // set recursive value, if any of the nodes are a directory, set
  63. // recursive to true. While we're at it, make a list of strings of
  64. // the node paths.
  65. boolean recursive = false;
  66. List<String> paths = new ArrayList<String>();
  67. for ( String node : nodes ) {
  68. if ( node != null ) {
  69. File file = new File( node );
  70. if ( file.isDirectory() ) {
  71. recursive = true;
  72. }
  73. paths.add( node );
  74. }
  75. }
  76. addData.setPaths( paths );
  77. addData.setRecursive( recursive );
  78. JLabel file_label = new JLabel( jEdit.getProperty("ips.Adding", "Adding") + " " + ( paths.size() == 1 ? jEdit.getProperty("ips.this_file", "this file") : jEdit.getProperty("ips.these_files", "these files")) + ":" );
  79. BestRowTable file_table = new BestRowTable();
  80. final DefaultTableModel file_table_model = new DefaultTableModel(
  81. new String[] {
  82. "", jEdit.getProperty("ips.File", "File")
  83. }, paths.size() ) {
  84. public Class getColumnClass( int index ) {
  85. if ( index == 0 ) {
  86. return Boolean.class;
  87. }
  88. else {
  89. return super.getColumnClass( index );
  90. }
  91. }
  92. };
  93. file_table.setModel( file_table_model );
  94. // load the table model
  95. int i = 0;
  96. for ( String path : paths ) {
  97. if ( path != null ) {
  98. file_table_model.setValueAt( true, i, 0 );
  99. file_table_model.setValueAt( path, i, 1 );
  100. ++i;
  101. }
  102. }
  103. file_table.getColumnModel().getColumn( 0 ).setMaxWidth( 25 );
  104. file_table.getColumnModel().getColumn( 1 ).setPreferredWidth( 625 );
  105. file_table.packRows();
  106. final JCheckBox recursive_cb = new JCheckBox( jEdit.getProperty("ips.Recursively_add", "Recursively add?") );
  107. recursive_cb.setSelected( recursive );
  108. recursive_cb.addActionListener( new ActionListener() {
  109. public void actionPerformed( ActionEvent ae ) {
  110. addData.setRecursive( recursive_cb.isSelected() );
  111. }
  112. }
  113. );
  114. // possible login
  115. final LoginPanel login = new LoginPanel(nodes.get(0));
  116. login.setVisible(showLogin);
  117. // buttons
  118. KappaLayout kl = new KappaLayout();
  119. JPanel btn_panel = new JPanel( kl );
  120. JButton ok_btn = new JButton( jEdit.getProperty("ips.Ok", "Ok") );
  121. ok_btn.setMnemonic(KeyEvent.VK_O);
  122. JButton cancel_btn = new JButton( jEdit.getProperty("ips.Cancel", "Cancel") );
  123. cancel_btn.setMnemonic(KeyEvent.VK_C);
  124. btn_panel.add( "0, 0, 1, 1, 0, w, 3", ok_btn );
  125. btn_panel.add( "1, 0, 1, 1, 0, w, 3", cancel_btn );
  126. kl.makeColumnsSameWidth( 0, 1 );
  127. ok_btn.addActionListener( new ActionListener() {
  128. public void actionPerformed( ActionEvent ae ) {
  129. // get the paths
  130. List<String> paths = new ArrayList<String>();
  131. for ( int row = 0; row < file_table_model.getRowCount(); row++ ) {
  132. Boolean selected = ( Boolean ) file_table_model.getValueAt( row, 0 );
  133. if ( selected ) {
  134. paths.add( ( String ) file_table_model.getValueAt( row, 1 ) );
  135. }
  136. }
  137. if ( paths.size() == 0 ) {
  138. // nothing to add, bail out
  139. addData = null;
  140. }
  141. else {
  142. addData.setPaths( paths );
  143. }
  144. addData.setUsername( login.getUsername() );
  145. addData.setPassword( login.getPassword() );
  146. AddDialog.this.setVisible( false );
  147. AddDialog.this.dispose();
  148. }
  149. }
  150. );
  151. cancel_btn.addActionListener( new ActionListener() {
  152. public void actionPerformed( ActionEvent ae ) {
  153. addData = null;
  154. AddDialog.this.setVisible( false );
  155. AddDialog.this.dispose();
  156. }
  157. }
  158. );
  159. // add the components to the option panel
  160. JScrollPane file_scroller = new JScrollPane( file_table );
  161. file_scroller.getViewport().setPreferredSize( new Dimension( 600, Math.min( file_table.getBestHeight(), 250 ) ) );
  162. panel.add( "0, 0, 1, 1, W, , 3", file_label );
  163. panel.add( "0, 1, 1, 1, W, wh, 3", file_scroller );
  164. if ( recursive ) {
  165. panel.add( "0, 2, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  166. panel.add( "0, 3, 1, 1, W, , 3", recursive_cb );
  167. }
  168. if ( showLogin ) {
  169. panel.add( "0, 5, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  170. panel.add( "0, 6, 1, 1, 0, w, 3", login);
  171. }
  172. panel.add( "0, 8, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  173. panel.add( "0, 9, 1, 1, E, , 0", btn_panel );
  174. setContentPane( panel );
  175. pack();
  176. getRootPane().setDefaultButton(ok_btn);
  177. ok_btn.requestFocus();
  178. }
  179. public SVNData getSVNData() {
  180. return addData;
  181. }
  182. public static void main ( String[] args ) {
  183. // for testing
  184. List<String> paths = new ArrayList<String>();
  185. paths.add( "/home/danson/path/filename.txt" );
  186. paths.add( "/home/danson/path/filename2.txt" );
  187. AddDialog dialog = new AddDialog( null, paths, true );
  188. dialog.setVisible( true );
  189. }
  190. }