Revision 5cfc8708
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeTargetHandlerE4.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.bulkeditor.e4.handler; |
10 | 10 |
|
11 |
import org.eclipse.core.commands.AbstractHandler; |
|
12 |
import org.eclipse.core.commands.ExecutionEvent; |
|
13 |
import org.eclipse.core.commands.ExecutionException; |
|
14 |
import org.eclipse.jface.text.IDocument; |
|
15 |
import org.eclipse.jface.text.TextSelection; |
|
16 |
import org.eclipse.jface.text.source.Annotation; |
|
17 |
import org.eclipse.jface.viewers.ISelection; |
|
18 |
import org.eclipse.ui.IEditorInput; |
|
19 |
import org.eclipse.ui.IEditorPart; |
|
20 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
21 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
|
11 |
import javax.inject.Named; |
|
22 | 12 |
|
23 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor; |
|
24 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel; |
|
25 |
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants; |
|
26 |
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput; |
|
13 |
import org.eclipse.e4.core.di.annotations.Execute; |
|
14 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
15 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
16 |
|
|
17 |
import eu.etaxonomy.taxeditor.bulkeditor.e4.AnnotatedTableItem; |
|
18 |
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4; |
|
27 | 19 |
|
28 | 20 |
/** |
29 |
* <p>SetMergeTargetHandler class.</p> |
|
30 | 21 |
* |
31 |
* @author p.ciardelli
|
|
32 |
* @created 25.06.2009
|
|
33 |
* @version 1.0
|
|
22 |
* @author pplitzner
|
|
23 |
* @date 12.09.2017
|
|
24 |
* |
|
34 | 25 |
*/ |
35 |
public class SetMergeTargetHandlerE4 extends AbstractHandler {
|
|
26 |
public class SetMergeTargetHandlerE4 { |
|
36 | 27 |
|
37 |
/* (non-Javadoc) |
|
38 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
39 |
*/ |
|
40 |
/** {@inheritDoc} */ |
|
41 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
42 |
|
|
43 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
44 |
IEditorInput input = editor.getEditorInput(); |
|
45 |
|
|
46 |
if (editor instanceof AnnotatedLineEditor && input instanceof AbstractBulkEditorInput) { |
|
47 |
|
|
48 |
IDocumentProvider provider = ((AnnotatedLineEditor) editor).getDocumentProvider(); |
|
49 |
LineAnnotationModel model = |
|
50 |
(LineAnnotationModel) provider.getAnnotationModel(input); |
|
51 |
IDocument document = provider.getDocument(input); |
|
52 |
|
|
53 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
|
54 |
if (selection instanceof TextSelection) { |
|
55 |
Annotation annotation = null; |
|
56 |
|
|
57 |
// Get annotation in current line |
|
58 |
int line = ((TextSelection) selection).getStartLine(); |
|
59 |
annotation = model.getAnnotationAtLine(line, document); |
|
60 |
|
|
61 |
// Remove existing merge target |
|
62 |
model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_TARGET); |
|
63 |
|
|
64 |
// Set annotation in current line to merge target |
|
65 |
if (annotation != null) { |
|
66 |
model.changeAnnotationType( |
|
67 |
annotation, IBulkEditorConstants.TYPE_MERGE_TARGET); |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
return null; |
|
28 |
@Execute |
|
29 |
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)AnnotatedTableItem item, |
|
30 |
@Named(IServiceConstants.ACTIVE_PART)MPart activePart) { |
|
31 |
BulkEditorE4 editor = (BulkEditorE4) activePart.getObject(); |
|
32 |
item.setMergeTarget(true); |
|
33 |
editor.refresh(); |
|
72 | 34 |
} |
73 | 35 |
} |
Also available in: Unified diff
ref #6932 Migrate bulk editor handlers and add annotation merge support