1 38 39 import javax.swing.tree.DefaultMutableTreeNode ; 40 import javax.mail.Store ; 41 import javax.mail.Folder ; 42 import javax.mail.MessagingException ; 43 44 50 public class FolderTreeNode extends DefaultMutableTreeNode { 51 52 protected Folder folder = null; 53 protected boolean hasLoaded = false; 54 55 60 public FolderTreeNode(Folder what) { 61 super(what); 62 folder = what; 63 } 64 65 66 69 public boolean isLeaf() { 70 try { 71 if ((folder.getType() & Folder.HOLDS_FOLDERS) == 0) 72 return true; 73 } catch (MessagingException me) { } 74 75 return false; 78 } 79 80 83 public Folder getFolder() { 84 return folder; 85 } 86 87 88 89 94 95 public int getChildCount() { 96 if (!hasLoaded) { 97 loadChildren(); 98 } 99 return super.getChildCount(); 100 } 101 102 protected void loadChildren() { 103 if (isLeaf()) { 105 hasLoaded = true; 106 return; 107 } 108 109 try { 110 Folder [] sub = folder.list(); 112 113 int num = sub.length; 115 for(int i = 0; i < num; i++) { 116 FolderTreeNode node = new FolderTreeNode(sub[i]); 117 insert(node, i); 120 } 121 122 } catch (MessagingException me) { 123 me.printStackTrace(); 124 } 125 } 126 127 128 132 public String toString() { 133 return folder.getName(); 134 } 135 136 } 137 138 | Popular Tags |