Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / BulkEditor.java
index 5b7b601e78eae0be27acafd4fa4c1947d50811a9..5bbdb2b3f3ebd96e59f684424dae3b3902de0ea4 100644 (file)
@@ -10,6 +10,8 @@
 
 package eu.etaxonomy.taxeditor.bulkeditor;
 
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.commands.operations.UndoContext;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.dialogs.MessageDialog;
@@ -48,6 +50,7 @@ import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
@@ -70,8 +73,11 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
 
        private boolean isDirty;
 
+    private IUndoContext undoContext;
+  
        public BulkEditor() {
                super(CdmStore.createConversation());
+        undoContext = new UndoContext();
        }
 
        /** {@inheritDoc} */
@@ -110,7 +116,12 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                if (!(input instanceof AbstractBulkEditorInput)) {
                        throw new PartInitException("Invalid Input: Must be BulkEditorInput");
                }
-
+               else{
+                   AbstractBulkEditorInput<?> bulkEditorInput = (AbstractBulkEditorInput<?>)input;
+                   if(bulkEditorInput.getEntityUuid()!=null){
+                       bulkEditorInput.performSearch(new BulkEditorQuery(bulkEditorInput.getEntityUuid().toString(), null));
+                   }
+               }
                super.init(site, input);
        }
 
@@ -163,7 +174,6 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
        @Override
        public void setFocus() {
            conversation.bind();
-               searchBar.setFocus();
 
                // TODO find a better place to put this - this dialog should be shown after initial contents of
                //      Editor are displayed
@@ -172,19 +182,27 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                        isInitialFocus = false;
                }
                super.setFocus();
+               searchBar.setFocus();
+       }
+
+       /**
+        * @return the searchBar
+        */
+       public BulkEditorSearch getSearchBar() {
+               return searchBar;
        }
 
        private void displayWarningDialog() {
                IPreferenceStore prefs = PreferencesUtil.getPreferenceStore();
-               if (!prefs.getBoolean(PreferencesUtil.HIDE_BULKEDITOR_INFO)) {
+               if (!prefs.getBoolean(IPreferenceKeys.HIDE_BULKEDITOR_INFO)) {
                        String msg = "The Bulk Editor allows you to edit objects used to reference other objects, such as names, references, and authors.\n\n" +
                                                        "Any changes you make to an object in the Bulk Editor will be displayed wherever the object is used.\n\n" +
                                                        "For instance, a reference may be displayed with both a name and a descriptive element. If the reference name is changed here, the display of both the name and the descriptive element will be affected.";
                        MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm
                                                                                                (getSite().getShell(), "Bulk Editor", msg, "Do not show this message again",
-                                                                                                               false, null, PreferencesUtil.HIDE_BULKEDITOR_INFO);
+                                                                                                               false, null, IPreferenceKeys.HIDE_BULKEDITOR_INFO);
                        if (dialog.getReturnCode() == Window.OK) {
-                               prefs.setValue(PreferencesUtil.HIDE_BULKEDITOR_INFO, dialog.getToggleState());
+                               prefs.setValue(IPreferenceKeys.HIDE_BULKEDITOR_INFO, dialog.getToggleState());
                        }
                }
        }
@@ -236,8 +254,9 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
            isDirty = true;
            firePropertyChange(PROP_DIRTY);
        }
-
-       @Override
+       
+       
+       @Override
        public void doSave(IProgressMonitor progressMonitor) {
            isDirty = false;
 
@@ -264,19 +283,24 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
 
                        // TODO check if dirty, prompt save
                        if (isDirty()) {
-                               boolean proceed = MessageDialog.openQuestion(getEditorSite().getShell(),
-                                               "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
-                               if (proceed) {
+                               String[] labels = {"Save (and Search)", "Don't save (and Search)","Cancel"};
+                               MessageDialog dialog =new MessageDialog(getEditorSite().getShell(), "Save changes", null, "You have made changes that must be saved before this query can be executed. Would you like to proceed?", MessageDialog.QUESTION,labels, 0);
+                               int result = dialog.open();
+                                               //MessageDialog.openQuestion(getEditorSite().getShell(),
+                                               //"Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
+                               if (result == 0) {
                                        doSave(null);
-                               } else {
+                               } else if (result == 2){
                                        return;
                                }
                        }
-                       conversation.commit();
-                       conversation.clear();
+                       //conversation.clear();
+                       //conversation.commit(true);
 
+                       getEditorInput().dispose();
+                       getEditorInput().bind();
                        getEditorInput().performSearch(query);
-
+                       
                        refresh();
 
                        selectFirstItem();
@@ -316,4 +340,10 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
        public boolean canAttachMedia() {
            return getEditorInput() instanceof TaxonEditorInput?true:false;
        }
+
+    public IUndoContext getUndoContext() {
+        return undoContext;
+    }
+
+       
 }