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.table.action;
017:
018: import java.awt.Toolkit;
019: import java.awt.event.ActionEvent;
020: import java.awt.event.KeyEvent;
021: import java.util.Observable;
022: import java.util.Observer;
023:
024: import javax.swing.KeyStroke;
025:
026: import org.columba.api.gui.frame.IFrameMediator;
027: import org.columba.api.selection.ISelectionListener;
028: import org.columba.api.selection.SelectionChangedEvent;
029: import org.columba.core.command.CommandProcessor;
030: import org.columba.core.gui.action.AbstractColumbaAction;
031: import org.columba.core.xml.XmlElement;
032: import org.columba.mail.command.IMailFolderCommandReference;
033: import org.columba.mail.config.MailConfig;
034: import org.columba.mail.gui.composer.command.ForwardCommand;
035: import org.columba.mail.gui.composer.command.ForwardInlineCommand;
036: import org.columba.mail.gui.frame.MailFrameMediator;
037: import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
038: import org.columba.mail.resourceloader.MailImageLoader;
039: import org.columba.mail.util.MailResourceLoader;
040:
041: /**
042: * Forward Message As Attachment or Inline.
043: * <p>
044: * Based on user configuration.
045: *
046: * @author fdietz
047: */
048: public class ForwardAction extends AbstractColumbaAction implements
049: ISelectionListener, Observer {
050: private XmlElement forward;
051: private String forwardStyle;
052:
053: public ForwardAction(IFrameMediator frameMediator) {
054: super (frameMediator, MailResourceLoader.getString("menu",
055: "mainframe", "menu_message_forward"));
056:
057: // tooltip text
058: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
059: "menu", "mainframe", "menu_message_forward_tooltip")
060: .replaceAll("&", ""));
061:
062: // icon for menu
063: putValue(SMALL_ICON, MailImageLoader
064: .getSmallIcon("mail-forward.png"));
065:
066: // icon for toolbar
067: putValue(LARGE_ICON, MailImageLoader
068: .getIcon("mail-forward.png"));
069:
070: // shortcut key
071: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L,
072: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
073:
074: // toolbar text is usually a bit shorter
075: putValue(TOOLBAR_NAME, MailResourceLoader.getString("menu",
076: "mainframe", "menu_message_forward_toolbar"));
077: setEnabled(false);
078: ((MailFrameMediator) frameMediator)
079: .registerTableSelectionListener(this );
080:
081: XmlElement composerOptions = MailConfig.getInstance()
082: .getComposerOptionsConfig().getRoot().getElement(
083: "/options");
084:
085: forward = composerOptions.getElement("forward");
086:
087: if (forward == null) {
088: forward = composerOptions.addSubElement("forward");
089: }
090:
091: // listen for configuration changes
092: forward.addObserver(this );
093:
094: forwardStyle = forward.getAttribute("style", "attachment");
095: }
096:
097: /* (non-Javadoc)
098: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
099: */
100: public void actionPerformed(ActionEvent evt) {
101: IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
102: .getTableSelection();
103:
104: if (forwardStyle.equals("attachment")) {
105: CommandProcessor.getInstance().addOp(new ForwardCommand(r));
106: } else {
107: CommandProcessor.getInstance().addOp(
108: new ForwardInlineCommand(r));
109: }
110: }
111:
112: /* (non-Javadoc)
113: * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
114: */
115: public void selectionChanged(SelectionChangedEvent e) {
116: setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
117: }
118:
119: /**
120: * Gets fired if configuration changes
121: *
122: * @see org.columba.mail.gui.config.general.MailOptionsDialog
123: *
124: * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
125: */
126: public void update(Observable arg0, Object arg1) {
127: forwardStyle = forward.getAttribute("style", "attachment");
128: }
129: }
|