Project

General

Profile

Download (3.53 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.bulkeditor.handler;
12

    
13
import org.eclipse.core.commands.AbstractHandler;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.ui.IEditorInput;
19
import org.eclipse.ui.IEditorPart;
20
import org.eclipse.ui.handlers.HandlerUtil;
21
import org.eclipse.ui.texteditor.IDocumentProvider;
22

    
23
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
24
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
25
import eu.etaxonomy.cdm.api.service.ITaxonService;
26
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
27
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
28
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService;
29
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
30
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
31
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
32
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
33
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
34
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36

    
37
/**
38
 * @author n.hoffmann
39
 * @created Mar 11, 2011
40
 * @version 1.0
41
 */
42
public class DeleteHandler extends AbstractHandler {
43

    
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46
	 */
47
	@Override
48
	public Object execute(ExecutionEvent event) throws ExecutionException {
49
		
50
		if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)){
51
			ISelection selection = HandlerUtil.getCurrentSelection(event);
52
			
53
			IEditorPart editor = HandlerUtil.getActiveEditor(event);
54
			
55
			IEditorInput input = editor.getEditorInput();
56
			
57
			if((input instanceof IEntityPersistenceService) && (selection instanceof IStructuredSelection)){
58
				
59
				
60
				IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
61
				LineAnnotationModel model = 
62
						(LineAnnotationModel) provider.getAnnotationModel(input);
63
				
64
				
65
				IStructuredSelection structuredSelection = (IStructuredSelection) selection;
66
				
67
				IEntityPersistenceService persistenceService = (IEntityPersistenceService) input;
68
				
69
				for(Object object : structuredSelection.toList()){
70
					
71
					LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);
72
							
73
					try {
74
						//persistenceService.delete(object);
75
						if (object instanceof SpecimenOrObservationBase){
76
							CdmApplicationController controller;
77
							
78
							controller = (CdmApplicationController) CdmStore.getCurrentApplicationConfiguration();
79
							
80
							IOccurrenceService service = controller.getOccurrenceService();
81
							service.delete((SpecimenOrObservationBase)object);
82
						}
83
						
84
					} catch (Exception e){
85
						BulkEditorUtil.errorDialog("Could not delete", getClass(), e.getMessage(), null);
86
					}
87
					((BulkEditor) editor).removeAnnotatedLine(annotation);
88
					
89
				}				
90
			}
91
		}else{
92
			BulkEditorUtil.warningDialog("Feature not enabled", getClass(), "Deletion is currently an experimental feature." +
93
					"Enable it via Preferences at your own risk.");
94
		}
95
		
96
		
97
		return null;
98
	}
99

    
100
}
(1-1/7)