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

# · Java · 244 lines · 178 code · 24 blank · 42 comment · 28 complexity · 2dbed6c1b1c9b094534f829627bc4a69 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. import java.awt.BorderLayout;
  27. import java.awt.event.*;
  28. import java.util.*;
  29. import javax.swing.*;
  30. import ise.plugin.svn.action.CommitAction;
  31. import ise.plugin.svn.action.RevertAction;
  32. import ise.plugin.svn.data.AddResults;
  33. import ise.plugin.svn.data.DeleteResults;
  34. import ise.plugin.svn.library.GUIUtils;
  35. import ise.java.awt.LambdaLayout;
  36. import org.gjt.sp.jedit.jEdit;
  37. import org.gjt.sp.jedit.View;
  38. import org.gjt.sp.jedit.GUIUtilities;
  39. /**
  40. * Used for both Add and Revert, and now Delete and Resolved, and lock, unlock
  41. * and remote delete.
  42. */
  43. public class AddResultsPanel extends JPanel {
  44. public static final int ADD = 0;
  45. public static final int REVERT = 1;
  46. public static final int DELETE = 2;
  47. public static final int RESOLVED = 3;
  48. public static final int LOCK = 4;
  49. public static final int UNLOCK = 5;
  50. public static final int REMOTE_DELETE = 6;
  51. private View view = null;
  52. private int action;
  53. private String username = null;
  54. private String password = null;
  55. public AddResultsPanel( AddResults results, int action, View view, String username, String password ) {
  56. super( new LambdaLayout() );
  57. if ( action < 0 || action > 6 ) {
  58. throw new IllegalArgumentException( "invalid action: " + action );
  59. }
  60. this.view = view;
  61. this.action = action;
  62. this.username = username;
  63. this.password = password;
  64. boolean top = false; // indicate good messages are displayed
  65. LambdaLayout.Constraints con = LambdaLayout.createConstraint();
  66. con.a = LambdaLayout.W;
  67. con.s = "wh";
  68. con.p = 3;
  69. // show paths scheduled for add
  70. List<String> paths = results.getPaths();
  71. if ( paths != null && paths.size() > 0 ) {
  72. JPanel top_panel = new JPanel( new BorderLayout() );
  73. String good_label_text = "";
  74. switch ( action ) {
  75. case ADD:
  76. good_label_text = "Scheduled for add:";
  77. break;
  78. case REVERT:
  79. good_label_text = "Reverted:";
  80. break;
  81. case DELETE:
  82. good_label_text = "Scheduled for delete:";
  83. break;
  84. case RESOLVED:
  85. good_label_text = "Resolved:";
  86. break;
  87. case LOCK:
  88. good_label_text = "Locked:";
  89. break;
  90. case UNLOCK:
  91. good_label_text = "Unlocked:";
  92. break;
  93. case REMOTE_DELETE:
  94. DeleteResults dr = (DeleteResults)results;
  95. good_label_text = "Deleted from repository, new revision " + dr.getRevision() + ":";
  96. break;
  97. }
  98. JLabel good_label = new JLabel( good_label_text );
  99. // data to display in a table, single column
  100. String[][] data = new String[ paths.size() ][ 1 ];
  101. Iterator it = paths.iterator();
  102. for ( int i = 0; it.hasNext(); i++ ) {
  103. String path = ( String ) it.next();
  104. data[ i ][ 0 ] = path;
  105. }
  106. // create the table, one column to contain the filename
  107. JTable good_table = new JTable( data, new String[] {"Path"} );
  108. if ( action == ADD || action == DELETE ) {
  109. good_table.addMouseListener( new TableMouseListener( good_table ) );
  110. }
  111. top_panel.add( good_label, BorderLayout.NORTH );
  112. top_panel.add( GUIUtils.createTablePanel( good_table ), BorderLayout.CENTER );
  113. add( top_panel, con );
  114. top = true;
  115. }
  116. // show paths that had a problem
  117. Map<String, String> error_map = results.getErrorPaths();
  118. if ( error_map != null && error_map.size() > 0 ) {
  119. JPanel bottom_panel = new JPanel( new BorderLayout() );
  120. String bad_label_text = "";
  121. switch ( action ) {
  122. case ADD:
  123. bad_label_text = "Unable to schedule for add:";
  124. break;
  125. case REVERT:
  126. bad_label_text = "Unable to revert:";
  127. break;
  128. case DELETE:
  129. bad_label_text = "Unable to schedule for delete:";
  130. break;
  131. case RESOLVED:
  132. bad_label_text = "Unable to resolve:";
  133. break;
  134. case LOCK:
  135. bad_label_text = "Unable to lock:";
  136. break;
  137. case UNLOCK:
  138. bad_label_text = "Unable to unlock:";
  139. break;
  140. case REMOTE_DELETE:
  141. bad_label_text = "Unable to delete from repository:";
  142. break;
  143. }
  144. JLabel bad_label = new JLabel( bad_label_text );
  145. String[][] data = new String[ error_map.size() ][ 2 ];
  146. Set < Map.Entry < String, String >> set = error_map.entrySet();
  147. int i = 0;
  148. for ( Map.Entry entry : set ) {
  149. String path = ( String ) entry.getKey();
  150. String msg = ( String ) entry.getValue();
  151. data[ i ][ 0 ] = path;
  152. data[ i ][ 1 ] = msg;
  153. ++i;
  154. }
  155. JTable bad_table = new JTable( data, new String[] {"Path", "Error Message"} );
  156. if ( top ) {
  157. ++con.y;
  158. add( LambdaLayout.createVerticalStrut( 6, true ), con );
  159. }
  160. bottom_panel.add( bad_label, BorderLayout.NORTH );
  161. bottom_panel.add( GUIUtils.createTablePanel( bad_table ), BorderLayout.CENTER );
  162. add( bottom_panel, con );
  163. }
  164. }
  165. /**
  166. * MouseListener to popup context menu on the table.
  167. */
  168. class TableMouseListener extends MouseAdapter {
  169. private JTable table = null;
  170. public TableMouseListener( JTable table ) {
  171. TableMouseListener.this.table = table;
  172. }
  173. public void mouseReleased( MouseEvent me ) {
  174. handleClick( me );
  175. }
  176. public void mousePressed( MouseEvent me ) {
  177. handleClick( me );
  178. }
  179. private void handleClick( MouseEvent me ) {
  180. if ( AddResultsPanel.this.action != REMOTE_DELETE ) {
  181. if ( me.isPopupTrigger() ) {
  182. JPopupMenu popup = getPopupMenu( table );
  183. if ( popup != null ) {
  184. GUIUtilities.showPopupMenu( popup, table, me.getX(), me.getY() );
  185. }
  186. }
  187. else if ( me.getClickCount() == 2 ) {
  188. // on double-click, open file in jEdit
  189. String filename = ( String ) table.getValueAt( table.getSelectedRow(), table.getSelectedColumn() );
  190. jEdit.openFile( view, filename );
  191. }
  192. }
  193. }
  194. }
  195. /**
  196. * Create the context menu.
  197. */
  198. private JPopupMenu getPopupMenu( final JTable table ) {
  199. int[] rows = table.getSelectedRows();
  200. if ( rows.length == 0 ) {
  201. return null;
  202. }
  203. JPopupMenu popup = new JPopupMenu();
  204. TreeMap<String, String> paths = new TreeMap<String, String>();
  205. for ( int row : rows ) {
  206. paths.put( ( String ) table.getValueAt( rows[ row ], 0 ), "" );
  207. }
  208. JMenuItem mi = new JMenuItem( "Commit" );
  209. popup.add( mi );
  210. mi.addActionListener( new CommitAction( view, paths, username, password ) );
  211. mi = new JMenuItem( "Revert" );
  212. popup.add( mi );
  213. ArrayList<String> files = new ArrayList<String>( paths.keySet() );
  214. mi.addActionListener( new RevertAction( view, files, username, password ) );
  215. return popup;
  216. }
  217. }