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
.ArrayList
;
14 import java
.util
.List
;
16 import org
.eclipse
.core
.commands
.AbstractHandler
;
17 import org
.eclipse
.core
.commands
.ExecutionEvent
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
22 import org
.eclipse
.ui
.IEditorInput
;
23 import org
.eclipse
.ui
.IEditorPart
;
24 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import org
.eclipse
.ui
.texteditor
.IDocumentProvider
;
27 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
28 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
29 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IGroupService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.config
.NameDeletionConfigurator
;
37 import eu
.etaxonomy
.cdm
.api
.service
.config
.SynonymDeletionConfigurator
;
38 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
39 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
40 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
41 import eu
.etaxonomy
.cdm
.model
.common
.User
;
42 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
43 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
44 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
45 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
48 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
49 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
50 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
51 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
52 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
53 import eu
.etaxonomy
.taxeditor
.model
.DeleteResultMessagingUtils
;
54 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
55 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
56 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.deleteConfigurator
.DeleteConfiguratorDialog
;
57 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.deleteConfigurator
.DeleteTaxonConfiguratorComposite
;
62 * @created Mar 11, 2011
65 public class DeleteHandler
extends AbstractHandler
{
68 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
71 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
75 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
77 IEditorInput input
= editor
.getEditorInput();
79 if((input
instanceof IEntityPersistenceService
) && (selection
instanceof IStructuredSelection
)){
82 IDocumentProvider provider
= ((BulkEditor
) editor
).getDocumentProvider();
83 LineAnnotationModel model
=
84 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
87 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
89 IEntityPersistenceService persistenceService
= (IEntityPersistenceService
) input
;
92 for(Object object
: structuredSelection
.toList()){
94 LineAnnotation annotation
= (LineAnnotation
) model
.getAnnotation(object
);
95 DeleteResult result
= new DeleteResult();
96 String errorMessage
= "The object ";
99 ICdmApplicationConfiguration controller
;
100 controller
= CdmStore
.getCurrentApplicationConfiguration();
102 if (object
instanceof SpecimenOrObservationBase
){
103 IOccurrenceService service
= controller
.getOccurrenceService();
105 result
= service
.delete(((SpecimenOrObservationBase
) object
).getUuid());
106 errorMessage
= "The specimen or observation ";
108 } else if (object
instanceof Reference
){
109 IReferenceService service
= controller
.getReferenceService();
111 result
= service
.delete(((Reference
) object
).getUuid());
112 errorMessage
= "The reference ";
115 } else if (object
instanceof Group
){
116 IGroupService service
= controller
.getGroupService();
118 result
= service
.delete(((Group
) object
).getUuid());
119 errorMessage
= "The group ";
121 }else if (object
instanceof User
){
122 IUserService service
= controller
.getUserService();
124 result
= service
.delete(((User
) object
).getUuid());
125 errorMessage
= "The user ";
127 } else if (object
instanceof TaxonNameBase
){
128 INameService service
= controller
.getNameService();
130 NameDeletionConfigurator config
= new NameDeletionConfigurator();
132 DeleteConfiguratorDialog dialog
= new DeleteConfiguratorDialog(config
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", null, "Do you really want to delete the name", MessageDialog
.WARNING
, new String
[] { "Delete", "Skip" }, 0);
133 int result_dialog
= dialog
.open();
134 if (result_dialog
== 1){
137 result
= service
.delete(((TaxonNameBase
) object
).getUuid(), config
);
138 errorMessage
= "The name ";
140 } else if (object
instanceof TaxonBase
){
141 ITaxonService service
= controller
.getTaxonService();
143 if (object
instanceof Taxon
){
144 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
145 config
.setDeleteInAllClassifications(true);
146 DeleteConfiguratorDialog dialog
= new DeleteConfiguratorDialog(config
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", null, "Do you really want to delete the taxon", MessageDialog
.WARNING
, new String
[] { "Delete", "Skip" }, 0);
147 int result_dialog
= dialog
.open();
148 if (result_dialog
== 1){
151 result
= service
.deleteTaxon(((TaxonBase
) object
).getUuid(), config
, null);
152 errorMessage
= "The taxon ";
154 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
156 result
= service
.deleteSynonym(((Synonym
)object
).getUuid(), config
);
157 errorMessage
= "The synonym ";
160 } else if (object
instanceof TeamOrPersonBase
){
161 IAgentService service
= controller
.getAgentService();
162 //TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
163 result
= service
.delete(((TeamOrPersonBase
)object
).getUuid());
164 errorMessage
= "The team or person ";
166 } catch (Exception e
){
167 MessagingUtils
.errorDialog("Exception occured. Delete not possible", getClass(), e
.getMessage(), TaxeditorBulkeditorPlugin
.PLUGIN_ID
, null, true);
169 if (result
.isError() || result
.isAbort()){
170 if (!result
.getExceptions().isEmpty()) {
171 List
<String
> messages
= new ArrayList
<String
>();
172 int i
= result
.getExceptions().size();
173 for (Exception e
:result
.getExceptions()){
174 messages
.add(e
.getMessage());
176 errorMessage
+= "could not be deleted.";
177 //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
178 DeleteResultMessagingUtils
.messageDialogWithDetails(result
,errorMessage
, TaxeditorBulkeditorPlugin
.PLUGIN_ID
);
180 MessagingUtils
.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
184 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
185 if(result
.getUpdatedObjects().size() != 0 || !result
.getExceptions().isEmpty()){
186 List
<String
> messages
= new ArrayList
<String
>();
187 int i
= result
.getExceptions().size();
188 for (Exception e
:result
.getExceptions()){
189 messages
.add(e
.getMessage());
191 errorMessage
+= "was deleted but related object(s) could not be deleted. ";
192 //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
193 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, errorMessage
, TaxeditorBulkeditorPlugin
.PLUGIN_ID
);