Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class CalendarScheduleModel

  1. Object
  2. AbstractScheduleModel
  3. CalendarScheduleModel

ImplementsScheduleModel

A schedule read from a CalendarSource: the device’s calendars, CalDAV, Google or Microsoft.

Every calendar added is a resource, so a resource view shows calendars side by side and dragging an event to another column moves it to that calendar. The model loads the events around the range a view shows, with recurring events expanded into their occurrences, and loads again when the view moves outside what it has or the source reports a change.

LocalCalendarSource source = LocalCalendarSource.getInstance();
CalendarScheduleModel model = new CalendarScheduleModel(source, ZoneId.systemDefault());
source.listCalendars(CalendarInfo.ContentType.EVENTS, null).ready(page -> {
    for (CalendarInfo calendar : page.getItems()) {
        model.addCalendar(calendar);
    }
});
Scheduler scheduler = new Scheduler(model);

An edit is shown at once and saved in the background; if the source refuses it, the item goes back and getLastError says why.

Constructors

public CalendarScheduleModel(CalendarSource source, ZoneId zone)A model over source.

Methods

public void dispose()Stops listening to the source.
public CalendarSource getSource()
public CalendarScheduleModel addCalendar(CalendarInfo info)Shows a calendar’s events, as a resource of its own.
public CalendarScheduleModel addFreeBusyCalendar(CalendarInfo info)Shows only when a calendar is busy, hatched, without any detail: the way somebody else’s calendar is shown.
public CalendarScheduleModel removeCalendar(String calendarId)
public CalendarScheduleModel setMutationScope(CalendarMutationScope scope)Which occurrences an edit of a recurring event changes.
public CalendarMutationScope getMutationScope()
public CalendarScheduleModel setCreationEnabled(boolean enabled, String title)Whether dragging on empty space saves a new event with title.
public Throwable getLastError()The last failure of a load, a save or a delete, or null.
public static CalendarEvent eventOf(ScheduleItem item)The calendar event an item was made from, or null for busy time.
public List<ScheduleResource> getResources()The resources, in the order they are shown.
public void getItems(long from, long to, List<ScheduleItem> out)Adds every item with any part inside [from, to) to out.
public void setVisibleRange(long from, long to)Told by a view whenever the range it shows changes, with a margin around it.
public void reload()Loads the events around the visible range again.
public boolean updateItem(ScheduleItem given, long start, long end, String resourceId)Moves or resizes an item, and gives it to another resource when resourceId differs from the one it has.
public ScheduleItem createItem(long start, long end, String resourceId)Creates an item for a range the user dragged out on empty space.
public boolean removeItem(ScheduleItem given)Removes an item.

Inherited methods

Constructor details

CalendarScheduleModel

public CalendarScheduleModel(CalendarSource source, ZoneId zone)
A model over source. zone decides where an all-day event’s days start; use the zone of the view.

Method details

dispose

public void dispose()
Stops listening to the source. Call it when the model is discarded.

getSource

public CalendarSource getSource()

addCalendar

public CalendarScheduleModel addCalendar(CalendarInfo info)
Shows a calendar’s events, as a resource of its own.

addFreeBusyCalendar

public CalendarScheduleModel addFreeBusyCalendar(CalendarInfo info)
Shows only when a calendar is busy, hatched, without any detail: the way somebody else’s calendar is shown.

removeCalendar

public CalendarScheduleModel removeCalendar(String calendarId)

setMutationScope

public CalendarScheduleModel setMutationScope(CalendarMutationScope scope)
Which occurrences an edit of a recurring event changes. A view asks the user and sets this before it commits the edit. One occurrence by default.

getMutationScope

public CalendarMutationScope getMutationScope()

setCreationEnabled

public CalendarScheduleModel setCreationEnabled(boolean enabled, String title)
Whether dragging on empty space saves a new event with title. Off by default: an application usually opens its own editor from the scheduler’s range listener instead.

getLastError

public Throwable getLastError()
The last failure of a load, a save or a delete, or null. It stays until reload is called or a later save or delete works: one calendar that loads says nothing of another that did not.

eventOf

public static CalendarEvent eventOf(ScheduleItem item)
The calendar event an item was made from, or null for busy time.

getResources

public List<ScheduleResource> getResources()
The resources, in the order they are shown. Empty for a schedule that is one person’s.

getItems

public void getItems(long from, long to, List<ScheduleItem> out)
Adds every item with any part inside [from, to) to out.

setVisibleRange

public void setVisibleRange(long from, long to)
Told by a view whenever the range it shows changes, with a margin around it. A model that keeps everything in memory ignores it.

reload

public void reload()
Loads the events around the visible range again.

updateItem

public boolean updateItem(ScheduleItem given, long start, long end, String resourceId)
Moves or resizes an item, and gives it to another resource when resourceId differs from the one it has.

Returns

false when the model refuses the change; the view puts the item back

createItem

public ScheduleItem createItem(long start, long end, String resourceId)
Creates an item for a range the user dragged out on empty space.

Returns

the new item, or null when the model does not create items this way

removeItem

public boolean removeItem(ScheduleItem given)
Removes an item.

Returns

false when the model refuses