/bundles/plugins-trunk/SVNPlugin/src/ise/plugin/svn/gui/SVNInfoPanel.java

#
Java | 184 lines | 143 code | 13 blank | 28 comment | 66 complexity | 412df359cc0aa201cd76bd042e0984f5 MD5 | raw file

✨ Summary
  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.GridLayout;
  28. import java.io.*;
  29. import java.util.*;
  30. import javax.swing.*;
  31. import javax.swing.border.EtchedBorder;
  32. import java.text.SimpleDateFormat;
  33. import javax.swing.table.*;
  34. import org.tmatesoft.svn.core.SVNLock;
  35. import org.tmatesoft.svn.core.SVNNodeKind;
  36. import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
  37. import org.tmatesoft.svn.core.wc.SVNInfo;
  38. import ise.plugin.svn.library.TableCellViewer;
  39. import ise.plugin.svn.command.SVNFormatUtil;
  40. import org.gjt.sp.jedit.jEdit;
  41. public class SVNInfoPanel extends JPanel {
  42. public SVNInfoPanel( List<SVNInfo> infos ) {
  43. super( new GridLayout( 0, 1, 0, 3 ) );
  44. for ( SVNInfo info : infos ) {
  45. addInfo( info );
  46. }
  47. }
  48. private void addInfo( SVNInfo info ) {
  49. if ( info == null ) {
  50. return ;
  51. }
  52. final DefaultTableModel info_table_model = new DefaultTableModel( 1, 2 );
  53. // load the table model
  54. if ( !info.isRemote() ) {
  55. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Path", "Path"), SVNFormatUtil.formatPath( info.getFile() ) } );
  56. }
  57. else if ( info.getPath() != null ) {
  58. String path = info.getPath();
  59. path = path.replace( '/', File.separatorChar );
  60. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Path", "Path"), path} );
  61. }
  62. if ( info.getKind() != SVNNodeKind.DIR ) {
  63. String v = "";
  64. if ( info.isRemote() ) {
  65. v = SVNPathUtil.tail( info.getPath() );
  66. }
  67. else {
  68. v = info.getFile().getName();
  69. }
  70. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Name", "Name"), v} );
  71. }
  72. if ( info.getURL() != null ) {
  73. info_table_model.addRow( new String[] {jEdit.getProperty("ips.URL", "URL"), info.getURL().toString() } );
  74. }
  75. if ( info.getRepositoryRootURL() != null ) {
  76. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Repository_Root", "Repository Root"), String.valueOf( info.getRepositoryRootURL() ) } );
  77. }
  78. if ( info.isRemote() && info.getRepositoryUUID() != null ) {
  79. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Repository_UUID", "Repository UUID"), info.getRepositoryUUID() } );
  80. }
  81. if ( info.getRevision() != null && info.getRevision().isValid() ) {
  82. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Revision", "Revision"), String.valueOf( info.getRevision() ) } );
  83. }
  84. if ( info.getKind() == SVNNodeKind.DIR ) {
  85. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Node_Kind", "Node Kind"), jEdit.getProperty("ips.directory", "directory")} );
  86. }
  87. else if ( info.getKind() == SVNNodeKind.FILE ) {
  88. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Node_Kind", "Node Kind"), jEdit.getProperty("ips.file", "file")} );
  89. }
  90. else if ( info.getKind() == SVNNodeKind.NONE ) {
  91. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Node_Kind", "Node Kind"), jEdit.getProperty("ips.none", "none")} );
  92. }
  93. else {
  94. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Node_Kind", "Node Kind"), jEdit.getProperty("ips.unknown", "unknown")} );
  95. }
  96. if ( info.getSchedule() == null && !info.isRemote() ) {
  97. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Schedule", "Schedule"), jEdit.getProperty("ips.normal", "normal")} );
  98. }
  99. else if ( !info.isRemote() ) {
  100. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Schedule", "Schedule"), info.getSchedule() } );
  101. }
  102. if ( info.getAuthor() != null ) {
  103. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Last_Changed_Author", "Last Changed Author"), info.getAuthor() } );
  104. }
  105. if ( info.getCommittedRevision() != null && info.getCommittedRevision().getNumber() >= 0 ) {
  106. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Last_Changed_Revision", "Last Changed Revision"), String.valueOf( info.getCommittedRevision() ) } );
  107. }
  108. if ( info.getCommittedDate() != null ) {
  109. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Last_Changed_Date", "Last Changed Date"), formatDate( info.getCommittedDate() ) } );
  110. }
  111. if ( !info.isRemote() ) {
  112. if ( info.getTextTime() != null ) {
  113. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Text_Last_Updated", "Text Last Updated"), formatDate( info.getTextTime() ) } );
  114. }
  115. if ( info.getPropTime() != null ) {
  116. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Properties_Last_Updated", "Properties Last Updated"), formatDate( info.getPropTime() ) } );
  117. }
  118. if ( info.getChecksum() != null ) {
  119. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Checksum", "Checksum"), info.getChecksum() } );
  120. }
  121. if ( info.getCopyFromURL() != null ) {
  122. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Copied_From_URL", "Copied From URL"), String.valueOf( info.getCopyFromURL() ) } );
  123. }
  124. if ( info.getCopyFromRevision() != null && info.getCopyFromRevision().getNumber() >= 0 ) {
  125. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Copied_From_Revision", "Copied From Revision"), String.valueOf( info.getCopyFromRevision() ) } );
  126. }
  127. if ( info.getConflictOldFile() != null ) {
  128. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Conflict_Previous_Base_File", "Conflict Previous Base File"), info.getConflictOldFile().getName() } );
  129. }
  130. if ( info.getConflictWrkFile() != null ) {
  131. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Conflict_Previous_Working_File", "Conflict Previous Working File"), info.getConflictWrkFile().getName() } );
  132. }
  133. if ( info.getConflictNewFile() != null ) {
  134. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Conflict_Current_Base_File", "Conflict Current Base File"), info.getConflictNewFile().getName() } );
  135. }
  136. if ( info.getPropConflictFile() != null ) {
  137. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Conflict_Properties_File", "Conflict Properties File"), info.getPropConflictFile().getName() } );
  138. }
  139. }
  140. if ( info.getLock() != null ) {
  141. SVNLock lock = info.getLock();
  142. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Lock_Token", "Lock Token"), lock.getID() } );
  143. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Lock_Owner", "Lock Owner"), lock.getOwner() } );
  144. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Lock_Created", "Lock Created"), formatDate( lock.getCreationDate() ) } );
  145. if ( lock.getComment() != null ) {
  146. info_table_model.addRow( new String[] {jEdit.getProperty("ips.Lock_Comment", "Lock Comment"), lock.getComment() } );
  147. }
  148. }
  149. info_table_model.removeRow(0);
  150. JPanel panel = new JPanel( new BorderLayout() );
  151. add( panel );
  152. panel.setBorder( new EtchedBorder() );
  153. BestRowTable info_table = new BestRowTable();
  154. info_table.setName("info_table");
  155. panel.add( info_table, BorderLayout.CENTER );
  156. info_table.setModel( info_table_model );
  157. TableColumn column1 = info_table.getColumnModel().getColumn( 1 );
  158. column1.setCellRenderer( new NoWrapCellRenderer() );
  159. info_table.getColumnModel().getColumn( 0 ).setMaxWidth( 150 );
  160. info_table.getColumnModel().getColumn( 0 ).setMinWidth( 150 );
  161. info_table.getColumnModel().getColumn( 1 ).setPreferredWidth( 600 );
  162. info_table.packRows();
  163. info_table.addMouseListener( new TableCellViewer( info_table ) );
  164. }
  165. private String formatDate( Date date ) {
  166. return new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss Z (EE, d MMM yyyy)", Locale.getDefault() ).format( date );
  167. }
  168. }