.
[taxeditor.git] / taxeditor-bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / handler / SetMergeCandidateHandler.java
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 package eu.etaxonomy.taxeditor.bulkeditor.handler;
11
12 import java.util.Iterator;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
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.annotatedlineeditor.LineSelection;
22 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
23 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
24
25 /**
26 * @author p.ciardelli
27 * @created 25.06.2009
28 * @version 1.0
29 */
30 public class SetMergeCandidateHandler extends AbstractHandler {
31
32 /* (non-Javadoc)
33 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
34 */
35 public Object execute(ExecutionEvent event) throws ExecutionException {
36
37 if (HandlerUtil.getCurrentSelection(event) instanceof LineSelection
38 && HandlerUtil.getActiveEditor(event) instanceof BulkEditor) {
39 LineSelection selection = (LineSelection) HandlerUtil.getCurrentSelection(event);
40 BulkEditor editor = (BulkEditor) HandlerUtil.getActiveEditor(event);
41
42 LineAnnotationModel model = (LineAnnotationModel) editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
43 if (model != null) {
44 Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
45 while (iter.hasNext()) {
46 Object next = iter.next();
47 if (next instanceof LineAnnotation) {
48 model.changeAnnotationType(
49 (LineAnnotation) next, IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
50 }
51 }
52 }
53 }
54
55 //
56 //
57 //
58 // IEditorPart editor = HandlerUtil.getActiveEditor(event);
59 // IEditorInput input = editor.getEditorInput();
60 //
61 // if (editor instanceof BulkEditor && input instanceof BulkEditorInput) {
62 //
63 // IDocumentProvider provider = ((AnnotatedLineEditor) editor).getDocumentProvider();
64 // LineAnnotationModel model =
65 // (LineAnnotationModel) provider.getAnnotationModel(input);
66 // IDocument document = provider.getDocument(input);
67 //
68 // ISelection selection = HandlerUtil.getActiveMenuSelection(event);
69 // if (selection instanceof TextSelection) {
70 // Annotation annotation = null;
71 //
72 // // Get annotation in current line
73 // int line = ((TextSelection) selection).getStartLine();
74 // annotation = model.getAnnotationAtLine(line, document);
75 //
76 // if (annotation != null) {
77 // if (annotation.getType().equals(IBulkEditorConstants.TYPE_MERGE_CANDIDATE)) {
78 // model.changeAnnotationType(
79 // annotation, LineAnnotation.TYPE_GENERIC);
80 // } else {
81 // model.changeAnnotationType(
82 // annotation, IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
83 // }
84 // }
85 // }
86 // }
87 return null;
88 }
89 }