diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/ModelDataPropertyNames.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/ModelDataPropertyNames.java index b091ea4d2705d539f1c85a751acd67e71996d8af..18ce5729d79f820b03604cca26632fcde004473a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/ModelDataPropertyNames.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/ModelDataPropertyNames.java @@ -38,6 +38,8 @@ public final class ModelDataPropertyNames { public static final String CODE = "code"; + public static final String CODE_WITH_LABEL = "code_with_label"; + public static final String LABEL = "label"; public static final String DATA_SET_TYPES = "data_set_types"; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyTermModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyTermModel.java index 83182d5d7013db77b261fb8b758521022c13e08c..7a66c9d14fc90adda9f819f6d508ab6a0ece6bc9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyTermModel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyTermModel.java @@ -17,34 +17,32 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.model; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import com.extjs.gxt.ui.client.data.BaseModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.renderer.VocabularyPropertyColRenderer; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; /** * @author Izabela Adamczyk */ -public class VocabularyTermModel extends BaseModel +public class VocabularyTermModel extends BaseModel implements Comparable<VocabularyTermModel> { private static final long serialVersionUID = 1L; public VocabularyTermModel(VocabularyTerm term) { - this(term.getCode()); + set(ModelDataPropertyNames.CODE, term.getCode()); + set(ModelDataPropertyNames.CODE_WITH_LABEL, getCodeWithLabel(term)); + set(ModelDataPropertyNames.OBJECT, term); } - public VocabularyTermModel(String termCode) + private String getCodeWithLabel(VocabularyTerm term) { - this(termCode, termCode); - } - - private VocabularyTermModel(String termCode, String object) - { - set(ModelDataPropertyNames.CODE, termCode); - set(ModelDataPropertyNames.OBJECT, object); + return VocabularyPropertyColRenderer.renderCodeWithLabel(term); } public static final List<VocabularyTermModel> convert(List<VocabularyTerm> terms) @@ -54,13 +52,28 @@ public class VocabularyTermModel extends BaseModel { list.add(new VocabularyTermModel(t)); } + Collections.sort(list); return list; } - public String getTerm() + public VocabularyTerm getTerm() + { + return (VocabularyTerm) get(ModelDataPropertyNames.OBJECT); + } + + // + // Comparable + // + + public int compareTo(VocabularyTermModel o) + { + return getValueToCompare().compareTo(o.getValueToCompare()); + } + + /** @return value that will be used to compare Vocabulary Terms and display them in order */ + private String getValueToCompare() { - final String code = get(ModelDataPropertyNames.OBJECT); - return code; + return get(ModelDataPropertyNames.CODE_WITH_LABEL); } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/VocabularyPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/VocabularyPropertyColRenderer.java index 28f9a1bb5a4bf0772466521679a390154de9bf37..2ed94de9d090f7004f9354aa1b8cdc9595805409 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/VocabularyPropertyColRenderer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/VocabularyPropertyColRenderer.java @@ -56,16 +56,10 @@ public class VocabularyPropertyColRenderer<T extends IEntityPropertiesHolder> ex { assert term != null : "term is not set"; - final String code = term.getCode(); - final String label = term.getLabel(); final String description = term.getDescription(); final String url = term.getUrl(); - String result = "[" + code + "]"; - if (label != null) - { - result = label + " " + result; - } + String result = renderCodeWithLabel(term); if (url != null) { result = ExternalHyperlink.createAnchorString(result, url); @@ -74,4 +68,11 @@ public class VocabularyPropertyColRenderer<T extends IEntityPropertiesHolder> ex return result; } + + public static final String renderCodeWithLabel(VocabularyTerm term) + { + final String code = term.getCode(); + final String label = term.getLabel(); + return (label != null ? label + " " : "") + "[" + code + "]"; + } } 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 4ca0c23fbaed3d913d7a97ac7f39362b9bff87ef..f311dcd10a026bc59be114cbb6515f6a2446a600 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 @@ -28,6 +28,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.D import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; public class PropertyFieldFactory { @@ -108,7 +109,8 @@ public class PropertyFieldFactory return DateRenderer.renderDate((Date) value); } else if (value instanceof VocabularyTermModel) { - return ((VocabularyTermModel) value).getTerm(); + final VocabularyTerm term = ((VocabularyTermModel) value).getTerm(); + return term.getCode(); } else { return value.toString(); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/VocabularyTermSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/VocabularyTermSelectionWidget.java index 90631f85759ee5c8dd13be3d5c655bea88d531b5..850affa65a5e9b73987966e1aef6f258535e9d7e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/VocabularyTermSelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/VocabularyTermSelectionWidget.java @@ -17,6 +17,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; @@ -59,10 +60,10 @@ public class VocabularyTermSelectionWidget extends */ public static DatabaseModificationAwareField<VocabularyTermModel> create(String idSuffix, String label, Vocabulary vocabulary, final boolean mandatory, - IViewContext<?> viewContext, String initialTermOrNull) + IViewContext<?> viewContext, String initialTermCodeOrNull) { return new VocabularyTermSelectionWidget(idSuffix, label, mandatory, vocabulary, - viewContext, null, initialTermOrNull).asDatabaseModificationAware(); + viewContext, null, initialTermCodeOrNull).asDatabaseModificationAware(); } /** @@ -76,13 +77,13 @@ public class VocabularyTermSelectionWidget extends private VocabularyTermSelectionWidget(String idSuffix, String label, boolean mandatory, Vocabulary vocabularyOrNull, IViewContext<?> viewContextOrNull, - List<VocabularyTerm> termsOrNull, String initialTermOrNull) + List<VocabularyTerm> termsOrNull, String initialTermCodeOrNull) { - super(idSuffix, ModelDataPropertyNames.CODE, label, CHOOSE_MSG, EMPTY_MSG, + super(idSuffix, ModelDataPropertyNames.CODE_WITH_LABEL, label, CHOOSE_MSG, EMPTY_MSG, VALUE_NOT_IN_LIST_MSG, mandatory, viewContextOrNull, termsOrNull == null); this.viewContextOrNull = viewContextOrNull; this.vocabularyOrNull = vocabularyOrNull; - this.initialTermCodeOrNull = initialTermOrNull; + this.initialTermCodeOrNull = initialTermCodeOrNull; FieldUtil.setMandatoryFlag(this, mandatory); setAllowBlank(mandatory == false); if (termsOrNull != null) @@ -94,8 +95,8 @@ public class VocabularyTermSelectionWidget extends private void setTerms(List<VocabularyTerm> terms) { final List<VocabularyTermModel> models = new ArrayList<VocabularyTermModel>(); - models.add(new VocabularyTermModel(GWTUtils.NONE_LIST_ITEM)); models.addAll(convertItems(terms)); + Collections.sort(models); updateStore(models); getPropertyEditor().setList(store.getModels()); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java index 7cf93eff3e508c2aa7a30c110af69419665b0402..6fc65bfa436afdbbb9e9ee64bb0f1faedce666c4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java @@ -453,8 +453,8 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm public void selectionChanged(SelectionChangedEvent<VocabularyTermModel> se) { VocabularyTermModel selectedItem = se.getSelectedItem(); - termToBeReplaced.setReplacementCode(selectedItem == null ? null : selectedItem - .getTerm()); + termToBeReplaced.setReplacementCode(selectedItem == null ? null + : selectedItem.getTerm().getCode()); dialog.setEnableOfAcceptButton(formPanel.isValid()); } }); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleRegistrationTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleRegistrationTest.java index b8700047a94ac37b0f5e71e97f1931f1e055a0c4..731dd3216bcb95e55220fca31207e8b5e44635bf 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleRegistrationTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleRegistrationTest.java @@ -67,7 +67,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase loginAndPreprareRegistration(sampleTypeCode); remoteConsole.prepare(new FillSampleRegistrationForm("CISD", GROUP_CL, true) .addProperty(new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry", - "1536_WELLS_32X48"))); + "[1536_WELLS_32X48]"))); remoteConsole.prepare(new InvokeActionMenu(TopMenu.ActionMenuKind.SAMPLE_MENU_BROWSE, GenericSampleRegistrationForm.RegisterSampleCallback.class)); remoteConsole.prepare(new ListSamples("CISD", sampleTypeCode)); @@ -86,7 +86,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase remoteConsole.prepare(new ChooseTypeOfNewSample(CONTROL_LAYOUT)); remoteConsole.prepare(new FillSampleRegistrationForm("TESTGROUP", GROUP_CL + "1", true) .addProperty(new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry", - "1536_WELLS_32X48"))); + "[1536_WELLS_32X48]"))); FailureExpectation failureExpectation = new FailureExpectation(GenericSampleRegistrationForm.RegisterSampleCallback.class) .with("Authorization failure: None of method roles " @@ -143,7 +143,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase new PropertyField(GenericSampleRegistrationForm.ID + "user-description", description)).addProperty( new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry", - "1536_WELLS_32X48"))); + "[1536_WELLS_32X48]"))); remoteConsole.prepare(new InvokeActionMenu(TopMenu.ActionMenuKind.SAMPLE_MENU_BROWSE, GenericSampleRegistrationForm.RegisterSampleCallback.class)); remoteConsole.prepare(new ListSamples(GroupSelectionWidget.SHARED_GROUP_CODE,