use of io.jmix.ui.component.Fragment 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();
}
Aggregations