further development of the checklist editor
authorKatja Luther <k.luther@bgbm.org>
Thu, 9 Jun 2016 08:58:20 +0000 (10:58 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 9 Jun 2016 08:58:20 +0000 (10:58 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistLabelProvider.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/edit/DistributionEditingSupport.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/filter/ChecklistEditorFilter.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java

index 8461e0e50526b9b311ef85ff122d3cd31a0ffb5f..9ae2a675c1e6a214a224ffdeaf60b9fbe13ad0db 100644 (file)
@@ -328,9 +328,16 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     private void createTable() {
         Table table = viewer.getTable();//new Table(parent, viewer.getTable().getStyle());
         List<String> titles = new ArrayList<String>();
-        Collections.addAll(titles, "Taxon", "Author", "Rank");
         List<Integer> bounds = new ArrayList<Integer>();
-        Collections.addAll(bounds, 300, 200, 200);
+        if (PreferencesUtil.isShowRankInChecklistEditor()){
+            Collections.addAll(titles, "Taxon",  "Rank");
+            Collections.addAll(bounds, 300, 200);
+        } else{
+            Collections.addAll(titles, "Taxon");
+            Collections.addAll(bounds, 300);
+        }
+
+
         Map<Integer, Boolean> restoreValuesForColumnWidth = restoreValuesForColumnWidth(titles, bounds);
         createInitalDistributionColumns(table, titles, bounds, restoreValuesForColumnWidth);
         table.setSortDirection(SWT.DOWN);
@@ -349,8 +356,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
      * @param restoreValuesForColumnWidth
      */
        private void createInitalDistributionColumns(Table table,
-                       List<String> titles, List<Integer> bounds,
-                       Map<Integer, Boolean> restoreValuesForColumnWidth) {
+                       List<String> titles, List<Integer> bounds, Map<Integer, Boolean> restoreValuesForColumnWidth) {
                for (int columnIndex = 0; columnIndex < titles.size(); columnIndex++) {
             TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
             column.getColumn().setText(titles.get(columnIndex));
@@ -361,16 +367,16 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
             if (columnIndex == 0) {
                 table.setSortColumn(column.getColumn());
             }
-            if (columnIndex == 2) {
+            if (columnIndex == 1 && PreferencesUtil.isShowRankInChecklistEditor()) {
                /** uncommented it for now because no rank editing is wanted **/
 //                column.setEditingSupport(new RankEditingSupport(viewer, this));
             }
-            if (columnIndex >= 3) {
+            if ((columnIndex == 1 && !PreferencesUtil.isShowRankInChecklistEditor()) || columnIndex >= 2 ) {
                 //read PrefrenceStore to setWidth according to last saved state
                 if(restoreValuesForColumnWidth.get(columnIndex)){
-                    column.getColumn().setWidth(100);
+                    column.getColumn().setWidth(50);
                 }else{
-                    column.getColumn().setWidth(100);
+                    column.getColumn().setWidth(50);
                 }
                 column.setEditingSupport(new DistributionEditingSupport(viewer, this, columnIndex));
             }
@@ -390,7 +396,12 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
                        List<Integer> bounds) {
                Map<Integer, Boolean> restoreColumnWidth = new HashMap<Integer, Boolean>();
                if (terms != null) {
-            int columnIndex = 3;
+                   int columnIndex;
+                   if (PreferencesUtil.isShowRankInChecklistEditor()){
+                       columnIndex = 2;
+                   } else{
+                       columnIndex = 1;
+                   }
             for (DefinedTermBase<DefinedTermBase> term : terms) {
                 if(term != null){
                     restoreColumnWidth.put(columnIndex, PreferencesUtil.getPreferenceStore().getBoolean(term.getUuid().toString()));
index 56c931a562aff65981d42a965d4d86c92f236f51..d9da0c0a2e3d705a8194197113ae4bf8e14b6a3b 100644 (file)
@@ -28,6 +28,7 @@ import org.eclipse.swt.widgets.TableColumn;
 
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Language;
@@ -90,11 +91,12 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
     /** {@inheritDoc} */
        @Override
     public String getColumnText(Object element, int columnIndex) {
-        descriptionService = CdmStore.getService(IDescriptionService.class);
+       // descriptionService = CdmStore.getService(IDescriptionService.class);
         Taxon taxon = (Taxon) element;
         //TODO load areas by this list
 
-        List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null, null, null, null, DESC_INIT_STRATEGY);;
+       // List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null, null, null, null, DESC_INIT_STRATEGY);;
+        Set<TaxonDescription> listTaxonDescriptions = taxon.getDescriptions();
         NonViralName<?> nonViralName = HibernateProxyHelper.deproxy(taxon.getName(), NonViralName.class);
 
         switch (columnIndex) {
@@ -103,10 +105,10 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
             taxonName = (nonViralName != null) ? nonViralName.getNameCache() : null;
             return (taxonName != null) ? taxonName : DEFAULT_ENTRY;
 
-        case 1:
-            String authorship = null;
-            authorship = (nonViralName != null) ? nonViralName.getAuthorshipCache() : null;
-            return (authorship != null) ? authorship : DEFAULT_ENTRY;
//       case 1:
+//            String authorship = null;
+//            authorship = (nonViralName != null) ? nonViralName.getAuthorshipCache() : null;
+//            return (authorship != null) ? authorship : DEFAULT_ENTRY;
 //        case 2:
 //            String ref = null;
 //            if (taxon.getName() != null) {
@@ -115,15 +117,18 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
 //                ref = (nomenclaturalReference != null) ? nomenclaturalReference.getAbbrevTitleCache() : null;
 //            }
 //            return (ref != null) ? ref : DEFAULT_ENTRY;
-        case 2:
-            String rank = null;
-            if (taxon.getName().getRank() != null) {
-                rank = taxon.getName().getRank().toString();
+        case 1:
+            if (PreferencesUtil.isShowRankInChecklistEditor()){
+                String rank = null;
+
+                if (taxon.getName().getRank() != null) {
+                    rank = taxon.getName().getRank().toString();
+                }
+                return (rank != null) ? rank : DEFAULT_ENTRY;
             }
-            return (rank != null) ? rank : DEFAULT_ENTRY;
         }
 
-        if(columnIndex >2){
+        if(columnIndex >2 || (!PreferencesUtil.isShowRankInChecklistEditor() && columnIndex > 1)){
 
             for (TaxonDescription td : listTaxonDescriptions) {
                 for (DescriptionElementBase deb : td.getElements()) {
@@ -132,7 +137,11 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
                         String area = null;
                         if (distribution.getArea() != null ){
                             if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
-                                area = distribution.getArea().getIdInVocabulary();
+                                if (distribution.getArea().getIdInVocabulary() != null){
+                                    area = distribution.getArea().getIdInVocabulary();
+                                } else{
+                                    area = distribution.getArea().getTitleCache();
+                                }
                             }else{
                                 area = distribution.getArea().getTitleCache();
                             }
@@ -143,7 +152,11 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
                         if(viewer != null){
                                TableColumn column = viewer.getTable().getColumn(columnIndex);
                                if (area.equalsIgnoreCase(column.getText())) {
-                                   return (distribution.getStatus().getTitleCache() != null)?distribution.getStatus().getTitleCache():DEFAULT_ENTRY;
+                                   if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
+                                       return (distribution.getStatus().getIdInVocabulary() != null)?distribution.getStatus().getIdInVocabulary():CdmUtils.Nz(distribution.getStatus().getTitleCache());
+                                   }else{
+                                       return (distribution.getStatus().getTitleCache() != null)?distribution.getStatus().getTitleCache():DEFAULT_ENTRY;
+                                   }
                             }
 
                         }
@@ -162,12 +175,13 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
     private SortedSet<DefinedTermBase> loadNamedAreas() {
         IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
         String values = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS);
+
         if (values != null && values != "") {
             String[] split = values.split(",");
             List<String> listValue = Arrays.asList(split);
             List<DefinedTermBase> termlist = new ArrayList<DefinedTermBase>();
-           Set<UUID> uuidList = new HashSet<UUID>();
-           UUID uuid;
+            Set<UUID> uuidList = new HashSet<UUID>();
+            UUID uuid;
             for(String s : listValue){
                 uuid = UUID.fromString(s);
                 uuidList.add(uuid);
@@ -175,13 +189,16 @@ public class ChecklistLabelProvider extends LabelProvider implements ITableLabel
             }
             ITermService service = CdmStore.getService(ITermService.class);
             termlist = service.find(uuidList);
-
-            return getTermsOrderedByIdInVocabulary(termlist);
+            if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
+                return getTermsOrderedByIdInVocabulary(termlist);
+            } else {
+                return getTermsOrderedByLabels(termlist, CdmStore.getDefaultLanguage());
+            }
         }
         return null;
     }
 
-    public SortedSet<?> getTermsOrderedByLabels(List<DefinedTermBase<?>> listTerm,Language language){
+    public SortedSet<DefinedTermBase> getTermsOrderedByLabels(List<DefinedTermBase> listTerm,Language language){
         TermLanguageComparator comp = new TermLanguageComparator();
         comp.setCompareLanguage(language);
         SortedSet result = new TreeSet(comp);
index 80153af575b95f64737d0c8d8aa4021e29e4229b..2274d9b3fe5af0643968c65b2e28ed9d9a7c8fa2 100644 (file)
@@ -71,7 +71,15 @@ public final class DistributionEditingSupport extends EditingSupport {
             Taxon taxon = (Taxon) element;
             Distribution distributionForColumn = getDistributionForColumn(taxon);
             if (distributionForColumn != null) {
-                return distributionForColumn.getStatus().getTitleCache();
+                if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
+                    if (distributionForColumn.getStatus().getIdInVocabulary() != null){
+                        return distributionForColumn.getStatus().getIdInVocabulary();
+                    } else{
+                        distributionForColumn.getStatus().getTitleCache();
+                    }
+                } else{
+                    return distributionForColumn.getStatus().getTitleCache();
+                }
             }
             // return PresenceAbsenceTerms
         }
@@ -108,8 +116,9 @@ public final class DistributionEditingSupport extends EditingSupport {
      * @return
      */
     private Distribution getDistributionForColumn(Taxon taxon) {
-        List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null,
-                null, null, null, DESC_INIT_STRATEGY);
+//        List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null,
+//                null, null, null, DESC_INIT_STRATEGY);
+        Set<TaxonDescription> listTaxonDescriptions = taxon.getDescriptions();
         TableColumn column = viewer.getTable().getColumn(columnIndex);
         for (TaxonDescription td : listTaxonDescriptions) {
             for (DescriptionElementBase deb : td.getElements()) {
index bcbc27f693b411aec3b99ea3e7efe851d420a988..fc1587c850e43c55cc6f4e688d32e840fb774a8f 100644 (file)
@@ -15,9 +15,9 @@ public class ChecklistEditorFilter extends ViewerFilter {
     public void setSearchText(String s) {
         // Search must be a substring of the existing value
         if(s.contains("*")){
-            s=s.replace("*", "");
+            s=s.replace("*", ".*");
         }
-        this.searchString = "(?i).*" + s + ".*";
+        this.searchString = ".*" + s + ".*";
     }
 
     @Override
@@ -34,17 +34,17 @@ public class ChecklistEditorFilter extends ViewerFilter {
             return true;
         }
         //Author
-        if (nonVirlaName.getAuthorshipCache() != null && nonVirlaName.getAuthorshipCache().matches(searchString)) {
-            return true;
-        }
-        //Reference
-        if(reference != null && reference.getAbbrevTitleCache().matches(searchString)){
-            return true;
-        }
-        //Rank
-        if (rank != null && rank.matches(searchString)) {
-            return true;
-        }
+//        if (nonVirlaName.getAuthorshipCache() != null && nonVirlaName.getAuthorshipCache().matches(searchString)) {
+//            return true;
+//        }
+//        //Reference
+//        if(reference != null && reference.getAbbrevTitleCache().matches(searchString)){
+//            return true;
+//        }
+//        //Rank
+//        if (rank != null && rank.matches(searchString)) {
+//            return true;
+//        }
         return false;
     }
 
index b8f4ae17a24f6ed975a3c1521f113a87d167ac1b..d7a342c6237b4b8e81b9d89206f865c39c79e8b3 100644 (file)
@@ -75,17 +75,29 @@ public class ChecklistEditorGeneralPreference extends PreferencePage implements
 
         button_openFeatureTree.setText("Open Distribution Selection Wizard");
         final Button showIdInVocabulary = new Button(child, SWT.CHECK);
-        boolean isShowIdInVocabulary = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_ID_IN_VOCABULARY);
+        boolean isShowIdInVocabulary = PreferencesUtil.isShowIdInVocabularyInChecklistEditor();
         showIdInVocabulary.setText("Show Id in Vocabulary instead of full title of the areas");
         showIdInVocabulary.setSelection(isShowIdInVocabulary);
         showIdInVocabulary.addSelectionListener(new SelectionAdapter(){
             @Override
             public void widgetSelected(SelectionEvent e) {
                 boolean isShowIdInVocabulary = showIdInVocabulary.getSelection();
-                PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.CHECKLIST_ID_IN_VOCABULARY, isShowIdInVocabulary);
+                PreferencesUtil.setShowIdInVocabularyInChecklistEditor(isShowIdInVocabulary);
              }
         });
         PreferencesUtil.recursiveSetEnabled(button_openFeatureTree, CdmStore.isActive());
+        boolean isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
+        final Button activateRankButton = new Button(child, SWT.CHECK);
+        activateRankButton.setText("Show Rank in Checklist Editor");
+        activateRankButton.setSelection(isShowRank);
+        activateRankButton.addSelectionListener(new SelectionAdapter(){
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                boolean isShowRank = activateRankButton.getSelection();
+                PreferencesUtil.setShowRankInChecklistEditor(isEditorActivated);
+            }
+        });
+
 
         if(isEditorActivated){
             child.setEnabled(true);
index 272244e7842b16b6b9e7d87695a3124bb0b8cfc4..c0b754723707476f953bb480eb17fda62458e055 100644 (file)
@@ -152,6 +152,7 @@ public interface IPreferenceKeys {
     public static final String DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED = "eu.etaxonomy.taxeditor.checklist.distributionAreaStatusGrayed";
 
     public static final String CHECKLIST_ID_IN_VOCABULARY = "eu.etaxonomy.taxeditor.checklist.checklistIdInVocabulary";
+    public static final String CHECKLIST_SHOW_RANK = "eu.etaxonomy.taxeditor.checklist.checklistShowRank";
 
     public static final String SHOW_ADVANCED_MEDIA_SECTION = "eu.etaxonomy.taxeditor.media.showAdvancedMedia";
     public static final String SHOW_SIMPLE_NAME_DETAILS_SECTION = "eu.etaxonomy.taxeditor.name.showSimpleName";
@@ -170,4 +171,6 @@ public interface IPreferenceKeys {
      */
     public static final String P2_REPOSITORY_LIST = "eu.etaxonomy.taxeditor.p2.repositories";
 
+
+
 }
index 3fe7ed44b579be4258035ee418f5f795f43f417a..cf3a9d8a3665f2f1bf18810cc0a0c1d8ca346f3d 100644 (file)
@@ -849,5 +849,14 @@ public class PreferencesUtil implements IPreferenceKeys {
         getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY, selection);
     }
 
+    /**
+     * @return
+     */
+    public static boolean isShowRankInChecklistEditor() {
+        return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_SHOW_RANK);
+    }
+    public static void setShowRankInChecklistEditor(boolean selection) {
+        getPreferenceStore().setValue(CHECKLIST_SHOW_RANK, selection);
+    }
 
 }