KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Calendar JavaDoc;
22
23 import org.columba.api.gui.frame.IFrameMediator;
24 import org.columba.calendar.command.AddEventCommand;
25 import org.columba.calendar.command.CalendarCommandReference;
26 import org.columba.calendar.model.Event;
27 import org.columba.calendar.model.EventInfo;
28 import org.columba.calendar.model.api.IDateRange;
29 import org.columba.calendar.model.api.IEvent;
30 import org.columba.calendar.model.api.IEventInfo;
31 import org.columba.calendar.resourceloader.IconKeys;
32 import org.columba.calendar.resourceloader.ResourceLoader;
33 import org.columba.calendar.store.CalendarStoreFactory;
34 import org.columba.calendar.store.api.ICalendarStore;
35 import org.columba.calendar.ui.dialog.EditEventDialog;
36 import org.columba.core.command.Command;
37 import org.columba.core.command.CommandProcessor;
38 import org.columba.core.gui.action.AbstractColumbaAction;
39
40 /**
41  * @author fdietz
42  *
43  */

44 public class NewAppointmentAction extends AbstractColumbaAction {
45
46     private IDateRange range;
47
48     public NewAppointmentAction(IFrameMediator frameMediator, IDateRange range) {
49         this(frameMediator);
50
51         this.range = range;
52     }
53
54     /**
55      * @param frameMediator
56      * @param name
57      */

58     public NewAppointmentAction(IFrameMediator frameMediator) {
59         super(frameMediator, "New Appointment");
60
61         putValue(AbstractColumbaAction.TOOLBAR_NAME, "New Appointment");
62         setShowToolBarText(true);
63
64         putValue(AbstractColumbaAction.LARGE_ICON, ResourceLoader
65                 .getIcon(IconKeys.NEW_APPOINTMENT));
66         putValue(AbstractColumbaAction.SMALL_ICON, ResourceLoader
67                 .getSmallIcon(IconKeys.NEW_APPOINTMENT));
68     }
69
70     /**
71      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
72      */

73     public void actionPerformed(ActionEvent JavaDoc e) {
74         IEvent model = new Event JavaDoc();
75         if (range != null) {
76             Calendar JavaDoc start = range.getStartTime();
77             int min = start.get(Calendar.MINUTE);
78             if (min < 30)
79                 min = 0;
80             else
81                 min = 30;
82             start.set(Calendar.MINUTE, min);
83
84             model.setDtStart(start);
85             Calendar JavaDoc c = (Calendar JavaDoc) start.clone();
86             c.add(Calendar.MINUTE, 30);
87             model.setDtEnd(c);
88         }
89         
90         // FIXME calendar?
91
IEventInfo eventInfo = new EventInfo(model.getId(), "", model);
92
93         EditEventDialog dialog = new EditEventDialog(null, eventInfo);
94
95         if (dialog.success()) {
96
97             ICalendarStore store = CalendarStoreFactory.getInstance()
98                     .getLocaleStore();
99
100             Command command = new AddEventCommand(new CalendarCommandReference(
101                     store), eventInfo);
102             CommandProcessor.getInstance().addOp(command);
103
104         }
105     }
106
107 }
108
Popular Tags