1
|
|
2
|
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.handler;
|
3
|
|
4
|
import java.util.Iterator;
|
5
|
|
6
|
import javax.inject.Named;
|
7
|
|
8
|
import org.eclipse.e4.core.di.annotations.Execute;
|
9
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
10
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
11
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
|
14
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
15
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator;
|
16
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
17
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
18
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
19
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
20
|
|
21
|
public class DeleteDescriptiveDataSetHandler {
|
22
|
|
23
|
@Execute
|
24
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
25
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
|
26
|
boolean confirm = MessagingUtils.confirmDialog(Messages.DeleteDescriptiveDataSetHandler_DELETE_TITLE, Messages.DeleteDescriptiveDataSetHandler_DELETE_MESSAGE);
|
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
|
}
|
43
|
}
|
44
|
}
|
45
|
}
|
46
|
|
47
|
}
|