Remove unused code for desktop LookupField with enum property in FieldGroup

This commit is contained in:
Yuriy Artamonov 2013-10-22 11:16:44 +00:00
parent fa0fb0e705
commit 2d4801438a
2 changed files with 13 additions and 22 deletions

View File

@ -7,7 +7,6 @@ package com.haulmont.cuba.desktop.gui.components;
import com.haulmont.chile.core.datatypes.Datatype;
import com.haulmont.chile.core.datatypes.Datatypes;
import com.haulmont.chile.core.datatypes.Enumeration;
import com.haulmont.chile.core.datatypes.impl.*;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
@ -21,8 +20,6 @@ import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;
import javax.persistence.TemporalType;
import java.util.Map;
import java.util.TreeMap;
/**
* @author krivopustov
@ -52,7 +49,7 @@ public abstract class AbstractFieldFactory implements FieldFactory {
} else if (mpp.getRange().isClass()) {
return createEntityField(datasource, property, xmlDescriptor);
} else if (mpp.getRange().isEnum()) {
return createEnumField(datasource, property, mpp.getMetaProperty());
return createEnumField(datasource, property);
}
}
return createUnsupportedField(mpp);
@ -193,16 +190,8 @@ public abstract class AbstractFieldFactory implements FieldFactory {
return pickerField;
}
protected Component createEnumField(Datasource datasource, String property, MetaProperty metaProperty) {
Map<String, Object> options = new TreeMap<>();
Enumeration<Enum> enumeration = metaProperty.getRange().asEnumeration();
for (Enum value : enumeration.getValues()) {
String caption = AppBeans.get(Messages.class).getMessage(value);
options.put(caption, value);
}
protected Component createEnumField(Datasource datasource, String property) {
DesktopLookupField lookupField = new DesktopLookupField();
lookupField.setOptionsMap(options);
lookupField.setDatasource(datasource, property);
return lookupField;
}

View File

@ -12,7 +12,8 @@ import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.chile.core.model.utils.InstanceUtils;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.MessageProvider;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.components.CaptionMode;
import com.haulmont.cuba.gui.components.OptionsField;
import com.haulmont.cuba.gui.data.CollectionDatasource;
@ -27,14 +28,14 @@ import java.util.List;
import java.util.Map;
/**
* <p>$Id$</p>
*
* @author krivopustov
* @version $Id$
*/
public abstract class DesktopAbstractOptionsField<C extends JComponent>
extends DesktopAbstractField<C>
implements OptionsField
{
extends
DesktopAbstractField<C>
implements
OptionsField {
protected CaptionMode captionMode = CaptionMode.ITEM;
protected String captionProperty;
@ -52,6 +53,8 @@ public abstract class DesktopAbstractOptionsField<C extends JComponent>
protected Object prevValue;
protected Messages messages = AppBeans.get(Messages.NAME);
@Override
public CollectionDatasource getOptionsDatasource() {
return optionsDatasource;
@ -125,8 +128,7 @@ public abstract class DesktopAbstractOptionsField<C extends JComponent>
metaPropertyPath = metaClass.getPropertyPath(property);
try {
metaProperty = metaPropertyPath.getMetaProperty();
}
catch (ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException e) {
throw new RuntimeException("Metaproperty name is possibly wrong: " + property, e);
}
@ -323,7 +325,7 @@ public abstract class DesktopAbstractOptionsField<C extends JComponent>
return InstanceUtils.getInstanceName((Instance) obj);
if (obj instanceof Enum)
return MessageProvider.getMessage((Enum) obj);
return messages.getMessage((Enum) obj);
return obj.toString();
}