use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.
the class FilterEditor method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
if (Boolean.TRUE.equals(useShortConditionForm)) {
setCaption(messages.getMessage("filter.editor.captionShortForm"));
}
getDialogOptions().setWidth(theme.get("cuba.gui.filterEditor.dialog.width")).setHeight(theme.get("cuba.gui.filterEditor.dialog.height")).setResizable(true);
filterEntity = (FilterEntity) params.get("filterEntity");
if (filterEntity == null) {
throw new RuntimeException("Filter entity was not passed to filter editor");
}
filter = (Filter) params.get("filter");
ConditionsTree paramConditions = (ConditionsTree) params.get("conditionsTree");
conditions = paramConditions.createCopy();
refreshConditionsDs();
conditionsTree.expandTree();
MetaProperty property = metadata.getClassNN(FilterEntity.class).getProperty("name");
Map<String, Object> annotations = property.getAnnotations();
Integer maxLength = (Integer) annotations.get("length");
if (maxLength != null) {
filterName.setMaxLength(maxLength);
}
if (!messages.getMessage("filter.adHocFilter").equals(filterEntity.getName())) {
filterName.setValue(filterEntity.getName());
}
availableForAllCb.setValue(filterEntity.getUsername() == null);
defaultCb.setValue(filterEntity.getIsDefault());
applyDefaultCb.setValue(filterEntity.getApplyDefault());
globalDefaultCb.setValue(filterEntity.getGlobalDefault());
if (filterEntity.getUsername() != null) {
globalDefaultCb.setEnabled(false);
}
if (!security.isSpecificPermitted(GLOBAL_FILTER_PERMISSION)) {
availableForAllCb.setVisible(false);
availableForAllLabel.setVisible(false);
globalDefaultCb.setVisible(false);
globalDefaultLabel.setVisible(false);
}
availableForAllCb.addValueChangeListener(e -> {
Boolean isFilterAvailableForAll = e.getValue();
globalDefaultCb.setEnabled(isFilterAvailableForAll);
if (!isFilterAvailableForAll) {
globalDefaultCb.setValue(null);
}
});
boolean manualApplyRequired = filter.getManualApplyRequired() != null ? filter.getManualApplyRequired() : AppBeans.get(CubaProperties.class).isGenericFilterManualApplyRequired();
if (!manualApplyRequired) {
applyDefaultCb.setVisible(manualApplyRequired);
applyDefaultLabel.setVisible(manualApplyRequired);
}
if (!(filter.getFrame().getFrameOwner() instanceof LegacyFrame)) {
ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
if (settingsFacet == null) {
defaultCb.setVisible(false);
defaultLabel.setVisible(false);
}
}
if (filterEntity.getFolder() != null) {
availableForAllCb.setVisible(false);
availableForAllLabel.setVisible(false);
globalDefaultCb.setVisible(false);
globalDefaultLabel.setVisible(false);
defaultCb.setVisible(false);
defaultLabel.setVisible(false);
}
conditionsDs.addItemChangeListener(e -> {
if (!treeItemChangeListenerEnabled) {
return;
}
// commit previously selected condition
if (activeConditionFrame != null) {
List<Validatable> validatables = new ArrayList<>();
Collection<Component> frameComponents = ComponentsHelper.getComponents(activeConditionFrame);
for (Component frameComponent : frameComponents) {
if (frameComponent instanceof Validatable) {
validatables.add((Validatable) frameComponent);
}
}
if (validate(validatables)) {
activeConditionFrame.commit();
} else {
treeItemChangeListenerEnabled = false;
conditionsTree.setSelected(e.getPrevItem());
treeItemChangeListenerEnabled = true;
return;
}
}
if (e.getItem() == null) {
activeConditionFrame = null;
} else {
if (e.getItem() instanceof PropertyCondition) {
activeConditionFrame = propertyConditionFrame;
} else if (e.getItem() instanceof DynamicAttributesCondition) {
activeConditionFrame = dynamicAttributesConditionFrame;
} else if (e.getItem() instanceof CustomCondition) {
activeConditionFrame = customConditionFrame;
} else if (e.getItem() instanceof GroupCondition) {
activeConditionFrame = groupConditionFrame;
} else if (e.getItem() instanceof FtsCondition) {
activeConditionFrame = ftsConditionFrame;
} else {
log.warn("Conditions frame for condition with type " + e.getItem().getClass().getSimpleName() + " not found");
}
}
propertyConditionFrame.setVisible(false);
customConditionFrame.setVisible(false);
dynamicAttributesConditionFrame.setVisible(false);
groupConditionFrame.setVisible(false);
ftsConditionFrame.setVisible(false);
if (activeConditionFrame != null) {
activeConditionFrame.setVisible(true);
activeConditionFrame.setCondition(e.getItem());
if (Boolean.TRUE.equals(useShortConditionForm)) {
for (String componentName : componentsToHideInShortForm) {
Component component = activeConditionFrame.getComponent(componentName);
if (component != null) {
if (BooleanUtils.isTrue(showConditionHiddenOption) && componentsForHiddenOption.contains(componentName)) {
continue;
}
component.setVisible(false);
}
}
}
}
});
addConditionHelper = new AddConditionHelper(filter, BooleanUtils.isTrue(hideDynamicAttributes), BooleanUtils.isTrue(hideCustomConditions), condition -> {
AbstractCondition item = conditionsDs.getItem();
if (item != null && item instanceof GroupCondition) {
Node<AbstractCondition> newNode = new Node<>(condition);
Node<AbstractCondition> selectedNode = conditions.getNode(item);
selectedNode.addChild(newNode);
refreshConditionsDs();
conditionsTree.expand(item);
} else {
conditions.getRootNodes().add(new Node<>(condition));
refreshConditionsDs();
}
conditionsTree.setSelected(condition);
});
FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
filterHelper.initConditionsDragAndDrop(conditionsTree, conditions);
if (Boolean.TRUE.equals(useShortConditionForm)) {
filterPropertiesGrid.setVisible(false);
}
}
use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.
the class FilterDelegateImpl method isScreenSettingsEnabled.
protected boolean isScreenSettingsEnabled() {
Frame frame = filter.getFrame();
if (frame == null) {
return false;
}
if (frame.getFrameOwner() instanceof LegacyFrame) {
return true;
}
ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(frame, ScreenSettingsFacet.class);
return settingsFacet != null;
}
use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.
the class FilterDelegateImpl method getDefaultFilterFromScreenSettings.
@Nullable
protected FilterEntity getDefaultFilterFromScreenSettings(List<FilterEntity> filters) {
if (filter.getFrame() == null || StringUtils.isBlank(filter.getId())) {
return null;
}
ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
if (settingsFacet == null || settingsFacet.getSettings() == null) {
return null;
}
CubaFilterSettings cubaFilterSettings = settingsFacet.getSettings().getSettings(filter.getId(), CubaFilterSettings.class).orElse(null);
if (cubaFilterSettings == null) {
return null;
}
String settingsDefaultId = cubaFilterSettings.getDefaultFilterId();
if (StringUtils.isBlank(settingsDefaultId)) {
return null;
}
UUID defaultId = null;
try {
defaultId = UUID.fromString(settingsDefaultId);
} catch (IllegalArgumentException ex) {
// do nothing
}
if (defaultId != null) {
for (FilterEntity filter : filters) {
if (defaultId.equals(filter.getId())) {
filter.setIsDefault(true);
filter.setApplyDefault(cubaFilterSettings.getApplyDefault());
return filter;
}
}
}
return null;
}
use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.
the class FilterMakeDefaultAction method execute.
@Override
public void execute() {
if (filter.getFrame() == null) {
throw new IllegalStateException("Filter component is not attached to the Frame");
}
ScreenSettingsFacet screenSettingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
if (screenSettingsFacet == null) {
throw new IllegalStateException("The Frame does no contain ScreenSettingsFacet");
}
ScreenSettings settings = screenSettingsFacet.getSettings();
if (settings == null) {
throw new IllegalStateException("ScreenSettingsFacet is not attached to the frame");
}
FilterSettings filterSettings = new FilterSettings();
filterSettings.setId(filter.getId());
filterSettings.setDefaultConfigurationId(filter.getCurrentConfiguration().getId());
settings.put(filterSettings);
}
use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.
the class UiDataFilterSupport method isDefaultForMeFieldVisible.
protected boolean isDefaultForMeFieldVisible(Filter.Configuration currentConfiguration, FilterConfiguration configurationModel) {
Frame filterFrame = currentConfiguration.getOwner().getFrame();
if (currentConfiguration.getOwner().getId() != null && filterFrame != null) {
ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filterFrame, ScreenSettingsFacet.class);
if (settingsFacet != null) {
ScreenSettings settings = settingsFacet.getSettings();
if (settings != null) {
settings.getSettings(currentConfiguration.getOwner().getId(), FilterSettings.class).ifPresent(filterSettings -> {
String defaultConfigurationId = filterSettings.getDefaultConfigurationId();
if (defaultConfigurationId != null) {
boolean defaultForMe = defaultConfigurationId.equals(configurationModel.getConfigurationId());
configurationModel.setDefaultForMe(defaultForMe);
}
});
}
return true;
}
}
return false;
}
Aggregations