Revision f0cff051
Added by Katja Luther about 7 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/DeleteDerivateHandler.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.editor.view.derivate.handler; |
11 | 11 |
|
12 |
import org.eclipse.core.commands.AbstractHandler; |
|
13 | 12 |
import org.eclipse.core.commands.ExecutionEvent; |
14 |
import org.eclipse.core.commands.ExecutionException; |
|
15 | 13 |
import org.eclipse.core.commands.common.NotDefinedException; |
14 |
import org.eclipse.core.commands.operations.AbstractOperation; |
|
16 | 15 |
import org.eclipse.core.commands.operations.IUndoContext; |
16 |
import org.eclipse.core.runtime.IStatus; |
|
17 |
import org.eclipse.core.runtime.Status; |
|
17 | 18 |
import org.eclipse.jface.viewers.IStructuredSelection; |
18 | 19 |
import org.eclipse.jface.viewers.TreeNode; |
20 |
import org.eclipse.ui.IEditorPart; |
|
19 | 21 |
import org.eclipse.ui.IWorkbenchPart; |
20 | 22 |
import org.eclipse.ui.handlers.HandlerUtil; |
21 | 23 |
|
22 | 24 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
23 | 25 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
26 |
import eu.etaxonomy.cdm.api.service.DeleteResult; |
|
27 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
24 | 28 |
import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator; |
29 |
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService; |
|
25 | 30 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
26 | 31 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
27 | 32 |
import eu.etaxonomy.cdm.model.molecular.SingleRead; |
28 | 33 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
29 | 34 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
35 |
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin; |
|
30 | 36 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
37 |
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView; |
|
31 | 38 |
import eu.etaxonomy.taxeditor.editor.view.derivate.operation.DeleteDerivateOperation; |
32 |
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
|
39 |
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
|
|
33 | 40 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
41 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
34 | 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; |
|
35 | 46 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider; |
36 | 47 |
|
37 | 48 |
/** |
... | ... | |
40 | 51 |
* @date Oct 21, 2014 |
41 | 52 |
* |
42 | 53 |
*/ |
43 |
public class DeleteDerivateHandler extends AbstractHandler {
|
|
54 |
public class DeleteDerivateHandler extends RemotingCdmHandler {
|
|
44 | 55 |
|
45 |
/** {@inheritDoc} */ |
|
56 |
SpecimenDeleteConfigurator deleteConfigurator; |
|
57 |
IEditorPart editor; |
|
58 |
TreeNode node; |
|
59 |
|
|
60 |
/** |
|
61 |
* @param label |
|
62 |
*/ |
|
63 |
public DeleteDerivateHandler(String label) { |
|
64 |
super(label); |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* @param label |
|
70 |
*/ |
|
71 |
public DeleteDerivateHandler() { |
|
72 |
super(Messages.DeleteDerivateHandler_LABEL); |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
// /** {@inheritDoc} */ |
|
77 |
// @Override |
|
78 |
// public Object execute(ExecutionEvent event) throws ExecutionException { |
|
79 |
// IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveSite(event).getSelectionProvider().getSelection(); |
|
80 |
// |
|
81 |
// IWorkbenchPart part = HandlerUtil.getActivePart(event); |
|
82 |
// IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null; |
|
83 |
// |
|
84 |
// try { |
|
85 |
// String label = event.getCommand().getName(); |
|
86 |
// |
|
87 |
// IUndoContext undoContext = EditorUtil.getUndoContext(); |
|
88 |
// |
|
89 |
// if(selection.size()>0){ |
|
90 |
// Object object = selection.iterator().next(); |
|
91 |
// |
|
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$ |
|
98 |
// } |
|
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); |
|
108 |
// |
|
109 |
// // derivateView.updateRootEntities(); |
|
110 |
// //update DerivateView |
|
111 |
// |
|
112 |
// |
|
113 |
// } |
|
114 |
// } |
|
115 |
// } |
|
116 |
// else{ |
|
117 |
// MessagingUtils.error(getClass(), Messages.DeleteDerivateHandler_INVALID_SELECTION, null); |
|
118 |
// } |
|
119 |
// } |
|
120 |
// |
|
121 |
// } catch (NotDefinedException e) { |
|
122 |
// MessagingUtils.warn(getClass(), "Command name not set"); //$NON-NLS-1$ |
|
123 |
// } |
|
124 |
// return null; |
|
125 |
// } |
|
126 |
|
|
127 |
/** |
|
128 |
* {@inheritDoc} |
|
129 |
*/ |
|
130 |
@Override |
|
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(); |
|
138 |
|
|
139 |
String confirmationQuestion = Messages.DeleteDerivateOperation_REALLY_DELETE; |
|
140 |
if(deleteConfigurator.isDeleteChildren()){ |
|
141 |
confirmationQuestion += Messages.DeleteDerivateOperation_AND_CHILDREN; |
|
142 |
} |
|
143 |
|
|
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; |
|
147 |
} |
|
148 |
|
|
149 |
confirmationQuestion += "?"; //$NON-NLS-1$ |
|
150 |
if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfigurator, null, Messages.DeleteDerivateOperation_CONFIRM, confirmationQuestion)){ |
|
151 |
return Status.CANCEL_STATUS; |
|
152 |
} |
|
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); |
|
160 |
} else{ |
|
161 |
deleteResult = CdmStore.getService(IOccurrenceService.class).isDeletable(((CdmBase)value).getUuid(), deleteConfigurator); |
|
162 |
} |
|
163 |
if (deleteResult.isOk() || deleteResult.getExceptions().isEmpty()){ return Status.OK_STATUS;} |
|
164 |
else{ |
|
165 |
if (!deleteResult.isOk()){ |
|
166 |
DeleteResultMessagingUtils.messageDialogWithDetails(deleteResult, Messages.DeleteDerivateOperation_DELETE_FAILED, TaxeditorEditorPlugin.PLUGIN_ID); |
|
167 |
} else { |
|
168 |
if (!deleteResult.getExceptions().isEmpty()){ |
|
169 |
DeleteResultMessagingUtils.messageDialogWithDetails(deleteResult, Messages.DeleteDerivateHandler_SUCCESSFULL_BUT_EXCEPTIONS, TaxeditorEditorPlugin.PLUGIN_ID); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
return Status.CANCEL_STATUS; |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
} |
|
178 |
|
|
179 |
return Status.CANCEL_STATUS; |
|
180 |
|
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* {@inheritDoc} |
|
185 |
*/ |
|
46 | 186 |
@Override |
47 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
|
187 |
public AbstractOperation prepareOperation(ExecutionEvent event) {
|
|
48 | 188 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveSite(event).getSelectionProvider().getSelection(); |
49 | 189 |
|
50 | 190 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
... | ... | |
59 | 199 |
Object object = selection.iterator().next(); |
60 | 200 |
|
61 | 201 |
if(object instanceof TreeNode){ |
202 |
node = (TreeNode)object; |
|
62 | 203 |
Object value = ((TreeNode) object).getValue(); |
63 | 204 |
if(value instanceof SpecimenOrObservationBase<?> || value instanceof Sequence || value instanceof SingleRead){ |
64 | 205 |
if(postOperationEnabled instanceof IConversationEnabled){ |
65 | 206 |
ConversationHolder conversationHolder = ((IConversationEnabled) postOperationEnabled).getConversationHolder(); |
66 | 207 |
label += " "+DerivateLabelProvider.getDerivateText(value, conversationHolder); //$NON-NLS-1$ |
67 | 208 |
} |
68 |
SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator(); |
|
69 |
boolean deepDelete = event.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.derivate.deepDelete"); //$NON-NLS-1$ |
|
70 |
config.setDeleteChildren(deepDelete); |
|
71 |
config.setDeleteMolecularData(deepDelete); |
|
72 |
DeleteDerivateOperation deleteDerivateOperation = new DeleteDerivateOperation(label, undoContext, (CdmBase) value, (TreeNode) object, postOperationEnabled, config); |
|
73 |
AbstractUtility.executeOperation(deleteDerivateOperation); |
|
209 |
|
|
210 |
|
|
211 |
DeleteDerivateOperation deleteDerivateOperation = new DeleteDerivateOperation(label, undoContext, (CdmBase) value, (TreeNode) object, postOperationEnabled, this.deleteConfigurator); |
|
212 |
return deleteDerivateOperation; |
|
74 | 213 |
} |
75 | 214 |
} |
76 |
else{ |
|
77 |
MessagingUtils.error(getClass(), Messages.DeleteDerivateHandler_INVALID_SELECTION, null); |
|
78 |
} |
|
79 | 215 |
} |
80 |
|
|
81 | 216 |
} catch (NotDefinedException e) { |
82 | 217 |
MessagingUtils.warn(getClass(), "Command name not set"); //$NON-NLS-1$ |
83 | 218 |
} |
84 | 219 |
return null; |
220 |
|
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* {@inheritDoc} |
|
225 |
*/ |
|
226 |
@Override |
|
227 |
public void onComplete() { |
|
228 |
|
|
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); |
|
234 |
|
|
235 |
} |
|
236 |
} |
|
85 | 237 |
} |
86 | 238 |
} |
Also available in: Unified diff
ref #4993: adapt deleteDerivateHandler and Operation