Search in sources :

Example 1 with OrganigramNodeExpandEvent

use of org.primefaces.event.organigram.OrganigramNodeExpandEvent 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)

Aggregations

FacesException (javax.faces.FacesException)1 FacesContext (javax.faces.context.FacesContext)1 AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)1 FacesEvent (javax.faces.event.FacesEvent)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 OrganigramNode (org.primefaces.model.OrganigramNode)1