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
.dialogs
.MessageDialog
;
19 import org
.eclipse
.jface
.viewers
.ISelection
;
20 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
21 import org
.eclipse
.ui
.IEditorInput
;
22 import org
.eclipse
.ui
.IEditorPart
;
23 import org
.eclipse
.ui
.IViewPart
;
24 import org
.eclipse
.ui
.IViewReference
;
25 import org
.eclipse
.ui
.PlatformUI
;
26 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
27 import org
.eclipse
.ui
.texteditor
.IDocumentProvider
;
28 import org
.eclipse
.ui
.IWorkbenchPage
;
30 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.IGroupService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
37 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
38 import eu
.etaxonomy
.cdm
.api
.service
.config
.NameDeletionConfigurator
;
39 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
40 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
41 import eu
.etaxonomy
.cdm
.model
.common
.User
;
43 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
44 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
45 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
48 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
49 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
50 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
51 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
52 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
53 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
54 import eu
.etaxonomy
.taxeditor
.bulkeditor
.referencingobjects
.ReferencingObjectsView
;
57 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
58 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
59 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
60 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
65 * @created Mar 11, 2011
68 public class DeleteHandler
extends AbstractHandler
{
71 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
74 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
76 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_EXPERIMENTAL_FEATURES
)){
77 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
79 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
81 IEditorInput input
= editor
.getEditorInput();
83 if((input
instanceof IEntityPersistenceService
) && (selection
instanceof IStructuredSelection
)){
86 IDocumentProvider provider
= ((BulkEditor
) editor
).getDocumentProvider();
87 LineAnnotationModel model
=
88 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
91 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
93 IEntityPersistenceService persistenceService
= (IEntityPersistenceService
) input
;
96 for(Object object
: structuredSelection
.toList()){
98 LineAnnotation annotation
= (LineAnnotation
) model
.getAnnotation(object
);
99 DeleteResult result
= new DeleteResult();
102 ICdmApplicationConfiguration controller
;
103 controller
= (ICdmApplicationConfiguration
) CdmStore
.getCurrentApplicationConfiguration();
104 //persistenceService.delete(object);
105 if (object
instanceof SpecimenOrObservationBase
){
107 IOccurrenceService service
= controller
.getOccurrenceService();
108 service
.load(((SpecimenOrObservationBase
) object
).getUuid());
109 result
= service
.delete((SpecimenOrObservationBase
)object
);
110 } else if (object
instanceof Reference
){
111 IReferenceService service
= controller
.getReferenceService();
112 service
.load(((Reference
) object
).getUuid());
113 result
= service
.delete((Reference
)object
);
114 } else if (object
instanceof Group
){
115 IGroupService service
= controller
.getGroupService();
116 service
.load(((Group
) object
).getUuid());
117 result
= service
.delete((Group
) object
);
118 }else if (object
instanceof User
){
119 IUserService service
= controller
.getUserService();
120 service
.load(((User
) object
).getUuid());
121 result
= service
.delete((User
) object
);
122 } else if (object
instanceof TaxonNameBase
){
123 INameService service
= controller
.getNameService();
124 TaxonNameBase name
= service
.load(((TaxonNameBase
) object
).getUuid());
125 NameDeletionConfigurator config
= new NameDeletionConfigurator();
127 result
= service
.delete(name
, config
);
128 } else if (object
instanceof TaxonBase
){
129 ITaxonService service
= controller
.getTaxonService();
130 service
.load(((TaxonBase
) object
).getUuid());
131 if (object
instanceof Taxon
){
132 result
= service
.deleteTaxon((Taxon
)object
, null, null);
134 result
= service
.deleteSynonym((Synonym
)object
, null);
136 } else if (object
instanceof TeamOrPersonBase
){
137 IAgentService service
= controller
.getAgentService();
138 object
= service
.load(((TeamOrPersonBase
) object
).getUuid());
139 result
= service
.delete((TeamOrPersonBase
)object
);
141 } catch (Exception e
){
142 MessagingUtils
.messageDialog("Exception occured. Could not delete", getClass(), e
.getMessage(), null);
144 if (result
.isError() || result
.isAbort()){
145 if (!result
.getExceptions().isEmpty()) {
146 MessagingUtils
.messageDialog("Could not delete", getClass(), result
.getExceptions().toString(), null);
148 MessagingUtils
.messageDialog("Could not delete", getClass(), "The object could not be deleted. An exception occured.", null);
153 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
154 if(result
.getUpdatedObjects().size() != 0 && !result
.getExceptions().isEmpty()){
155 MessageDialog
.openInformation(null, "Delete successfull", "The Synonym could be deleted, but there is an updated object: " + result
.getExceptions().toString());
163 MessagingUtils
.warningDialog("Feature not enabled", getClass(), "Deletion is currently an experimental feature." +
164 "Enable it via Preferences at your own risk.");