Search in sources :

Example 1 with DualListModel

use of org.primefaces.model.DualListModel in project meveo by meveo-org.

the class EndpointBean method getPathParametersDL.

public DualListModel<String> getPathParametersDL() {
    List<String> perksTarget;
    if (pathParametersDL == null) {
        List<String> perksSource = new ArrayList<>();
        if (scriptInstance != null && CollectionUtils.isNotEmpty(scriptInstance.getInputs())) {
            List<FunctionIO> functionIOList = scriptInstance.getInputs();
            Set<String> parameterTarget = new HashSet<>();
            perksTarget = new ArrayList<>();
            if (entity.getPathParameters() != null && CollectionUtils.isNotEmpty(entity.getPathParameters())) {
                entity.getPathParameters().stream().filter(item -> item != null && item.getEndpointParameter() != null).forEach(item -> parameterTarget.add(item.getEndpointParameter().getParameter()));
            }
            for (FunctionIO functionIO : functionIOList) {
                if (!parameterTarget.contains(functionIO.getName())) {
                    perksSource.add(functionIO.getName());
                } else {
                    perksTarget.add(functionIO.getName());
                }
            }
            pathParametersDL = new DualListModel<String>(perksSource, perksTarget);
        } else {
            perksTarget = new ArrayList<>();
            pathParametersDL = new DualListModel<String>(perksSource, perksTarget);
        }
    } else if (scriptInstance != null && !scriptInstance.getCode().equals(serviceCode)) {
        List<FunctionIO> functionIOList = scriptInstance.getInputs();
        List<String> perksSource = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(functionIOList)) {
            for (FunctionIO functionIO : functionIOList) {
                perksSource.add(functionIO.getName());
            }
        }
        perksTarget = new ArrayList<>();
        pathParametersDL = new DualListModel<String>(perksSource, perksTarget);
    }
    return pathParametersDL;
}
Also used : Arrays(java.util.Arrays) EndpointService(org.meveo.service.technicalservice.endpoint.EndpointService) ELException(org.meveo.elresolver.ELException) HashMap(java.util.HashMap) StringUtils(org.meveo.commons.utils.StringUtils) ArrayList(java.util.ArrayList) ScriptInstanceService(org.meveo.service.script.ScriptInstanceService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ScriptInstance(org.meveo.model.scripts.ScriptInstance) CollectionUtils(org.apache.commons.collections.CollectionUtils) FunctionIO(org.meveo.model.scripts.FunctionIO) TSParameterMapping(org.meveo.model.technicalservice.endpoint.TSParameterMapping) Map(java.util.Map) Function(org.meveo.model.scripts.Function) Named(javax.inject.Named) DualListModel(org.primefaces.model.DualListModel) EJB(javax.ejb.EJB) EndpointPathParameter(org.meveo.model.technicalservice.endpoint.EndpointPathParameter) Transactional(javax.transaction.Transactional) KeycloakAdminClientService(org.meveo.keycloak.client.KeycloakAdminClientService) EndpointParameter(org.meveo.model.technicalservice.endpoint.EndpointParameter) Messages(org.jboss.seam.international.status.Messages) Endpoint(org.meveo.model.technicalservice.endpoint.Endpoint) Set(java.util.Set) Collectors(java.util.stream.Collectors) BusinessException(org.meveo.admin.exception.BusinessException) ViewScoped(javax.faces.view.ViewScoped) IPersistenceService(org.meveo.service.base.local.IPersistenceService) List(java.util.List) TransferEvent(org.primefaces.event.TransferEvent) BaseBean(org.meveo.admin.action.BaseBean) EndpointApi(org.meveo.api.technicalservice.endpoint.EndpointApi) BundleKey(org.jboss.seam.international.status.builder.BundleKey) ActionMethod(org.meveo.admin.web.interceptor.ActionMethod) DualListModel(org.primefaces.model.DualListModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FunctionIO(org.meveo.model.scripts.FunctionIO) HashSet(java.util.HashSet)

Example 2 with DualListModel

use of org.primefaces.model.DualListModel in project primefaces by primefaces.

the class PickList method validate.

@Override
public void validate(FacesContext context) {
    super.validate(context);
    if (isValid() && customEvents != null) {
        for (Map.Entry<String, AjaxBehaviorEvent> event : customEvents.entrySet()) {
            String eventName = event.getKey();
            AjaxBehaviorEvent behaviorEvent = event.getValue();
            Map<String, String> params = context.getExternalContext().getRequestParameterMap();
            String clientId = getClientId(context);
            DualListModel<?> list = (DualListModel<?>) getValue();
            FacesEvent wrapperEvent = null;
            if ("select".equals(eventName)) {
                String listName = params.get(clientId + "_listName");
                int itemIndex = Integer.parseInt(params.get(clientId + "_itemIndex"));
                if ("target".equals(listName)) {
                    wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), list.getTarget().get(itemIndex));
                } else {
                    wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), list.getSource().get(itemIndex));
                }
            } else if ("unselect".equals(eventName)) {
                String listName = params.get(clientId + "_listName");
                int itemIndex = Integer.parseInt(params.get(clientId + "_itemIndex"));
                if ("target".equals(listName)) {
                    wrapperEvent = new UnselectEvent(this, behaviorEvent.getBehavior(), list.getTarget().get(itemIndex));
                } else {
                    wrapperEvent = new UnselectEvent(this, behaviorEvent.getBehavior(), list.getSource().get(itemIndex));
                }
            } else if ("reorder".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);
        }
    }
}
Also used : DualListModel(org.primefaces.model.DualListModel) UnselectEvent(org.primefaces.event.UnselectEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) SelectEvent(org.primefaces.event.SelectEvent) FacesException(javax.faces.FacesException)

