Project

General

Profile

Download (2.69 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.taxeditor.annotatedlineeditor.IEntityPersistenceService;
24
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
25
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
26
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
27
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
28
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
29
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30

    
31
/**
32
 * @author n.hoffmann
33
 * @created Mar 11, 2011
34
 * @version 1.0
35
 */
36
public class DeleteHandler extends AbstractHandler {
37

    
38
	/* (non-Javadoc)
39
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
40
	 */
41
	@Override
42
	public Object execute(ExecutionEvent event) throws ExecutionException {
43
		
44
		if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)){
45
			ISelection selection = HandlerUtil.getCurrentSelection(event);
46
			
47
			IEditorPart editor = HandlerUtil.getActiveEditor(event);
48
			
49
			IEditorInput input = editor.getEditorInput();
50
			
51
			if((input instanceof IEntityPersistenceService) && (selection instanceof IStructuredSelection)){
52
				
53
				
54
				IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
55
				LineAnnotationModel model = 
56
						(LineAnnotationModel) provider.getAnnotationModel(input);
57
				
58
				
59
				IStructuredSelection structuredSelection = (IStructuredSelection) selection;
60
				
61
				IEntityPersistenceService persistenceService = (IEntityPersistenceService) input;
62
				
63
				for(Object object : structuredSelection.toList()){
64
					
65
					LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);
66
									
67
	//				persistenceService.delete(object);
68
					((BulkEditor) editor).removeAnnotatedLine(annotation);
69
					
70
				}				
71
			}
72
		}else{
73
			BulkEditorUtil.warningDialog("Feature not enabled", getClass(), "Deletion is currently an experimental feature." +
74
					"Enable it via Preferences at your own risk.");
75
		}
76
		
77
		
78
		return null;
79
	}
80

    
81
}
(1-1/7)