4 package eu
.etaxonomy
.taxeditor
.editor
.view
.media
.handler
;
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
;
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
;
32 * <p>DeleteMediaHandler class.</p>
37 public class DeleteMediaHandler
extends AbstractHandler
{
40 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
45 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
46 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
48 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
49 if (editor
instanceof FormEditor
) {
50 editor
= ((FormEditor
) editor
).getActiveEditor();
52 IEditorInput input
= editor
.getEditorInput();
53 if (input
instanceof TaxonEditorInput
) {
54 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
56 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
57 if (selection
instanceof TreeSelection
) {
58 TreePath
[] paths
= ((TreeSelection
) selection
).getPaths();
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
);
68 ImageFile image
= (ImageFile
) paths
[0].getLastSegment();
70 AbstractPostOperation operation
= null;
71 // TODO use undo context specific to editor
72 MediaDeletionConfigurator config
= new MediaDeletionConfigurator();
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
){
83 // if (config.isOnlyRemoveFromGallery()){
84 // operation = new RemoveImageFromDescriptionElementOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), taxon, image, element, postOperationEnabled);
86 // operation = new DeleteMediaOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), element, image, config, postOperationEnabled);
89 EditorUtil
.executeOperation(operation
);