Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / handler / RemoveMergeCandidateHandler.java
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
23 /**
24 * <p>RemoveMergeCandidateHandler class.</p>
25 *
26 * @author p.ciardelli
27 * @created 25.06.2009
28 * @version 1.0
29 */
30 public class RemoveMergeCandidateHandler extends AbstractHandler {
31
32 /* (non-Javadoc)
33 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
34 */
35 /** {@inheritDoc} */
36 public Object execute(ExecutionEvent event) throws ExecutionException {
37
38 if (HandlerUtil.getCurrentSelection(event) instanceof TextSelection
39 && HandlerUtil.getActiveEditor(event) instanceof BulkEditor) {
40 TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event);
41 BulkEditor editor = (BulkEditor) HandlerUtil.getActiveEditor(event);
42
43 LineAnnotationModel model = (LineAnnotationModel) editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
44 if (model != null) {
45 Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
46 while (iter.hasNext()) {
47 Object next = iter.next();
48 if (next instanceof LineAnnotation) {
49 model.changeAnnotationType(
50 (LineAnnotation) next, LineAnnotation.TYPE_GENERIC);
51 }
52 }
53 }
54 }
55 return null;
56 }
57 }