use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method updateEventAlreadyInSync.
/**
* @see org.olat.commons.calendar.CalendarManager#updateEventFrom(org.olat.commons.calendar.model.Kalendar, org.olat.commons.calendar.model.KalendarEvent)
*/
@Override
public boolean updateEventAlreadyInSync(final Kalendar cal, final KalendarEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(calOres);
Kalendar reloadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
if (StringHelper.containsNonWhitespace(kalendarEvent.getRecurrenceRule())) {
Date oldBegin = kalendarEvent.getImmutableBegin();
Date oldEnd = kalendarEvent.getImmutableEnd();
KalendarEvent originalEvent = reloadedCal.getEvent(kalendarEvent.getID(), null);
Date newBegin = kalendarEvent.getBegin();
Date newEnd = kalendarEvent.getEnd();
long beginDiff = newBegin.getTime() - oldBegin.getTime();
long endDiff = newEnd.getTime() - oldEnd.getTime();
java.util.Calendar cl = java.util.Calendar.getInstance();
cl.setTime(originalEvent.getBegin());
cl.add(java.util.Calendar.MILLISECOND, (int) beginDiff);
kalendarEvent.setBegin(cl.getTime());
cl.setTime(originalEvent.getEnd());
cl.add(java.util.Calendar.MILLISECOND, (int) endDiff);
kalendarEvent.setEnd(cl.getTime());
List<KalendarEvent> exEvents = new ArrayList<>();
List<KalendarEvent> allEvents = reloadedCal.getEvents();
for (KalendarEvent event : allEvents) {
if (event.getID().equals(kalendarEvent.getID()) && StringHelper.containsNonWhitespace(event.getRecurrenceID())) {
exEvents.add(event);
}
}
if (exEvents.size() > 0) {
for (KalendarEvent exEvent : exEvents) {
try {
reloadedCal.removeEvent(exEvent);
String recurrenceId = exEvent.getRecurrenceID();
RecurrenceId recurId = new RecurrenceId(recurrenceId, tz);
Date currentRecurrence = recurId.getDate();
java.util.Calendar calc = java.util.Calendar.getInstance();
calc.clear();
calc.setTime(currentRecurrence);
if (beginDiff > 0) {
calc.add(java.util.Calendar.MILLISECOND, (int) beginDiff);
}
Date newRecurrenceDate = calc.getTime();
boolean allDay = kalendarEvent.isAllDayEvent();
RecurrenceId newRecurId;
if (allDay) {
newRecurId = new RecurrenceId(tz);
newRecurId.setDate(CalendarUtils.createDate(newRecurrenceDate));
} else {
String startString = CalendarUtils.formatRecurrenceDate(newRecurrenceDate, false);
newRecurId = new RecurrenceId(startString, tz);
}
exEvent.setRecurrenceID(newRecurId.getValue());
reloadedCal.addEvent(exEvent);
} catch (ParseException e) {
log.error("", e);
}
}
}
}
// remove old event
reloadedCal.removeEvent(kalendarEvent);
kalendarEvent.resetImmutableDates();
// add changed event
reloadedCal.addEvent(kalendarEvent);
boolean successfullyPersist = persistCalendar(reloadedCal);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return successfullyPersist;
}
use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method removeOccurenceOfEvent.
@Override
public boolean removeOccurenceOfEvent(final Kalendar cal, final KalendarRecurEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
String uid = kalendarEvent.getID();
Date occurenceDate = kalendarEvent.getBegin();
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
rootEvent.addRecurrenceExc(kalendarEvent.getBegin());
for (KalendarEvent kEvent : loadedCal.getEvents()) {
if (uid.equals(kEvent.getID()) && kEvent.getOccurenceDate() != null && occurenceDate.equals(kEvent.getOccurenceDate())) {
loadedCal.removeEvent(kEvent);
}
}
boolean successfullyPersist = persistCalendar(loadedCal);
return new Boolean(successfullyPersist);
}
});
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return removeSuccessful.booleanValue();
}
use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method updateCalendar.
@Override
public boolean updateCalendar(final Kalendar cal, final Kalendar importedCal) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean updatedSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
Map<KalendarEventKey, KalendarEvent> uidToEvent = new HashMap<>();
for (KalendarEvent event : cal.getEvents()) {
if (StringHelper.containsNonWhitespace(event.getID())) {
uidToEvent.put(new KalendarEventKey(event), event);
}
}
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
for (KalendarEvent importedEvent : importedCal.getEvents()) {
KalendarEventKey uid = new KalendarEventKey(importedEvent);
if (uidToEvent.containsKey(uid)) {
// remove old event
loadedCal.removeEvent(importedEvent);
// add changed event
loadedCal.addEvent(importedEvent);
} else {
loadedCal.addEvent(importedEvent);
}
}
boolean successfullyPersist = persistCalendar(cal);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return new Boolean(successfullyPersist);
}
});
return updatedSuccessful.booleanValue();
}
use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project OpenOLAT by OpenOLAT.
the class ChoiceOfToolsForm method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup);
if (source == cots && event.getCommand().equals("ONCHANGE")) {
Collection<String> set = cots.getSelected();
for (int i = 0; i < availableTools.length; i++) {
// usually one should check which one changed but here
// it is okay to set all of them because ctsm has a cache
// and writes only when really necessary.
collabTools.setToolEnabled(availableTools[i], set.contains("" + i));
}
// reload tools after a change
collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup);
fireEvent(ureq, Event.CHANGED_EVENT);
// update news form: only show when enabled
if (collabTools.isToolEnabled(CollaborationTools.TOOL_NEWS)) {
addNewsTool(ureq);
} else {
vc_collabtools.contextPut("newsToolEnabled", Boolean.FALSE);
}
// update calendar form: only show when enabled
boolean newCalendarEnabledState = collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR);
if (newCalendarEnabledState != lastCalendarEnabledState) {
if (newCalendarEnabledState) {
vc_collabtools.contextPut("calendarToolEnabled", Boolean.TRUE);
int iCalendarAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
Long lCalendarAccess = collabTools.lookupCalendarAccess();
if (lCalendarAccess != null)
iCalendarAccess = lCalendarAccess.intValue();
if (calendarForm != null) {
this.removeAsListenerAndDispose(calendarForm);
}
calendarForm = new CalendarToolSettingsController(ureq, getWindowControl(), iCalendarAccess);
calendarForm.setEnabled(!managed);
listenTo(calendarForm);
vc_collabtools.put("calendarform", calendarForm.getInitialComponent());
} else {
vc_collabtools.contextPut("calendarToolEnabled", Boolean.FALSE);
// notify calendar components to refresh their calendars
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(), OresHelper.lookupType(CalendarManager.class));
}
lastCalendarEnabledState = newCalendarEnabledState;
}
// update quota form: only show when enabled
if (collabTools.isToolEnabled(CollaborationTools.TOOL_FOLDER)) {
vc_collabtools.contextPut("folderToolEnabled", Boolean.TRUE);
if (folderForm != null) {
removeAsListenerAndDispose(folderForm);
}
Long lFolderAccess = collabTools.lookupFolderAccess();
int access = lFolderAccess == null ? CollaborationTools.FOLDER_ACCESS_ALL : lFolderAccess.intValue();
folderForm = new FolderToolSettingsController(ureq, getWindowControl(), access);
folderForm.setEnabled(!managed);
listenTo(folderForm);
vc_collabtools.put("folderform", folderForm.getInitialComponent());
if (ureq.getUserSession().getRoles().isOLATAdmin()) {
vc_collabtools.put("quota", quotaCtr.getInitialComponent());
}
} else {
vc_collabtools.contextPut("folderToolEnabled", Boolean.FALSE);
}
} else if (source == newsController) {
if (event.equals(Event.DONE_EVENT)) {
String access = newsController.getAccessPropertyValue();
collabTools.saveNewsAccessProperty(access);
}
} else if (source == calendarForm) {
collabTools.saveCalendarAccess(new Long(calendarForm.getCalendarAccess()));
// notify calendar components to refresh their calendars
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(), OresHelper.lookupType(CalendarManager.class));
} else if (source == folderForm) {
collabTools.saveFolderAccess(new Long(folderForm.getFolderAccess()));
}
}
use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project openolat by klemens.
the class WeeklyCalendarController method event.
@Override
public void event(UserRequest ureq, Component source, Event event) {
if (event == ComponentUtil.VALIDATE_EVENT && dirty) {
dirty = false;
fireEvent(ureq, new CalendarGUIModifiedEvent());
} else if (event == ComponentUtil.VALIDATE_EVENT && calendarEl.getComponent().isDirty() && modifiedCalenderDirty) {
KalendarRenderWrapper kalendarRenderWrapper = calendarEl.getCalendar(modifiedCalendarId);
kalendarRenderWrapper.reloadKalendar();
}
super.event(ureq, source, event);
}
Aggregations