.
[taxeditor.git] / taxeditor-bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / BulkEditorViewerConfiguration.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;
11
12 import java.util.Iterator;
13
14 import org.apache.log4j.Logger;
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.IRegion;
17 import org.eclipse.jface.text.TextPresentation;
18 import org.eclipse.jface.text.presentation.IPresentationReconciler;
19 import org.eclipse.jface.text.presentation.PresentationReconciler;
20 import org.eclipse.jface.text.source.ISourceViewer;
21 import org.eclipse.jface.text.source.SourceViewerConfiguration;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.custom.StyleRange;
24
25 import eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy;
26 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
27 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
28
29
30 /**
31 * @author p.ciardelli
32 * @created 25.06.2009
33 * @version 1.0
34 */
35 public class BulkEditorViewerConfiguration extends SourceViewerConfiguration {
36 private static final Logger logger = Logger
37 .getLogger(BulkEditorViewerConfiguration.class);
38
39 private ILineDisplayStrategy lineDisplayStrategy;
40
41 /**
42 * @param lineDisplayStrategy
43 */
44 public BulkEditorViewerConfiguration(
45 ILineDisplayStrategy lineDisplayStrategy) {
46 this.lineDisplayStrategy = lineDisplayStrategy;
47 }
48
49 /* (non-Javadoc)
50 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)
51 */
52 @Override
53 public IPresentationReconciler getPresentationReconciler(
54 final ISourceViewer sourceViewer) {
55 return new PresentationReconciler() {
56 /* (non-Javadoc)
57 * @see org.eclipse.jface.text.presentation.PresentationReconciler#createPresentation(org.eclipse.jface.text.IRegion, org.eclipse.jface.text.IDocument)
58 */
59 @Override
60 protected TextPresentation createPresentation(IRegion damage,
61 IDocument document) {
62
63 TextPresentation presentation = super.createPresentation(damage, document);
64 LineAnnotationModel model = (LineAnnotationModel) sourceViewer.getAnnotationModel();
65
66 // Update all annotated lines in the damage zone
67 Iterator iter = model.getAnnotationIterator(damage.getOffset(), damage.getLength() + 1, true, true);
68 while (iter.hasNext()) {
69 Object next = iter.next();
70 if (next instanceof LineAnnotation) {
71 for (StyleRange styleRange : lineDisplayStrategy.getTextStyleRanges(((LineAnnotation) next).getEntity())) {
72 styleRange.start += model.getPosition((LineAnnotation) next).getOffset();
73 presentation.addStyleRange(styleRange);
74 }
75 }
76 }
77
78 return presentation;
79 }
80 };
81 }
82
83 }