3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.bulkeditor
.handler
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.jface
.viewers
.ISelection
;
17 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import org
.eclipse
.ui
.IEditorInput
;
19 import org
.eclipse
.ui
.IEditorPart
;
20 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
21 import org
.eclipse
.ui
.texteditor
.IDocumentProvider
;
23 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
24 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
25 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
26 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
27 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
28 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
29 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 * @created Mar 11, 2011
36 public class DeleteHandler
extends AbstractHandler
{
39 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
42 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
44 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_EXPERIMENTAL_FEATURES
)){
45 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
47 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
49 IEditorInput input
= editor
.getEditorInput();
51 if((input
instanceof IEntityPersistenceService
) && (selection
instanceof IStructuredSelection
)){
54 IDocumentProvider provider
= ((BulkEditor
) editor
).getDocumentProvider();
55 LineAnnotationModel model
=
56 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
59 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
61 IEntityPersistenceService persistenceService
= (IEntityPersistenceService
) input
;
63 for(Object object
: structuredSelection
.toList()){
65 LineAnnotation annotation
= (LineAnnotation
) model
.getAnnotation(object
);
68 persistenceService
.delete(object
);
69 } catch (Exception e
){
70 BulkEditorUtil
.errorDialog("Could not delete", getClass(), e
.getMessage(), null);
72 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
77 BulkEditorUtil
.warningDialog("Feature not enabled", getClass(), "Deletion is currently an experimental feature." +
78 "Enable it via Preferences at your own risk.");