01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
19: import java.awt.event.KeyEvent;
20:
21: import javax.swing.KeyStroke;
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",
45: "mainframe", "menu_folder_movedown"));
46: setEnabled(false);
47:
48: // shortcut key
49: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(
50: KeyEvent.VK_DOWN, ActionEvent.ALT_MASK));
51: }
52:
53: /**
54: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
55: */
56: public void actionPerformed(ActionEvent 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(
67: folder.getParent());
68:
69: // select folder again after move operation
70: ((TreeViewOwner) frameMediator).getTreeController()
71: .setSelected(folder);
72: }
73:
74: /** {@inheritDoc} */
75: protected boolean isActionEnabledByIndex(int folderIndex) {
76: return (folderIndex < (getLastSelectedFolder().getParent()
77: .getChildCount() - 1));
78: }
79: }
|