Class CalendarScheduleModel

java.lang.Object
com.codename1.scheduling.AbstractScheduleModel
com.codename1.scheduling.CalendarScheduleModel
All Implemented Interfaces:
ScheduleModel

public class CalendarScheduleModel extends AbstractScheduleModel

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.

  • 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()
      Description copied from interface: ScheduleModel
      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)
      Description copied from interface: ScheduleModel
      Adds every item with any part inside [from, to) to out.
    • setVisibleRange

      public void setVisibleRange(long from, long to)
      Description copied from interface: ScheduleModel
      Told by a view whenever the range it shows changes, with a margin around it. A model that keeps everything in memory ignores it.
      Specified by:
      setVisibleRange in interface ScheduleModel
      Overrides:
      setVisibleRange in class AbstractScheduleModel
    • reload

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

      public boolean updateItem(ScheduleItem given, long start, long end, String resourceId)
      Description copied from interface: ScheduleModel

      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

      Specified by:
      updateItem in interface ScheduleModel
      Overrides:
      updateItem in class AbstractScheduleModel
    • createItem

      public ScheduleItem createItem(long start, long end, String resourceId)
      Description copied from interface: ScheduleModel

      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

      Specified by:
      createItem in interface ScheduleModel
      Overrides:
      createItem in class AbstractScheduleModel
    • removeItem

      public boolean removeItem(ScheduleItem given)
      Description copied from interface: ScheduleModel

      Removes an item.

      Returns

      false when the model refuses

      Specified by:
      removeItem in interface ScheduleModel
      Overrides:
      removeItem in class AbstractScheduleModel