Creating Appointments and Implementing MAF Calendar Data Provider

The MAF Calendar component does not store any data about the appointments that it presents. Your application has to store the data.

The MAF Calendar component defines the structure of a valid appointment via the IMAFAppointment interface. It provides the IMAFCalendarDataProvider interface, which the application needs to implement to feed the calendar controls with data. To make multiple calendar handling possible (appointments from different types of calendars are colored differently), each appointment object must refer to a parent calendar instance that is defined by IMAFCalendar interface.

To provide appointments data for the MAF Calendar component, implement first the IMAFCalendarDataProvider interface. MAF Calendar queries the list of available appointments through this interface, using the various getAppointments(…) methods.

To implement this data provider, use one of the already existing data model classes, or create a new one, as shown in this code:
class MyAppointmentDataProvider implements IMAFCalendarDataProvider {

ArrayList<IMAFAppointment> appointments = 
new ArrayList<IMAFAppointment>();
			
public List<IMAFAppointment> getAppointments(Date start, Date end) {
		List<IMAFAppointment> filteredAppointments; // = new Ar...
		// filter 'appointments' here to return only appointments
		// in the proper time frame, between 'start' and 'end'
		return filteredAppointments;
	}

	// rest of implementation

// Eclipse warns you to implement the other getAppointments methods as
// well, so please do so. The most important one is the above one, shown // in this sample, so you might leave those implementations blank
}	
Next, add appointment objects to the appointments data list. The framework provides you with default implementations for creating calendar and appointment objects: DefaultMAFCalendar and DefaultMAFAppointment classes are compatible with the IMAFCalendar and IMAFAppointment definitions, respectively. This code shows how to create a private calendar and a private appointment:
// create a calendar instance
IMAFCalendar privateCalendar = new DefaultMAFCalendar(
"private", 
							"id1", 											Color.GREEN);

// specify start/end dates
Date startDate, endDate;
// you might use =>
// MAFDateHelper.createDateFromString("12.09.2012 10:00.00");

// create an appointment instance
IMAFAppointment aPrivateAppointment = new DefaultMAFAppointment(
								privateCalendar, 
								startDate, 
								endDate, 
								"Visiting home", 
								"Budapest");

To construct dates, use the MAFDateHelper utility class, which is part of the MAFCalendar component and holds methods for date creations and localizations. To see the MAF Calendar component working with appointments, bind the MyAppointmentDataProvider object to the MAF Calendar UI controls.

For the complete list of data provider an appointment related interface methods, see the API documentation.