ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / BulkEditor.java
index bbd7e4d2025753158b41e538665acdcb46c50013..ff0356c16d2716730b518420a106c113602e58e2 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
 * European Distributed Institute of Taxonomy
@@ -10,6 +9,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;
@@ -34,9 +35,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 
 import eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineDocumentProvider;
@@ -44,20 +43,18 @@ import eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
 import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
-import eu.etaxonomy.taxeditor.bulkeditor.referencingobjects.ReferencingObjectsView;
+import eu.etaxonomy.taxeditor.bulkeditor.input.OccurrenceEditorInput;
+import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart;
 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;
 
 /**
- * <p>
- * BulkEditor class.
- * </p>
- *
  * @author p.ciardelli
  * @created 07.07.2009
  * @version 1.0
@@ -76,16 +73,13 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
 
        private boolean isDirty;
 
-       /**
-        * <p>Constructor for BulkEditor.</p>
-        */
+    private IUndoContext undoContext;
+  
        public BulkEditor() {
                super(CdmStore.createConversation());
+        undoContext = new UndoContext();
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.editors.text.TextEditor#initializeEditor()
-        */
        /** {@inheritDoc} */
        @Override
        protected void initializeEditor() {
@@ -103,9 +97,6 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                setSourceViewerConfiguration(new BulkEditorViewerConfiguration(lineDisplayStrategy));
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.bulkeditor.ListEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
-        */
        /** {@inheritDoc} */
        @Override
     protected ISourceViewer createSourceViewer(Composite parent,
@@ -117,9 +108,6 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                return viewer;
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.bulkeditor.AnnotatedLineEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
-        */
        /** {@inheritDoc} */
        @Override
        public void init(IEditorSite site, IEditorInput input)
@@ -128,13 +116,15 @@ 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);
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
-        */
        /** {@inheritDoc} */
        @Override
        public void createPartControl(Composite parent) {
@@ -164,9 +154,6 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                }
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.editors.text.TextEditor#dispose()
-        */
        /** {@inheritDoc} */
        @Override
        public void dispose() {
@@ -177,23 +164,16 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
        }
 
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#isEditable()
-        */
        /** {@inheritDoc} */
        @Override
        public boolean isEditable() {
                return false;
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#setFocus()
-        */
        /** {@inheritDoc} */
        @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
@@ -201,29 +181,32 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                        displayWarningDialog();
                        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());
                        }
                }
        }
 
-       /**
-        * @param control
-        */
        private void addToggleMergeCandidateListener(Control control) {
                control.addMouseListener(new MouseAdapter() {
                        @Override
@@ -235,11 +218,6 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                });
        }
 
-       /**
-        * <p>toggleMergeCandidateAnnotation</p>
-        *
-        * @param line a int.
-        */
        public void toggleMergeCandidateAnnotation(int line) {
 
                IDocument document = getSourceViewer().getDocument();
@@ -261,9 +239,6 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                }
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#isDirty()
-        */
        @Override
        public boolean isDirty() {
            if(isDirty){
@@ -279,18 +254,16 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
            isDirty = true;
            firePropertyChange(PROP_DIRTY);
        }
-
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#doSave(org.eclipse.core.runtime.IProgressMonitor)
-        */
-       @Override
+       
+       
+       @Override
        public void doSave(IProgressMonitor progressMonitor) {
            isDirty = false;
-          
+
            super.doSave(progressMonitor);
 
            selectFirstItem();
-          
+
                getSourceViewer().getTextWidget().setFocus();
 
        }
@@ -304,26 +277,30 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
 //             firePropertyChange(PROP_DIRTY);
        }
 
-       /* (non-Javadoc)
-        * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
-        */
        /** {@inheritDoc} */
        public void performSearch(BulkEditorQuery query) {
                if (query != null) {
 
                        // 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.clear();
+                       //conversation.commit(true);
 
+                       getEditorInput().dispose();
+                       getEditorInput().bind();
                        getEditorInput().performSearch(query);
-
+                       
                        refresh();
 
                        selectFirstItem();
@@ -337,9 +314,6 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                getSelectionProvider().setSelection(selection);
        }
 
-       /**
-        *
-        */
        public void refresh() {
                if(getDocumentProvider().getAnnotationModel(getEditorInput()) != null){
                        ((AnnotationModel) getDocumentProvider().getAnnotationModel(getEditorInput())).removeAllAnnotations();
@@ -361,4 +335,15 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
                menu.remove(ITextEditorActionConstants.SHIFT_LEFT);
                menu.remove(ITextEditorActionConstants.CONTEXT_PREFERENCES);
        }
+
+       @Override
+       public boolean canAttachMedia() {
+           return (getEditorInput() instanceof TaxonEditorInput || getEditorInput() instanceof OccurrenceEditorInput) ?true:false;
+       }
+
+    public IUndoContext getUndoContext() {
+        return undoContext;
+    }
+
+       
 }