KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.JOptionPane JavaDoc;
23
24 import org.columba.api.gui.frame.IFrameMediator;
25 import org.columba.calendar.base.api.IActivity;
26 import org.columba.calendar.model.api.IEvent;
27 import org.columba.calendar.model.api.IEventInfo;
28 import org.columba.calendar.store.CalendarStoreFactory;
29 import org.columba.calendar.store.api.ICalendarStore;
30 import org.columba.calendar.store.api.StoreException;
31 import org.columba.calendar.ui.calendar.api.ActivitySelectionChangedEvent;
32 import org.columba.calendar.ui.calendar.api.IActivitySelectionChangedListener;
33 import org.columba.calendar.ui.calendar.api.ICalendarView;
34 import org.columba.calendar.ui.dialog.EditEventDialog;
35 import org.columba.calendar.ui.frame.api.ICalendarMediator;
36 import org.columba.core.gui.action.AbstractColumbaAction;
37 import org.columba.core.gui.frame.FrameManager;
38
39 /**
40  * Edit activity.
41  *
42  * @author fdietz
43  *
44  */

45
46 public class EditActivityAction extends AbstractColumbaAction implements
47         IActivitySelectionChangedListener {
48
49     public EditActivityAction(IFrameMediator frameMediator) {
50         super(frameMediator, "Edit Activity");
51
52         putValue(AbstractColumbaAction.TOOLBAR_NAME, "Edit");
53         setShowToolBarText(true);
54
55         // putValue(AbstractColumbaAction.LARGE_ICON, ResourceLoader
56
// .getImageIcon("new_appointment-32.png"));
57
// putValue(AbstractColumbaAction.SMALL_ICON, ResourceLoader
58
// .getImageIcon("new_appointment.png"));
59
setEnabled(false);
60
61         ICalendarMediator m = (ICalendarMediator) getFrameMediator();
62         m.getCalendarView().addSelectionChangedListener(this);
63     }
64
65     public void actionPerformed(ActionEvent JavaDoc e) {
66         ICalendarMediator m = (ICalendarMediator) getFrameMediator();
67
68         ICalendarView c = m.getCalendarView();
69
70         IActivity activity = c.getSelectedActivity();
71
72         String JavaDoc id = (String JavaDoc) activity.getId();
73
74         ICalendarStore store = CalendarStoreFactory.getInstance()
75                 .getLocaleStore();
76
77         // retrieve event from store
78
try {
79             IEventInfo model = (IEventInfo) store.get(id);
80
81             EditEventDialog dialog = new EditEventDialog(m.getContainer()
82                     .getFrame(), model);
83             if (dialog.success()) {
84                 IEventInfo updatedModel = dialog.getModel();
85                 
86                 // update store
87
store.modify(id, updatedModel);
88             }
89
90         } catch (StoreException e1) {
91             JOptionPane.showMessageDialog(FrameManager.getInstance()
92                     .getActiveFrame(), e1.getMessage());
93             e1.printStackTrace();
94         }
95
96     }
97
98     public void selectionChanged(ActivitySelectionChangedEvent event) {
99
100
101         if (event.getSelection().length == 0)
102             setEnabled(false);
103         else
104             setEnabled(true);
105
106     }
107
108 }
109
Popular Tags