3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.handler
;
12 import org
.eclipse
.core
.commands
.AbstractHandler
;
13 import org
.eclipse
.core
.commands
.ExecutionEvent
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.jface
.text
.IDocument
;
16 import org
.eclipse
.jface
.text
.TextSelection
;
17 import org
.eclipse
.jface
.text
.source
.Annotation
;
18 import org
.eclipse
.jface
.viewers
.ISelection
;
19 import org
.eclipse
.ui
.IEditorInput
;
20 import org
.eclipse
.ui
.IEditorPart
;
21 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
22 import org
.eclipse
.ui
.texteditor
.IDocumentProvider
;
24 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.AnnotatedLineEditor
;
25 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
26 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
27 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
28 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorConstants
;
29 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.BulkEditorInput
;
36 public class ToggleMergeCandidateHandler
extends AbstractHandler
{
39 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
41 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
43 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
44 IEditorInput input
= editor
.getEditorInput();
46 if (editor
instanceof BulkEditor
&& input
instanceof BulkEditorInput
) {
48 IDocumentProvider provider
= ((AnnotatedLineEditor
) editor
).getDocumentProvider();
49 LineAnnotationModel model
=
50 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
51 IDocument document
= provider
.getDocument(input
);
53 ISelection selection
= HandlerUtil
.getActiveMenuSelection(event
);
54 if (selection
instanceof TextSelection
) {
55 Annotation annotation
= null;
57 // Get annotation in current line
58 int line
= ((TextSelection
) selection
).getStartLine();
59 annotation
= model
.getAnnotationAtLine(line
, document
);
61 if (annotation
!= null) {
62 if (annotation
.getType().equals(IBulkEditorConstants
.TYPE_MERGE_CANDIDATE
)) {
63 model
.changeAnnotationType(
64 annotation
, LineAnnotation
.TYPE_GENERIC
);
66 model
.changeAnnotationType(
67 annotation
, IBulkEditorConstants
.TYPE_MERGE_CANDIDATE
);