KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > FolderChildrenIterator


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.mail.folder;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Enumeration JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import javax.swing.tree.TreeNode JavaDoc;
25
26
27 /**
28  * Iterate through all children using depth-first search.
29  *
30  * @author tstich
31  */

32 public class FolderChildrenIterator {
33     private List JavaDoc folderList;
34     Iterator JavaDoc folderIterator;
35     
36     public FolderChildrenIterator(IMailFolder parent) {
37         folderList = new ArrayList JavaDoc();
38         Enumeration JavaDoc childEnum = parent.children();
39         while( childEnum.hasMoreElements() ) {
40             appendAllChildren(folderList, (TreeNode JavaDoc)childEnum.nextElement());
41         }
42         
43         folderIterator = folderList.iterator();
44     }
45     
46     private void appendAllChildren(List JavaDoc folderList, TreeNode JavaDoc folder) {
47         folderList.add(folder);
48         if( folder.getChildCount() > 0) {
49             Enumeration JavaDoc childEnum = folder.children();
50             while( childEnum.hasMoreElements() ) {
51                 appendAllChildren(folderList, (TreeNode JavaDoc) childEnum.nextElement());
52             }
53         }
54     }
55     
56     public boolean hasMoreChildren() {
57         return folderIterator.hasNext();
58     }
59
60     public AbstractFolder nextChild() {
61         return (AbstractFolder) folderIterator.next();
62     }
63     
64 }
65
Popular Tags