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);
}
}
Aggregations