Search in sources :

Example 6 with FacesEvent

use of javax.faces.event.FacesEvent in project primefaces by primefaces.

the class TreeTable method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    if (ComponentUtils.isRequestSource(this, context) && (event instanceof AjaxBehaviorEvent)) {
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
        String clientId = getClientId(context);
        FacesEvent wrapperEvent = null;
        TreeNode root = getValue();
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        if ("expand".equals(eventName)) {
            String nodeKey = params.get(clientId + "_expand");
            setRowKey(root, nodeKey);
            TreeNode node = getRowNode();
            wrapperEvent = new NodeExpandEvent(this, behaviorEvent.getBehavior(), node);
            wrapperEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
        } else if ("collapse".equals(eventName)) {
            String nodeKey = params.get(clientId + "_collapse");
            setRowKey(root, nodeKey);
            TreeNode node = getRowNode();
            node.setExpanded(false);
            wrapperEvent = new NodeCollapseEvent(this, behaviorEvent.getBehavior(), node);
            wrapperEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
        } else if ("select".equals(eventName) || "contextMenu".equals(eventName)) {
            String nodeKey = params.get(clientId + "_instantSelection");
            setRowKey(root, nodeKey);
            TreeNode node = getRowNode();
            wrapperEvent = new NodeSelectEvent(this, behaviorEvent.getBehavior(), node);
            wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        } else if ("unselect".equals(eventName)) {
            String nodeKey = params.get(clientId + "_instantUnselection");
            setRowKey(root, nodeKey);
            TreeNode node = getRowNode();
            wrapperEvent = new NodeUnselectEvent(this, behaviorEvent.getBehavior(), node);
            wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        } else if ("colResize".equals(eventName)) {
            String columnId = params.get(clientId + "_columnId");
            int width = Integer.parseInt(params.get(clientId + "_width"));
            int height = Integer.parseInt(params.get(clientId + "_height"));
            wrapperEvent = new ColumnResizeEvent(this, behaviorEvent.getBehavior(), width, height, findColumn(columnId));
        } else if ("sort".equals(eventName)) {
            wrapperEvent = new SortEvent(this, behaviorEvent.getBehavior(), getSortByAsMap());
        } else if ("filter".equals(eventName)) {
            deferredEvents.put("filter", (AjaxBehaviorEvent) event);
            return;
        } else if ("rowEdit".equals(eventName) || "rowEditCancel".equals(eventName) || "rowEditInit".equals(eventName)) {
            String nodeKey = params.get(clientId + "_rowEditIndex");
            setRowKey(root, nodeKey);
            wrapperEvent = new RowEditEvent(this, behaviorEvent.getBehavior(), getRowNode());
            wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        } else if ("cellEdit".equals(eventName) || "cellEditCancel".equals(eventName) || "cellEditInit".equals(eventName)) {
            String[] cellInfo = params.get(clientId + "_cellInfo").split(",");
            String rowKey = cellInfo[0];
            int cellIndex = Integer.parseInt(cellInfo[1]);
            int i = -1;
            UIColumn column = null;
            for (UIColumn col : getColumns()) {
                if (col.isRendered()) {
                    i++;
                    if (i == cellIndex) {
                        column = col;
                        break;
                    }
                }
            }
            wrapperEvent = new CellEditEvent(this, behaviorEvent.getBehavior(), column, rowKey);
            wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        } else if ("page".equals(eventName)) {
            int rows = getRowsToRender();
            int first = Integer.parseInt(params.get(clientId + "_first"));
            int page = rows > 0 ? (first / rows) : 0;
            wrapperEvent = new PageEvent(this, behaviorEvent.getBehavior(), page);
            wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        }
        super.queueEvent(wrapperEvent);
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UIColumn(org.primefaces.component.api.UIColumn) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) SortEvent(org.primefaces.event.data.SortEvent) PageEvent(org.primefaces.event.data.PageEvent)

Example 7 with FacesEvent

use of javax.faces.event.FacesEvent in project primefaces by primefaces.

