Fixes #204 Контроль уникальности имени фильтра

This commit is contained in:
Konstantin Krivopustov 2010-01-14 13:03:19 +00:00
parent 5c876bcea0
commit 5bcc271b7f
4 changed files with 25 additions and 2 deletions

View File

@ -10,6 +10,8 @@
*/
package com.haulmont.cuba.web.gui.components;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.haulmont.bali.util.Dom4j;
import com.haulmont.chile.core.model.Instance;
import com.haulmont.chile.core.model.utils.InstanceUtils;
@ -47,6 +49,9 @@ import org.dom4j.Attribute;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.BooleanUtils;
import javax.annotation.Nullable;
import static org.apache.commons.lang.BooleanUtils.isTrue;
import java.util.*;
@ -361,7 +366,12 @@ public class WebFilter
editLayout = new VerticalLayout();
editLayout.setSpacing(true);
final FilterEditor editor = new FilterEditor(this, filterEntity, getXmlDescriptor());
List<String> names = new ArrayList<String>();
for (Object id : select.getItemIds()) {
names.add(((FilterEntity) id).getName());
}
final FilterEditor editor = new FilterEditor(this, filterEntity, getXmlDescriptor(), names);
editLayout.addComponent(editor.getLayout());
}

View File

@ -39,6 +39,7 @@ public class FilterEditor {
private MetaClass metaClass;
private CollectionDatasource datasource;
private List<ConditionDescriptor> descriptors = new ArrayList<ConditionDescriptor>();
private List<String> existingNames;
private List<Condition> conditions = new ArrayList<Condition>();
private AbstractOrderedLayout layout;
@ -53,7 +54,8 @@ public class FilterEditor {
private CheckBox globalCb;
private Button saveBtn;
public FilterEditor(final WebFilter webFilter, FilterEntity filterEntity, Element filterDescriptor)
public FilterEditor(final WebFilter webFilter, FilterEntity filterEntity,
Element filterDescriptor, List<String> existingNames)
{
this.filterEntity = filterEntity;
this.filterDescriptor = filterDescriptor;
@ -61,6 +63,7 @@ public class FilterEditor {
this.datasource = webFilter.getDatasource();
this.messagesPack = webFilter.getFrame().getMessagesPack();
this.metaClass = datasource.getMetaClass();
this.existingNames = existingNames;
parseDescriptorXml();
@ -347,6 +350,14 @@ public class FilterEditor {
}
public boolean commit() {
if (existingNames.contains(nameField.getValue())) {
App.getInstance().getAppWindow().showNotification(
getMessage("FilterEditor.commitError"),
getMessage("FilterEditor.nameAlreadyExists"),
Window.Notification.TYPE_HUMANIZED_MESSAGE);
return false;
}
StringBuilder sb = new StringBuilder();
for (Condition condition : conditions) {
String error = condition.getError();

View File

@ -19,6 +19,7 @@ FilterEditor.cancelBtn=Cancel
FilterEditor.global=Global (available to all users)
FilterEditor.nameLab=Name
FilterEditor.addCondition=Add condition
FilterEditor.nameAlreadyExists=A filter with this name already exists
FilterEditor.commitError=Error
FilterEditor.column.name=Name

View File

@ -15,6 +15,7 @@ FilterEditor.cancelBtn=Отмена
FilterEditor.global=Глобальный (доступен всем пользователям)
FilterEditor.nameLab=Имя
FilterEditor.addCondition=Добавить условие
FilterEditor.nameAlreadyExists=Фильтр с таким именем уже существует
FilterEditor.commitError=Ошибка
FilterEditor.column.name=Имя