Refresh hierarchy tree after searching
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 7 Oct 2015 07:20:38 +0000 (09:20 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 7 Oct 2015 07:20:38 +0000 (09:20 +0200)
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/searchFilter/DerivateSearchCompositeController.java

index e754897f4f9447995668d95784deb3f951a3e2ab..bc3f8b08fd2f2f467dfbe2d13b4086a07a32de1d 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.UUID;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.MenuManager;
@@ -245,6 +246,10 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         changed(null);
     }
 
+    protected void setRootEntities(Collection<UUID> rootEntityUuids){
+        ((DerivateViewEditorInput)getEditorInput()).updateRootEntities(rootEntityUuids);
+    }
+
     /**
      * Refreshes the derivate hierarchy tree and expands the tree
      * to show and select the given object.
index 9aba5bfb6954f12c1b7d267321de121306f2f6f1..e0e5efc73865a30af6946722f8b5b1f11a25be1e 100644 (file)
@@ -11,6 +11,7 @@ package eu.etaxonomy.taxeditor.editor.view.derivate;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -46,7 +47,7 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
     /**
      * The selected derivate {@link UUID}s
      */
-    private final Set<SpecimenOrObservationBase<?>> derivateEntities;
+    private Set<SpecimenOrObservationBase<?>> derivateEntities;
     /**
      * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
      */
@@ -86,24 +87,7 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
         //then be used for the hashCode, equals methods
         initSession();
         this.conversationHolder = CdmStore.createConversation();
-        this.derivateEntities = new HashSet<SpecimenOrObservationBase<?>>();
-        this.rootEntities = new HashSet<SpecimenOrObservationBase<?>>();
-        for (UUID uuid : derivateUuids) {
-            SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
-            derivateEntities.add(derivate);
-            if(derivate instanceof FieldUnit){
-                rootEntities.add(derivate);
-            }
-            else if(derivate instanceof DerivedUnit){
-                SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
-                if(topMostDerivate!=null){
-                    rootEntities.add(topMostDerivate);
-                }
-            }
-        }
-        if(rootEntities.isEmpty()){
-            rootEntities = derivateEntities;
-        }
+        updateRootEntities(derivateUuids);
 
     }
 
@@ -193,9 +177,6 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
         return conversationHolder;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -204,9 +185,6 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
         return result;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
     @Override
     public boolean equals(Object obj) {
         if (this == obj) {
@@ -229,9 +207,6 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
         return true;
     }
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
-     */
     @Override
     public void merge() {
         if(CdmStore.getCurrentSessionManager().isRemoting()) {
@@ -240,9 +215,6 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
 
     }
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
-     */
     @Override
     public Map<Object, List<String>> getPropertyPathsMap() {
         List<String> specimenPropertyPaths = Arrays.asList(new String[] {
@@ -261,5 +233,25 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
         return specimenPropertyPathMap;
     }
 
+    public void updateRootEntities(Collection<UUID> derivateUuids) {
+        this.derivateEntities = new HashSet<SpecimenOrObservationBase<?>>();
+        this.rootEntities = new HashSet<SpecimenOrObservationBase<?>>();
+        for (UUID uuid : derivateUuids) {
+            SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
+            derivateEntities.add(derivate);
+            if(derivate instanceof FieldUnit){
+                rootEntities.add(derivate);
+            }
+            else if(derivate instanceof DerivedUnit){
+                SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
+                if(topMostDerivate!=null){
+                    rootEntities.add(topMostDerivate);
+                }
+            }
+        }
+        if(rootEntities.isEmpty()){
+            rootEntities = derivateEntities;
+        }
+    }
 
 }
index 09553a06f0c86e88daca140947d12428d37dbd3c..b1f0190618f80c1bc2b1e9fa7a8ae692f4005c1d 100644 (file)
@@ -11,13 +11,13 @@ package eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.UUID;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.forms.widgets.TableWrapData;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
@@ -26,6 +26,7 @@ import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.SearchManager;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
@@ -106,8 +107,15 @@ public class DerivateSearchCompositeController implements Listener{
             }
             occurrences = specimensWithNoDetermination;
         }
-        //TODO add to DerivateViewEditorInput
-//        derivateSearchComposite.getResultViewer().setInput(occurrences);
+        List<UUID> derivateUuids = new ArrayList<UUID>();
+        for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
+            derivateUuids.add(specimenOrObservationBase.getUuid());
+        }
+        //update tree
+        DerivateViewEditorInput editorInput = (DerivateViewEditorInput)derivativeEditor.getEditorInput();
+        editorInput.updateRootEntities(derivateUuids);
+        derivativeEditor.getViewer().setInput(editorInput.getRootEntities());
+        derivativeEditor.refreshTree();
     }
 
     @Override
@@ -139,7 +147,7 @@ public class DerivateSearchCompositeController implements Listener{
         }
     }
 
-    public void setLayoutData(TableWrapData layoutData){
+    public void setLayoutData(Object layoutData){
         derivateSearchComposite.setLayoutData(layoutData);
     }