001: /*--------------------------------------------------------------------------*
002: | Copyright (C) 2006 Christopher Kohlhaas |
003: | |
004: | This program is free software; you can redistribute it and/or modify |
005: | it under the terms of the GNU General Public License as published by the |
006: | Free Software Foundation. A copy of the license has been included with |
007: | these distribution in the COPYING file, if not go to www.fsf.org |
008: | |
009: | As a special exception, you are granted the permissions to link this |
010: | program with every library, which license fulfills the Open Source |
011: | Definition as published by the Open Source Initiative (OSI). |
012: *--------------------------------------------------------------------------*/
013: package org.rapla.gui.internal.view;
014:
015: import java.util.ArrayList;
016: import java.util.List;
017:
018: import org.rapla.entities.User;
019: import org.rapla.entities.domain.Allocatable;
020: import org.rapla.entities.domain.Appointment;
021: import org.rapla.entities.domain.Repeating;
022: import org.rapla.entities.domain.Reservation;
023: import org.rapla.framework.RaplaContext;
024: import org.rapla.framework.RaplaException;
025:
026: public class ReservationInfoUI extends ClassificationInfoUI {
027:
028: public ReservationInfoUI(RaplaContext sm) throws RaplaException {
029: super (sm);
030: }
031:
032: private void addRestriction(Reservation reservation,
033: Allocatable allocatable, StringBuffer buf) {
034: Appointment[] appointments = reservation
035: .getRestriction(allocatable);
036: if (appointments.length == 0)
037: return;
038: buf.append("<small>");
039: buf.append(" (");
040: for (int i = 0; i < appointments.length; i++) {
041: if (i > 0)
042: buf.append(", ");
043: encode(getAppointmentFormater().getShortSummary(
044: appointments[i]), buf);
045: }
046: buf.append(")");
047: buf.append("</small>");
048: }
049:
050: private String allocatableList(Reservation reservation,
051: Allocatable[] allocatables, User user,
052: LinkController controller) {
053: StringBuffer buf = new StringBuffer();
054: for (int i = 0; i < allocatables.length; i++) {
055: Allocatable allocatable = allocatables[i];
056: if (user != null && !allocatable.canRead(user))
057: continue;
058: if (controller != null)
059: controller.createLink(allocatable,
060: getName(allocatable), buf);
061: else
062: encode(getName(allocatable), buf);
063: addRestriction(reservation, allocatable, buf);
064: if (i < allocatables.length - 1) {
065: buf.append(",");
066: }
067: }
068: return buf.toString();
069: }
070:
071: protected String getTooltip(Object object) {
072: Reservation reservation = (Reservation) object;
073: StringBuffer buf = new StringBuffer();
074: insertModificationRow(reservation, buf);
075: insertClassificationTitle(reservation, buf);
076: createTable(getAttributes(reservation, null, null, true), buf,
077: false);
078: return buf.toString();
079: }
080:
081: protected String getHTML(Object object, LinkController controller) {
082: Reservation reservation = (Reservation) object;
083: StringBuffer buf = new StringBuffer();
084: insertModificationRow(reservation, buf);
085: insertClassificationTitle(reservation, buf);
086: createTable(
087: getAttributes(reservation, controller, null, false),
088: buf, false);
089: this .insertAllAppointments(reservation, buf);
090: return buf.toString();
091: }
092:
093: public List getAttributes(Reservation reservation,
094: LinkController controller, User user,
095: boolean excludeAdditionalInfos) {
096: ArrayList att = new ArrayList();
097: att.addAll(getClassificationAttributes(reservation,
098: excludeAdditionalInfos));
099: User owner = reservation.getOwner();
100: String ownerText = encode(owner.getName());
101: if (controller != null)
102: ownerText = controller.createLink(owner, owner.getName());
103:
104: att.add(new Row(getString("reservation.owner"), ownerText));
105: User lastChangeBy = reservation.getLastChangedBy();
106: if (lastChangeBy != null && !lastChangeBy.equals(owner)) {
107: String lastChangeByText = encode(lastChangeBy.getName());
108: if (controller != null)
109: lastChangeByText = controller.createLink(lastChangeBy,
110: lastChangeBy.getName());
111: att.add(new Row(getString("last_changed_by"),
112: lastChangeByText));
113: }
114:
115: Allocatable[] resources = reservation.getResources();
116: String resourceList = allocatableList(reservation, resources,
117: user, controller);
118: if (resourceList.length() > 0) {
119: att.add(new Row(getString("resources"), resourceList));
120: }
121: Allocatable[] persons = reservation.getPersons();
122: String personList = allocatableList(reservation, persons, user,
123: controller);
124: if (personList.length() > 0) {
125: att.add(new Row(getString("persons"), personList));
126: }
127: return att;
128: }
129:
130: void insertAllAppointments(Reservation reservation, StringBuffer buf) {
131: buf.append("<table cellpadding=\"2\">");
132: buf.append("<tr>\n");
133: buf.append("<td colspan=\"2\" class=\"label\">");
134: String appointmentLabel = getString("appointments");
135: encode(appointmentLabel, buf);
136: buf.append(":");
137: buf.append("</td>\n");
138: buf.append("</tr>\n");
139: Appointment[] appointments = reservation.getAppointments();
140: for (int i = 0; i < appointments.length; i++) {
141: buf.append("<tr>\n");
142: buf.append("<td valign=\"top\">\n");
143: if (appointments[i].getRepeating() != null) {
144: buf
145: .append("<img width=\"16\" height=\"16\" src=\"org/rapla/gui/images/repeating.png\">");
146: } else {
147: buf
148: .append("<img width=\"16\" height=\"16\" src=\"org/rapla/gui/images/single.png\">");
149: }
150: buf.append("</td>\n");
151: buf.append("<td>\n");
152: String appointmentSummary = getAppointmentFormater()
153: .getSummary(appointments[i]);
154: encode(appointmentSummary, buf);
155: Repeating repeating = appointments[i].getRepeating();
156: if (repeating != null) {
157: buf.append("<br>");
158: buf.append("<small>");
159: List periods = getPeriodModel().getPeriodsFor(
160: appointments[i].getStart());
161: String repeatingSummary = getAppointmentFormater()
162: .getSummary(repeating, periods);
163: encode(repeatingSummary, buf);
164: if (repeating.hasExceptions()) {
165: buf.append("<br>");
166: buf.append(getAppointmentFormater()
167: .getExceptionSummary(repeating));
168: }
169: buf.append("</small>");
170: }
171: buf.append("</td>\n");
172: buf.append("<td></td>");
173: buf.append("</tr>\n");
174: }
175: buf.append("</table>\n");
176: }
177:
178: void insertModificationRow(Reservation reservation, StringBuffer buf) {
179: buf.append("<div style=\"font-size:7px;margin-bottom:4px;\">");
180: buf.append(getString("created_at"));
181: buf.append(" ");
182: buf.append(getRaplaLocale().formatDate(
183: reservation.getCreateTime()));
184: buf.append(", ");
185: buf.append(getString("last_changed"));
186: buf.append(" ");
187: buf.append(getRaplaLocale().formatDate(
188: reservation.getLastChangeTime()));
189: buf.append("</div>");
190: buf.append("\n");
191: }
192:
193: }
|