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.calendar.ui.action;
19:
20: import java.awt.event.ActionEvent;
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
45: implements 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
54: .getSmallIcon(IconKeys.EDIT_DELETE));
55: putValue(AbstractColumbaAction.LARGE_ICON, ImageLoader
56: .getIcon(IconKeys.EDIT_DELETE));
57:
58: setEnabled(false);
59:
60: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
61: m.getCalendarView().addSelectionChangedListener(this );
62: }
63:
64: public void actionPerformed(ActionEvent e) {
65: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
66:
67: ICalendarView c = m.getCalendarView();
68:
69: IActivity activity = c.getSelectedActivity();
70:
71: ICalendarStore store = CalendarStoreFactory.getInstance()
72: .getLocaleStore();
73:
74: Command command = new DeleteEventCommand(
75: new CalendarCommandReference(store, activity));
76:
77: CommandProcessor.getInstance().addOp(command);
78:
79: }
80:
81: public void selectionChanged(ActivitySelectionChangedEvent event) {
82: if (event.getSelection().length == 0)
83: setEnabled(false);
84: else
85: setEnabled(true);
86:
87: }
88:
89: }
|