2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.bulkeditor
.handler
;
11 import java
.util
.Iterator
;
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
;
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
;
26 * <p>SetMergeCandidateHandler class.</p>
32 public class SetMergeCandidateHandler
extends AbstractHandler
{
35 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
38 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
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
);
45 LineAnnotationModel model
= (LineAnnotationModel
) editor
.getDocumentProvider().getAnnotationModel(editor
.getEditorInput());
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
);