KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > action > AddGroupCardAction


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.gui.action;
19
20 import java.awt.event.ActionEvent JavaDoc;
21
22 import org.columba.addressbook.folder.AddressbookFolder;
23 import org.columba.addressbook.folder.AddressbookTreeNode;
24 import org.columba.addressbook.folder.FolderFactory;
25 import org.columba.addressbook.gui.dialog.group.EditGroupDialog;
26 import org.columba.addressbook.gui.frame.AddressbookFrameMediator;
27 import org.columba.addressbook.gui.tree.AddressbookTreeModel;
28 import org.columba.addressbook.model.GroupModel;
29 import org.columba.addressbook.model.IGroupModel;
30 import org.columba.addressbook.util.AddressbookResourceLoader;
31 import org.columba.api.gui.frame.IFrameMediator;
32 import org.columba.core.resourceloader.IconKeys;
33 import org.columba.core.resourceloader.ImageLoader;
34
35 /**
36  * Add new groupw card to selected addressbook.
37  *
38  * @author fdietz
39  */

40 @SuppressWarnings JavaDoc({"serial","serial"})
41 public class AddGroupCardAction extends DefaultTreeAction {
42     public AddGroupCardAction(IFrameMediator frameController) {
43         super(frameController, AddressbookResourceLoader.getString("menu",
44                 "mainframe", "menu_file_addgroup"));
45
46         // tooltip text
47
putValue(SHORT_DESCRIPTION, AddressbookResourceLoader.getString("menu",
48                 "mainframe", "menu_file_addgroup_tooltip").replaceAll("&", ""));
49
50         putValue(TOOLBAR_NAME, AddressbookResourceLoader.getString("menu",
51                 "mainframe", "menu_file_addgroup_toolbar"));
52
53         // icons
54
putValue(SMALL_ICON, ImageLoader.getSmallIcon(IconKeys.USER));
55         putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.USER));
56
57         setEnabled(false);
58     }
59
60     /**
61      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
62      */

63     public void actionPerformed(ActionEvent JavaDoc evt) {
64         AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator;
65
66         // get selected folder
67
AddressbookFolder folder = (AddressbookFolder) mediator.getTree()
68                 .getSelectedFolder();
69
70         if (folder == null) {
71             return;
72         }
73
74         IGroupModel group = new GroupModel();
75
76         EditGroupDialog dialog = new EditGroupDialog(mediator.getView()
77                 .getFrame(), group, folder);
78
79         if (dialog.getResult()) {
80
81             // add new group to folder
82
FolderFactory.createGroupFolder(folder, group);
83
84             // get parent
85
AddressbookTreeNode parent = (AddressbookTreeNode) folder
86                     .getParent();
87
88             // notify model
89
AddressbookTreeModel.getInstance().nodeStructureChanged(parent);
90
91         }
92     }
93 }
Popular Tags