Class CalendarScheduleModel
- All Implemented Interfaces:
ScheduleModel
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 Summary
ConstructorsConstructorDescriptionCalendarScheduleModel(CalendarSource source, ZoneId zone) A model oversource. -
Method Summary
Modifier and TypeMethodDescriptionaddCalendar(CalendarInfo info) Shows a calendar's events, as a resource of its own.Shows only when a calendar is busy, hatched, without any detail: the way somebody else's calendar is shown.createItem(long start, long end, String resourceId) Creates an item for a range the user dragged out on empty space.voiddispose()Stops listening to the source.static CalendarEventeventOf(ScheduleItem item) The calendar event an item was made from, or null for busy time.voidgetItems(long from, long to, List<ScheduleItem> out) Adds every item with any part inside[from, to)toout.The last failure of a load, a save or a delete, or null.The resources, in the order they are shown.voidreload()Loads the events around the visible range again.removeCalendar(String calendarId) booleanremoveItem(ScheduleItem given) Removes an item.setCreationEnabled(boolean enabled, String title) Whether dragging on empty space saves a new event withtitle.Which occurrences an edit of a recurring event changes.voidsetVisibleRange(long from, long to) Told by a view whenever the range it shows changes, with a margin around it.booleanupdateItem(ScheduleItem given, long start, long end, String resourceId) Moves or resizes an item, and gives it to another resource whenresourceIddiffers from the one it has.Methods inherited from class AbstractScheduleModel
addChangeListener, fireChanged, removeChangeListener
-
Constructor Details
-
CalendarScheduleModel
A model oversource.zonedecides 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
-
addCalendar
Shows a calendar's events, as a resource of its own. -
addFreeBusyCalendar
Shows only when a calendar is busy, hatched, without any detail: the way somebody else's calendar is shown. -
removeCalendar
-
setMutationScope
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
-
setCreationEnabled
Whether dragging on empty space saves a new event withtitle. Off by default: an application usually opens its own editor from the scheduler's range listener instead. -
getLastError
The last failure of a load, a save or a delete, or null. It stays untilreloadis called or a later save or delete works: one calendar that loads says nothing of another that did not. -
eventOf
The calendar event an item was made from, or null for busy time. -
getResources
Description copied from interface:ScheduleModelThe resources, in the order they are shown. Empty for a schedule that is one person's. -
getItems
Description copied from interface:ScheduleModelAdds every item with any part inside[from, to)toout. -
setVisibleRange
public void setVisibleRange(long from, long to) Description copied from interface:ScheduleModelTold 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:
setVisibleRangein interfaceScheduleModel- Overrides:
setVisibleRangein classAbstractScheduleModel
-
reload
public void reload()Loads the events around the visible range again. -
updateItem
Description copied from interface:ScheduleModelMoves or resizes an item, and gives it to another resource when
resourceIddiffers from the one it has.Returns
false when the model refuses the change; the view puts the item back
- Specified by:
updateItemin interfaceScheduleModel- Overrides:
updateItemin classAbstractScheduleModel
-
createItem
Description copied from interface:ScheduleModelCreates 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:
createItemin interfaceScheduleModel- Overrides:
createItemin classAbstractScheduleModel
-
removeItem
Description copied from interface:ScheduleModelRemoves an item.
Returns
false when the model refuses
- Specified by:
removeItemin interfaceScheduleModel- Overrides:
removeItemin classAbstractScheduleModel
-