KickJava   Java API By Example, From Geeks To Geeks.

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


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 down for one row.
33  * <p>
34  *
35  * @author fdietz
36  * @author redsolo
37  */

38 public class MoveDownAction extends AbstractMoveFolderAction {
39     /**
40      * @param frameMediator
41      * the frame controller.
42      */

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

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