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

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