the class GMap 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 ("overlaySelect".equals(eventName) || "overlayDblSelect".equals(eventName)) {
            wrapperEvent = new OverlaySelectEvent(this, behaviorEvent.getBehavior(), getModel().findOverlay(params.get(clientId + "_overlayId")));
            // if there is info window, update and show it
            GMapInfoWindow infoWindow = getInfoWindow();
            if (infoWindow != null) {
                PrimeFaces.current().ajax().update(infoWindow.getClientId(context));
            }
        } else if ("stateChange".equals(eventName)) {
            String[] centerLoc = params.get(clientId + "_center").split(",");
            String[] northeastLoc = params.get(clientId + "_northeast").split(",");
            String[] southwestLoc = params.get(clientId + "_southwest").split(",");
            int zoomLevel = Integer.parseInt(params.get(clientId + "_zoom"));
            LatLng center = new LatLng(Double.valueOf(centerLoc[0]), Double.valueOf(centerLoc[1]));
            LatLng northeast = new LatLng(Double.valueOf(northeastLoc[0]), Double.valueOf(northeastLoc[1]));
            LatLng southwest = new LatLng(Double.valueOf(southwestLoc[0]), Double.valueOf(southwestLoc[1]));
            wrapperEvent = new StateChangeEvent(this, behaviorEvent.getBehavior(), new LatLngBounds(northeast, southwest), zoomLevel, center);
        } else if ("pointSelect".equals(eventName) || "pointDblSelect".equals(eventName)) {
            String[] latlng = params.get(clientId + "_pointLatLng").split(",");
            LatLng position = new LatLng(Double.valueOf(latlng[0]), Double.valueOf(latlng[1]));
            wrapperEvent = new PointSelectEvent(this, behaviorEvent.getBehavior(), position);
        } else if ("markerDrag".equals(eventName)) {
            Marker marker = (Marker) getModel().findOverlay(params.get(clientId + "_markerId"));
            double lat = Double.parseDouble(params.get(clientId + "_lat"));
            double lng = Double.parseDouble(params.get(clientId + "_lng"));
            marker.setLatlng(new LatLng(lat, lng));
            wrapperEvent = new MarkerDragEvent(this, behaviorEvent.getBehavior(), marker);
        } else if ("geocode".equals(eventName)) {
            List<GeocodeResult> results = new ArrayList<>();
            String query = params.get(clientId + "_query");
            String[] addresses = params.get(clientId + "_addresses").split("_primefaces_");
            String[] lats = params.get(clientId + "_lat").split(",");
            String[] lngs = params.get(clientId + "_lng").split(",");
            for (int i = 0; i < addresses.length; i++) {
                results.add(new GeocodeResult(addresses[i], new LatLng(Double.valueOf(lats[i]), Double.valueOf(lngs[i]))));
            }
            wrapperEvent = new GeocodeEvent(this, behaviorEvent.getBehavior(), query, results);
        } else if ("reverseGeocode".equals(eventName)) {
            String[] results = params.get(clientId + "_address").split("_primefaces_");
            List<String> addresses = Arrays.asList(results);
            double lat = Double.parseDouble(params.get(clientId + "_lat"));
            double lng = Double.parseDouble(params.get(clientId + "_lng"));
            LatLng coord = new LatLng(lat, lng);
            wrapperEvent = new ReverseGeocodeEvent(this, behaviorEvent.getBehavior(), coord, addresses);
        }
        if (wrapperEvent == null) {
            throw new FacesException("Component " + getClass().getName() + " does not support event " + eventName + "!");
        }
        wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        super.queueEvent(wrapperEvent);
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) LatLngBounds(org.primefaces.model.map.LatLngBounds) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) Marker(org.primefaces.model.map.Marker) FacesException(javax.faces.FacesException) LatLng(org.primefaces.model.map.LatLng) GeocodeResult(org.primefaces.model.map.GeocodeResult)

Example 8 with FacesEvent

use of javax.faces.event.FacesEvent 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)

Example 9 with FacesEvent

use of javax.faces.event.FacesEvent in project primefaces by primefaces.

