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
.model
.MessagingUtils
;
47 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
52 * @created Mar 11, 2011
55 public class DeleteHandler
extends AbstractHandler
{
58 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
61 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
63 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
65 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
67 IEditorInput input
= editor
.getEditorInput();
69 if((input
instanceof IEntityPersistenceService
) && (selection
instanceof IStructuredSelection
)){
72 IDocumentProvider provider
= ((BulkEditor
) editor
).getDocumentProvider();
73 LineAnnotationModel model
=
74 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
77 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
79 IEntityPersistenceService persistenceService
= (IEntityPersistenceService
) input
;
82 for(Object object
: structuredSelection
.toList()){
84 LineAnnotation annotation
= (LineAnnotation
) model
.getAnnotation(object
);
85 DeleteResult result
= new DeleteResult();
88 ICdmApplicationConfiguration controller
;
89 controller
= CdmStore
.getCurrentApplicationConfiguration();
91 if (object
instanceof SpecimenOrObservationBase
){
92 IOccurrenceService service
= controller
.getOccurrenceService();
94 result
= service
.delete(((SpecimenOrObservationBase
) object
).getUuid());
96 } else if (object
instanceof Reference
){
97 IReferenceService service
= controller
.getReferenceService();
99 result
= service
.delete(((Reference
) object
).getUuid());
102 } else if (object
instanceof Group
){
103 IGroupService service
= controller
.getGroupService();
105 result
= service
.delete(((Group
) object
).getUuid());
107 }else if (object
instanceof User
){
108 IUserService service
= controller
.getUserService();
110 result
= service
.delete(((User
) object
).getUuid());
112 } else if (object
instanceof TaxonNameBase
){
113 INameService service
= controller
.getNameService();
115 NameDeletionConfigurator config
= new NameDeletionConfigurator();
116 result
= service
.delete(((TaxonNameBase
) object
).getUuid(), config
);
118 } else if (object
instanceof TaxonBase
){
119 ITaxonService service
= controller
.getTaxonService();
121 if (object
instanceof Taxon
){
122 result
= service
.deleteTaxon(((TaxonBase
) object
).getUuid(), null, null);
124 result
= service
.deleteSynonym(((Synonym
)object
).getUuid(), null);
127 } else if (object
instanceof TeamOrPersonBase
){
128 IAgentService service
= controller
.getAgentService();
129 //TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
130 result
= service
.delete(((TeamOrPersonBase
)object
).getUuid());
132 } catch (Exception e
){
133 MessagingUtils
.messageDialog("Exception occured. Could not delete", getClass(), e
.getMessage(), null);
135 if (result
.isError() || result
.isAbort()){
136 if (!result
.getExceptions().isEmpty()) {
137 MessagingUtils
.messageDialog("Could not delete", getClass(), result
.getExceptions().toString(), null);
139 MessagingUtils
.messageDialog("Could not delete", getClass(), "The object could not be deleted. An exception occured.", null);
144 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
145 if(result
.getUpdatedObjects().size() != 0 && !result
.getExceptions().isEmpty()){
146 MessagingUtils
.informationDialog("Delete successfull", "The object is deleted but there are updated objects: " + result
.toString());