ref #10473: fix problems in factual data view for names
authorKatja <k.luther@bgbm.org>
Fri, 16 Feb 2024 12:56:55 +0000 (13:56 +0100)
committerKatja <k.luther@bgbm.org>
Fri, 16 Feb 2024 12:56:55 +0000 (13:56 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/CreateDescriptionElementHandlerE4.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java

index c254e5cd9b49942073cb56809c76a57e5cbf57b6..97288993f898de5145bb482d5bad14bef361bf72 100644 (file)
@@ -28,6 +28,7 @@ import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonEditor;
@@ -89,7 +90,7 @@ public class CreateDescriptionElementHandlerE4 {
                 description = TaxonDescription.NewInstance(taxon);
                 description.setDefault(true);
             }
-        } 
+        }
         else {
             MessagingUtils.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); //$NON-NLS-1$
             return;
@@ -111,11 +112,7 @@ public class CreateDescriptionElementHandlerE4 {
             Object o = activePart.getObject();
             if (o instanceof FactualDataPartE4) {
                 FactualDataPartE4 part = (FactualDataPartE4)o;
-                MPart selectionProvidingPart = part.getSelectionProvidingPart();
-                if (selectionProvidingPart.getObject() instanceof TaxonEditor) {
-                    TaxonEditor editor = (TaxonEditor)selectionProvidingPart.getObject();
-                    object = editor.getTaxon();
-                }                
+                object = part.getViewer().getInput();
             }else if (o instanceof TaxonEditor) {
                 TaxonEditor editor = (TaxonEditor)AbstractUtility.getActiveEditor();
                 object = editor.getTaxon();
@@ -132,8 +129,7 @@ public class CreateDescriptionElementHandlerE4 {
             description = HibernateProxyHelper.deproxy(object, DescriptionBase.class);
         }else if (object instanceof Taxon){
             Taxon taxon = (Taxon) object;
-            description =taxon.getDefaultDescription();
-            
+            description =taxon.getDefaultDescription();            
         } 
 
         if (description != null &&((description.isComputed() || description.isCloneForSource())&& PreferencesUtil.isComputedDesciptionHandlingDisabled())){
@@ -146,7 +142,8 @@ public class CreateDescriptionElementHandlerE4 {
                     || selection.getFirstElement() instanceof DescriptionElementBase
                     || selection.getFirstElement() instanceof FeatureNodeContainer
                     || object instanceof Taxon))
-                    || (selection.size() == 0 && object instanceof Taxon);
+                    || (selection.size() == 0 && object instanceof Taxon)
+                    || (selection.size() == 0 && object instanceof TaxonName);
         }
         menuItem.setVisible(canExecute);
         return canExecute;
index 716530c0a4d7e79e4dc416862b13186be1cda600..d7a3f747f9ddc1d1985ae08b0b44b800ab825ac4 100644 (file)
@@ -20,6 +20,7 @@ import java.util.UUID;
 
 import javax.inject.Named;
 
+import org.eclipse.e4.core.di.annotations.Optional;
 import org.eclipse.e4.ui.di.AboutToShow;
 import org.eclipse.e4.ui.model.application.commands.MCommand;
 import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
@@ -37,6 +38,7 @@ import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
+import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
 import eu.etaxonomy.cdm.model.term.TermNode;
@@ -56,33 +58,33 @@ import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
  * @date 15.08.2017
  */
 public class DynamicFeatureMenuE4 {
+    Object selectedElement = null;
 
     @AboutToShow
-    public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection) {
+    public void aboutToShow(List<MMenuElement> items, @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection) {
         Language globalLanguage = PreferencesUtil.getGlobalLanguage();
 
         MMenu menu = MMenuFactory.INSTANCE.createMenu();
         menu.setLabel(Messages.DynamicFeatureMenuE4_new);
         items.add(menu);
         List<MMenuElement> menuItems = new ArrayList<>();
-        Object selectedElement = selection.getFirstElement();
-        if (selectedElement == null) {
+        if (selection != null) {
+            selectedElement = selection.getFirstElement();
+        }
+        if (selectedElement == null || !(selectedElement instanceof DescriptionBase<?> || selectedElement instanceof DescriptionElementBase || selectedElement instanceof FeatureNodeContainer )) {
             MPart activePart = EventUtility.getActivePart();
             Object o = activePart.getObject();
             if (o instanceof FactualDataPartE4) {
                 FactualDataPartE4 part = (FactualDataPartE4)o;
-                MPart selectionProvidingPart = part.getSelectionProvidingPart();
-                if (selectionProvidingPart.getObject() instanceof TaxonEditor) {
-                    TaxonEditor editor = (TaxonEditor)selectionProvidingPart.getObject();
-                    selectedElement = editor.getTaxon();
-                }
+                selectedElement = part.getViewer().getInput();
+
             }else if (o instanceof TaxonEditor) {
                 TaxonEditor editor = (TaxonEditor)AbstractUtility.getActiveEditor();
                 selectedElement = editor.getTaxon();
             }
         }
 
-        DescriptionBase<?> description;
+        DescriptionBase<?> description = null;
         if (selectedElement instanceof DescriptionBase<?>) {
             description = (DescriptionBase<?>) selectedElement;
         } else if (selectedElement instanceof FeatureNodeContainer){
@@ -92,6 +94,11 @@ public class DynamicFeatureMenuE4 {
         } else if (selectedElement instanceof Taxon){
             Taxon taxon = (Taxon) selectedElement;
             description = taxon.getDefaultDescription();
+        } else if (selectedElement instanceof TaxonName){
+            TaxonName taxonName = (TaxonName) selectedElement;
+            if (taxonName.getDescriptions() != null && taxonName.getDescriptions().size()>1) {
+                description = taxonName.getDescriptions().iterator().next();
+            }
         } else {
             //TODO or should we throw exception instead?
             return;
@@ -107,7 +114,7 @@ public class DynamicFeatureMenuE4 {
 
         //compute menu to show
         List<Feature> featureList = new ArrayList<>();
-        if (selectedElement instanceof DescriptionBase<?> || selectedElement instanceof Taxon) {
+        if (selectedElement instanceof DescriptionBase<?> || selectedElement instanceof Taxon || selectedElement instanceof TaxonName) {
             TermTree<Feature> featureTree = (TermTree)getFeatureTree(description);
             for (TermNode<Feature> childNode : featureTree.getRootChildren()) {
                 Feature feature = childNode.getTerm();
@@ -158,6 +165,7 @@ public class DynamicFeatureMenuE4 {
     }
 
     protected Map<UUID, Integer> getElementCounts(DescriptionBase<?> selectedElement) {
+
         if (selectedElement == null) {
             return null;
         }
@@ -238,7 +246,11 @@ public class DynamicFeatureMenuE4 {
                 featureTree = TermEditorInput.getPreferredTaxonFeatureTree(false);
             }
         }else {
-            featureTree = TermEditorInput.getPreferredTaxonFeatureTree(false);
+            if (selectedElement instanceof TaxonName) {
+                featureTree = TermEditorInput.getPreferredNameFeatureTree(false);
+            }else {
+                featureTree = TermEditorInput.getPreferredTaxonFeatureTree(false);
+            }
         }
 
                return featureTree;