Skip to content
Snippets Groups Projects
Commit 7bbeb5cb authored by buczekp's avatar buczekp
Browse files

[LMS-1020] implemented - input/editing part ('labels and descriptions needed...

[LMS-1020] implemented - input/editing part ('labels and descriptions needed for controlled vocabulary terms')

SVN: 11920
parent 79a0652c
No related branches found
No related tags found
No related merge requests found
Showing
with 51 additions and 32 deletions
...@@ -38,6 +38,8 @@ public final class ModelDataPropertyNames ...@@ -38,6 +38,8 @@ public final class ModelDataPropertyNames
{ {
public static final String CODE = "code"; 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 LABEL = "label";
public static final String DATA_SET_TYPES = "data_set_types"; public static final String DATA_SET_TYPES = "data_set_types";
......
...@@ -17,34 +17,32 @@ ...@@ -17,34 +17,32 @@
package ch.systemsx.cisd.openbis.generic.client.web.client.application.model; package ch.systemsx.cisd.openbis.generic.client.web.client.application.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import com.extjs.gxt.ui.client.data.BaseModel; 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; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm;
/** /**
* @author Izabela Adamczyk * @author Izabela Adamczyk
*/ */
public class VocabularyTermModel extends BaseModel public class VocabularyTermModel extends BaseModel implements Comparable<VocabularyTermModel>
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public VocabularyTermModel(VocabularyTerm term) 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); return VocabularyPropertyColRenderer.renderCodeWithLabel(term);
}
private VocabularyTermModel(String termCode, String object)
{
set(ModelDataPropertyNames.CODE, termCode);
set(ModelDataPropertyNames.OBJECT, object);
} }
public static final List<VocabularyTermModel> convert(List<VocabularyTerm> terms) public static final List<VocabularyTermModel> convert(List<VocabularyTerm> terms)
...@@ -54,13 +52,28 @@ public class VocabularyTermModel extends BaseModel ...@@ -54,13 +52,28 @@ public class VocabularyTermModel extends BaseModel
{ {
list.add(new VocabularyTermModel(t)); list.add(new VocabularyTermModel(t));
} }
Collections.sort(list);
return 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 get(ModelDataPropertyNames.CODE_WITH_LABEL);
return code;
} }
} }
\ No newline at end of file
...@@ -56,16 +56,10 @@ public class VocabularyPropertyColRenderer<T extends IEntityPropertiesHolder> ex ...@@ -56,16 +56,10 @@ public class VocabularyPropertyColRenderer<T extends IEntityPropertiesHolder> ex
{ {
assert term != null : "term is not set"; assert term != null : "term is not set";
final String code = term.getCode();
final String label = term.getLabel();
final String description = term.getDescription(); final String description = term.getDescription();
final String url = term.getUrl(); final String url = term.getUrl();
String result = "[" + code + "]"; String result = renderCodeWithLabel(term);
if (label != null)
{
result = label + " " + result;
}
if (url != null) if (url != null)
{ {
result = ExternalHyperlink.createAnchorString(result, url); result = ExternalHyperlink.createAnchorString(result, url);
...@@ -74,4 +68,11 @@ public class VocabularyPropertyColRenderer<T extends IEntityPropertiesHolder> ex ...@@ -74,4 +68,11 @@ public class VocabularyPropertyColRenderer<T extends IEntityPropertiesHolder> ex
return result; return result;
} }
public static final String renderCodeWithLabel(VocabularyTerm term)
{
final String code = term.getCode();
final String label = term.getLabel();
return (label != null ? label + " " : "") + "[" + code + "]";
}
} }
...@@ -28,6 +28,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.D ...@@ -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.DataTypeCode;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; 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.Vocabulary;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm;
public class PropertyFieldFactory public class PropertyFieldFactory
{ {
...@@ -108,7 +109,8 @@ public class PropertyFieldFactory ...@@ -108,7 +109,8 @@ public class PropertyFieldFactory
return DateRenderer.renderDate((Date) value); return DateRenderer.renderDate((Date) value);
} else if (value instanceof VocabularyTermModel) } else if (value instanceof VocabularyTermModel)
{ {
return ((VocabularyTermModel) value).getTerm(); final VocabularyTerm term = ((VocabularyTermModel) value).getTerm();
return term.getCode();
} else } else
{ {
return value.toString(); return value.toString();
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field; package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback;
...@@ -59,10 +60,10 @@ public class VocabularyTermSelectionWidget extends ...@@ -59,10 +60,10 @@ public class VocabularyTermSelectionWidget extends
*/ */
public static DatabaseModificationAwareField<VocabularyTermModel> create(String idSuffix, public static DatabaseModificationAwareField<VocabularyTermModel> create(String idSuffix,
String label, Vocabulary vocabulary, final boolean mandatory, String label, Vocabulary vocabulary, final boolean mandatory,
IViewContext<?> viewContext, String initialTermOrNull) IViewContext<?> viewContext, String initialTermCodeOrNull)
{ {
return new VocabularyTermSelectionWidget(idSuffix, label, mandatory, vocabulary, return new VocabularyTermSelectionWidget(idSuffix, label, mandatory, vocabulary,
viewContext, null, initialTermOrNull).asDatabaseModificationAware(); viewContext, null, initialTermCodeOrNull).asDatabaseModificationAware();
} }
/** /**
...@@ -76,13 +77,13 @@ public class VocabularyTermSelectionWidget extends ...@@ -76,13 +77,13 @@ public class VocabularyTermSelectionWidget extends
private VocabularyTermSelectionWidget(String idSuffix, String label, boolean mandatory, private VocabularyTermSelectionWidget(String idSuffix, String label, boolean mandatory,
Vocabulary vocabularyOrNull, IViewContext<?> viewContextOrNull, 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); VALUE_NOT_IN_LIST_MSG, mandatory, viewContextOrNull, termsOrNull == null);
this.viewContextOrNull = viewContextOrNull; this.viewContextOrNull = viewContextOrNull;
this.vocabularyOrNull = vocabularyOrNull; this.vocabularyOrNull = vocabularyOrNull;
this.initialTermCodeOrNull = initialTermOrNull; this.initialTermCodeOrNull = initialTermCodeOrNull;
FieldUtil.setMandatoryFlag(this, mandatory); FieldUtil.setMandatoryFlag(this, mandatory);
setAllowBlank(mandatory == false); setAllowBlank(mandatory == false);
if (termsOrNull != null) if (termsOrNull != null)
...@@ -94,8 +95,8 @@ public class VocabularyTermSelectionWidget extends ...@@ -94,8 +95,8 @@ public class VocabularyTermSelectionWidget extends
private void setTerms(List<VocabularyTerm> terms) private void setTerms(List<VocabularyTerm> terms)
{ {
final List<VocabularyTermModel> models = new ArrayList<VocabularyTermModel>(); final List<VocabularyTermModel> models = new ArrayList<VocabularyTermModel>();
models.add(new VocabularyTermModel(GWTUtils.NONE_LIST_ITEM));
models.addAll(convertItems(terms)); models.addAll(convertItems(terms));
Collections.sort(models);
updateStore(models); updateStore(models);
getPropertyEditor().setList(store.getModels()); getPropertyEditor().setList(store.getModels());
} }
......
...@@ -453,8 +453,8 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm ...@@ -453,8 +453,8 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm
public void selectionChanged(SelectionChangedEvent<VocabularyTermModel> se) public void selectionChanged(SelectionChangedEvent<VocabularyTermModel> se)
{ {
VocabularyTermModel selectedItem = se.getSelectedItem(); VocabularyTermModel selectedItem = se.getSelectedItem();
termToBeReplaced.setReplacementCode(selectedItem == null ? null : selectedItem termToBeReplaced.setReplacementCode(selectedItem == null ? null
.getTerm()); : selectedItem.getTerm().getCode());
dialog.setEnableOfAcceptButton(formPanel.isValid()); dialog.setEnableOfAcceptButton(formPanel.isValid());
} }
}); });
......
...@@ -67,7 +67,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase ...@@ -67,7 +67,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase
loginAndPreprareRegistration(sampleTypeCode); loginAndPreprareRegistration(sampleTypeCode);
remoteConsole.prepare(new FillSampleRegistrationForm("CISD", GROUP_CL, true) remoteConsole.prepare(new FillSampleRegistrationForm("CISD", GROUP_CL, true)
.addProperty(new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry", .addProperty(new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry",
"1536_WELLS_32X48"))); "[1536_WELLS_32X48]")));
remoteConsole.prepare(new InvokeActionMenu(TopMenu.ActionMenuKind.SAMPLE_MENU_BROWSE, remoteConsole.prepare(new InvokeActionMenu(TopMenu.ActionMenuKind.SAMPLE_MENU_BROWSE,
GenericSampleRegistrationForm.RegisterSampleCallback.class)); GenericSampleRegistrationForm.RegisterSampleCallback.class));
remoteConsole.prepare(new ListSamples("CISD", sampleTypeCode)); remoteConsole.prepare(new ListSamples("CISD", sampleTypeCode));
...@@ -86,7 +86,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase ...@@ -86,7 +86,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase
remoteConsole.prepare(new ChooseTypeOfNewSample(CONTROL_LAYOUT)); remoteConsole.prepare(new ChooseTypeOfNewSample(CONTROL_LAYOUT));
remoteConsole.prepare(new FillSampleRegistrationForm("TESTGROUP", GROUP_CL + "1", true) remoteConsole.prepare(new FillSampleRegistrationForm("TESTGROUP", GROUP_CL + "1", true)
.addProperty(new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry", .addProperty(new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry",
"1536_WELLS_32X48"))); "[1536_WELLS_32X48]")));
FailureExpectation failureExpectation = FailureExpectation failureExpectation =
new FailureExpectation(GenericSampleRegistrationForm.RegisterSampleCallback.class) new FailureExpectation(GenericSampleRegistrationForm.RegisterSampleCallback.class)
.with("Authorization failure: None of method roles " .with("Authorization failure: None of method roles "
...@@ -143,7 +143,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase ...@@ -143,7 +143,7 @@ public class GenericSampleRegistrationTest extends AbstractGWTTestCase
new PropertyField(GenericSampleRegistrationForm.ID + "user-description", new PropertyField(GenericSampleRegistrationForm.ID + "user-description",
description)).addProperty( description)).addProperty(
new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry", new PropertyField(GenericSampleRegistrationForm.ID + "plate-geometry",
"1536_WELLS_32X48"))); "[1536_WELLS_32X48]")));
remoteConsole.prepare(new InvokeActionMenu(TopMenu.ActionMenuKind.SAMPLE_MENU_BROWSE, remoteConsole.prepare(new InvokeActionMenu(TopMenu.ActionMenuKind.SAMPLE_MENU_BROWSE,
GenericSampleRegistrationForm.RegisterSampleCallback.class)); GenericSampleRegistrationForm.RegisterSampleCallback.class));
remoteConsole.prepare(new ListSamples(GroupSelectionWidget.SHARED_GROUP_CODE, remoteConsole.prepare(new ListSamples(GroupSelectionWidget.SHARED_GROUP_CODE,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment