Project

General

Profile

Download (2.06 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.bulkeditor.handler;
10

    
11
import java.util.Iterator;
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.text.TextSelection;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

    
19
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
20
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
21
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
22
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
23
import eu.etaxonomy.taxeditor.model.LineSelection;
24

    
25
/**
26
 * <p>SetMergeCandidateHandler class.</p>
27
 *
28
 * @author p.ciardelli
29
 * @created 25.06.2009
30
 * @version 1.0
31
 */
32
public class SetMergeCandidateHandler extends AbstractHandler {
33

    
34
	/* (non-Javadoc)
35
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
36
	 */
37
	/** {@inheritDoc} */
38
	public Object execute(ExecutionEvent event) throws ExecutionException {
39
				
40
		if (HandlerUtil.getCurrentSelection(event) instanceof TextSelection 
41
				&& HandlerUtil.getActiveEditor(event) instanceof BulkEditor) {
42
			TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event);
43
			BulkEditor editor = (BulkEditor) HandlerUtil.getActiveEditor(event);
44
			
45
			LineAnnotationModel model = (LineAnnotationModel) editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
46
			if (model != null) {
47
				Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
48
				while (iter.hasNext()) {
49
					Object next = iter.next();
50
					if (next instanceof LineAnnotation) {
51
						model.changeAnnotationType(
52
								(LineAnnotation) next, IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
53
					}
54
				}
55
			}
56
		}	
57
		return null;
58
	}
59
}
(8-8/9)