automated build configuration is on its way
[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.jface.text.TextSelection;
18 import org.eclipse.ui.handlers.HandlerUtil;
19
20 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
21 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
22 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
23 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
24 import eu.etaxonomy.taxeditor.model.LineSelection;
25
26 /**
27 * <p>SetMergeCandidateHandler class.</p>
28 *
29 * @author p.ciardelli
30 * @created 25.06.2009
31 * @version 1.0
32 */
33 public class SetMergeCandidateHandler extends AbstractHandler {
34
35 /* (non-Javadoc)
36 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
37 */
38 /** {@inheritDoc} */
39 public Object execute(ExecutionEvent event) throws ExecutionException {
40
41 if (HandlerUtil.getCurrentSelection(event) instanceof TextSelection
42 && HandlerUtil.getActiveEditor(event) instanceof BulkEditor) {
43 TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event);
44 BulkEditor editor = (BulkEditor) HandlerUtil.getActiveEditor(event);
45
46 LineAnnotationModel model = (LineAnnotationModel) editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
47 if (model != null) {
48 Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
49 while (iter.hasNext()) {
50 Object next = iter.next();
51 if (next instanceof LineAnnotation) {
52 model.changeAnnotationType(
53 (LineAnnotation) next, IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
54 }
55 }
56 }
57 }
58 return null;
59 }
60 }