KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > command > MarkFolderAsReadCommand


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.command;
18
19 import java.text.MessageFormat JavaDoc;
20
21 import org.columba.api.command.ICommandReference;
22 import org.columba.api.command.IWorkerStatusController;
23 import org.columba.core.command.Command;
24 import org.columba.mail.command.IMailFolderCommandReference;
25 import org.columba.mail.command.MailFolderCommandReference;
26 import org.columba.mail.folder.IMailbox;
27 import org.columba.mail.util.MailResourceLoader;
28
29 /**
30  * A command that marks all messages in a folder as read.
31  * <p>
32  * The command reference should be inserted as these:
33  * <ol>
34  * <li> A <code>Folder</code> that is going to be marked as read, and the uids to mark as read.
35  * </ol>
36  * <p>
37  * First implementation marks all messages as read, a better approach would
38  * be to only mark those who arent read.
39  * <p>
40  * @author redsolo
41  */

42 public class MarkFolderAsReadCommand extends Command {
43
44     /** The folder that is supposed to be marked as read. */
45     private IMailbox folderToBeRead;
46     
47     /**
48      * Command doing the actual work.
49      */

50     private MarkMessageCommand markMessageCommand;
51
52     /**
53      * @param reference folder reference
54      */

55     public MarkFolderAsReadCommand(ICommandReference reference) {
56         super(reference);
57     }
58
59     /** {@inheritDoc} */
60     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
61         // get folder that is going to be moved
62
folderToBeRead = (IMailbox) ((IMailFolderCommandReference) getReference()).getSourceFolder();
63
64         worker.setDisplayText(MessageFormat.format(
65                 MailResourceLoader.getString("statusbar", "message",
66                     "folder_markasread"), new Object JavaDoc[] {folderToBeRead.getName()}));
67
68         worker.clearDisplayTextWithDelay();
69
70         IMailFolderCommandReference markCommandRefs = new MailFolderCommandReference(folderToBeRead);
71         Object JavaDoc[] uids = folderToBeRead.getUids();
72         if ((uids != null) && (uids.length > 0)) {
73             markCommandRefs.setUids(uids);
74             markCommandRefs.setMarkVariant(MarkMessageCommand.MARK_AS_READ);
75
76             markMessageCommand = new MarkMessageCommand(markCommandRefs);
77             markMessageCommand.execute(worker);
78         }
79     }
80
81 }
82
Popular Tags