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

# · Java · 149 lines · 96 code · 22 blank · 31 comment · 16 complexity · f47dd8739fda6d7bc3dd169a9b9e2a50 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.Color;
  28. import java.awt.Component;
  29. import java.awt.event.*;
  30. import java.util.*;
  31. import javax.swing.*;
  32. import javax.swing.table.*;
  33. import javax.swing.tree.*;
  34. import javax.swing.border.EmptyBorder;
  35. import ise.plugin.svn.data.MergeResults;
  36. import ise.plugin.svn.action.*;
  37. import org.gjt.sp.jedit.jEdit;
  38. /**
  39. * Shows the results of a dry-run merge. Non-dry-run merge results are shown
  40. * in a StatusResultsPanel. There are no actions associated with this display.
  41. */
  42. public class MergeResultsPanel extends JPanel {
  43. private JTree tree = null;
  44. private static Color background = jEdit.getColorProperty("view.bgColor", Color.WHITE);
  45. private static Color selection = jEdit.getColorProperty("view.selectionColor", Color.LIGHT_GRAY);
  46. public MergeResultsPanel( MergeResults results ) {
  47. super( new BorderLayout() );
  48. setBorder( new EmptyBorder( 3, 3, 3, 3 ) );
  49. JTextArea label = new JTextArea();
  50. label.setText(jEdit.getProperty("ips.Merge_Dry_Run_Results>", "Merge Dry Run Results:") + "\n" + results.getCommandLineEquivalent() );
  51. label.setEditable(false);
  52. label.setBorder( new EmptyBorder( 6, 3, 6, 3 ) );
  53. boolean added = false;
  54. DefaultMutableTreeNode root = new DefaultMutableTreeNode();
  55. List<String> list = results.getConflicted();
  56. if ( list != null ) {
  57. root.add( createNode( jEdit.getProperty("ips.Files_with_conflicts>", "Files with conflicts:"), list ) );
  58. added = true;
  59. }
  60. list = results.getAdded();
  61. if ( list != null ) {
  62. root.add( createNode( jEdit.getProperty("ips.Added_files>", "Added files:"), list ) );
  63. added = true;
  64. }
  65. list = results.getDeleted();
  66. if ( list != null ) {
  67. root.add( createNode( jEdit.getProperty("ips.Deleted_files>", "Deleted files:"), list ) );
  68. added = true;
  69. }
  70. list = results.getMerged();
  71. if ( list != null ) {
  72. root.add( createNode( jEdit.getProperty("ips.Merged_files>", "Merged files:"), list ) );
  73. added = true;
  74. }
  75. list = results.getSkipped();
  76. if ( list != null ) {
  77. root.add( createNode( jEdit.getProperty("ips.Skipped_files>", "Skipped files:"), list ) );
  78. added = true;
  79. }
  80. list = results.getUpdated();
  81. if ( list != null ) {
  82. root.add( createNode( jEdit.getProperty("ips.Updated_files>", "Updated files:"), list ) );
  83. added = true;
  84. }
  85. if ( added ) {
  86. tree = new JTree( root );
  87. tree.setRootVisible( false );
  88. tree.setCellRenderer(new CellRenderer());
  89. for ( int i = 0; i < tree.getRowCount(); i++ ) {
  90. tree.expandRow( i );
  91. }
  92. add( tree, BorderLayout.CENTER );
  93. }
  94. else {
  95. label.setText( label.getText() + "\n\n" + jEdit.getProperty("ips.(All_files_up_to_date.)", "(All files up to date.)") );
  96. }
  97. add( label, BorderLayout.NORTH );
  98. }
  99. private DefaultMutableTreeNode createNode( String title, List<String> values ) {
  100. DefaultMutableTreeNode node = new DefaultMutableTreeNode( title );
  101. for ( String filename : values ) {
  102. DefaultMutableTreeNode child = new DefaultMutableTreeNode( filename );
  103. node.add( child );
  104. }
  105. return node;
  106. }
  107. class CellRenderer extends DefaultTreeCellRenderer {
  108. public Component getTreeCellRendererComponent(
  109. JTree tree,
  110. Object value,
  111. boolean sel,
  112. boolean expanded,
  113. boolean leaf,
  114. int row,
  115. boolean hasFocus ) {
  116. Component r = super.getTreeCellRendererComponent(
  117. tree, value, sel,
  118. expanded, leaf, row,
  119. hasFocus );
  120. r.setBackground( sel ? MergeResultsPanel.selection : MergeResultsPanel.background );
  121. return r;
  122. }
  123. }
  124. }