/plugins/SVNPlugin/branches/1.2.0_svn1.4/src/ise/plugin/svn/gui/DirTreeNode.java

# · Java · 126 lines · 63 code · 16 blank · 47 comment · 10 complexity · 289c1a59accbd0fc0c0ce64cdb7d4f3d 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.util.*;
  27. import javax.swing.tree.DefaultMutableTreeNode;
  28. import javax.swing.tree.TreePath;
  29. /**
  30. * Represents a node in a repository tree. Overrides <code>isLeaf</code> so
  31. * that if the node represents a directory that hasn't been populated yet, it
  32. * will still be displayed as a folder instead of a file.
  33. */
  34. public class DirTreeNode extends DefaultMutableTreeNode implements Comparable<DirTreeNode> {
  35. private boolean isLeaf = true;
  36. private boolean external = false;
  37. private boolean hasProperties = false;
  38. private String repositoryLocation = null;
  39. private Properties properties = null;
  40. public DirTreeNode( Object userObject, boolean isLeaf ) {
  41. super( userObject );
  42. if ( userObject == null ) {
  43. throw new IllegalArgumentException( "null user object not allowed" );
  44. }
  45. this.isLeaf = isLeaf;
  46. }
  47. @Override
  48. public boolean isLeaf() {
  49. return this.isLeaf;
  50. }
  51. /**
  52. * @return true if the node represents a url as specified in an
  53. * svn:externals property
  54. */
  55. public boolean isExternal() {
  56. return external;
  57. }
  58. public void setExternal( boolean b ) {
  59. external = b;
  60. }
  61. public boolean hasProperties() {
  62. return hasProperties;
  63. }
  64. public void setHasProperties(boolean b) {
  65. hasProperties = b;
  66. }
  67. /**
  68. * @return the url of the external location, only valid if <code>isExternal</code>
  69. * returns true.
  70. */
  71. public String getRepositoryLocation() {
  72. return repositoryLocation;
  73. }
  74. public void setRepositoryLocation( String s ) {
  75. repositoryLocation = s;
  76. }
  77. /**
  78. * For sorting. Directories sort before files, otherwise, sort by name.
  79. */
  80. public int compareTo( DirTreeNode node ) {
  81. // sort directories first
  82. if ( !this.isLeaf() && node.isLeaf() ) {
  83. return -1;
  84. }
  85. if ( this.isLeaf() && !node.isLeaf() ) {
  86. return 1;
  87. }
  88. // otherwise, sort by name
  89. String a = this.getUserObject().toString().toLowerCase();
  90. String b = ( ( DirTreeNode ) node ).getUserObject().toString().toLowerCase();
  91. return a.compareTo( b );
  92. }
  93. public boolean equals( Object o ) {
  94. if ( o == null ) {
  95. return false;
  96. }
  97. if ( !( o instanceof DirTreeNode ) ) {
  98. return false;
  99. }
  100. return o.hashCode() == hashCode();
  101. }
  102. public int hashCode() {
  103. return this.getUserObject().toString().toLowerCase().hashCode();
  104. //TreePath path = new TreePath(getPath());
  105. //return path.hashCode();
  106. }
  107. }