Revision af3a8a41
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/handler/DeleteDescriptiveDataSetHandler.java | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.handler; |
3 | 3 |
|
4 |
import java.util.Iterator; |
|
5 |
|
|
4 | 6 |
import javax.inject.Named; |
5 | 7 |
|
6 | 8 |
import org.eclipse.e4.core.di.annotations.Execute; |
7 | 9 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
8 | 10 |
import org.eclipse.e4.ui.services.IServiceConstants; |
11 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
9 | 12 |
|
10 | 13 |
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService; |
11 | 14 |
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet; |
... | ... | |
18 | 21 |
public class DeleteDescriptiveDataSetHandler { |
19 | 22 |
|
20 | 23 |
@Execute |
21 |
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
|
|
24 |
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
|
22 | 25 |
@Named(IServiceConstants.ACTIVE_PART)MPart activePart) { |
23 | 26 |
boolean confirm = MessagingUtils.confirmDialog(Messages.DeleteDescriptiveDataSetHandler_DELETE_TITLE, Messages.DeleteDescriptiveDataSetHandler_DELETE_MESSAGE); |
24 |
if(confirm && selection instanceof DescriptiveDataSet){ |
|
25 |
Object object = activePart.getObject(); |
|
26 |
if(object instanceof DescriptiveDataSetNavigator){ |
|
27 |
IDescriptiveDataSetService descriptiveDataSetService = CdmStore.getService(IDescriptiveDataSetService.class); |
|
28 |
descriptiveDataSetService.delete(((DescriptiveDataSet) selection).getUuid()); |
|
29 |
DescriptiveDataSetNavigator navigator = (DescriptiveDataSetNavigator) object; |
|
30 |
navigator.removeDescriptiveDataSet((DescriptiveDataSet) selection); |
|
31 |
navigator.getConversationHolder().commit(); |
|
32 |
} |
|
33 |
else{ |
|
34 |
MessagingUtils.errorDialog(Messages.DeleteDescriptiveDataSetHandler_DELETE_FAILED_TITLE, DeleteDescriptiveDataSetHandler.class, Messages.DeleteDescriptiveDataSetHandler_DELETE_FAILED_MESSAGE, TaxeditorEditorPlugin.PLUGIN_ID, null, false); |
|
27 |
Object object = activePart.getObject(); |
|
28 |
if(!selection.isEmpty() && confirm && object instanceof DescriptiveDataSetNavigator){ |
|
29 |
Iterator iterator = selection.iterator(); |
|
30 |
while(iterator.hasNext()){ |
|
31 |
Object next = iterator.next(); |
|
32 |
if(next instanceof DescriptiveDataSet){ |
|
33 |
IDescriptiveDataSetService descriptiveDataSetService = CdmStore.getService(IDescriptiveDataSetService.class); |
|
34 |
descriptiveDataSetService.delete(((DescriptiveDataSet) next).getUuid()); |
|
35 |
DescriptiveDataSetNavigator navigator = (DescriptiveDataSetNavigator) object; |
|
36 |
navigator.removeDescriptiveDataSet((DescriptiveDataSet) next); |
|
37 |
navigator.getConversationHolder().commit(); |
|
38 |
} |
|
39 |
else{ |
|
40 |
MessagingUtils.errorDialog(Messages.DeleteDescriptiveDataSetHandler_DELETE_FAILED_TITLE, DeleteDescriptiveDataSetHandler.class, Messages.DeleteDescriptiveDataSetHandler_DELETE_FAILED_MESSAGE, TaxeditorEditorPlugin.PLUGIN_ID, null, false); |
|
41 |
return; |
|
42 |
} |
|
35 | 43 |
} |
36 | 44 |
} |
37 | 45 |
} |
Also available in: Unified diff
ref #7010 Adapt DDS navigator handler