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

# · Java · 223 lines · 156 code · 28 blank · 39 comment · 26 complexity · 6694aa5c1fafe6c3053a5e471e3df1c2 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.GUIUtilities;
  37. import org.gjt.sp.jedit.jEdit;
  38. import org.gjt.sp.jedit.View;
  39. import org.gjt.sp.util.Log;
  40. import org.gjt.sp.jedit.browser.VFSBrowser;
  41. import projectviewer.ProjectViewer;
  42. import projectviewer.config.ProjectOptions;
  43. import ise.java.awt.KappaLayout;
  44. import ise.java.awt.LambdaLayout;
  45. import ise.plugin.svn.data.DeleteData;
  46. import ise.plugin.svn.library.PasswordHandler;
  47. import ise.plugin.svn.library.PasswordHandlerException;
  48. import ise.plugin.svn.library.PropertyComboBox;
  49. /**
  50. * Dialog for deleting items from a repository.
  51. */
  52. public class RemoteDeleteDialog extends JDialog {
  53. // instance fields
  54. private View view = null;
  55. private JTextArea comment = null;
  56. private PropertyComboBox commentList = null;
  57. private boolean canceled = false;
  58. private DeleteData data = null;
  59. public RemoteDeleteDialog( View view, DeleteData data ) {
  60. super( ( JFrame ) view, "Delete", true );
  61. if ( data == null ) {
  62. throw new IllegalArgumentException( "data may not be null" );
  63. }
  64. this.view = view;
  65. this.data = data;
  66. _init();
  67. }
  68. /** Initialises the option pane. */
  69. protected void _init() {
  70. JPanel panel = new JPanel( new KappaLayout() );
  71. panel.setBorder( new EmptyBorder( 6, 6, 6, 6 ) );
  72. data.setPathsAreURLs( true ); // should already be set, right?
  73. JLabel file_label = new JLabel( "Delete these files:" );
  74. BestRowTable file_table = new BestRowTable();
  75. final DefaultTableModel file_table_model = new DefaultTableModel(
  76. new String[] {
  77. "", "File"
  78. }, data.getPaths().size() ) {
  79. public Class getColumnClass( int index ) {
  80. if ( index == 0 ) {
  81. return Boolean.class;
  82. }
  83. else {
  84. return super.getColumnClass( index );
  85. }
  86. }
  87. };
  88. file_table.setModel( file_table_model );
  89. // load the table model
  90. int i = 0;
  91. for ( String path : data.getPaths() ) {
  92. if ( path != null ) {
  93. file_table_model.setValueAt( true, i, 0 );
  94. file_table_model.setValueAt( path, i, 1 );
  95. ++i;
  96. }
  97. }
  98. file_table.getColumnModel().getColumn( 0 ).setMaxWidth( 25 );
  99. file_table.getColumnModel().getColumn( 1 ).setPreferredWidth( 625 );
  100. file_table.packRows();
  101. JLabel label = new JLabel( "Enter comment for delete:" );
  102. comment = new JTextArea( 5, 50 );
  103. comment.setLineWrap( true );
  104. comment.setWrapStyleWord( true );
  105. // list for previous comments
  106. final PropertyComboBox commentList = new PropertyComboBox( "ise.plugin.svn.comment." );
  107. commentList.setEditable( false );
  108. commentList.addItemListener( new ItemListener() {
  109. public void itemStateChanged( ItemEvent e ) {
  110. if ( PropertyComboBox.SELECT.equals( commentList.getSelectedItem().toString() ) ) {
  111. return ;
  112. }
  113. comment.setText( commentList.getSelectedItem().toString() );
  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. data = null;
  138. }
  139. else {
  140. data.setPaths( paths );
  141. String msg = comment.getText();
  142. if ( msg == null || msg.length() == 0 ) {
  143. msg = "no comment";
  144. }
  145. else {
  146. if ( commentList != null ) {
  147. commentList.addValue( msg );
  148. }
  149. }
  150. data.setCommitMessage( msg );
  151. }
  152. RemoteDeleteDialog.this._save();
  153. RemoteDeleteDialog.this.setVisible( false );
  154. RemoteDeleteDialog.this.dispose();
  155. }
  156. }
  157. );
  158. cancel_btn.addActionListener( new ActionListener() {
  159. public void actionPerformed( ActionEvent ae ) {
  160. data = null;
  161. RemoteDeleteDialog.this.setVisible( false );
  162. RemoteDeleteDialog.this.dispose();
  163. }
  164. }
  165. );
  166. // add the components to the option panel
  167. JScrollPane file_scroller = new JScrollPane( file_table );
  168. file_scroller.getViewport().setPreferredSize( new Dimension( 600, Math.min( file_table.getBestHeight(), 250 ) ) );
  169. panel.add( "0, 0, 1, 1, W, , 3", file_label );
  170. panel.add( "0, 1, 1, 1, W, wh, 3", file_scroller );
  171. panel.add( "0, 4, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  172. panel.add( "0, 5, 1, 1, W, , 3", label );
  173. panel.add( "0, 6, 1, 1, W, wh, 3", new JScrollPane( comment ) );
  174. if ( commentList != null && commentList.getModel().getSize() > 0 ) {
  175. commentList.setPreferredSize( new Dimension( 600, commentList.getPreferredSize().height ) );
  176. panel.add( "0, 7, 1, 1, W, , 3", new JLabel( "Select a previous comment:" ) );
  177. panel.add( "0, 8, 1, 1, W, w, 3", commentList );
  178. }
  179. panel.add( "0, 9, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  180. panel.add( "0, 10, 1, 1, E, , 0", btn_panel );
  181. setContentPane( panel );
  182. pack();
  183. }
  184. protected void _save() {
  185. if ( commentList != null ) {
  186. commentList.save();
  187. }
  188. }
  189. public DeleteData getData() {
  190. return data;
  191. }
  192. }