diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/PropertyFieldFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/PropertyFieldFactory.java index a4d95a6f836e8b7aa7b056fadd3cc480543684ef..bef935d3567cbf8980d822f339eac193349f55a8 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/PropertyFieldFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/PropertyFieldFactory.java @@ -20,6 +20,8 @@ import java.util.Date; import com.extjs.gxt.ui.client.widget.form.Field; +import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyTermModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.DateRenderer; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; @@ -30,44 +32,48 @@ public class PropertyFieldFactory /** * Creates a field for given data type. */ - @SuppressWarnings("unchecked") - public static <T> Field<T> createField(final PropertyType pt, boolean isMandatory, - String label, String fieldId, String originalRawValue) + public static Field<?> createField(final PropertyType pt, boolean isMandatory, String label, + String fieldId, String originalRawValue, + IViewContext<ICommonClientServiceAsync> viewContext) + { + final Field<?> field = createField(pt, isMandatory, label, fieldId, viewContext); + field.setId(fieldId); + if (originalRawValue != null) + { + setValue(field, originalRawValue); + } + return field; + } + + private static Field<?> createField(final PropertyType pt, boolean isMandatory, String label, + String fieldId, IViewContext<ICommonClientServiceAsync> viewContext) { - final Field<T> field; final DataTypeCode dataType = pt.getDataType().getCode(); switch (dataType) { case BOOLEAN: - field = (Field<T>) new CheckBoxField(label, isMandatory); - break; + return new CheckBoxField(label, isMandatory); case VARCHAR: - field = (Field<T>) new VarcharField(label, isMandatory); - break; + return new VarcharField(label, isMandatory); case TIMESTAMP: - field = (Field<T>) new DateFormField(label, isMandatory); - break; + return new DateFormField(label, isMandatory); case CONTROLLEDVOCABULARY: - field = - (Field<T>) new VocabularyTermSelectionWidget(fieldId, label, pt - .getVocabulary().getTerms(), isMandatory); - break; + return new VocabularyTermSelectionWidget(fieldId, label, pt.getVocabulary() + .getTerms(), isMandatory); case INTEGER: - field = (Field<T>) new IntegerField(label, isMandatory); - break; + return new IntegerField(label, isMandatory); case REAL: - field = (Field<T>) new RealField(label, isMandatory); - break; - default: - field = (Field<T>) new VarcharField(label, isMandatory); - break; + return new RealField(label, isMandatory); + case MATERIAL: + return MaterialChooserField.create(label, isMandatory, pt.getMaterialType(), + viewContext); } - field.setId(fieldId); - if (originalRawValue != null) - { - field.setValue(field.getPropertyEditor().convertStringValue(originalRawValue)); - } - return field; + throw new IllegalStateException("unknown enum " + dataType); + } + + private static <T> void setValue(final Field<T> field, String originalRawValue) + { + field.setValue(field.getPropertyEditor().convertStringValue(originalRawValue)); } public static final String valueToString(final Object value) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/GenericExperimentRegistrationForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/GenericExperimentRegistrationForm.java index 073c0b0d3f5445548b13586a2491043a7a00ca27..837afdd0490956b95de7141a592b1bef59cf35c9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/GenericExperimentRegistrationForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/GenericExperimentRegistrationForm.java @@ -140,7 +140,7 @@ public final class GenericExperimentRegistrationForm protected void createEntitySpecificFields() { - projectSelectionWidget = new ProjectSelectionWidget(viewContext, getId()); + projectSelectionWidget = new ProjectSelectionWidget(viewContext, null, getId()); FieldUtil.markAsMandatory(projectSelectionWidget); projectSelectionWidget.setFieldLabel(viewContext.getMessage(Dict.PROJECT)); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java index 1b3a9374484c702d134f37214f07877a1bba676d..3eaa53e446cbeaf1ae673a7ec368378ccabd2df4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java @@ -96,7 +96,7 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp final String propertyTypeCode = etpt.getPropertyType().getCode(); field = PropertyFieldFactory.createField(etpt.getPropertyType(), isMandatory, label, - createFormFieldId(getId(), propertyTypeCode), value); + createFormFieldId(getId(), propertyTypeCode), value, null); field.setData(ETPT, etpt); field.setTitle(propertyTypeCode); return field;