Skip to content

Package: FolderTreeNode

FolderTreeNode

nameinstructionbranchcomplexitylinemethod
FolderTreeNode(Folder)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getChildCount()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getFolder()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isLeaf()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
loadChildren()
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
toString()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: import javax.swing.tree.DefaultMutableTreeNode;
12: import jakarta.mail.Store;
13: import jakarta.mail.Folder;
14: import jakarta.mail.MessagingException;
15:
16: /**
17: * Node which represents a Folder in the jakarta.mail apis.
18: *
19: * @author Christopher Cotton
20: */
21: public class FolderTreeNode extends DefaultMutableTreeNode {
22:
23: protected Folder        folder = null;
24: protected boolean        hasLoaded = false;
25:
26: /**
27: * creates a tree node that points to the particular Store.
28: *
29: * @param what        the store for this node
30: */
31: public FolderTreeNode(Folder what) {
32:         super(what);
33:         folder = what;
34: }
35:
36:
37: /**
38: * a Folder is a leaf if it cannot contain sub folders
39: */
40: public boolean isLeaf() {
41:         try {
42:•         if ((folder.getType() & Folder.HOLDS_FOLDERS) == 0)
43:                 return true;
44:         } catch (MessagingException me) { }
45:         
46:         // otherwise it does hold folders, and therefore not
47:         // a leaf
48:         return false;
49: }
50:
51: /**
52: * returns the folder for this node
53: */
54: public Folder getFolder() {
55:         return folder;
56: }
57:
58:
59:
60: /**
61: * return the number of children for this folder node. The first
62: * time this method is called we load up all of the folders
63: * under the store's defaultFolder
64: */
65:
66: public int getChildCount() {
67:•        if (!hasLoaded) {
68:          loadChildren();
69:         }
70:         return super.getChildCount();
71: }
72:
73: protected void loadChildren() {
74:         // if it is a leaf, just say we have loaded them
75:•        if (isLeaf()) {
76:          hasLoaded = true;
77:          return;
78:         }
79:
80:         try {
81:          // Folder[] sub = folder.listSubscribed();
82:          Folder[] sub = folder.list();
83:
84:          // add a FolderTreeNode for each Folder
85:          int num = sub.length;
86:•         for(int i = 0; i < num; i++) {
87:                 FolderTreeNode node = new FolderTreeNode(sub[i]);
88:                 // we used insert here, since add() would make
89:                 // another recursive call to getChildCount();
90:                 insert(node, i);
91:          }
92:         
93:         } catch (MessagingException me) {
94:          me.printStackTrace();
95:         }
96: }
97:
98:
99: /**
100: * override toString() since we only want to display a folder's
101: * name, and not the full path of the folder
102: */
103: public String toString() {
104:         return folder.getName();
105: }
106:
107: }
108: