01: /*--------------------------------------------------------------------------*
02: | Copyright (C) 2006 Christopher Kohlhaas, Bettina Lademann |
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.action;
14:
15: import java.awt.Component;
16: import java.awt.Point;
17:
18: import org.rapla.entities.domain.Reservation;
19: import org.rapla.entities.dynamictype.DynamicType;
20: import org.rapla.entities.dynamictype.DynamicTypeAnnotations;
21: import org.rapla.framework.RaplaContext;
22: import org.rapla.framework.RaplaException;
23: import org.rapla.gui.CalendarModel;
24: import org.rapla.gui.ReservationWizard;
25: import org.rapla.plugin.RaplaExtensionPoints;
26:
27: public class ReservationAction extends RaplaObjectAction {
28: ReservationWizard m_wizard;
29: public final static int EXCHANGE_ALLOCATABLE = 20;
30: public final static int NEW_WIZARD = 800;
31:
32: public ReservationAction(RaplaContext sm, Component parent, Point p)
33: throws RaplaException {
34: super (sm, parent, p);
35: raplaType = Reservation.TYPE;
36: }
37:
38: public ReservationAction setExchangeAllocatables(Object obj) {
39: this .type = EXCHANGE_ALLOCATABLE;
40: putValue(NAME, getString("exchange_allocatables"));
41: putValue(SMALL_ICON, getIcon("icon.edit"));
42: changeObject(obj);
43: return this ;
44: }
45:
46: public ReservationAction setNew(ReservationWizard wizard) {
47: super .setNew(Reservation.TYPE);
48: m_wizard = wizard;
49: if (m_wizard == null) {
50: m_wizard = (ReservationWizard) getService(RaplaExtensionPoints.RESERVATION_WIZARD_EXTENSION);
51: }
52: if (m_wizard != null)
53: putValue(NAME, m_wizard.toString());
54: return this ;
55: }
56:
57: protected void edit() throws RaplaException {
58: getReservationController().edit((Reservation) object);
59: }
60:
61: protected boolean canModifiy(Object object) {
62: if (super .canModify(object)) {
63: return true;
64: }
65: if (object instanceof Reservation) {
66: return getQuery().canExchangeAllocatables(
67: (Reservation) object);
68: }
69: return false;
70: }
71:
72: public DynamicType guessType() throws RaplaException {
73: DynamicType type = super .guessType();
74: if (type
75: .getAnnotation(
76: DynamicTypeAnnotations.KEY_CLASSIFICATION_TYPE)
77: .equals(
78: DynamicTypeAnnotations.VALUE_RESERVATION_CLASSIFICATION)) {
79: return type;
80: }
81: return getQuery()
82: .getDynamicTypes(
83: DynamicTypeAnnotations.VALUE_RESERVATION_CLASSIFICATION)[0];
84: }
85:
86: public void changeObject(Object object) {
87: super .changeObject(object);
88: if (type == NEW) {
89: setEnabled(m_wizard != null);
90: }
91: }
92:
93: protected void newEntity() throws RaplaException {
94: m_wizard.start(parent,
95: (CalendarModel) getService(CalendarModel.ROLE),
96: guessType());
97: }
98: }
|