the class Organigram method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    if (ComponentUtils.isRequestSource(this, context) && event instanceof AjaxBehaviorEvent) {
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
        String clientId = getClientId(context);
        FacesEvent wrapperEvent = null;
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        if ("expand".equals(eventName)) {
            OrganigramNode node = findTreeNode(getValue(), params.get(clientId + "_expandNode"));
            node.setExpanded(true);
            wrapperEvent = new OrganigramNodeExpandEvent(this, behaviorEvent.getBehavior(), node);
        } else if ("collapse".equals(eventName)) {
            OrganigramNode node = findTreeNode(getValue(), params.get(clientId + "_collapseNode"));
            node.setExpanded(false);
            wrapperEvent = new OrganigramNodeCollapseEvent(this, behaviorEvent.getBehavior(), node);
        } else if ("select".equals(eventName) || "contextmenu".equals(eventName)) {
            OrganigramNode node = findTreeNode(getValue(), params.get(clientId + "_selectNode"));
            wrapperEvent = new OrganigramNodeSelectEvent(this, behaviorEvent.getBehavior(), node);
        } else if ("dragdrop".equals(eventName)) {
            OrganigramNode dragNode = findTreeNode(getValue(), params.get(clientId + "_dragNode"));
            OrganigramNode dropNode = findTreeNode(getValue(), params.get(clientId + "_dropNode"));
            // remove node from current parent
            if (dragNode != null && dropNode != null) {
                OrganigramNode sourceNode = dragNode.getParent();
                if (sourceNode != null) {
                    sourceNode.getChildren().remove(dragNode);
                }
                // set new parent
                dragNode.setParent(dropNode);
                wrapperEvent = new OrganigramNodeDragDropEvent(this, behaviorEvent.getBehavior(), dragNode, dropNode, sourceNode);
            }
        }
        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 : FacesContext(javax.faces.context.FacesContext) OrganigramNodeCollapseEvent(org.primefaces.event.organigram.OrganigramNodeCollapseEvent) OrganigramNodeSelectEvent(org.primefaces.event.organigram.OrganigramNodeSelectEvent) OrganigramNode(org.primefaces.model.OrganigramNode) OrganigramNodeDragDropEvent(org.primefaces.event.organigram.OrganigramNodeDragDropEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) OrganigramNodeExpandEvent(org.primefaces.event.organigram.OrganigramNodeExpandEvent) FacesException(javax.faces.FacesException)

Example 10 with FacesEvent

use of javax.faces.event.FacesEvent in project primefaces by primefaces.

the class Tree method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    if (ComponentUtils.isRequestSource(this, context) && event instanceof AjaxBehaviorEvent) {
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
        String clientId = getClientId(context);
        FacesEvent wrapperEvent = null;
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        TreeNode root = getValue();
        if ("expand".equals(eventName)) {
            setRowKey(root, params.get(clientId + "_expandNode"));
            TreeNode expandedNode = getRowNode();
            expandedNode.setExpanded(true);
            wrapperEvent = new NodeExpandEvent(this, behaviorEvent.getBehavior(), expandedNode);
        } else if ("collapse".equals(eventName)) {
            setRowKey(root, params.get(clientId + "_collapseNode"));
            TreeNode collapsedNode = getRowNode();
            collapsedNode.setExpanded(false);
            wrapperEvent = new NodeCollapseEvent(this, behaviorEvent.getBehavior(), collapsedNode);
        } else if ("select".equals(eventName)) {
            setRowKey(root, params.get(clientId + "_instantSelection"));
            wrapperEvent = new NodeSelectEvent(this, behaviorEvent.getBehavior(), getRowNode());
        } else if ("unselect".equals(eventName)) {
            setRowKey(root, params.get(clientId + "_instantUnselection"));
            wrapperEvent = new NodeUnselectEvent(this, behaviorEvent.getBehavior(), getRowNode());
        } else if ("dragdrop".equals(eventName)) {
            if (!retValOnDrop) {
                return;
            }
            int dndIndex = Integer.parseInt(params.get(clientId + "_dndIndex"));
            boolean isDroppedNodeCopy = Boolean.parseBoolean(params.get(clientId + "_isDroppedNodeCopy"));
            if (isMultipleDrag()) {
                wrapperEvent = new TreeDragDropEvent(this, behaviorEvent.getBehavior(), dragNodes, dropNode, dndIndex, isDroppedNodeCopy);
            } else {
                wrapperEvent = new TreeDragDropEvent(this, behaviorEvent.getBehavior(), dragNode, dropNode, dndIndex, isDroppedNodeCopy);
            }
        } else if ("contextMenu".equals(eventName)) {
            setRowKey(root, params.get(clientId + "_contextMenuNode"));
            wrapperEvent = new NodeSelectEvent(this, behaviorEvent.getBehavior(), getRowNode(), true);
        } else if ("filter".equals(eventName)) {
            wrapperEvent = behaviorEvent;
        }
        if (wrapperEvent == null) {
            throw new FacesException("Component " + this.getClass().getName() + " does not support event " + eventName + "!");
        }
        wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        super.queueEvent(wrapperEvent);
        setRowKey(root, null);
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) FacesException(javax.faces.FacesException) TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode)

Aggregations

FacesEvent (javax.faces.event.FacesEvent)11 AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)9 FacesException (javax.faces.FacesException)7 FacesContext (javax.faces.context.FacesContext)7 SelectEvent (org.primefaces.event.SelectEvent)4 UnselectEvent (org.primefaces.event.UnselectEvent)2 LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 Renderer (javax.faces.render.Renderer)1 UIColumn (org.primefaces.component.api.UIColumn)1 PageEvent (org.primefaces.event.data.PageEvent)1 SortEvent (org.primefaces.event.data.SortEvent)1 ConnectEvent (org.primefaces.event.diagram.ConnectEvent)1 ConnectionChangeEvent (org.primefaces.event.diagram.ConnectionChangeEvent)1 DisconnectEvent (org.primefaces.event.diagram.DisconnectEvent)1 PositionChangeEvent (org.primefaces.event.diagram.PositionChangeEvent)1 OrganigramNodeCollapseEvent (org.primefaces.event.organigram.OrganigramNodeCollapseEvent)1 OrganigramNodeDragDropEvent (org.primefaces.event.organigram.OrganigramNodeDragDropEvent)1 OrganigramNodeExpandEvent (org.primefaces.event.organigram.OrganigramNodeExpandEvent)1 OrganigramNodeSelectEvent (org.primefaces.event.organigram.OrganigramNodeSelectEvent)1