KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > tree > command > MailboxSizeCommand


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.tree.command;
19
20 import org.columba.api.command.ICommandReference;
21 import org.columba.api.command.IWorkerStatusController;
22 import org.columba.core.command.Command;
23 import org.columba.mail.command.IMailFolderCommandReference;
24 import org.columba.mail.folder.IMailFolder;
25 import org.columba.mail.folder.IMailbox;
26 import org.columba.mail.gui.config.folder.FolderOptionsDialog;
27 import org.columba.mail.message.ICloseableIterator;
28 import org.columba.mail.message.IColumbaHeader;
29 import org.columba.mail.message.IHeaderList;
30
31 public class MailboxSizeCommand extends Command {
32
33     private FolderOptionsDialog dialog;
34
35     private int total = 0;
36
37     public MailboxSizeCommand(ICommandReference reference,
38             FolderOptionsDialog dialog) {
39         super(reference);
40
41         this.dialog = dialog;
42     }
43
44     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
45
46         IMailFolder folder = (IMailFolder) ((IMailFolderCommandReference) getReference())
47                 .getSourceFolder();
48
49         total = 0;
50         
51         if (folder instanceof IMailbox) {
52             IHeaderList headerList = ((IMailbox) folder).getHeaderList();
53             ICloseableIterator it = headerList.headerIterator();
54             while (it.hasNext()) {
55                 IColumbaHeader header = (IColumbaHeader) it.next();
56                 Integer JavaDoc sizeInt = (Integer JavaDoc) header.getAttributes().get(
57                         "columba.size");
58
59                 if (sizeInt != null) {
60                     total += sizeInt.intValue();
61                 }
62             }
63             it.close();
64         }
65     }
66
67     /**
68      * @see org.columba.core.command.Command#updateGUI()
69      */

70     public void updateGUI() throws Exception JavaDoc {
71         dialog.setMailboxSize(total);
72     }
73
74 }
75
Popular Tags