Set taxon filter when opening derivativwe editor from taxon navigator
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 30 Mar 2016 09:18:06 +0000 (11:18 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 30 Mar 2016 09:19:00 +0000 (11:19 +0200)
#5514

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewEditorInput.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/OpenDerivativeEditorForTaxonNode.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchCompositeController.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java

index b319d21..632d315 100644 (file)
@@ -203,6 +203,8 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
 
         //init tree
         updateRootEntities(((DerivateViewEditorInput)getEditorInput()).getDerivativeUuids());
+        //set taxon filter
+        derivateSearchCompositeController.setTaxonFilter(((DerivateViewEditorInput) getEditorInput()).getTaxonUuid());
         //reset status bar
         getEditorSite().getActionBars().getStatusLineManager().setMessage("");
 
@@ -276,7 +278,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
             getEditorSite().getActionBars().getStatusLineManager().setMessage(rootElements.size() +" derivative hierarchies found");
 
             //set selection to derivatives if the filter criteria
-            //taxon assignment or or derivative type are set
+            //taxon assignment or derivative type are set
             if(derivates!=null && !derivateSearchCompositeController.isDefaultSearch()){
                 List<TreeNode> nodesToSelect = new ArrayList<TreeNode>();
                 for (SpecimenOrObservationBase specimenOrObservationBase : derivates) {
@@ -566,7 +568,9 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
     @Override
     public void contextStart(IMemento memento, IProgressMonitor monitor) {
         derivateSearchCompositeController.setEnabled(!listenToSelectionChange);
-        viewer.getTree().setEnabled(true);
+        if(!viewer.getTree().isDisposed()){
+            viewer.getTree().setEnabled(true);
+        }
         refreshTree();
     }
 
index 808ed74..76358b0 100644 (file)
@@ -25,19 +25,29 @@ import org.eclipse.ui.IPersistableElement;
  */
 public class DerivateViewEditorInput implements IEditorInput {
 
-    Collection<UUID> derivativeUuids;
+    private Collection<UUID> derivativeUuids;
+    private UUID taxonUuid;
 
     public DerivateViewEditorInput() {
     }
 
-    public DerivateViewEditorInput(Collection<UUID> derivativeUuids) {
+    public DerivateViewEditorInput(Collection<UUID> derivativeUuids, UUID taxonUuid) {
         this.derivativeUuids = derivativeUuids;
+        this.taxonUuid = taxonUuid;
+    }
+
+    public DerivateViewEditorInput(Collection<UUID> derivativeUuids) {
+        this(derivativeUuids, null);
     }
 
     public Collection<UUID> getDerivativeUuids() {
         return derivativeUuids;
     }
 
+    public UUID getTaxonUuid() {
+        return taxonUuid;
+    }
+
     @Override
     public Object getAdapter(Class adapter) {
         return null;
index 6fdbcd4..fbaa4e8 100644 (file)
@@ -10,6 +10,7 @@ import org.eclipse.ui.PartInitException;
 
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
@@ -28,13 +29,16 @@ public class OpenDerivativeEditorForTaxonNode extends DefaultOpenHandlerBase<Tax
 
     @Override
     protected void open(ExecutionEvent event, TaxonNode entity) {
-        List<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, entity.getTaxon(), null, null, null, null, null);
+        FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
+        UUID taxonUuid = entity.getTaxon().getUuid();
+        config.setAssociatedTaxonUuid(taxonUuid);
+        List<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).findByTitle(config).getRecords();
         Collection<UUID> specimenUuids = new ArrayList<UUID>();
         for (SpecimenOrObservationBase specimenOrObservationBase : specimens) {
             specimenUuids.add(specimenOrObservationBase.getUuid());
         }
         try {
-            EditorUtil.open(new DerivateViewEditorInput(specimenUuids));
+            EditorUtil.open(new DerivateViewEditorInput(specimenUuids, taxonUuid));
         } catch (PartInitException e) {
             MessagingUtils.error(OpenDerivateViewHandler.class, "Derivative Editor could not be opened", e);
         }
index 0cf0191..3f07f19 100644 (file)
@@ -10,6 +10,7 @@
 package eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter;
 
 import java.util.List;
+import java.util.UUID;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
@@ -19,12 +20,16 @@ import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Widget;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
 import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator.AssignmentStatus;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.SearchManager;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
 import eu.etaxonomy.taxeditor.ui.mvc.combo.EnumTermComboController;
@@ -137,7 +142,7 @@ public class DerivateSearchCompositeController implements Listener{
 
     /**
      * Checks whether or not the search criteria are set to their default value.<br>
-     * This does not consider the title search field. 
+     * This does not consider the title search field.
      * @return <code>true</code> if search criteria are set to default.
      */
     public boolean isDefaultSearch(){
@@ -163,4 +168,15 @@ public class DerivateSearchCompositeController implements Listener{
         labelProvider.setConversation(conversationHolder);
     }
 
+    public void setTaxonFilter(UUID taxonUuid) {
+        TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(taxonUuid);
+        if(taxonBase!=null && taxonBase.isInstanceOf(Taxon.class)){
+            selectedTaxon = HibernateProxyHelper.deproxy(taxonBase, Taxon.class);
+            derivateSearchComposite.getTextTaxonName().setText(taxonBase.getTitleCache());
+            derivateSearchComposite.getLbltaxonAssignment().setEnabled(false);
+            derivateSearchComposite.getComboTaxonAssignment().select(DerivateSearchComposite.ASSIGNED_SPECIMENS);
+            derivateSearchComposite.getComboTaxonAssignment().setEnabled(false);
+        }
+    }
+
 }
index 91ae87e..e4dab75 100644 (file)
@@ -39,7 +39,6 @@ import eu.etaxonomy.cdm.model.common.User;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.name.NameRelationship;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
@@ -179,14 +178,6 @@ public class SearchManager {
                        "mediaSpecimen"
                });
 
-               if(configurator.getClazz()==null){
-                   if(showFieldUnits){
-                       configurator.setClazz(SpecimenOrObservationBase.class);
-                   }
-                   else{
-                       configurator.setClazz(DerivedUnit.class);
-                   }
-               }
                List<String> occurrencePropertyPaths = new ArrayList<String>();
                occurrencePropertyPaths.addAll(BASE_OCCURRENCE_INIT_STRATEGY);
                for(String propertyPath:BASE_OCCURRENCE_INIT_STRATEGY) {