001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.calendar.ui.action;
019:
020: import java.awt.event.ActionEvent;
021: import java.util.Calendar;
022:
023: import org.columba.api.gui.frame.IFrameMediator;
024: import org.columba.calendar.command.AddEventCommand;
025: import org.columba.calendar.command.CalendarCommandReference;
026: import org.columba.calendar.model.Event;
027: import org.columba.calendar.model.EventInfo;
028: import org.columba.calendar.model.api.IDateRange;
029: import org.columba.calendar.model.api.IEvent;
030: import org.columba.calendar.model.api.IEventInfo;
031: import org.columba.calendar.resourceloader.IconKeys;
032: import org.columba.calendar.resourceloader.ResourceLoader;
033: import org.columba.calendar.store.CalendarStoreFactory;
034: import org.columba.calendar.store.api.ICalendarStore;
035: import org.columba.calendar.ui.dialog.EditEventDialog;
036: import org.columba.core.command.Command;
037: import org.columba.core.command.CommandProcessor;
038: import org.columba.core.gui.action.AbstractColumbaAction;
039:
040: /**
041: * @author fdietz
042: *
043: */
044: public class NewAppointmentAction extends AbstractColumbaAction {
045:
046: private IDateRange range;
047:
048: public NewAppointmentAction(IFrameMediator frameMediator,
049: IDateRange range) {
050: this (frameMediator);
051:
052: this .range = range;
053: }
054:
055: /**
056: * @param frameMediator
057: * @param name
058: */
059: public NewAppointmentAction(IFrameMediator frameMediator) {
060: super (frameMediator, "New Appointment");
061:
062: putValue(AbstractColumbaAction.TOOLBAR_NAME, "New Appointment");
063: setShowToolBarText(true);
064:
065: putValue(AbstractColumbaAction.LARGE_ICON, ResourceLoader
066: .getIcon(IconKeys.NEW_APPOINTMENT));
067: putValue(AbstractColumbaAction.SMALL_ICON, ResourceLoader
068: .getSmallIcon(IconKeys.NEW_APPOINTMENT));
069: }
070:
071: /**
072: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
073: */
074: public void actionPerformed(ActionEvent e) {
075: IEvent model = new Event();
076: if (range != null) {
077: Calendar start = range.getStartTime();
078: int min = start.get(Calendar.MINUTE);
079: if (min < 30)
080: min = 0;
081: else
082: min = 30;
083: start.set(Calendar.MINUTE, min);
084:
085: model.setDtStart(start);
086: Calendar c = (Calendar) start.clone();
087: c.add(Calendar.MINUTE, 30);
088: model.setDtEnd(c);
089: }
090:
091: // FIXME calendar?
092: IEventInfo eventInfo = new EventInfo(model.getId(), "", model);
093:
094: EditEventDialog dialog = new EditEventDialog(null, eventInfo);
095:
096: if (dialog.success()) {
097:
098: ICalendarStore store = CalendarStoreFactory.getInstance()
099: .getLocaleStore();
100:
101: Command command = new AddEventCommand(
102: new CalendarCommandReference(store), eventInfo);
103: CommandProcessor.getInstance().addOp(command);
104:
105: }
106: }
107:
108: }
|