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.gui.composer.action;
017:
018: import java.awt.Toolkit;
019: import java.awt.event.ActionEvent;
020: import java.awt.event.KeyEvent;
021:
022: import javax.swing.KeyStroke;
023:
024: import org.columba.api.gui.frame.IFrameMediator;
025: import org.columba.core.command.CommandProcessor;
026: import org.columba.core.gui.action.AbstractColumbaAction;
027: import org.columba.core.resourceloader.ImageLoader;
028: import org.columba.mail.command.ComposerCommandReference;
029: import org.columba.mail.command.MailFolderCommandReference;
030: import org.columba.mail.config.AccountItem;
031: import org.columba.mail.config.SpecialFoldersItem;
032: import org.columba.mail.folder.IMailbox;
033: import org.columba.mail.folder.command.ExpungeFolderCommand;
034: import org.columba.mail.folder.command.MarkMessageCommand;
035: import org.columba.mail.gui.composer.ComposerController;
036: import org.columba.mail.gui.composer.ComposerModel;
037: import org.columba.mail.gui.composer.command.SaveMessageCommand;
038: import org.columba.mail.gui.tree.FolderTreeModel;
039: import org.columba.mail.util.MailResourceLoader;
040: import org.columba.ristretto.message.Flags;
041:
042: /**
043: * @author freddy
044: */
045: public class SaveAsDraftAction extends AbstractColumbaAction {
046: public SaveAsDraftAction(IFrameMediator frameMediator) {
047: super (frameMediator, MailResourceLoader.getString("menu",
048: "composer", "menu_file_savedraft"));
049:
050: putValue(SMALL_ICON, ImageLoader
051: .getSmallIcon("document-save.png"));
052: putValue(LARGE_ICON, ImageLoader.getIcon("document-save.png"));
053:
054: // tooltip text
055: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
056: "menu", "composer", "menu_file_savedraft").replaceAll(
057: "&", ""));
058:
059: // shortcut key
060: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S,
061: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
062: }
063:
064: /*
065: * (non-Javadoc)
066: *
067: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
068: */
069: public void actionPerformed(ActionEvent evt) {
070: final ComposerController composerController = (ComposerController) getFrameMediator();
071:
072: // view data ->model
073: composerController.updateComponents(false);
074:
075: ComposerModel model = ((ComposerModel) composerController
076: .getModel());
077:
078: // get selected account
079: AccountItem item = model.getAccountItem();
080: // get "Drafts" folder of account
081: SpecialFoldersItem folderItem = item.getSpecialFoldersItem();
082: String str = folderItem.get("drafts");
083: IMailbox destFolder = (IMailbox) FolderTreeModel.getInstance()
084: .getFolder(str);
085:
086: // check if we are currently editing a draft message
087: if (model.getMessage().getHeader().getFlags().getDraft()) {
088: // -> we need to replace old message
089:
090: // delete source message
091: MailFolderCommandReference r = model.getSourceReference();
092: if (r != null) {
093: r.setMarkVariant(MarkMessageCommand.MARK_AS_EXPUNGED);
094: CommandProcessor.getInstance().addOp(
095: new MarkMessageCommand(r));
096: CommandProcessor.getInstance().addOp(
097: new ExpungeFolderCommand(r));
098: }
099: }
100:
101: // mark as read, mark as draft
102: Flags flags = new Flags();
103: flags.setSeen(true);
104: flags.setDraft(true);
105: model.getMessage().getHeader().setFlags(flags);
106:
107: // create command reference
108: ComposerCommandReference r = new ComposerCommandReference(
109: composerController, destFolder);
110: r.setAppendSignature(false);
111:
112: // create command
113: SaveMessageCommand c = new SaveMessageCommand(r);
114:
115: CommandProcessor.getInstance().addOp(c);
116: }
117: }
|