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();
131 result
= service
.delete(((TaxonNameBase
) object
).getUuid(), config
);
132 errorMessage
= "The name ";
134 } else if (object
instanceof TaxonBase
){
135 ITaxonService service
= controller
.getTaxonService();
137 if (object
instanceof Taxon
){
138 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
139 config
.setDeleteInAllClassifications(true);
140 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);
141 int result_dialog
= dialog
.open();
142 if (result_dialog
== 1){
145 result
= service
.deleteTaxon(((TaxonBase
) object
).getUuid(), config
, null);
146 errorMessage
= "The taxon ";
148 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
149 DeleteConfiguratorDialog dialog
= new DeleteConfiguratorDialog(config
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", null, "Do you really want to delete the synonym", MessageDialog
.WARNING
, new String
[] { "Delete", "Skip" }, 0);
150 int result_dialog
= dialog
.open();
151 if (result_dialog
== 1){
154 result
= service
.deleteSynonym(((Synonym
)object
).getUuid(), config
);
155 errorMessage
= "The synonym ";
158 } else if (object
instanceof TeamOrPersonBase
){
159 IAgentService service
= controller
.getAgentService();
160 //TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
161 result
= service
.delete(((TeamOrPersonBase
)object
).getUuid());
162 errorMessage
= "The team or person ";
164 } catch (Exception e
){
165 MessagingUtils
.errorDialog("Exception occured. Delete not possible", getClass(), e
.getMessage(), TaxeditorBulkeditorPlugin
.PLUGIN_ID
, null, true);
167 if (result
.isError() || result
.isAbort()){
168 if (!result
.getExceptions().isEmpty()) {
169 List
<String
> messages
= new ArrayList
<String
>();
170 int i
= result
.getExceptions().size();
171 for (Exception e
:result
.getExceptions()){
172 messages
.add(e
.getMessage());
174 errorMessage
+= "could not be deleted.";
175 //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
176 DeleteResultMessagingUtils
.messageDialogWithDetails(result
,errorMessage
, TaxeditorBulkeditorPlugin
.PLUGIN_ID
);
178 MessagingUtils
.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
182 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
183 if(result
.getUpdatedObjects().size() != 0 || !result
.getExceptions().isEmpty()){
184 List
<String
> messages
= new ArrayList
<String
>();
185 int i
= result
.getExceptions().size();
186 for (Exception e
:result
.getExceptions()){
187 messages
.add(e
.getMessage());
189 errorMessage
+= "was deleted but related object(s) could not be deleted. ";
190 //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
191 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, errorMessage
, TaxeditorBulkeditorPlugin
.PLUGIN_ID
);