01: /*--------------------------------------------------------------------------*
02: | Copyright (C) 2006 Christopher Kohlhaas |
03: | |
04: | This program is free software; you can redistribute it and/or modify |
05: | it under the terms of the GNU General Public License as published by the |
06: | Free Software Foundation. A copy of the license has been included with |
07: | these distribution in the COPYING file, if not go to www.fsf.org |
08: | |
09: | As a special exception, you are granted the permissions to link this |
10: | program with every library, which license fulfills the Open Source |
11: | Definition as published by the Open Source Initiative (OSI). |
12: *--------------------------------------------------------------------------*/
13: package org.rapla.gui.internal.edit.reservation;
14:
15: import java.awt.Component;
16: import java.util.Date;
17:
18: import org.rapla.components.util.DateTools;
19: import org.rapla.entities.domain.Allocatable;
20: import org.rapla.entities.domain.Appointment;
21: import org.rapla.entities.domain.Reservation;
22: import org.rapla.entities.dynamictype.DynamicType;
23: import org.rapla.framework.RaplaContext;
24: import org.rapla.framework.RaplaException;
25: import org.rapla.gui.CalendarModel;
26: import org.rapla.gui.RaplaGUIComponent;
27: import org.rapla.gui.ReservationWizard;
28:
29: /** This ReservationWizard displays no wizard and directly opens a ReservationEdit Window
30: */
31: public class NoWizard extends RaplaGUIComponent implements
32: ReservationWizard {
33: public NoWizard(RaplaContext sm) throws RaplaException {
34: super (sm);
35: }
36:
37: public void start(Component component, CalendarModel model,
38: DynamicType type) throws RaplaException {
39: Date startDate = model.getSelectedDate();
40: if (startDate != null) {
41: Date time = new Date(DateTools.MILLISECONDS_PER_HOUR
42: * getCalendarOptions().getWorktimeStart());
43: startDate = getRaplaLocale().toDate(startDate, time);
44: }
45: if (startDate == null) {
46: startDate = getQuery().today();
47: Date time = new Date(DateTools.MILLISECONDS_PER_HOUR
48: * getCalendarOptions().getWorktimeStart());
49: startDate = getRaplaLocale().toDate(startDate, time);
50: }
51: Date endDate = new Date(startDate.getTime()
52: + DateTools.MILLISECONDS_PER_HOUR);
53: Reservation r = getModification().newReservation();
54: if (type != null)
55: r.setClassification(type.newClassification());
56: Appointment appointment = getModification().newAppointment(
57: startDate, endDate);
58: r.addAppointment(appointment);
59: Allocatable[] allocatables = model.getSelectedAllocatables();
60: if (allocatables.length == 1) {
61: r.addAllocatable(allocatables[0]);
62: }
63: getReservationController().edit(r);
64: }
65:
66: public String toString() {
67: return getString("reservation.create_without_wizard");
68: }
69: }
|