KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > tree > action > MoveUpAction


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.tree.action;
17
18 import java.awt.event.ActionEvent JavaDoc;
19 import java.awt.event.KeyEvent JavaDoc;
20
21 import javax.swing.KeyStroke JavaDoc;
22
23 import org.columba.api.gui.frame.IFrameMediator;
24 import org.columba.mail.command.MailFolderCommandReference;
25 import org.columba.mail.folder.IMailFolder;
26 import org.columba.mail.gui.frame.MailFrameMediator;
27 import org.columba.mail.gui.frame.TreeViewOwner;
28 import org.columba.mail.gui.tree.FolderTreeModel;
29 import org.columba.mail.util.MailResourceLoader;
30
31 /**
32  * Move selected folder up for one row.
33  * <p>
34  *
35  * @author fdietz
36  * @author redsolo
37  */

38 public class MoveUpAction extends AbstractMoveFolderAction {
39
40     /**
41      * @param frameMediator
42      * the frame cpntroller.
43      */

44     public MoveUpAction(IFrameMediator frameMediator) {
45         super(frameMediator, MailResourceLoader.getString("menu", "mainframe",
46                 "menu_folder_moveup"));
47         setEnabled(false);
48
49         // shortcut key
50
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_UP,
51                 ActionEvent.ALT_MASK));
52     }
53
54     /**
55      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
56      */

57     public void actionPerformed(ActionEvent JavaDoc arg0) {
58         MailFolderCommandReference r = (MailFolderCommandReference) ((MailFrameMediator) frameMediator)
59                 .getTreeSelection();
60
61         IMailFolder folder = (IMailFolder) r.getSourceFolder();
62
63         int newIndex = folder.getParent().getIndex(folder);
64         newIndex = newIndex - 1;
65         ((IMailFolder) folder.getParent()).insert(folder, newIndex);
66
67         FolderTreeModel.getInstance().nodeStructureChanged(folder.getParent());
68
69         // select folder again after move operation
70
((TreeViewOwner) frameMediator).getTreeController().setSelected(folder);
71     }
72
73     /** {@inheritDoc} */
74     protected boolean isActionEnabledByIndex(int folderIndex) {
75         return (folderIndex > 0);
76     }
77 }
78
Popular Tags