Search in sources :

Example 1 with DisconnectEvent

use of org.primefaces.event.diagram.DisconnectEvent 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

FacesException (javax.faces.FacesException)1 FacesContext (javax.faces.context.FacesContext)1 AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)1 FacesEvent (javax.faces.event.FacesEvent)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 DiagramModel (org.primefaces.model.diagram.DiagramModel)1 Element (org.primefaces.model.diagram.Element)1 EndPoint (org.primefaces.model.diagram.endpoint.EndPoint)1