minor
authorKatja Luther <k.luther@bgbm.org>
Tue, 17 Jan 2017 10:57:44 +0000 (11:57 +0100)
committerKatja Luther <k.luther@bgbm.org>
Tue, 17 Jan 2017 10:57:44 +0000 (11:57 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java

index 1dfa1451dbbcbadfe3f2342c1a6ddb337e79ea53..cfb1c3afc8ae4dffc18690cfeec739b7403b50dc 100644 (file)
@@ -1,12 +1,13 @@
 /**
- * 
+ *
  */
 package eu.etaxonomy.taxeditor.editor.view.media.handler;
 
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.TreePath;
 import org.eclipse.jface.viewers.TreeSelection;
@@ -16,15 +17,15 @@ import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.forms.editor.FormEditor;
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.media.ImageFile;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
-import eu.etaxonomy.taxeditor.editor.view.media.operation.RemoveImageFromDescriptionElementOperation;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog;
 
 /**
  * <p>DeleteMediaHandler class.</p>
@@ -38,10 +39,11 @@ public class DeleteMediaHandler extends AbstractHandler {
         * @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 {
                IWorkbenchPart part = HandlerUtil.getActivePart(event);
                IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
-                               
+
                IEditorPart editor = HandlerUtil.getActiveEditor(event);
                if (editor instanceof FormEditor) {
                        editor = ((FormEditor) editor).getActiveEditor();
@@ -49,11 +51,11 @@ public class DeleteMediaHandler extends AbstractHandler {
                IEditorInput input = editor.getEditorInput();
                if (input instanceof TaxonEditorInput) {
                        Taxon taxon = ((TaxonEditorInput) input).getTaxon();
-                       
+
                        ISelection selection = HandlerUtil.getCurrentSelection(event);
                        if (selection instanceof TreeSelection) {
                                TreePath[] paths = ((TreeSelection) selection).getPaths();
-                               
+
                                int count = paths[0].getSegmentCount();
                                DescriptionElementBase element = null;
                                for (int i = 0; i < count; i++ ) {
@@ -63,16 +65,27 @@ public class DeleteMediaHandler extends AbstractHandler {
                                        }
                                }
                                ImageFile image = (ImageFile) paths[0].getLastSegment();
-                               
+
                                AbstractPostOperation operation = null;
-                               try {
-                                       // TODO use undo context specific to editor
-                                       operation = new RemoveImageFromDescriptionElementOperation(event.getCommand().getName(), 
-                                                       EditorUtil.getUndoContext(), taxon, image, element, postOperationEnabled);
-                                       EditorUtil.executeOperation(operation);
-                               } catch (NotDefinedException e) {
-                                       MessagingUtils.warn(getClass(), "Command name not set.");
-                               }
+                               // TODO use undo context specific to editor
+                MediaDeletionConfigurator config = new MediaDeletionConfigurator();
+
+                DeleteConfiguratorDialog dialog;
+                dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), "Confirm Deletion",  null,  "Do you really want to delete the media?", MessageDialog.WARNING, new String[] { "Delete", "Skip" }, 0);
+                int result_dialog= dialog.open();
+                if (result_dialog != Status.OK){
+                    return null;
+                }
+
+
+//
+//                                 if (config.isOnlyRemoveFromGallery()){
+//                                     operation = new RemoveImageFromDescriptionElementOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), taxon, image, element, postOperationEnabled);
+//                                 }else{
+//                                     operation = new DeleteMediaOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), element, image, config, postOperationEnabled);
+//                                 }
+
+                EditorUtil.executeOperation(operation);
                        }
                }
                return null;