ref #8228: fix refresh in details view
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / e4 / AbstractCdmEditorPartE4.java
index 4446c1ef52a86f6e4e28315aacd1aad42fd59c4d..a1cc6f414652e030068d481b4f826603b1081efe 100644 (file)
@@ -31,18 +31,22 @@ import org.eclipse.swt.SWTException;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.description.Distribution;
+import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
 import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
 import eu.etaxonomy.taxeditor.view.e4.details.DetailsViewerE4;
 import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
@@ -111,14 +115,6 @@ public abstract class AbstractCdmEditorPartE4
 
     protected Object previousSelection;
 
-    public Object getPreviousSelection() {
-        return previousSelection;
-    }
-
-    public void setPreviousSelection(Object previousSelection) {
-        this.previousSelection = previousSelection;
-    }
-
     protected ISelectionChangedListener selectionChangedListener;
 
     public ISelectionChangedListener getSelectionChangedListener() {
@@ -147,6 +143,7 @@ public abstract class AbstractCdmEditorPartE4
             showEmptyPage();
             return;
         }
+        // no active editor found
         if(activePart==thisPart && WorkbenchUtility.getActiveEditorPart(partService)==null){
             showEmptyPage();
             return;
@@ -160,20 +157,23 @@ public abstract class AbstractCdmEditorPartE4
 
         }
 
-
-        if(previousSelection==null ||
-                previousSelection!=selection){//skip redundant rendering of details view
-            if(delaySelection==null){
-                delaySelection = new DelaySelection(selection, activePart, thisPart);
-            }
-            delaySelection.setSelection(selection);
-            delaySelection.setActivePart(activePart);
-            delaySelection.setThisPart(thisPart);
-            if(!isInDelay){
-                isInDelay = true;
-                sync.asyncExec(delaySelection);
-                previousSelection = selection;
-            }
+        if((previousSelection!=null && selection!=null) && activePart.equals(selectionProvidingPart) &&
+                (previousSelection==selection
+                || previousSelection.equals(selection)
+                || new StructuredSelection(selection).equals(previousSelection))
+                ) {
+            return;
+        }
+        if(delaySelection==null){
+            delaySelection = new DelaySelection(selection, activePart, thisPart);
+        }
+        delaySelection.setSelection(selection);
+        delaySelection.setActivePart(activePart);
+        delaySelection.setThisPart(thisPart);
+        if(!isInDelay){
+            isInDelay = true;
+            sync.asyncExec(delaySelection);
+            previousSelection = selection;
         }
     }
 
@@ -200,7 +200,7 @@ public abstract class AbstractCdmEditorPartE4
             if(selection.getFirstElement()!=null){
                 if (element instanceof Taxon){
                     Taxon taxon = HibernateProxyHelper.deproxy(element, Taxon.class);
-                    if (taxon.isMisapplication() || taxon.isProparteSynonym()){
+                    if (taxon.isMisapplication() || taxon.isProparteSynonym() || taxon.isInvalidDesignation()){
 
                         if(part instanceof ITaxonEditor){
                             Taxon accepted = ((ITaxonEditor) part).getTaxon();
@@ -208,7 +208,7 @@ public abstract class AbstractCdmEditorPartE4
 
                             if (rels != null && rels.iterator().hasNext() && !taxon.equals(accepted)){
                                 TaxonRelationship rel = rels.iterator().next();
-                                if ((rel.getType().isAnyMisappliedName() || rel.getType().isAnySynonym())&& !rel.getFromTaxon().equals(((ITaxonEditor) part).getTaxon())){
+                                if ((rel.getType().isMisappliedNameOrInvalidDesignation() || rel.getType().isAnySynonym()) && !rel.getFromTaxon().equals(((ITaxonEditor) part).getTaxon())){
                                     viewer.setInput(rel);
                                     selectionProvidingPart = activePart;
                                     return;
@@ -219,15 +219,27 @@ public abstract class AbstractCdmEditorPartE4
 
                     }
                 }
-                if (element instanceof Distribution && part instanceof IDistributionEditor){
+                //unwrap term DTOs
+                if(element instanceof TermDto){
+                    element = CdmStore.getService(ITermService.class).load(((TermDto) element).getUuid());
+                }
+                else if(element instanceof TermVocabularyDto){
+                    element = CdmStore.getService(IVocabularyService.class).load(((TermVocabularyDto) element).getUuid());
+                }
+
+                selectionProvidingPart = activePart;
+                if (viewer instanceof DetailsViewerE4){
                     ((DetailsViewerE4)viewer).setInput(element, part);
-                }else{
-                    viewer.setInput(element);
-                    if (viewer instanceof DetailsViewerE4){
-                       ((DetailsViewerE4)viewer).setDetailsEnabled(true);
+                    ((DetailsViewerE4)viewer).setDetailsEnabled(true);
+
+                }
+
+                else{
+                    if (activePart.getObject() instanceof DetailsPartE4 && element instanceof TaxonName){
+                        selectionProvidingPart = ((DetailsPartE4)activePart.getObject()).getSelectionProvidingPart();
                     }
+                    viewer.setInput(element);
                 }
-                selectionProvidingPart = activePart;
             }
         }
     }
@@ -296,7 +308,7 @@ public abstract class AbstractCdmEditorPartE4
      * {@inheritDoc}
      */
     @Override
-    public boolean postOperation(CdmBase objectAffectedByOperation) {
+    public boolean postOperation(Object objectAffectedByOperation) {
         changed(objectAffectedByOperation);
         return true;
     }