01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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;
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({"serial","serial"})
41: public class AddGroupCardAction extends DefaultTreeAction {
42: public AddGroupCardAction(IFrameMediator frameController) {
43: super (frameController, AddressbookResourceLoader.getString(
44: "menu", "mainframe", "menu_file_addgroup"));
45:
46: // tooltip text
47: putValue(SHORT_DESCRIPTION, AddressbookResourceLoader
48: .getString("menu", "mainframe",
49: "menu_file_addgroup_tooltip").replaceAll("&",
50: ""));
51:
52: putValue(TOOLBAR_NAME, AddressbookResourceLoader.getString(
53: "menu", "mainframe", "menu_file_addgroup_toolbar"));
54:
55: // icons
56: putValue(SMALL_ICON, ImageLoader.getSmallIcon(IconKeys.USER));
57: putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.USER));
58:
59: setEnabled(false);
60: }
61:
62: /**
63: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
64: */
65: public void actionPerformed(ActionEvent evt) {
66: AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator;
67:
68: // get selected folder
69: AddressbookFolder folder = (AddressbookFolder) mediator
70: .getTree().getSelectedFolder();
71:
72: if (folder == null) {
73: return;
74: }
75:
76: IGroupModel group = new GroupModel();
77:
78: EditGroupDialog dialog = new EditGroupDialog(mediator.getView()
79: .getFrame(), group, folder);
80:
81: if (dialog.getResult()) {
82:
83: // add new group to folder
84: FolderFactory.createGroupFolder(folder, group);
85:
86: // get parent
87: AddressbookTreeNode parent = (AddressbookTreeNode) folder
88: .getParent();
89:
90: // notify model
91: AddressbookTreeModel.getInstance().nodeStructureChanged(
92: parent);
93:
94: }
95: }
96: }
|