2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.handler
;
12 import org
.eclipse
.core
.commands
.ExecutionEvent
;
13 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
14 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
15 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.core
.runtime
.Status
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.jface
.viewers
.TreeNode
;
20 import org
.eclipse
.ui
.IEditorPart
;
21 import org
.eclipse
.ui
.IWorkbenchPart
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
25 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
26 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
27 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.config
.SpecimenDeleteConfigurator
;
29 import eu
.etaxonomy
.cdm
.api
.service
.molecular
.ISequenceService
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.molecular
.Sequence
;
32 import eu
.etaxonomy
.cdm
.model
.molecular
.SingleRead
;
33 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
34 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
35 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
36 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
37 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.DerivateView
;
38 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.operation
.DeleteDerivateOperation
;
39 import eu
.etaxonomy
.taxeditor
.model
.DeleteResultMessagingUtils
;
40 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
41 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
42 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
43 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
44 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
45 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.deleteConfigurator
.DeleteConfiguratorDialog
;
46 import eu
.etaxonomy
.taxeditor
.view
.derivateSearch
.DerivateLabelProvider
;
54 public class DeleteDerivateHandler
extends RemotingCdmHandler
{
56 SpecimenDeleteConfigurator deleteConfigurator
;
63 public DeleteDerivateHandler(String label
) {
71 public DeleteDerivateHandler() {
72 super(Messages
.DeleteDerivateHandler_LABEL
);
76 // /** {@inheritDoc} */
78 // public Object execute(ExecutionEvent event) throws ExecutionException {
79 // IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveSite(event).getSelectionProvider().getSelection();
81 // IWorkbenchPart part = HandlerUtil.getActivePart(event);
82 // IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
85 // String label = event.getCommand().getName();
87 // IUndoContext undoContext = EditorUtil.getUndoContext();
89 // if(selection.size()>0){
90 // Object object = selection.iterator().next();
92 // if(object instanceof TreeNode){
93 // Object value = ((TreeNode) object).getValue();
94 // if(value instanceof SpecimenOrObservationBase<?> || value instanceof Sequence || value instanceof SingleRead){
95 // if(postOperationEnabled instanceof IConversationEnabled){
96 // ConversationHolder conversationHolder = ((IConversationEnabled) postOperationEnabled).getConversationHolder();
97 // label += " "+DerivateLabelProvider.getDerivateText(value, conversationHolder); //$NON-NLS-1$
99 // SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
100 // boolean deepDelete = event.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.derivate.deepDelete"); //$NON-NLS-1$
101 // config.setDeleteChildren(deepDelete);
102 // config.setDeleteMolecularData(deepDelete);
103 // DeleteDerivateOperation deleteDerivateOperation = new DeleteDerivateOperation(label, undoContext, (CdmBase) value, (TreeNode) object, postOperationEnabled, config);
104 // IStatus status = AbstractUtility.executeOperation(deleteDerivateOperation);
105 // DerivateView derivateView = (DerivateView)postOperationEnabled;
106 // if(derivateView.postOperation(null)){
107 // derivateView.remove(object);
109 // // derivateView.updateRootEntities();
110 // //update DerivateView
117 // MessagingUtils.error(getClass(), Messages.DeleteDerivateHandler_INVALID_SELECTION, null);
121 // } catch (NotDefinedException e) {
122 // MessagingUtils.warn(getClass(), "Command name not set"); //$NON-NLS-1$
131 public IStatus
allowOperations(ExecutionEvent event
) {
132 //check whether object can be deleted
133 editor
= HandlerUtil
.getActiveEditor(event
);
134 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
135 .getCurrentSelection(event
);
136 AbstractPostOperation operation
;
137 deleteConfigurator
= new SpecimenDeleteConfigurator();
139 String confirmationQuestion
= Messages
.DeleteDerivateOperation_REALLY_DELETE
;
140 if(deleteConfigurator
.isDeleteChildren()){
141 confirmationQuestion
+= Messages
.DeleteDerivateOperation_AND_CHILDREN
;
144 if(editor
.isDirty()){
145 MessagingUtils
.warningDialog(DerivateView
.VIEW_HAS_UNSAVED_CHANGES
, this, DerivateView
.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION
);
146 return Status
.CANCEL_STATUS
;
149 confirmationQuestion
+= "?"; //$NON-NLS-1$
150 if(!DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfigurator
, null, Messages
.DeleteDerivateOperation_CONFIRM
, confirmationQuestion
)){
151 return Status
.CANCEL_STATUS
;
153 Object object
= selection
.iterator().next();
154 DeleteResult deleteResult
;
155 if(object
instanceof TreeNode
){
156 Object value
= ((TreeNode
) object
).getValue();
157 if(value
instanceof SpecimenOrObservationBase
<?
> || value
instanceof Sequence
|| value
instanceof SingleRead
){
158 if (value
instanceof Sequence
|| value
instanceof SingleRead
){
159 deleteResult
= CdmStore
.getService(ISequenceService
.class).isDeletable(((CdmBase
)value
).getUuid(), deleteConfigurator
);
161 deleteResult
= CdmStore
.getService(IOccurrenceService
.class).isDeletable(((CdmBase
)value
).getUuid(), deleteConfigurator
);
163 if (deleteResult
.isOk() || deleteResult
.getExceptions().isEmpty()){ return Status
.OK_STATUS
;}
165 if (!deleteResult
.isOk()){
166 DeleteResultMessagingUtils
.messageDialogWithDetails(deleteResult
, Messages
.DeleteDerivateOperation_DELETE_FAILED
, TaxeditorEditorPlugin
.PLUGIN_ID
);
168 if (!deleteResult
.getExceptions().isEmpty()){
169 DeleteResultMessagingUtils
.messageDialogWithDetails(deleteResult
, Messages
.DeleteDerivateHandler_SUCCESSFULL_BUT_EXCEPTIONS
, TaxeditorEditorPlugin
.PLUGIN_ID
);
173 return Status
.CANCEL_STATUS
;
179 return Status
.CANCEL_STATUS
;
187 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
188 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getActiveSite(event
).getSelectionProvider().getSelection();
190 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
191 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
194 String label
= event
.getCommand().getName();
196 IUndoContext undoContext
= EditorUtil
.getUndoContext();
198 if(selection
.size()>0){
199 Object object
= selection
.iterator().next();
201 if(object
instanceof TreeNode
){
202 node
= (TreeNode
)object
;
203 Object value
= ((TreeNode
) object
).getValue();
204 if(value
instanceof SpecimenOrObservationBase
<?
> || value
instanceof Sequence
|| value
instanceof SingleRead
){
205 if(postOperationEnabled
instanceof IConversationEnabled
){
206 ConversationHolder conversationHolder
= ((IConversationEnabled
) postOperationEnabled
).getConversationHolder();
207 label
+= " "+DerivateLabelProvider
.getDerivateText(value
, conversationHolder
); //$NON-NLS-1$
211 DeleteDerivateOperation deleteDerivateOperation
= new DeleteDerivateOperation(label
, undoContext
, (CdmBase
) value
, (TreeNode
) object
, postOperationEnabled
, this.deleteConfigurator
);
212 return deleteDerivateOperation
;
216 } catch (NotDefinedException e
) {
217 MessagingUtils
.warn(getClass(), "Command name not set"); //$NON-NLS-1$
227 public void onComplete() {
229 IPostOperationEnabled postOperationEnabled
= (editor
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) editor
: null;
230 if (postOperationEnabled
!= null){
231 DerivateView derivateView
= (DerivateView
)postOperationEnabled
;
232 if(derivateView
.postOperation(null)){
233 derivateView
.remove(node
);