1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.view.media.handler;
|
5
|
|
6
|
import org.eclipse.core.commands.AbstractHandler;
|
7
|
import org.eclipse.core.commands.ExecutionEvent;
|
8
|
import org.eclipse.core.commands.ExecutionException;
|
9
|
import org.eclipse.core.runtime.Status;
|
10
|
import org.eclipse.jface.dialogs.MessageDialog;
|
11
|
import org.eclipse.jface.viewers.ISelection;
|
12
|
import org.eclipse.jface.viewers.TreePath;
|
13
|
import org.eclipse.jface.viewers.TreeSelection;
|
14
|
import org.eclipse.ui.IEditorInput;
|
15
|
import org.eclipse.ui.IEditorPart;
|
16
|
import org.eclipse.ui.IWorkbenchPart;
|
17
|
import org.eclipse.ui.forms.editor.FormEditor;
|
18
|
import org.eclipse.ui.handlers.HandlerUtil;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
|
21
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
22
|
import eu.etaxonomy.cdm.model.media.ImageFile;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
25
|
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
|
26
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
27
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
28
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
29
|
import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog;
|
30
|
|
31
|
/**
|
32
|
* <p>DeleteMediaHandler class.</p>
|
33
|
*
|
34
|
* @author p.ciardelli
|
35
|
* @version $Id: $
|
36
|
*/
|
37
|
public class DeleteMediaHandler extends AbstractHandler {
|
38
|
|
39
|
/* (non-Javadoc)
|
40
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
41
|
*/
|
42
|
/** {@inheritDoc} */
|
43
|
@Override
|
44
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
45
|
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
46
|
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
|
47
|
|
48
|
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
49
|
if (editor instanceof FormEditor) {
|
50
|
editor = ((FormEditor) editor).getActiveEditor();
|
51
|
}
|
52
|
IEditorInput input = editor.getEditorInput();
|
53
|
if (input instanceof TaxonEditorInput) {
|
54
|
Taxon taxon = ((TaxonEditorInput) input).getTaxon();
|
55
|
|
56
|
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
57
|
if (selection instanceof TreeSelection) {
|
58
|
TreePath[] paths = ((TreeSelection) selection).getPaths();
|
59
|
|
60
|
int count = paths[0].getSegmentCount();
|
61
|
DescriptionElementBase element = null;
|
62
|
for (int i = 0; i < count; i++ ) {
|
63
|
if (paths[0].getSegment(i) instanceof DescriptionElementBase) {
|
64
|
element = (DescriptionElementBase) paths[0].getSegment(i);
|
65
|
break;
|
66
|
}
|
67
|
}
|
68
|
ImageFile image = (ImageFile) paths[0].getLastSegment();
|
69
|
|
70
|
AbstractPostOperation<?> operation = null;
|
71
|
// TODO use undo context specific to editor
|
72
|
MediaDeletionConfigurator config = new MediaDeletionConfigurator();
|
73
|
|
74
|
DeleteConfiguratorDialog dialog;
|
75
|
dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), Messages.DeleteMediaHandler_CONFIRM, null, Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0);
|
76
|
int result_dialog= dialog.open();
|
77
|
if (result_dialog != Status.OK){
|
78
|
return null;
|
79
|
}
|
80
|
|
81
|
|
82
|
//
|
83
|
// if (config.isOnlyRemoveFromGallery()){
|
84
|
// operation = new RemoveImageFromDescriptionElementOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), taxon, image, element, postOperationEnabled);
|
85
|
// }else{
|
86
|
// operation = new DeleteMediaOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), element, image, config, postOperationEnabled);
|
87
|
// }
|
88
|
|
89
|
EditorUtil.executeOperation(operation);
|
90
|
}
|
91
|
}
|
92
|
return null;
|
93
|
}
|
94
|
|
95
|
}
|