Example 3 with DualListModel

use of org.primefaces.model.DualListModel in project primefaces by primefaces.

the class PickList method validateValue.

@Override
protected void validateValue(FacesContext facesContext, Object newValue) {
    super.validateValue(facesContext, newValue);
    DualListModel<?> newModel = (DualListModel<?>) newValue;
    DualListModel<?> oldModel = (DualListModel<?>) getValue();
    String clientId = getClientId(facesContext);
    String label = getLabel();
    if (label == null) {
        label = clientId;
    }
    if (isRequired() && newModel.getTarget().isEmpty()) {
        String requiredMessage = getRequiredMessage();
        FacesMessage message = null;
        if (requiredMessage != null) {
            message = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
        } else {
            message = MessageFactory.getFacesMessage(REQUIRED_MESSAGE_ID, FacesMessage.SEVERITY_ERROR, label);
        }
        facesContext.addMessage(clientId, message);
        setValid(false);
    }
    checkDisabled(facesContext, label, newModel.getSource(), oldModel == null ? Collections.emptyList() : oldModel.getSource());
    checkDisabled(facesContext, label, newModel.getTarget(), oldModel == null ? Collections.emptyList() : oldModel.getTarget());
}
Also used : DualListModel(org.primefaces.model.DualListModel) FacesMessage(javax.faces.application.FacesMessage)

Example 4 with DualListModel

use of org.primefaces.model.DualListModel in project primefaces by primefaces.

the class PickListRenderer method encodeMarkup.

