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
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.ui
.IEditorInput
;
21 import org
.eclipse
.ui
.IEditorPart
;
22 import org
.eclipse
.ui
.IViewPart
;
23 import org
.eclipse
.ui
.IViewReference
;
24 import org
.eclipse
.ui
.PlatformUI
;
25 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 import org
.eclipse
.ui
.texteditor
.IDocumentProvider
;
27 import org
.eclipse
.ui
.IWorkbenchPage
;
29 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IGroupService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
37 import eu
.etaxonomy
.cdm
.api
.service
.config
.NameDeletionConfigurator
;
38 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
39 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
40 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
.cdm
.api
.application
.ICdmApplicationConfiguration
;
49 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
50 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
51 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
52 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
53 import eu
.etaxonomy
.taxeditor
.bulkeditor
.referencingobjects
.ReferencingObjectsView
;
56 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
57 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
58 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
59 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
64 * @created Mar 11, 2011
67 public class DeleteHandler
extends AbstractHandler
{
70 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
73 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
75 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_EXPERIMENTAL_FEATURES
)){
76 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
78 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
80 IEditorInput input
= editor
.getEditorInput();
82 if((input
instanceof IEntityPersistenceService
) && (selection
instanceof IStructuredSelection
)){
85 IDocumentProvider provider
= ((BulkEditor
) editor
).getDocumentProvider();
86 LineAnnotationModel model
=
87 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
90 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
92 IEntityPersistenceService persistenceService
= (IEntityPersistenceService
) input
;
93 IViewPart part
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
94 .findView("eu.etaxonomy.taxeditor.bulkeditor.view.referencingobjects");
96 ((ReferencingObjectsView
)part
).dispose();
99 for(Object object
: structuredSelection
.toList()){
101 LineAnnotation annotation
= (LineAnnotation
) model
.getAnnotation(object
);
102 DeleteResult result
= new DeleteResult();
105 ICdmApplicationConfiguration controller
;
106 controller
= (ICdmApplicationConfiguration
) CdmStore
.getCurrentApplicationConfiguration();
107 //persistenceService.delete(object);
108 if (object
instanceof SpecimenOrObservationBase
){
110 IOccurrenceService service
= controller
.getOccurrenceService();
111 service
.load(((SpecimenOrObservationBase
) object
).getUuid());
112 result
= service
.delete((SpecimenOrObservationBase
)object
);
113 } else if (object
instanceof Reference
){
114 IReferenceService service
= controller
.getReferenceService();
115 service
.load(((Reference
) object
).getUuid());
116 result
= service
.delete((Reference
)object
);
117 } else if (object
instanceof Group
){
118 IGroupService service
= controller
.getGroupService();
119 service
.load(((Group
) object
).getUuid());
120 result
= service
.delete((Group
) object
);
121 }else if (object
instanceof User
){
122 IUserService service
= controller
.getUserService();
123 service
.load(((User
) object
).getUuid());
124 result
= service
.delete((User
) object
);
125 } else if (object
instanceof TaxonNameBase
){
126 INameService service
= controller
.getNameService();
127 TaxonNameBase name
= service
.load(((TaxonNameBase
) object
).getUuid());
128 NameDeletionConfigurator config
= new NameDeletionConfigurator();
130 result
= service
.delete(name
, config
);
131 } else if (object
instanceof TaxonBase
){
132 ITaxonService service
= controller
.getTaxonService();
133 service
.load(((TaxonBase
) object
).getUuid());
134 if (object
instanceof Taxon
){
135 result
= service
.deleteTaxon((Taxon
)object
, null, null);
137 result
= service
.deleteSynonym((Synonym
)object
, null);
139 } else if (object
instanceof TeamOrPersonBase
){
140 IAgentService service
= controller
.getAgentService();
141 object
= service
.load(((TeamOrPersonBase
) object
).getUuid());
142 result
= service
.delete((TeamOrPersonBase
)object
);
144 } catch (Exception e
){
145 MessagingUtils
.messageDialog("Exception occured. Could not delete", getClass(), e
.getMessage(), null);
147 if (result
.isError() || result
.isAbort()|| !result
.getExceptions().isEmpty()){
148 if (!result
.getExceptions().isEmpty()) {
149 MessagingUtils
.messageDialog("Could not delete", getClass(), result
.getExceptions().get(0).getMessage(), null);
151 MessagingUtils
.messageDialog("Could not delete", getClass(), "The object could not be deleted. An exception occured.", null);
155 if (result
.isOk() && result
.getExceptions().isEmpty()){
156 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
161 ((ReferencingObjectsView
)part
).refresh();
163 part
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
164 .findView("eu.etaxonomy.taxeditor.editor.view.descriptive");
166 //((DescriptiveViewPart)part).dispose();
171 MessagingUtils
.warningDialog("Feature not enabled", getClass(), "Deletion is currently an experimental feature." +
172 "Enable it via Preferences at your own risk.");