ref #10107: remember the last selection in bulkeditor and set it after search
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / e4 / BulkEditor.java
index 450eac4795f35be79ab64626699e2f66441b1fbb..f2dddc570450e094f1dc903818244f774bc32c35 100644 (file)
@@ -65,6 +65,7 @@ import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
 import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
 import eu.etaxonomy.taxeditor.bulkeditor.input.GroupEditorInput;
+import eu.etaxonomy.taxeditor.bulkeditor.input.MediaEditorInput;
 import eu.etaxonomy.taxeditor.bulkeditor.input.NameEditorInput;
 import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.editor.IBulkEditor;
@@ -138,6 +139,7 @@ public class BulkEditor implements IPartContentHasDetails, IConversationEnabled,
        }
 
     public void save(IProgressMonitor monitor, boolean resetMerge) {
+       IStructuredSelection selection = getLastSelection();
        for(AbstractPostOperation<?> entry:operations){
             IStatus status = Status.CANCEL_STATUS;
             final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
@@ -166,7 +168,7 @@ public class BulkEditor implements IPartContentHasDetails, IConversationEnabled,
         }
         input.saveModel(resetMerge);
 
-        IStructuredSelection selection = getSelection();
+//       IStructuredSelection selection = getSelection();
 
         dirty.setDirty(false);
         input.dispose();
@@ -176,9 +178,14 @@ public class BulkEditor implements IPartContentHasDetails, IConversationEnabled,
         if (lastQuery != null){
             bulkEditorComposite.performSearch(lastQuery, selection);
         }
+       
     }
 
 
+       private IStructuredSelection getLastSelection() {
+               return new StructuredSelection(this.bulkEditorComposite.getLastSelectedObject());
+       }
+
        @Focus
        public void setFocus() {
         //make sure to bind again if maybe in another view the conversation was unbound
@@ -323,7 +330,10 @@ public class BulkEditor implements IPartContentHasDetails, IConversationEnabled,
                     getEditorInput().addSaveCandidate(changedSpecimen);
                     input.replaceInModel(changedSpecimen);
                 }
-            }else if (element instanceof Media){
+            }else if (element instanceof Media && input instanceof MediaEditorInput){
+               getEditorInput().addSaveCandidate((Media)element);
+                input.replaceInModel((Media)element);
+            }else if (element instanceof Media ) {             
                 IStructuredSelection sel = getSelection();
                 Object firstElement = sel.getFirstElement();
                 if (firstElement instanceof TaxonBase){
@@ -334,10 +344,7 @@ public class BulkEditor implements IPartContentHasDetails, IConversationEnabled,
                     SpecimenOrObservationBase changedSpecimen = (SpecimenOrObservationBase)sel.getFirstElement();
                     getEditorInput().addSaveCandidate(changedSpecimen);
                     input.replaceInModel(changedSpecimen);
-                } else if (firstElement instanceof Media){
-                    getEditorInput().addSaveCandidate((Media)element);
-                    input.replaceInModel((Media)element);
-                }
+                } 
             }else if(element instanceof Group){
                  Group oldGroup = ((GroupEditorInput)input).getEntityFromModel((Group)element);
                  ((GroupEditorInput)input).getSaveUserCandidates().addAll(oldGroup.getMembers());