Skip to content

Package: StoreTreeNode

StoreTreeNode

nameinstructionbranchcomplexitylinemethod
StoreTreeNode(Store)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 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%
isLeaf()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
loadChildren()
M: 42 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: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 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.*;
13:
14: /**
15: * Node which represents a Store in the jakarta.mail apis.
16: *
17: * @author Christopher Cotton
18: */
19: public class StoreTreeNode extends DefaultMutableTreeNode {
20:
21: protected Store        store = null;
22: protected Folder        folder = null;
23: protected String        display = null;
24:
25: /**
26: * creates a tree node that points to the particular Store.
27: *
28: * @param what        the store for this node
29: */
30: public StoreTreeNode(Store what) {
31:         super(what);
32:         store = what;
33: }
34:
35:
36: /**
37: * a Store is never a leaf node. It can always contain stuff
38: */
39: public boolean isLeaf() {
40:         return false;
41: }
42:
43:
44: /**
45: * return the number of children for this store node. The first
46: * time this method is called we load up all of the folders
47: * under the store's defaultFolder
48: */
49:
50: public int getChildCount() {
51:•        if (folder == null) {
52:          loadChildren();
53:         }
54:         return super.getChildCount();
55: }
56:
57: protected void loadChildren() {
58:         try {
59:          // connect to the Store if we need to
60:•         if (!store.isConnected()) {
61:                 store.connect();
62:          }
63:
64:          // get the default folder, and list the
65:          // subscribed folders on it
66:          folder = store.getDefaultFolder();
67:          // Folder[] sub = folder.listSubscribed();
68:          Folder[] sub = folder.list();
69:
70:          // add a FolderTreeNode for each Folder
71:          int num = sub.length;
72:•         for(int i = 0; i < num; i++) {
73:                 FolderTreeNode node = new FolderTreeNode(sub[i]);
74:                 // we used insert here, since add() would make
75:                 // another recursive call to getChildCount();
76:                 insert(node, i);
77:          }
78:         
79:         } catch (MessagingException me) {
80:          me.printStackTrace();
81:         }
82: }
83:
84: /**
85: * We override toString() so we can display the store URLName
86: * without the password.
87: */
88:
89: public String toString() {
90:•        if (display == null) {
91:          URLName url = store.getURLName();
92:•         if (url == null) {
93:                 display = store.toString();
94:          } else {
95:                 // don't show the password
96:                 URLName too = new URLName( url.getProtocol(), url.getHost(), url.getPort(),
97:                                          url.getFile(), url.getUsername(), null);
98:                 display = too.toString();
99:          }
100:         }
101:         
102:         return display;
103: }
104:
105:
106: }
107: