use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class FakeFilterSupport method createFakeFilterEntity.
public FilterEntity createFakeFilterEntity(String xml) {
if (filterEntity != null)
return filterEntity;
Metadata metadata = AppBeans.get(Metadata.NAME);
FilterEntity fakeFilterEntity = metadata.create(FilterEntity.class);
fakeFilterEntity.setXml(xml);
return fakeFilterEntity;
}
use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class FilterDelegateImpl method saveSettings.
@Override
public boolean saveSettings(Element element) {
Boolean changed = false;
Element e = element.element("defaultFilter");
if (e == null)
e = element.addElement("defaultFilter");
UUID defaultId = null;
Boolean applyDefault = false;
for (FilterEntity filter : filterEntities) {
if (BooleanUtils.isTrue(filter.getIsDefault())) {
defaultId = filter.getId();
applyDefault = filter.getApplyDefault();
break;
}
}
String newDef = defaultId != null ? defaultId.toString() : null;
Attribute attr = e.attribute("id");
String oldDef = attr != null ? attr.getValue() : null;
if (!Objects.equals(oldDef, newDef)) {
if (newDef == null && attr != null) {
e.remove(attr);
} else {
if (attr == null)
e.addAttribute("id", newDef);
else
attr.setValue(newDef);
}
changed = true;
}
Boolean newApplyDef = BooleanUtils.isTrue(applyDefault);
Attribute applyDefaultAttr = e.attribute("applyDefault");
Boolean oldApplyDef = applyDefaultAttr != null ? Boolean.valueOf(applyDefaultAttr.getValue()) : false;
if (!Objects.equals(oldApplyDef, newApplyDef)) {
if (applyDefaultAttr != null) {
applyDefaultAttr.setValue(newApplyDef.toString());
} else {
e.addAttribute("applyDefault", newApplyDef.toString());
}
changed = true;
}
Element groupBoxExpandedEl = element.element("groupBoxExpanded");
if (groupBoxExpandedEl == null)
groupBoxExpandedEl = element.addElement("groupBoxExpanded");
Boolean oldGroupBoxExpandedValue = Boolean.valueOf(groupBoxExpandedEl.getText());
Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded();
if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) {
groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString());
changed = true;
}
if (isMaxResultsLayoutVisible()) {
Element maxResultsEl = element.element("maxResults");
if (maxResultsEl == null)
maxResultsEl = element.addElement("maxResults");
try {
Integer oldMaxResultsValue = !Strings.isNullOrEmpty(maxResultsEl.getText()) ? Integer.valueOf(maxResultsEl.getText()) : null;
Integer newMaxResultsValue = maxResultsField.getValue();
if (newMaxResultsValue != null && !Objects.equals(oldMaxResultsValue, newMaxResultsValue)) {
maxResultsEl.setText(newMaxResultsValue.toString());
changed = true;
}
} catch (NumberFormatException ex) {
log.error("Error on parsing maxResults setting value", ex);
}
}
return changed;
}
use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class FilterDelegateImpl method initFiltersLookup.
protected void initFiltersLookup() {
Map<Object, String> captionsMap = new LinkedHashMap<>();
for (FilterEntity entity : filterEntities) {
String caption = getFilterCaption(entity);
if (entity.getIsDefault()) {
caption += " " + getMainMessage("filter.default");
}
captionsMap.put(entity, caption);
}
captionsMap.put(adHocFilter, getFilterCaption(adHocFilter));
filtersLookupListenerEnabled = false;
// set null to remove previous value from lookup options list
filtersLookup.setValue(null);
List<Object> optionsList = new ArrayList<>();
optionsList.add(adHocFilter);
optionsList.addAll(filterEntities);
filtersLookup.setOptionsList(optionsList);
filterHelper.setLookupCaptions(filtersLookup, captionsMap);
filtersLookup.setValue(filterEntity);
filtersLookupListenerEnabled = true;
}
use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class FilterDelegateImpl method addFiltersPopupActions.
protected void addFiltersPopupActions() {
addResetFilterAction(filtersPopupButton);
filterEntities.sort(Comparator.comparing(this::getFilterCaption));
Iterator<FilterEntity> it = filterEntities.iterator();
int addedEntitiesCount = 0;
while (it.hasNext() && addedEntitiesCount < clientConfig.getGenericFilterPopupListSize()) {
final FilterEntity fe = it.next();
addSetFilterEntityAction(filtersPopupButton, fe);
addedEntitiesCount++;
}
if (filterEntities.size() > clientConfig.getGenericFilterPopupListSize()) {
addShowMoreFilterEntitiesAction(filtersPopupButton);
}
}
use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class FilterDelegateImpl method loadFiltersAndApplyDefault.
/**
* Loads filter entities, finds default filter and applies it if found
*/
@Override
public void loadFiltersAndApplyDefault() {
initShortcutActions();
initAdHocFilter();
loadFilterEntities();
FilterEntity defaultFilter = getDefaultFilter(filterEntities);
initFilterSelectComponents();
if (defaultFilter == null) {
defaultFilter = adHocFilter;
}
try {
setFilterEntity(defaultFilter);
} catch (Exception e) {
log.error("Exception on loading default filter '" + defaultFilter.getName() + "'", e);
windowManager.showNotification(messages.formatMainMessage("filter.errorLoadingDefaultFilter", defaultFilter.getName()), Frame.NotificationType.ERROR);
defaultFilter = adHocFilter;
setFilterEntity(adHocFilter);
}
if (defaultFilter != adHocFilter && (filterMode == FilterMode.GENERIC_MODE)) {
Window window = ComponentsHelper.getWindow(filter);
if (!WindowParams.DISABLE_AUTO_REFRESH.getBool(window.getContext())) {
if (getResultingManualApplyRequired()) {
if (BooleanUtils.isTrue(defaultFilter.getApplyDefault())) {
apply(true);
}
} else
apply(true);
if (filterEntity != null) {
window.setDescription(getFilterCaption(filterEntity));
} else
window.setDescription(null);
}
}
}
Aggregations