- derivate view shows derivate hierarchy of FieldUnits and DerivedUnits
authorPatric Plitzner <p.plitzner@bgbm.org>
Mon, 14 Oct 2013 07:51:49 +0000 (07:51 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Mon, 14 Oct 2013 07:51:49 +0000 (07:51 +0000)
.gitattributes
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineDocumentProvider.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/DerivedUnitEditorInput.java [moved from eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/DataImportSpecimenEditorInput.java with 89% similarity]
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/transientServices/TransientTaxonService.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/wizard/SpecimenSearchWizard.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java

index 3288a9212e64caf514f1262d658e27a5f6d2f6ef..780377389f5028841dce0c8316921fc14fa58985 100644 (file)
@@ -117,7 +117,7 @@ eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkedito
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/DataImportEditor.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/DataImportEditorLineDisplayStrategy.java -text
-eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/DataImportSpecimenEditorInput.java -text
+eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/DerivedUnitEditorInput.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/transientServices/TransientAgentService.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/transientServices/TransientCdmRepository.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/dataimport/transientServices/TransientClassificationService.java -text
index 64df8cf93ea32ff427ddd024c36c4fcf91428a7b..af7d40c9f9eb56ca838ce40cc67e4dbae0b58da6 100644 (file)
@@ -26,7 +26,7 @@ import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.texteditor.AbstractDocumentProvider;
 
 import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
-import eu.etaxonomy.taxeditor.dataimport.DataImportSpecimenEditorInput;
+import eu.etaxonomy.taxeditor.dataimport.DerivedUnitEditorInput;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 
 
@@ -219,8 +219,8 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                if (element instanceof AbstractBulkEditorInput) {
                        return ((AbstractBulkEditorInput)element).getModel();
                }
-               else if(element instanceof DataImportSpecimenEditorInput){
-                   return ((DataImportSpecimenEditorInput) element).getResults();
+               else if(element instanceof DerivedUnitEditorInput){
+                   return ((DerivedUnitEditorInput) element).getResults();
                }
                return null;
        }
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.dataimport;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.http.client.ClientProtocolException;
@@ -33,17 +34,20 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @date 20.09.2013
  *
  */
-public class DataImportSpecimenEditorInput implements IEditorInput {
+public class DerivedUnitEditorInput implements IEditorInput {
 
-    private static Logger logger = Logger.getLogger(DataImportSpecimenEditorInput.class);
+    private static Logger logger = Logger.getLogger(DerivedUnitEditorInput.class);
 
-    private BioCaseQuery query;
+    private final BioCaseQuery query;
+
+    private List<SpecimenOrObservationBase> results;
 
     /**
      * @param results
      */
-    public DataImportSpecimenEditorInput(BioCaseQuery query) {
+    public DerivedUnitEditorInput(BioCaseQuery query) {
         this.query = query;
+        results = new ArrayList<SpecimenOrObservationBase>();
     }
 
     /* (non-Javadoc)
@@ -100,7 +104,9 @@ public class DataImportSpecimenEditorInput implements IEditorInput {
      * @return the results
      */
     public List<SpecimenOrObservationBase> getResults() {
-        List<SpecimenOrObservationBase> results = null;
+        if(results!=null && !results.isEmpty()){
+            return results;
+        }
         String errorMessage = "Could not execute query " + query;
         try {
             InputStream resultStream = new BioCaseQueryServiceWrapper().query(query);
@@ -151,7 +157,7 @@ public class DataImportSpecimenEditorInput implements IEditorInput {
         if (getClass() != obj.getClass()) {
             return false;
         }
-        DataImportSpecimenEditorInput other = (DataImportSpecimenEditorInput) obj;
+        DerivedUnitEditorInput other = (DerivedUnitEditorInput) obj;
         if (query == null) {
             if (other.query != null) {
                 return false;
index 6c76d93fb41b7736daf325c7ff0af758712d37a7..1cb2b6d99b4af8a5a7d171cfa69ba5356bb1b29a 100644 (file)
@@ -29,9 +29,10 @@ import eu.etaxonomy.cdm.api.service.TaxaAndNamesSearchMode;
 import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
 import eu.etaxonomy.cdm.api.service.config.MatchingTaxonConfigurator;
+import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
+import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
 import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;
-import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.api.service.search.LuceneMultiSearchException;
 import eu.etaxonomy.cdm.api.service.search.SearchResult;
@@ -86,7 +87,7 @@ import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
  */
 public class TransientTaxonService implements ITaxonService {
 
-    private ITaxonService defaultTaxonService;
+    private final ITaxonService defaultTaxonService;
 
     /**
      * @param defaultTaxonService
@@ -734,17 +735,6 @@ public class TransientTaxonService implements ITaxonService {
         return null;
     }
 
-    /**
-     * @param taxon
-     * @param config
-     * @throws ReferencedObjectUndeletableException
-     * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteTaxon(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator)
-     */
-    @Override
-    public void deleteTaxon(Taxon taxon, TaxonDeletionConfigurator config) throws ReferencedObjectUndeletableException {
-        defaultTaxonService.deleteTaxon(taxon, config);
-    }
-
     /**
      * @param transientObject
      * @return
@@ -1271,18 +1261,6 @@ public class TransientTaxonService implements ITaxonService {
         return defaultTaxonService.deleteSynonymRelationships(syn);
     }
 
-    /**
-     * @param synonym
-     * @param taxon
-     * @param removeNameIfPossible
-     * @param newHomotypicGroupIfNeeded
-     * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon, boolean, boolean)
-     */
-    @Override
-    public void deleteSynonym(Synonym synonym, Taxon taxon, boolean removeNameIfPossible, boolean newHomotypicGroupIfNeeded) {
-        defaultTaxonService.deleteSynonym(synonym, taxon, removeNameIfPossible, newHomotypicGroupIfNeeded);
-    }
-
     /**
      * @param taxonBase
      * @param type
@@ -1382,6 +1360,31 @@ public class TransientTaxonService implements ITaxonService {
         return defaultTaxonService.createAllInferredSynonyms(taxon, tree, doWithMisappliedNames);
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator)
+     */
+    @Override
+    public void deleteSynonym(Synonym arg0, SynonymDeletionConfigurator arg1) {
+        defaultTaxonService.deleteSynonym(arg0, arg1);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator)
+     */
+    @Override
+    public void deleteSynonym(Synonym arg0, Taxon arg1, SynonymDeletionConfigurator arg2) {
+        defaultTaxonService.deleteSynonym(arg0, arg1, arg2);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteTaxon(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator, eu.etaxonomy.cdm.model.taxon.Classification)
+     */
+    @Override
+    public void deleteTaxon(Taxon arg0, TaxonDeletionConfigurator arg1, Classification arg2)
+            throws DataChangeNoRollbackException {
+        defaultTaxonService.deleteTaxon(arg0, arg1, arg2);
+    }
+
 
 
 }
index 2923b3b362bb8eaea6705fe948ebf2aae017c1a4..62642019ae0b0269fdbf23ed155e91759180e0de 100644 (file)
@@ -20,7 +20,7 @@ import org.eclipse.ui.PlatformUI;
 
 import eu.etaxonomy.cdm.ext.biocase.BioCaseQuery;
 import eu.etaxonomy.taxeditor.dataimport.DataImportEditor;
-import eu.etaxonomy.taxeditor.dataimport.DataImportSpecimenEditorInput;
+import eu.etaxonomy.taxeditor.dataimport.DerivedUnitEditorInput;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -56,7 +56,7 @@ public class SpecimenSearchWizard extends Wizard implements IImportWizard {
 
         try {
             query = searchPage.getQuery();
-            DataImportSpecimenEditorInput input = new DataImportSpecimenEditorInput(query);
+            DerivedUnitEditorInput input = new DerivedUnitEditorInput(query);
             page.openEditor(input, DataImportEditor.ID, true);
         } catch ( PartInitException e ) {
             //Put your exception handler here if you wish to
index 47c5d234afae2cfa59f3f074c7440e9fe2b948e0..37d5e7f2f51998dd60bfa627c2625f0f006706a3 100644 (file)
@@ -1,10 +1,18 @@
 package eu.etaxonomy.taxeditor.editor.view.derivate;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
+import java.util.Set;
 
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.Viewer;
 
+import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+
 public class DerivateContentProvider implements ITreeContentProvider {
 
        @Override
@@ -19,24 +27,63 @@ public class DerivateContentProvider implements ITreeContentProvider {
 
        @Override
        public Object[] getElements(Object inputElement) {
-               return Collections.singleton(inputElement).toArray();
+           // return the parent FieldUnit if element is a DerivedUnit
+           if(inputElement instanceof DerivedUnit){
+               DerivedUnit derivedUnit = (DerivedUnit)inputElement;
+               for(SpecimenOrObservationBase original:derivedUnit.getOriginals()){
+                 if(original instanceof FieldUnit){
+                     return Collections.singletonList(original).toArray();
+                 }
+                 else{
+                     return getElements(original);
+                 }
+               }
+           }
+           // return the FieldUnit itself if element is a FieldUnit (used clone() due to recursion issues -> see javadoc of this method)
+           else if(inputElement instanceof FieldUnit){
+               FieldUnit fieldUnit = ((FieldUnit) inputElement).clone();
+               fieldUnit.getTitleCache();
+               return Collections.singleton(fieldUnit).toArray();
+           }
+               return Collections.EMPTY_LIST.toArray();
        }
 
        @Override
        public Object[] getChildren(Object parentElement) {
-               return null;
+           if(parentElement instanceof SpecimenOrObservationBase){
+               return getDerivates((SpecimenOrObservationBase) parentElement).toArray();
+           }
+           return null;
        }
 
        @Override
        public Object getParent(Object element) {
-               // TODO Auto-generated method stub
+           if(element instanceof DerivedUnit){
+               DerivedUnit derivedUnit = (DerivedUnit)element;
+               return derivedUnit.getOriginalUnit();
+           }
                return null;
        }
 
        @Override
        public boolean hasChildren(Object element) {
-               // TODO Auto-generated method stub
+           if(element instanceof SpecimenOrObservationBase){
+               SpecimenOrObservationBase specimenOrObservation = (SpecimenOrObservationBase)element;
+               for(DerivationEvent event:(Set<DerivationEvent>)specimenOrObservation.getDerivationEvents()){
+                   if(!event.getDerivatives().isEmpty()){
+                       return true;
+                   }
+               }
+           }
                return false;
        }
 
+       private List<DerivedUnit> getDerivates(SpecimenOrObservationBase specimenOrObservation){
+           List<DerivedUnit> derivates = new ArrayList<DerivedUnit>();
+           for(DerivationEvent derivationEvent:(Set<DerivationEvent>)specimenOrObservation.getDerivationEvents()){
+               derivates.addAll(derivationEvent.getDerivatives());
+           }
+           return derivates;
+       }
+
 }
index da6c9c079a7f2c218e8ece014647d64a9f7e6fcc..ce5036414611dcb8eb1234847b8b2601fa8676ce 100644 (file)
@@ -11,6 +11,7 @@ import org.eclipse.ui.IWorkbenchPart;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
@@ -38,12 +39,12 @@ public class DerivateView extends AbstractCdmEditorViewPart implements IPartCont
 
        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
-           if(part instanceof BulkEditor && selection instanceof IStructuredSelection){
-               showViewer(part, (IStructuredSelection)selection);
+           if(AbstractUtility.getActiveEditor()==null || !(AbstractUtility.getActiveEditor() instanceof BulkEditor)){
+               showEmptyPage();
                return;
            }
-           else {
-               showEmptyPage();
+           else if(part instanceof BulkEditor && selection instanceof IStructuredSelection){
+               showViewer(part, (IStructuredSelection)selection);
                return;
            }
        }