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