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:
022: import javax.swing.JCheckBoxMenuItem;
023: import javax.swing.KeyStroke;
024:
025: import org.columba.api.gui.frame.IFrameMediator;
026: import org.columba.api.selection.ISelectionListener;
027: import org.columba.api.selection.SelectionChangedEvent;
028: import org.columba.core.gui.action.AbstractSelectableAction;
029: import org.columba.core.xml.XmlElement;
030: import org.columba.mail.folder.IMailFolder;
031: import org.columba.mail.folder.IMailbox;
032: import org.columba.mail.gui.frame.MailFrameMediator;
033: import org.columba.mail.gui.frame.TableViewOwner;
034: import org.columba.mail.gui.tree.selection.TreeSelectionChangedEvent;
035: import org.columba.mail.util.MailResourceLoader;
036:
037: /**
038: * @author frd
039: *
040: * To change this generated comment edit the template variable "typecomment":
041: * Window>Preferences>Java>Templates. To enable and disable the creation of type
042: * comments go to Window>Preferences>Java>Code Generation.
043: */
044: public class ThreadedViewAction extends AbstractSelectableAction
045: implements ISelectionListener {
046: /**
047: * Constructor for ThreadedViewAction.
048: *
049: * @param frameMediator
050: */
051: public ThreadedViewAction(IFrameMediator frameMediator) {
052: super (frameMediator, MailResourceLoader.getString("menu",
053: "mainframe", "menu_view_viewthreaded"));
054:
055: // tooltip text
056: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
057: "menu", "mainframe", "menu_view_viewthreaded_tooltip")
058: .replaceAll("&", ""));
059:
060: // shortcut key
061: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_T,
062: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
063:
064: ((MailFrameMediator) frameMediator)
065: .registerTreeSelectionListener(this );
066:
067: setEnabled(true);
068: }
069:
070: public void actionPerformed(ActionEvent e) {
071: if (!(frameMediator instanceof TableViewOwner)) {
072: return;
073: }
074:
075: JCheckBoxMenuItem item = (JCheckBoxMenuItem) e.getSource();
076:
077: boolean enableThreadedView = item.isSelected();
078:
079: /*
080: * folder.getConfiguration().set("property", "enable_threaded_view",
081: * enableThreadedView);
082: */
083: updateTable(enableThreadedView);
084: }
085:
086: protected void updateTable(boolean enableThreadedView) {
087: if (!(frameMediator instanceof TableViewOwner)) {
088: return;
089: }
090:
091: ((TableViewOwner) frameMediator).getTableController()
092: .enableThreadedView(enableThreadedView, true);
093:
094: }
095:
096: /**
097: * @see org.columba.core.gui.util.ISelectionListener#connectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
098: */
099: public void selectionChanged(SelectionChangedEvent e) {
100: IMailFolder[] selection = ((TreeSelectionChangedEvent) e)
101: .getSelected();
102:
103: if (!(selection[0] instanceof IMailbox)) {
104: return;
105: }
106:
107: if (selection.length == 1) {
108: XmlElement threadedview = ((MailFrameMediator) getFrameMediator())
109: .getFolderOptionsController().getConfigNode(
110: (IMailbox) selection[0],
111: "ThreadedViewOptions");
112: if (threadedview != null) {
113: // *20040510, karlpeder* columns may be null (first time we
114: // visit a folder!?)
115: String attribute = threadedview.getAttribute("enabled");
116: setState(Boolean.valueOf(attribute).booleanValue());
117: }
118: }
119: }
120: }
|