001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.folder.command;
017:
018: import java.util.logging.Logger;
019:
020: import org.columba.api.command.ICommandReference;
021: import org.columba.api.command.IWorkerStatusController;
022: import org.columba.core.command.StatusObservableImpl;
023: import org.columba.core.command.Worker;
024: import org.columba.mail.command.IMailFolderCommandReference;
025: import org.columba.mail.folder.IMailbox;
026:
027: /**
028: * Move selected messages from source to destination folder.
029: * <p>
030: * A dialog asks the user the destination folder to use.
031: *
032: * @author fdietz
033: */
034: public class MoveMessageCommand extends CopyMessageCommand {
035:
036: /** JDK 1.4+ logging framework logger, used for logging. */
037: private static final Logger LOG = Logger
038: .getLogger("org.columba.mail.folder.command");
039:
040: /**
041: * Constructor for MoveMessageCommand.
042: *
043: * @param frameMediator
044: * @param references
045: */
046: public MoveMessageCommand(ICommandReference reference) {
047: super (reference);
048: }
049:
050: /**
051: * @see org.columba.api.command.Command#execute(Worker)
052: */
053: public void execute(IWorkerStatusController worker)
054: throws Exception {
055:
056: // get references
057: r = (IMailFolderCommandReference) getReference();
058:
059: // get source folder
060: IMailbox srcFolder = (IMailbox) r.getSourceFolder();
061:
062: // get destination foldedr
063: destFolder = (IMailbox) r.getDestinationFolder();
064:
065: // cancel, if source equals destination folder
066: if (srcFolder.getId() == destFolder.getId())
067: return;
068:
069: // calling CopyMessageCommand.execute() here!
070: //super.execute(worker);
071: doExecute(worker, "move_messages", "err_copy_messages_retry",
072: "err_copy_messages_ignore", "err_move_messages_msg",
073: "err_move_messages_title", "move_messages_cancelled");
074:
075: // get messgae UIDs
076: Object[] uids = r.getUids();
077:
078: // register for status events
079: ((StatusObservableImpl) srcFolder.getObservable())
080: .setWorker(worker);
081:
082: // setting lastSelection to null
083: srcFolder.setLastSelection(null);
084:
085: LOG.info("src=" + srcFolder + " dest=" + destFolder);
086:
087: // update status message
088: worker.setDisplayText("Moving messages to "
089: + destFolder.getName() + "...");
090: worker.setProgressBarMaximum(uids.length);
091:
092: // mark all messages as expunged
093: srcFolder
094: .markMessage(uids, MarkMessageCommand.MARK_AS_EXPUNGED);
095:
096: // expunge folder
097: srcFolder.expungeFolder();
098:
099: // We are done - clear the status message after a delay
100: worker.clearDisplayTextWithDelay();
101:
102: }
103: }
|