01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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)
45: throws Exception {
46:
47: IMailFolder folder = (IMailFolder) ((IMailFolderCommandReference) getReference())
48: .getSourceFolder();
49:
50: total = 0;
51:
52: if (folder instanceof IMailbox) {
53: IHeaderList headerList = ((IMailbox) folder)
54: .getHeaderList();
55: ICloseableIterator it = headerList.headerIterator();
56: while (it.hasNext()) {
57: IColumbaHeader header = (IColumbaHeader) it.next();
58: Integer sizeInt = (Integer) header.getAttributes().get(
59: "columba.size");
60:
61: if (sizeInt != null) {
62: total += sizeInt.intValue();
63: }
64: }
65: it.close();
66: }
67: }
68:
69: /**
70: * @see org.columba.core.command.Command#updateGUI()
71: */
72: public void updateGUI() throws Exception {
73: dialog.setMailboxSize(total);
74: }
75:
76: }
|