use of io.jmix.ui.component.LogicalFilterComponent in project jmix by jmix-framework.
the class FilterSupport method refreshConfigurationValuesMap.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void refreshConfigurationValuesMap(Filter.Configuration configuration, Map<String, Object> valuesMap) {
LogicalFilterComponent rootLogicalComponent = configuration.getRootLogicalFilterComponent();
for (FilterComponent filterComponent : rootLogicalComponent.getFilterComponents()) {
if (filterComponent instanceof SingleFilterComponent) {
String parameterName = ((SingleFilterComponent<?>) filterComponent).getParameterName();
Object value = valuesMap.get(parameterName);
Object defaultValue = configuration.getFilterComponentDefaultValue(parameterName);
if (value == null && defaultValue != null) {
((SingleFilterComponent) filterComponent).setValue(defaultValue);
} else {
try {
((SingleFilterComponent) filterComponent).setValue(value);
} catch (ClassCastException e) {
((SingleFilterComponent) filterComponent).setValue(defaultValue);
}
}
}
}
}
use of io.jmix.ui.component.LogicalFilterComponent in project jmix by jmix-framework.
the class FilterConfigurationConverter method toConfigurationModel.
public FilterConfiguration toConfigurationModel(Filter.Configuration configuration, FilterConfiguration configurationModel) {
Filter filter = configuration.getOwner();
String filterComponentId = generateFilterPath(filter);
configurationModel.setComponentId(filterComponentId);
LogicalFilterComponent rootLogicalFilterComponent = configuration.getRootLogicalFilterComponent();
FilterConverter converter = filterComponents.getConverterByComponentClass(rootLogicalFilterComponent.getClass(), configuration.getOwner());
configurationModel.setRootCondition((GroupFilterCondition) converter.convertToModel(rootLogicalFilterComponent));
return configurationModel;
}
use of io.jmix.ui.component.LogicalFilterComponent in project jmix by jmix-framework.
the class FilterEditAction method onEditScreenAfterCommit.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void onEditScreenAfterCommit(ScreenFragment configurationFormFragment, LogicalFilterCondition filterCondition, FilterConverter converter, boolean isNewConfiguration, Filter.Configuration currentConfiguration, Map<String, Object> valuesMap) {
LogicalFilterComponent rootFilterComponent = (LogicalFilterComponent) converter.convertToComponent(filterCondition);
Filter.Configuration resultConfiguration = filterSupport.saveCurrentFilterConfiguration(currentConfiguration, isNewConfiguration, rootFilterComponent, configurationFormFragment);
filterSupport.refreshConfigurationDefaultValues(resultConfiguration);
resultConfiguration.setModified(false);
filterSupport.refreshConfigurationValuesMap(resultConfiguration, valuesMap);
if (isNewConfiguration || !currentConfiguration.getId().equals(resultConfiguration.getId())) {
filter.addConfiguration(resultConfiguration);
}
filter.setCurrentConfiguration(resultConfiguration);
if (isNewConfiguration) {
filter.getEmptyConfiguration().getRootLogicalFilterComponent().removeAll();
}
filter.apply();
}
use of io.jmix.ui.component.LogicalFilterComponent in project jmix by jmix-framework.
the class FilterEditAction method execute.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
if (filter.getFrame() == null) {
throw new IllegalStateException("Filter component is not attached to the Frame");
}
Filter.Configuration currentConfiguration = filter.getCurrentConfiguration();
boolean isNewConfiguration = Objects.equals(currentConfiguration.getId(), filter.getEmptyConfiguration().getId());
LogicalFilterComponent rootComponent = currentConfiguration.getRootLogicalFilterComponent();
Class modelClass = filterComponents.getModelClass(rootComponent.getClass());
FilterConverter converter = filterComponents.getConverterByComponentClass(rootComponent.getClass(), filter);
Map<String, Object> valuesMap = filterSupport.initConfigurationValuesMap(currentConfiguration);
LogicalFilterCondition model = (LogicalFilterCondition) converter.convertToModel(rootComponent);
Screen editScreen = createEditScreen(modelClass, model);
applyScreenConfigurer(editScreen);
ScreenFragment screenFragment = filterSupport.createFilterConfigurationFragment(editScreen.getWindow().getFrameOwner(), isNewConfiguration, currentConfiguration);
Fragment fragment = screenFragment.getFragment();
fragment.setWidthFull();
editScreen.getWindow().add(fragment, 0);
editScreen.getWindow().setCaption(messages.getMessage(FilterEditAction.class, "configurationEdit.caption"));
if (editScreen instanceof GroupFilterConditionEdit) {
Component groupConditionBox = editScreen.getWindow().getComponent("groupConditionBox");
if (groupConditionBox instanceof Component.HasCaption) {
((Component.HasCaption) groupConditionBox).setCaption(messages.getMessage(FilterEditAction.class, "configurationEdit.rootGroupCondition"));
}
}
editScreen.addAfterCloseListener(afterCloseEvent -> {
if (afterCloseEvent.closedWith(StandardOutcome.COMMIT)) {
LogicalFilterCondition filterCondition = (LogicalFilterCondition) ((FilterConditionEdit) afterCloseEvent.getSource()).getInstanceContainer().getItem();
onEditScreenAfterCommit(screenFragment, filterCondition, converter, isNewConfiguration, currentConfiguration, valuesMap);
} else {
filterSupport.resetConfigurationValuesMap(currentConfiguration, valuesMap);
}
});
editScreen.show();
}
use of io.jmix.ui.component.LogicalFilterComponent in project jmix by jmix-framework.
the class ConfigurationConditionBuilder method createFilterConditionsByConfiguration.
protected List<FilterCondition> createFilterConditionsByConfiguration(Filter.Configuration configuration, @Nullable FilterCondition parent, boolean addHeaderCondition) {
List<FilterCondition> conditions = new ArrayList<>();
LogicalFilterComponent rootLogicalFilterComponent = configuration.getRootLogicalFilterComponent();
FilterConverter converter = filterComponents.getConverterByComponentClass(rootLogicalFilterComponent.getClass(), configuration.getOwner());
LogicalFilterCondition rootGroupCondition = (LogicalFilterCondition) converter.convertToModel(rootLogicalFilterComponent);
FilterCondition configurationHeaderCondition = null;
if (addHeaderCondition) {
configurationHeaderCondition = createHeaderFilterCondition(configuration.getName());
configurationHeaderCondition.setParent(parent);
conditions.add(configurationHeaderCondition);
}
List<FilterCondition> groupConditions = createFilterConditionsByLogicalFilterCondition(rootGroupCondition, addHeaderCondition ? configurationHeaderCondition : parent, true);
conditions.addAll(groupConditions);
return conditions;
}
Aggregations