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 java
.util
.UUID
;
15 import org
.eclipse
.core
.commands
.AbstractHandler
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.jface
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.ui
.IEditorInput
;
21 import org
.eclipse
.ui
.IEditorPart
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
23 import org
.eclipse
.ui
.texteditor
.IDocumentProvider
;
25 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.IGroupService
;
27 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
32 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
34 import eu
.etaxonomy
.cdm
.model
.common
.User
;
35 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
36 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
42 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
43 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
44 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
45 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
46 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
47 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
48 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
49 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
50 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
51 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
55 * @created Mar 11, 2011
58 public class DeleteHandler
extends AbstractHandler
{
61 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
64 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
66 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_EXPERIMENTAL_FEATURES
)){
67 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
69 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
71 IEditorInput input
= editor
.getEditorInput();
73 if((input
instanceof IEntityPersistenceService
) && (selection
instanceof IStructuredSelection
)){
76 IDocumentProvider provider
= ((BulkEditor
) editor
).getDocumentProvider();
77 LineAnnotationModel model
=
78 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
81 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
83 IEntityPersistenceService persistenceService
= (IEntityPersistenceService
) input
;
85 for(Object object
: structuredSelection
.toList()){
87 LineAnnotation annotation
= (LineAnnotation
) model
.getAnnotation(object
);
90 ICdmApplicationConfiguration controller
;
91 controller
= (ICdmApplicationConfiguration
) CdmStore
.getCurrentApplicationConfiguration();
92 //persistenceService.delete(object);
93 if (object
instanceof SpecimenOrObservationBase
){
95 IOccurrenceService service
= controller
.getOccurrenceService();
96 result
= service
.delete((SpecimenOrObservationBase
)object
);
97 } else if (object
instanceof Reference
){
98 IReferenceService service
= controller
.getReferenceService();
99 result
= service
.delete((Reference
)object
);
100 } else if (object
instanceof Group
){
101 IGroupService service
= controller
.getGroupService();
102 result
= service
.delete((Group
) object
);
103 }else if (object
instanceof User
){
104 IUserService service
= controller
.getUserService();
105 result
= service
.delete((User
) object
);
106 } else if (object
instanceof TaxonNameBase
){
107 INameService service
= controller
.getNameService();
108 result
= service
.delete((TaxonNameBase
)object
);
109 } else if (object
instanceof TaxonBase
){
110 ITaxonService service
= controller
.getTaxonService();
111 if (object
instanceof Taxon
){
112 result
= service
.deleteTaxon((Taxon
)object
, null, null);
114 result
= service
.deleteSynonym((Synonym
)object
, null);
116 } else if (object
instanceof TeamOrPersonBase
){
117 IAgentService service
= controller
.getAgentService();
118 result
= service
.delete((TeamOrPersonBase
)object
);
120 } catch (Exception e
){
121 BulkEditorUtil
.errorDialog("Could not delete", getClass(), e
.getMessage(), null);
124 UUID uuid
= UUID
.fromString(result
);
125 }catch (IllegalArgumentException e
){
126 BulkEditorUtil
.errorDialog("Could not delete", getClass(), result
, null);
128 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
133 BulkEditorUtil
.warningDialog("Feature not enabled", getClass(), "Deletion is currently an experimental feature." +
134 "Enable it via Preferences at your own risk.");