Search in sources :

Example 1 with ScheduleRangeEvent

use of org.primefaces.event.schedule.ScheduleRangeEvent in project primefaces by primefaces.

the class Schedule method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
    String clientId = getClientId(context);
    if (ComponentUtils.isRequestSource(this, context)) {
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        FacesEvent wrapperEvent = null;
        if ("dateSelect".equals(eventName) || "dateDblSelect".equals(eventName)) {
            String selectedDateStr = params.get(clientId + "_selectedDate");
            ZoneId zoneId = CalendarUtils.calculateZoneId(this.getTimeZone());
            LocalDateTime selectedDate = CalendarUtils.toLocalDateTime(zoneId, selectedDateStr);
            SelectEvent<?> selectEvent = new SelectEvent(this, behaviorEvent.getBehavior(), selectedDate);
            selectEvent.setPhaseId(behaviorEvent.getPhaseId());
            wrapperEvent = selectEvent;
        }
        if ("rangeSelect".equals(eventName)) {
            String startDateStr = params.get(clientId + "_startDate");
            String endDateStr = params.get(clientId + "_endDate");
            ZoneId zoneId = CalendarUtils.calculateZoneId(this.getTimeZone());
            LocalDateTime startDate = CalendarUtils.toLocalDateTime(zoneId, startDateStr);
            LocalDateTime endDate = CalendarUtils.toLocalDateTime(zoneId, endDateStr);
            ScheduleRangeEvent selectEvent = new ScheduleRangeEvent(this, behaviorEvent.getBehavior(), startDate, endDate);
            selectEvent.setPhaseId(behaviorEvent.getPhaseId());
            wrapperEvent = selectEvent;
        } else if ("eventSelect".equals(eventName)) {
            String selectedEventId = params.get(clientId + "_selectedEventId");
            ScheduleEvent<?> selectedEvent = getValue().getEvent(selectedEventId);
            wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), selectedEvent);
        } else if ("eventMove".equals(eventName)) {
            String movedEventId = params.get(clientId + "_movedEventId");
            ScheduleEvent<?> movedEvent = getValue().getEvent(movedEventId);
            int yearDelta = Double.valueOf(params.get(clientId + "_yearDelta")).intValue();
            int monthDelta = Double.valueOf(params.get(clientId + "_monthDelta")).intValue();
            int dayDelta = Double.valueOf(params.get(clientId + "_dayDelta")).intValue();
            int minuteDelta = Double.valueOf(params.get(clientId + "_minuteDelta")).intValue();
            boolean allDay = Boolean.parseBoolean(params.get(clientId + "_allDay"));
            LocalDateTime startDate = movedEvent.getStartDate();
            LocalDateTime endDate = movedEvent.getEndDate();
            startDate = startDate.plusYears(yearDelta).plusMonths(monthDelta).plusDays(dayDelta).plusMinutes(minuteDelta);
            endDate = endDate.plusYears(yearDelta).plusMonths(monthDelta).plusDays(dayDelta).plusMinutes(minuteDelta);
            movedEvent.setAllDay(allDay);
            movedEvent.setStartDate(startDate);
            movedEvent.setEndDate(endDate);
            wrapperEvent = new ScheduleEntryMoveEvent(this, behaviorEvent.getBehavior(), movedEvent, yearDelta, monthDelta, dayDelta, minuteDelta);
        } else if ("eventResize".equals(eventName)) {
            String resizedEventId = params.get(clientId + "_resizedEventId");
            ScheduleEvent<?> resizedEvent = getValue().getEvent(resizedEventId);
            int startDeltaYear = Double.valueOf(params.get(clientId + "_startDeltaYear")).intValue();
            int startDeltaMonth = Double.valueOf(params.get(clientId + "_startDeltaMonth")).intValue();
            int startDeltaDay = Double.valueOf(params.get(clientId + "_startDeltaDay")).intValue();
            int startDeltaMinute = Double.valueOf(params.get(clientId + "_startDeltaMinute")).intValue();
            LocalDateTime startDate = resizedEvent.getStartDate();
            startDate = startDate.plusYears(startDeltaYear).plusMonths(startDeltaMonth).plusDays(startDeltaDay).plusMinutes(startDeltaMinute);
            resizedEvent.setStartDate(startDate);
            int endDeltaYear = Double.valueOf(params.get(clientId + "_endDeltaYear")).intValue();
            int endDeltaMonth = Double.valueOf(params.get(clientId + "_endDeltaMonth")).intValue();
            int endDeltaDay = Double.valueOf(params.get(clientId + "_endDeltaDay")).intValue();
            int endDeltaMinute = Double.valueOf(params.get(clientId + "_endDeltaMinute")).intValue();
            LocalDateTime endDate = resizedEvent.getEndDate();
            endDate = endDate.plusYears(endDeltaYear).plusMonths(endDeltaMonth).plusDays(endDeltaDay).plusMinutes(endDeltaMinute);
            resizedEvent.setEndDate(endDate);
            wrapperEvent = new ScheduleEntryResizeEvent(this, behaviorEvent.getBehavior(), resizedEvent, startDeltaYear, startDeltaMonth, startDeltaDay, startDeltaMinute, endDeltaYear, endDeltaMonth, endDeltaDay, endDeltaMinute);
        } else if ("viewChange".equals(eventName)) {
            wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), getView());
        }
        if (wrapperEvent == null) {
            throw new FacesException("Component " + this.getClass().getName() + " does not support event " + eventName + "!");
        }
        wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        super.queueEvent(wrapperEvent);
    } else {
        super.queueEvent(event);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) FacesContext(javax.faces.context.FacesContext) ScheduleRangeEvent(org.primefaces.event.schedule.ScheduleRangeEvent) ZoneId(java.time.ZoneId) ScheduleEntryMoveEvent(org.primefaces.event.schedule.ScheduleEntryMoveEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) SelectEvent(org.primefaces.event.SelectEvent) FacesException(javax.faces.FacesException) ScheduleEvent(org.primefaces.model.ScheduleEvent) ScheduleEntryResizeEvent(org.primefaces.event.schedule.ScheduleEntryResizeEvent)

Aggregations

LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 FacesException (javax.faces.FacesException)1 FacesContext (javax.faces.context.FacesContext)1 AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)1 FacesEvent (javax.faces.event.FacesEvent)1 SelectEvent (org.primefaces.event.SelectEvent)1 ScheduleEntryMoveEvent (org.primefaces.event.schedule.ScheduleEntryMoveEvent)1 ScheduleEntryResizeEvent (org.primefaces.event.schedule.ScheduleEntryResizeEvent)1 ScheduleRangeEvent (org.primefaces.event.schedule.ScheduleRangeEvent)1 ScheduleEvent (org.primefaces.model.ScheduleEvent)1