1 38 39 import javax.swing.tree.DefaultMutableTreeNode ; 40 import javax.mail.*; 41 42 48 public class StoreTreeNode extends DefaultMutableTreeNode { 49 50 protected Store store = null; 51 protected Folder folder = null; 52 protected String display = null; 53 54 59 public StoreTreeNode(Store what) { 60 super(what); 61 store = what; 62 } 63 64 65 68 public boolean isLeaf() { 69 return false; 70 } 71 72 73 78 79 public int getChildCount() { 80 if (folder == null) { 81 loadChildren(); 82 } 83 return super.getChildCount(); 84 } 85 86 protected void loadChildren() { 87 try { 88 if (!store.isConnected()) { 90 store.connect(); 91 } 92 93 folder = store.getDefaultFolder(); 96 Folder[] sub = folder.list(); 98 99 int num = sub.length; 101 for(int i = 0; i < num; i++) { 102 FolderTreeNode node = new FolderTreeNode(sub[i]); 103 insert(node, i); 106 } 107 108 } catch (MessagingException me) { 109 me.printStackTrace(); 110 } 111 } 112 113 117 118 public String toString() { 119 if (display == null) { 120 URLName url = store.getURLName(); 121 if (url == null) { 122 display = store.toString(); 123 } else { 124 URLName too = new URLName( url.getProtocol(), url.getHost(), url.getPort(), 126 url.getFile(), url.getUsername(), null); 127 display = too.toString(); 128 } 129 } 130 131 return display; 132 } 133 134 135 } 136 137 | Popular Tags |