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