fix #5641
authorKatja Luther <k.luther@bgbm.org>
Wed, 30 Mar 2016 13:04:27 +0000 (15:04 +0200)
committerKatja Luther <k.luther@bgbm.org>
Wed, 30 Mar 2016 13:05:15 +0000 (15:05 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/ChangeToMisapplicationHandler.java

index 02288fa44f83e4923e931268f000c26badfc9fa2..2ef2872023236ed84102e73f53a620795e434a2a 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -16,6 +16,8 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.IHandler;
 import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.IHandler;
 import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
@@ -43,28 +45,32 @@ public class ChangeToMisapplicationHandler extends AbstractHandler implements
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        /** {@inheritDoc} */
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        /** {@inheritDoc} */
-       public Object execute(ExecutionEvent event) throws ExecutionException {
+       @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
                TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
                                Page.NAME);
                TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
                                Page.NAME);
-
+               Shell shell = HandlerUtil.getActiveShell(event);
+               if (!EditorUtil.forceUserSave(editor, shell)) {
+            return null;
+        }
                Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
                Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
-               
+
                AbstractPostOperation operation = null;
                try {
                        if(selectedElement instanceof Taxon){
                AbstractPostOperation operation = null;
                try {
                        if(selectedElement instanceof Taxon){
-                               operation = new ChangeConceptRelationshipTypeOperation(event.getCommand().getName(), 
+                               operation = new ChangeConceptRelationshipTypeOperation(event.getCommand().getName(),
                                                                                editor.getUndoContext(), editor.getTaxon(), (Taxon) selectedElement, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), editor);
                        }
                        if(selectedElement instanceof Synonym){
                                                                                editor.getUndoContext(), editor.getTaxon(), (Taxon) selectedElement, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), editor);
                        }
                        if(selectedElement instanceof Synonym){
-                               operation = new ChangeSynonymToMisapplicationOperation(event.getCommand().getName(), 
+                               operation = new ChangeSynonymToMisapplicationOperation(event.getCommand().getName(),
                                                editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
                        }
                                                editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
                        }
-                       
+
                        EditorUtil.executeOperation(operation);
                } catch (NotDefinedException e) {
                        logger.warn("Command name not set");
                }
                        EditorUtil.executeOperation(operation);
                } catch (NotDefinedException e) {
                        logger.warn("Command name not set");
                }
-               
+
                return null;
        }
 }
                return null;
        }
 }