KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > composer > contact > FolderComboBox


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.gui.composer.contact;
19
20 import java.awt.Component JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import javax.swing.DefaultListCellRenderer JavaDoc;
24 import javax.swing.JComboBox JavaDoc;
25 import javax.swing.JList JavaDoc;
26
27 import org.columba.addressbook.facade.IFolderFacade;
28
29 import org.columba.addressbook.facade.IFolder;
30 import org.columba.api.exception.ServiceNotFoundException;
31 import org.columba.mail.connector.ServiceConnector;
32
33 public class FolderComboBox extends JComboBox JavaDoc {
34
35     public FolderComboBox(boolean showRootFolders) {
36         super();
37
38         IFolderFacade folderFacade = null;
39         try {
40             folderFacade = ServiceConnector.getFolderFacade();
41             Iterator JavaDoc<IFolder> it = folderFacade.getAllFolders()
42                     .listIterator();
43
44             while (it.hasNext()) {
45                 IFolder folder = it.next();
46                 if (!showRootFolders) {
47                     //if (folder instanceof IContactFolder)
48
addItem(folder);
49                 }
50             }
51
52         } catch (ServiceNotFoundException e) {
53             e.printStackTrace();
54         }
55
56         setRenderer(new MyListCellRenderer());
57     }
58
59     class MyListCellRenderer extends DefaultListCellRenderer JavaDoc {
60
61         MyListCellRenderer() {
62
63         }
64
65         /**
66          * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList,
67          * java.lang.Object, int, boolean, boolean)
68          */

69         @Override JavaDoc
70         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
71                 int index, boolean isSelected, boolean cellHasFocus) {
72
73             super.getListCellRendererComponent(list, value, index, isSelected,
74                     cellHasFocus);
75
76             IFolder folder = (IFolder) value;
77
78             setText(folder.getName());
79             setIcon(folder.getIcon());
80
81             return this;
82         }
83
84     }
85 }
86
Popular Tags