KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > ui > action > DeleteActivityAction


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.calendar.ui.action;
19
20 import java.awt.event.ActionEvent JavaDoc;
21
22 import org.columba.api.gui.frame.IFrameMediator;
23 import org.columba.calendar.base.api.IActivity;
24 import org.columba.calendar.command.CalendarCommandReference;
25 import org.columba.calendar.command.DeleteEventCommand;
26 import org.columba.calendar.store.CalendarStoreFactory;
27 import org.columba.calendar.store.api.ICalendarStore;
28 import org.columba.calendar.ui.calendar.api.ActivitySelectionChangedEvent;
29 import org.columba.calendar.ui.calendar.api.IActivitySelectionChangedListener;
30 import org.columba.calendar.ui.calendar.api.ICalendarView;
31 import org.columba.calendar.ui.frame.api.ICalendarMediator;
32 import org.columba.core.command.Command;
33 import org.columba.core.command.CommandProcessor;
34 import org.columba.core.gui.action.AbstractColumbaAction;
35 import org.columba.core.resourceloader.IconKeys;
36 import org.columba.core.resourceloader.ImageLoader;
37
38 /**
39  * Delete selected activity.
40  *
41  * @author fdietz
42  */

43
44 public class DeleteActivityAction extends AbstractColumbaAction implements
45         IActivitySelectionChangedListener {
46
47     public DeleteActivityAction(IFrameMediator frameMediator) {
48         super(frameMediator, "Remove Activity");
49
50         putValue(AbstractColumbaAction.TOOLBAR_NAME, "Remove");
51         setShowToolBarText(true);
52
53         putValue(AbstractColumbaAction.SMALL_ICON, ImageLoader.getSmallIcon(IconKeys.EDIT_DELETE));
54         putValue(AbstractColumbaAction.LARGE_ICON, ImageLoader.getIcon(IconKeys.EDIT_DELETE));
55     
56         
57         setEnabled(false);
58
59         ICalendarMediator m = (ICalendarMediator) getFrameMediator();
60         m.getCalendarView().addSelectionChangedListener(this);
61     }
62
63     public void actionPerformed(ActionEvent JavaDoc e) {
64         ICalendarMediator m = (ICalendarMediator) getFrameMediator();
65
66         ICalendarView c = m.getCalendarView();
67
68         IActivity activity = c.getSelectedActivity();
69
70         ICalendarStore store = CalendarStoreFactory.getInstance()
71                 .getLocaleStore();
72
73         Command command = new DeleteEventCommand(new CalendarCommandReference(
74                 store, activity));
75
76         CommandProcessor.getInstance().addOp(command);
77
78     }
79
80     public void selectionChanged(ActivitySelectionChangedEvent event) {
81         if (event.getSelection().length == 0)
82             setEnabled(false);
83         else
84             setEnabled(true);
85
86     }
87
88 }
89
Popular Tags