01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
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)
61: throws Exception {
62: // get folder that is going to be moved
63: folderToBeRead = (IMailbox) ((IMailFolderCommandReference) getReference())
64: .getSourceFolder();
65:
66: worker.setDisplayText(MessageFormat.format(
67: MailResourceLoader.getString("statusbar", "message",
68: "folder_markasread"),
69: new Object[] { folderToBeRead.getName() }));
70:
71: worker.clearDisplayTextWithDelay();
72:
73: IMailFolderCommandReference markCommandRefs = new MailFolderCommandReference(
74: folderToBeRead);
75: Object[] uids = folderToBeRead.getUids();
76: if ((uids != null) && (uids.length > 0)) {
77: markCommandRefs.setUids(uids);
78: markCommandRefs
79: .setMarkVariant(MarkMessageCommand.MARK_AS_READ);
80:
81: markMessageCommand = new MarkMessageCommand(markCommandRefs);
82: markMessageCommand.execute(worker);
83: }
84: }
85:
86: }
|