ref #8047: show symbol and label in drop down of distribution editor
authorKatja Luther <k.luther@bgbm.org>
Tue, 4 Jun 2019 07:45:35 +0000 (09:45 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 4 Jun 2019 07:45:35 +0000 (09:45 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionColumnAccessor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/StatusComboBoxDataProvider.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/StatusHelper.java [new file with mode: 0755]

index 373cf790bab1a254ec3841227924ef4bc9e1df20..b5ed03f8a0f590e578b3e9b772c13ce02e463883 100755 (executable)
@@ -24,7 +24,6 @@ import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
 import eu.etaxonomy.cdm.model.description.Distribution;
-import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.taxeditor.event.EventUtility;
@@ -117,7 +116,7 @@ public class DistributionColumnAccessor implements IColumnPropertyAccessor<Taxon
      */
     @Override
     public void setDataValue(TaxonDistributionDTO taxonWrapper, int columnIndex, Object newValue) {
-        if (newValue instanceof PresenceAbsenceTerm){
+        if (newValue instanceof StatusHelper){
                 NamedArea area =editor.getAreaToColumnIndexMap().get(columnIndex);
                 Map<NamedArea, Set<DescriptionElementBase>> distributionMap = editor.taxonDistributionMap.get(taxonWrapper.getTaxonUuid());
                 if (distributionMap == null){
@@ -129,22 +128,22 @@ public class DistributionColumnAccessor implements IColumnPropertyAccessor<Taxon
                 if (distributions != null && !distributions.isEmpty()){
                     DescriptionElementBase desc = distributions.iterator().next();
                     if (desc instanceof Distribution){
-                        if (((PresenceAbsenceTerm)newValue).getId() == 0){
+                        if (((StatusHelper)newValue).term.getId() == 0){
                             desc.getInDescription().removeElement(desc);
                             distributions.remove(desc);
                         }else {
-                            ((Distribution)desc).setStatus((PresenceAbsenceTerm)newValue);
+                            ((Distribution)desc).setStatus(((StatusHelper)newValue).term);
                         }
                     }
                 }else{
-                    if (((PresenceAbsenceTerm)newValue).getId() == 0){
+                    if (((StatusHelper)newValue).term.getId() == 0){
                         return;
                     }
                     if (distributions == null){
                         distributions = new HashSet();
                         distributionMap.put(area, distributions);
                     }
-                    dist = Distribution.NewInstance(area, (PresenceAbsenceTerm)newValue);
+                    dist = Distribution.NewInstance(area, ((StatusHelper)newValue).term);
                     Set<TaxonDescription> descs = taxonWrapper.getDescriptionsWrapper().getDescriptions();
                     TaxonDescription desc;
                     if (descs.size() >= 1){
index 77fc37aff5aed445e099cbb282f4924f48cf547e..4162a16d2a8e3945fb97f3fa8dab095426d4cfc7 100755 (executable)
@@ -69,11 +69,11 @@ public class StatusComboBoxDataProvider implements IComboBoxDataProvider {
 
 
     public static List<?> getValues(CdmPreference pref){
-        List<DefinedTermBase> inputAll = new ArrayList<>();
+        List<StatusHelper> inputAll = new ArrayList<>();
         PresenceAbsenceTerm noneTerm = PresenceAbsenceTerm.NewInstance();
         noneTerm.setTitleCache(" - ", true);
         noneTerm.addRepresentation(Representation.NewInstance(" - ", " ", " ", CdmStore.getDefaultLanguage()));
-        inputAll.add(noneTerm);
+        inputAll.add(new StatusHelper(noneTerm));
         String statusString = pref.getValue();
 
         List<PresenceAbsenceTerm> inputList;
@@ -93,8 +93,11 @@ public class StatusComboBoxDataProvider implements IComboBoxDataProvider {
         Comparator<DefinedTermBase> comp = new OrderedTermComparator<>();
         Collections.sort(inputList, comp);
         Collections.sort(inputList, Collections.reverseOrder());
-
-        inputAll.addAll(1, inputList);
+        int index = 1;
+        for (PresenceAbsenceTerm term: inputList){
+            inputAll.add(index, new StatusHelper(term));
+        }
+       // inputAll.addAll(1, inputList);
         return inputAll;
     }
 
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/StatusHelper.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/StatusHelper.java
new file mode 100755 (executable)
index 0000000..47337cb
--- /dev/null
@@ -0,0 +1,42 @@
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
+
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
+import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+
+/**
+ * @author k.luther
+ * @since 27.05.2019
+ *
+ */
+public class StatusHelper {
+    PresenceAbsenceTerm term;
+    String label;
+
+    public StatusHelper(PresenceAbsenceTerm term){
+        this.term = term;
+        TermDisplayEnum display = TermDisplayEnum.valueOf(PreferencesUtil.displayStatusInChecklistEditor());
+        if (display.equals(TermDisplayEnum.IdInVocabulary) && term.getIdInVocabulary() != null){
+            label = "[" + term.getIdInVocabulary()+ "] " + term.getTitleCache();
+        }else if (display.equals(TermDisplayEnum.Symbol1) && term.getSymbol() != null){
+            label = "[" + term.getSymbol()+ "] " + term.getTitleCache();
+        } else if (display.equals(TermDisplayEnum.Symbol2) && term.getSymbol2() != null){
+            label = "[" + term.getSymbol2()+ "] " + term.getTitleCache();
+        } else{
+            label = term.getTitleCache();
+        }
+    }
+    @Override
+    public String toString(){
+        return label;
+    }
+
+}