Search in sources :

Example 11 with FacesEvent

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

the class Diagram 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);
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        DiagramModel model = (DiagramModel) getValue();
        if (model != null) {
            if ("connect".equals(eventName) || "disconnect".equals(eventName)) {
                FacesEvent wrapperEvent = null;
                Element sourceElement = model.findElement(params.get(clientId + "_sourceId"));
                Element targetElement = model.findElement(params.get(clientId + "_targetId"));
                EndPoint sourceEndPoint = model.findEndPoint(sourceElement, params.get(clientId + "_sourceEndPointId"));
                EndPoint targetEndPoint = model.findEndPoint(targetElement, params.get(clientId + "_targetEndPointId"));
                if ("connect".equals(eventName)) {
                    wrapperEvent = new ConnectEvent(this, behaviorEvent.getBehavior(), sourceElement, targetElement, sourceEndPoint, targetEndPoint);
                } else if ("disconnect".equals(eventName)) {
                    wrapperEvent = new DisconnectEvent(this, behaviorEvent.getBehavior(), sourceElement, targetElement, sourceEndPoint, targetEndPoint);
                }
                if (wrapperEvent == null) {
                    throw new FacesException("Component " + this.getClass().getName() + " does not support event " + eventName + "!");
                }
                wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
                super.queueEvent(wrapperEvent);
            } else if ("connectionChange".equals(eventName)) {
                Element originalSourceElement = model.findElement(params.get(clientId + "_originalSourceId"));
                Element newSourceElement = model.findElement(params.get(clientId + "_newSourceId"));
                Element originalTargetElement = model.findElement(params.get(clientId + "_originalTargetId"));
                Element newTargetElement = model.findElement(params.get(clientId + "_newTargetId"));
                EndPoint originalSourceEndPoint = model.findEndPoint(originalSourceElement, params.get(clientId + "_originalSourceEndPointId"));
                EndPoint newSourceEndPoint = model.findEndPoint(newSourceElement, params.get(clientId + "_newSourceEndPointId"));
                EndPoint originalTargetEndPoint = model.findEndPoint(originalTargetElement, params.get(clientId + "_originalTargetEndPointId"));
                EndPoint newTargetEndPoint = model.findEndPoint(newTargetElement, params.get(clientId + "_newTargetEndPointId"));
                ConnectionChangeEvent connectionChangeEvent = new ConnectionChangeEvent(this, behaviorEvent.getBehavior(), originalSourceElement, newSourceElement, originalTargetElement, newTargetElement, originalSourceEndPoint, newSourceEndPoint, originalTargetEndPoint, newTargetEndPoint);
                connectionChangeEvent.setPhaseId(behaviorEvent.getPhaseId());
                super.queueEvent(connectionChangeEvent);
            } else if ("positionChange".equals(eventName)) {
                Element element = model.findElement(params.get(clientId + "_elementId"));
                String[] position = params.get(clientId + "_position").split(",");
                PositionChangeEvent positionChangeEvent = new PositionChangeEvent(this, behaviorEvent.getBehavior(), element, position[0] + "px", position[1] + "px");
                positionChangeEvent.setPhaseId(behaviorEvent.getPhaseId());
                super.queueEvent(positionChangeEvent);
            }
        }
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ConnectionChangeEvent(org.primefaces.event.diagram.ConnectionChangeEvent) ConnectEvent(org.primefaces.event.diagram.ConnectEvent) Element(org.primefaces.model.diagram.Element) PositionChangeEvent(org.primefaces.event.diagram.PositionChangeEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) EndPoint(org.primefaces.model.diagram.endpoint.EndPoint) FacesException(javax.faces.FacesException) DiagramModel(org.primefaces.model.diagram.DiagramModel) DisconnectEvent(org.primefaces.event.diagram.DisconnectEvent)

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