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
;
12 import org
.eclipse
.jface
.text
.IDocument
;
13 import org
.eclipse
.jface
.text
.source
.Annotation
;
14 import org
.eclipse
.jface
.text
.source
.ISourceViewer
;
15 import org
.eclipse
.jface
.text
.source
.IVerticalRuler
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.custom
.StyledText
;
18 import org
.eclipse
.swt
.events
.MouseAdapter
;
19 import org
.eclipse
.swt
.events
.MouseEvent
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.ui
.IEditorInput
;
23 import org
.eclipse
.ui
.IEditorSite
;
24 import org
.eclipse
.ui
.PartInitException
;
25 import org
.eclipse
.ui
.editors
.text
.TextEditor
;
28 * A document provider is responsible not just for providing the document for a
29 * given editor input but for the complete translation between the domain model
30 * and the editor's internal document-based model. Document provider can be shared
37 public class BulkEditor
extends TextEditor
{
39 public static final String ID
= "bulkeditor.editor";
41 private ISourceViewer viewer
;
47 * see AbstractTextEditor javadoc for explanation of context menu ids
49 setEditorContextMenuId("#BulkEditorContext");
53 public void init(IEditorSite site
, IEditorInput input
)
54 throws PartInitException
{
55 setDocumentProvider(new BulkEditorDocumentProvider());
56 super.init(site
, input
);
60 protected ISourceViewer
createSourceViewer(Composite parent
,
61 IVerticalRuler ruler
, int styles
) {
62 viewer
= super.createSourceViewer(parent
, ruler
, styles
| SWT
.WRAP
);
63 setSourceViewerConfiguration(new BulkEditorSourceViewerConfiguration());
65 addToggleMergeCandidateListener(ruler
.getControl());
69 private void addToggleMergeCandidateListener(Control control
) {
70 control
.addMouseListener(new MouseAdapter() {
72 public void mouseDoubleClick(MouseEvent e
) {
73 StyledText textWidget
= viewer
.getTextWidget();
74 int line
= textWidget
.getLineIndex(e
.y
);
75 toggleMergeCandidateAnnotation(line
);
80 private void toggleMergeCandidateAnnotation(int line
) {
81 IDocument document
= viewer
.getDocument();
82 BulkEditorAnnotationModel model
=
83 (BulkEditorAnnotationModel
) viewer
.getAnnotationModel();
85 Annotation annotation
= model
.getAnnotationAtLine(line
, document
);
87 if (annotation
!= null) {
88 if (annotation
.getType().equals(BulkEditorAnnotation
.TYPE_MERGE_CANDIDATE
)) {
89 model
.changeAnnotationType(
90 annotation
, BulkEditorAnnotation
.TYPE_GENERIC
);
92 model
.changeAnnotationType(
93 annotation
, BulkEditorAnnotation
.TYPE_MERGE_CANDIDATE
);