ref #8124: remaining issues for name facts (protologue filter)
authorKatja Luther <k.luther@bgbm.org>
Tue, 9 Apr 2019 11:33:49 +0000 (13:33 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 9 Apr 2019 11:34:42 +0000 (13:34 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/NameDescriptionFilter.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/FactualDataPartE4.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/NameDescriptionFilter.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/NameDescriptionFilter.java
new file mode 100755 (executable)
index 0000000..fc3a145
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+* 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.descriptive;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
+
+/**
+ * @author k.luther
+ * @since 09.04.2019
+ *
+ */
+public class NameDescriptionFilter extends ViewerFilter {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean select(Viewer viewer, Object parentElement, Object element) {
+        if (element instanceof FeatureNodeContainer ){
+            FeatureNodeContainer desc = (FeatureNodeContainer)element;
+            if(!desc.getFeature().equals(Feature.PROTOLOGUE())){
+                return true;
+            }
+        }
+        if (element instanceof DescriptionBase){
+            for (Object desc:((DescriptionBase) element).getElements()){
+                if (desc instanceof DescriptionElementBase){
+                    if (!((DescriptionElementBase)desc).getFeature().equals(Feature.PROTOLOGUE())){
+                        return true;
+                    }
+                }
+            }
+            if (((DescriptionBase) element).getElements().isEmpty()){
+                return true;
+            }
+        }
+        if (element instanceof DescriptionElementBase){
+            if (!((DescriptionElementBase)element).getFeature().equals(Feature.PROTOLOGUE())){
+                return true;
+            }
+        }
+        return false;
+    }
+
+}
index 4e31818..808248a 100644 (file)
@@ -51,6 +51,7 @@ import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementTransfer
 import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveContentProvider;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveLabelProvider;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewerSorter;
+import eu.etaxonomy.taxeditor.editor.view.descriptive.NameDescriptionFilter;
 import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
 import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
@@ -96,6 +97,7 @@ public class FactualDataPartE4 extends AbstractCdmEditorPartE4
         treeViewer.setContentProvider(provider);
         treeViewer.setLabelProvider(new DescriptiveLabelProvider());
         treeViewer.setSorter(new DescriptiveViewerSorter());
+        treeViewer.setFilters(new NameDescriptionFilter());
         treeViewer.setAutoExpandLevel(2);
         Transfer[] transfers = new Transfer[] { DescriptionElementTransfer.getInstance() };
         treeViewer.addDragSupport(dndOperations, transfers, new DescriptionElementDragListener(
@@ -109,6 +111,7 @@ public class FactualDataPartE4 extends AbstractCdmEditorPartE4
         viewer.addSelectionChangedListener(selectionChangedListener);
         DescriptionElementDropAdapter dropListener = new DescriptionElementDropAdapter(viewer);
         ContextInjectionFactory.inject(dropListener, context);
+
         treeViewer.addDropSupport(dndOperations, transfers,
                 dropListener);
         //create context menu
index e781d57..d3a892d 100644 (file)
@@ -140,7 +140,9 @@ public class DynamicFeatureMenuE4 {
                        featureTree = TermEditorInput.getDefaultFeatureTree();
                }
                if (description instanceof TaxonNameDescription){
-                   featureTree = FeatureTree.NewInstance(CdmStore.getTermManager().getPreferredTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid())));
+                   List<Feature> terms = CdmStore.getTermManager().getPreferredTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid()));
+                   terms.remove(Feature.PROTOLOGUE());
+                   featureTree = FeatureTree.NewInstance(terms);
                }
 
                return featureTree;