/**
- *
+ *
*/
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;
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>
* @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();
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++ ) {
}
}
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;