KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > table > action > ThreadedViewAction


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
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
package org.columba.mail.gui.table.action;
17
18 import java.awt.Toolkit JavaDoc;
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.awt.event.KeyEvent JavaDoc;
21
22 import javax.swing.JCheckBoxMenuItem JavaDoc;
23 import javax.swing.KeyStroke JavaDoc;
24
25 import org.columba.api.gui.frame.IFrameMediator;
26 import org.columba.api.selection.ISelectionListener;
27 import org.columba.api.selection.SelectionChangedEvent;
28 import org.columba.core.gui.action.AbstractSelectableAction;
29 import org.columba.core.xml.XmlElement;
30 import org.columba.mail.folder.IMailFolder;
31 import org.columba.mail.folder.IMailbox;
32 import org.columba.mail.gui.frame.MailFrameMediator;
33 import org.columba.mail.gui.frame.TableViewOwner;
34 import org.columba.mail.gui.tree.selection.TreeSelectionChangedEvent;
35 import org.columba.mail.util.MailResourceLoader;
36
37 /**
38  * @author frd
39  *
40  * To change this generated comment edit the template variable "typecomment":
41  * Window>Preferences>Java>Templates. To enable and disable the creation of type
42  * comments go to Window>Preferences>Java>Code Generation.
43  */

44 public class ThreadedViewAction extends AbstractSelectableAction implements
45         ISelectionListener {
46     /**
47      * Constructor for ThreadedViewAction.
48      *
49      * @param frameMediator
50      */

51     public ThreadedViewAction(IFrameMediator frameMediator) {
52         super(frameMediator, MailResourceLoader.getString("menu", "mainframe",
53                 "menu_view_viewthreaded"));
54
55         // tooltip text
56
putValue(SHORT_DESCRIPTION, MailResourceLoader.getString("menu",
57                 "mainframe", "menu_view_viewthreaded_tooltip").replaceAll("&",
58                 ""));
59
60         // shortcut key
61
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_T,
62                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
63
64         ((MailFrameMediator) frameMediator).registerTreeSelectionListener(this);
65
66         setEnabled(true);
67     }
68
69     public void actionPerformed(ActionEvent JavaDoc e) {
70         if (!(frameMediator instanceof TableViewOwner)) {
71             return;
72         }
73
74         JCheckBoxMenuItem JavaDoc item = (JCheckBoxMenuItem JavaDoc) e.getSource();
75
76         boolean enableThreadedView = item.isSelected();
77
78         /*
79          * folder.getConfiguration().set("property", "enable_threaded_view",
80          * enableThreadedView);
81          */

82         updateTable(enableThreadedView);
83     }
84
85     protected void updateTable(boolean enableThreadedView) {
86         if (!(frameMediator instanceof TableViewOwner)) {
87             return;
88         }
89
90         ((TableViewOwner) frameMediator).getTableController()
91                 .enableThreadedView(enableThreadedView, true);
92
93     }
94
95     /**
96      * @see org.columba.core.gui.util.ISelectionListener#connectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
97      */

98     public void selectionChanged(SelectionChangedEvent e) {
99         IMailFolder[] selection = ((TreeSelectionChangedEvent) e).getSelected();
100
101         if (!(selection[0] instanceof IMailbox)) {
102             return;
103         }
104
105         if (selection.length == 1) {
106             XmlElement threadedview = ((MailFrameMediator) getFrameMediator())
107                     .getFolderOptionsController().getConfigNode(
108                             (IMailbox) selection[0], "ThreadedViewOptions");
109             if (threadedview != null) {
110                 // *20040510, karlpeder* columns may be null (first time we
111
// visit a folder!?)
112
String JavaDoc attribute = threadedview.getAttribute("enabled");
113                 setState(Boolean.valueOf(attribute).booleanValue());
114             }
115         }
116     }
117 }
Popular Tags