protected void encodeMarkup(FacesContext context, PickList pickList) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = pickList.getClientId(context);
    DualListModel model = getModelValueToRender(context, pickList);
    String styleClass = pickList.getStyleClass();
    styleClass = styleClass == null ? PickList.CONTAINER_CLASS : PickList.CONTAINER_CLASS + " " + styleClass;
    String labelDisplay = pickList.getLabelDisplay();
    boolean vertical = pickList.getOrientation().equals("vertical");
    if (vertical) {
        styleClass += " ui-picklist-vertical";
    }
    if (pickList.isResponsive()) {
        styleClass += " ui-picklist-responsive";
    }
    writer.startElement("div", pickList);
    writer.writeAttribute("id", clientId, "id");
    writer.writeAttribute("class", styleClass, null);
    if (pickList.getStyle() != null) {
        writer.writeAttribute("style", pickList.getStyle(), null);
    }
    // Target List Reorder Buttons
    if (pickList.isShowSourceControls()) {
        encodeListControls(context, pickList, PickList.SOURCE_CONTROLS, labelDisplay);
    }
    // Source List
    encodeList(context, pickList, clientId + "_source", PickList.SOURCE_CLASS, model.getSource(), pickList.getFacet("sourceCaption"), pickList.isShowSourceFilter(), true);
    // Buttons
    writer.startElement("div", null);
    writer.writeAttribute("class", PickList.BUTTONS_CLASS, null);
    writer.startElement("div", null);
    writer.writeAttribute("class", PickList.BUTTONS_CELL_CLASS, null);
    if (vertical) {
        encodeButton(context, pickList.getAddLabel(), PickList.ADD_BUTTON_CLASS, PickList.VERTICAL_ADD_BUTTON_ICON_CLASS, labelDisplay);
        encodeButton(context, pickList.getAddAllLabel(), PickList.ADD_ALL_BUTTON_CLASS, PickList.VERTICAL_ADD_ALL_BUTTON_ICON_CLASS, labelDisplay);
        encodeButton(context, pickList.getRemoveLabel(), PickList.REMOVE_BUTTON_CLASS, PickList.VERTICAL_REMOVE_BUTTON_ICON_CLASS, labelDisplay);
        encodeButton(context, pickList.getRemoveAllLabel(), PickList.REMOVE_ALL_BUTTON_CLASS, PickList.VERTICAL_REMOVE_ALL_BUTTON_ICON_CLASS, labelDisplay);
    } else {
        encodeButton(context, pickList.getAddLabel(), PickList.ADD_BUTTON_CLASS, PickList.ADD_BUTTON_ICON_CLASS, labelDisplay);
        encodeButton(context, pickList.getAddAllLabel(), PickList.ADD_ALL_BUTTON_CLASS, PickList.ADD_ALL_BUTTON_ICON_CLASS, labelDisplay);
        encodeButton(context, pickList.getRemoveLabel(), PickList.REMOVE_BUTTON_CLASS, PickList.REMOVE_BUTTON_ICON_CLASS, labelDisplay);
        encodeButton(context, pickList.getRemoveAllLabel(), PickList.REMOVE_ALL_BUTTON_CLASS, PickList.REMOVE_ALL_BUTTON_ICON_CLASS, labelDisplay);
    }
    writer.endElement("div");
    writer.endElement("div");
    // Target List
    encodeList(context, pickList, clientId + "_target", PickList.TARGET_CLASS, model.getTarget(), pickList.getFacet("targetCaption"), pickList.isShowTargetFilter(), false);
    // Target List Reorder Buttons
    if (pickList.isShowTargetControls()) {
        encodeListControls(context, pickList, PickList.TARGET_CONTROLS, labelDisplay);
    }
    /* For ScreenReader */
    encodeAriaRegion(context, clientId);
    writer.endElement("div");
}
Also used : DualListModel(org.primefaces.model.DualListModel) ResponseWriter(javax.faces.context.ResponseWriter)

Example 5 with DualListModel

use of org.primefaces.model.DualListModel in project primefaces by primefaces.

the class PickListRenderer method getConvertedValue.

@Override
@SuppressWarnings("unchecked")
public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException {
    try {
        PickList pickList = (PickList) component;
        String[][] value = (String[][]) submittedValue;
        String[] sourceValue = value[0];
        String[] targetValue = value[1];
        DualListModel model = new DualListModel();
        pickList.populateModel(context, sourceValue, model.getSource());
        pickList.populateModel(context, targetValue, model.getTarget());
        return model;
    } catch (Exception exception) {
        throw new ConverterException(exception);
    }
}
Also used : ConverterException(javax.faces.convert.ConverterException) DualListModel(org.primefaces.model.DualListModel) IOException(java.io.IOException) ConverterException(javax.faces.convert.ConverterException)

Aggregations

DualListModel (org.primefaces.model.DualListModel)8 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 EJB (javax.ejb.EJB)2 FacesMessage (javax.faces.application.FacesMessage)2 ViewScoped (javax.faces.view.ViewScoped)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 Transactional (javax.transaction.Transactional)2 CollectionUtils (org.apache.commons.collections.CollectionUtils)2 Messages (org.jboss.seam.international.status.Messages)2 BundleKey (org.jboss.seam.international.status.builder.BundleKey)2 BaseBean (org.meveo.admin.action.BaseBean)2 BusinessException (org.meveo.admin.exception.BusinessException)2