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
.cdm
.api
.application
.ICdmApplicationConfiguration
;
24 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
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
.api
.service
.config
.NameDeletionConfigurator
;
33 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
35 import eu
.etaxonomy
.cdm
.model
.common
.User
;
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
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
43 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
44 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
45 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
46 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
47 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
48 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
53 * @created Mar 11, 2011
56 public class DeleteHandler
extends AbstractHandler
{
59 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
62 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
64 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
66 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
68 IEditorInput input
= editor
.getEditorInput();
70 if((input
instanceof IEntityPersistenceService
) && (selection
instanceof IStructuredSelection
)){
73 IDocumentProvider provider
= ((BulkEditor
) editor
).getDocumentProvider();
74 LineAnnotationModel model
=
75 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
78 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
80 IEntityPersistenceService persistenceService
= (IEntityPersistenceService
) input
;
83 for(Object object
: structuredSelection
.toList()){
85 LineAnnotation annotation
= (LineAnnotation
) model
.getAnnotation(object
);
86 DeleteResult result
= new DeleteResult();
89 ICdmApplicationConfiguration controller
;
90 controller
= CdmStore
.getCurrentApplicationConfiguration();
92 if (object
instanceof SpecimenOrObservationBase
){
93 IOccurrenceService service
= controller
.getOccurrenceService();
95 result
= service
.delete(((SpecimenOrObservationBase
) object
).getUuid());
97 } else if (object
instanceof Reference
){
98 IReferenceService service
= controller
.getReferenceService();
100 result
= service
.delete(((Reference
) object
).getUuid());
103 } else if (object
instanceof Group
){
104 IGroupService service
= controller
.getGroupService();
106 result
= service
.delete(((Group
) object
).getUuid());
108 }else if (object
instanceof User
){
109 IUserService service
= controller
.getUserService();
111 result
= service
.delete(((User
) object
).getUuid());
113 } else if (object
instanceof TaxonNameBase
){
114 INameService service
= controller
.getNameService();
116 NameDeletionConfigurator config
= new NameDeletionConfigurator();
117 result
= service
.delete(((TaxonNameBase
) object
).getUuid(), config
);
119 } else if (object
instanceof TaxonBase
){
120 ITaxonService service
= controller
.getTaxonService();
122 if (object
instanceof Taxon
){
123 result
= service
.deleteTaxon(((TaxonBase
) object
).getUuid(), null, null);
125 result
= service
.deleteSynonym(((Synonym
)object
).getUuid(), null);
128 } else if (object
instanceof TeamOrPersonBase
){
129 IAgentService service
= controller
.getAgentService();
130 //TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
131 result
= service
.delete(((TeamOrPersonBase
)object
).getUuid());
133 } catch (Exception e
){
134 MessagingUtils
.errorDialog("Exception occured. Delete not possible", getClass(), e
.getMessage(), TaxeditorBulkeditorPlugin
.PLUGIN_ID
, null, true);
136 if (result
.isError() || result
.isAbort()){
137 if (!result
.getExceptions().isEmpty()) {
138 String message
= null;
139 int i
= result
.getExceptions().size();
140 for (Exception e
:result
.getExceptions()){
142 message
+= e
.getMessage();
149 MessagingUtils
.messageDialog("Delete not possible", getClass(), result
.getExceptions().toString(), null);
151 MessagingUtils
.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
155 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
156 if(result
.getUpdatedObjects().size() != 0 || !result
.getExceptions().isEmpty()){
157 MessagingUtils
.informationDialog("Delete successfull", "The object is deleted but there are updated objects: " + result
.toString());