129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.source.VisualAnnotationModel;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18 import java.util.ArrayList;
|
|
19 import java.util.Iterator;
|
|
20
|
|
21 import dwtx.jface.text.IDocument;
|
|
22 import dwtx.jface.text.Position;
|
|
23
|
|
24
|
|
25
|
|
26 /**
|
|
27 * Annotation model for visual annotations. Assume a viewer's input element is annotated with
|
|
28 * some semantic annotation such as a breakpoint and that it is simultaneously shown in multiple
|
|
29 * viewers. A source viewer, e.g., supports visual range indication for which it utilizes
|
|
30 * annotations. The range indicating annotation is specific to the visual presentation
|
|
31 * of the input element in this viewer and thus should only be visible in this viewer. The
|
|
32 * breakpoints however are independent from the input element's presentation and thus should
|
|
33 * be shown in all viewers in which the element is shown. As a viewer supports one vertical
|
|
34 * ruler which is based on one annotation model, there must be a visual annotation model for
|
|
35 * each viewer which all wrap the same element specific model annotation model.
|
|
36 */
|
|
37 class VisualAnnotationModel : AnnotationModel , IAnnotationModelListener {
|
|
38
|
|
39 /** The wrapped model annotation model */
|
|
40 private IAnnotationModel fModel;
|
|
41
|
|
42 /**
|
|
43 * Constructs a visual annotation model which wraps the given
|
|
44 * model based annotation model
|
|
45 *
|
|
46 * @param modelAnnotationModel the model based annotation model
|
|
47 */
|
|
48 public VisualAnnotationModel(IAnnotationModel modelAnnotationModel) {
|
|
49 fModel= modelAnnotationModel;
|
|
50 }
|
|
51
|
|
52 /**
|
|
53 * Returns the visual annotation model's wrapped model based annotation model.
|
|
54 *
|
|
55 * @return the model based annotation model
|
|
56 */
|
|
57 public IAnnotationModel getModelAnnotationModel() {
|
|
58 return fModel;
|
|
59 }
|
|
60
|
|
61 /*
|
|
62 * @see IAnnotationModel#addAnnotationModelListener(IAnnotationModelListener)
|
|
63 */
|
|
64 public void addAnnotationModelListener(IAnnotationModelListener listener) {
|
|
65
|
|
66 if (fModel !is null && fAnnotationModelListeners.isEmpty())
|
|
67 fModel.addAnnotationModelListener(this);
|
|
68
|
|
69 super.addAnnotationModelListener(listener);
|
|
70 }
|
|
71
|
|
72 /*
|
|
73 * @see IAnnotationModel#connect(IDocument)
|
|
74 */
|
|
75 public void connect(IDocument document) {
|
|
76 super.connect(document);
|
|
77 if (fModel !is null)
|
|
78 fModel.connect(document);
|
|
79 }
|
|
80
|
|
81 /*
|
|
82 * @see IAnnotationModel#disconnect(IDocument)
|
|
83 */
|
|
84 public void disconnect(IDocument document) {
|
|
85 super.disconnect(document);
|
|
86 if (fModel !is null)
|
|
87 fModel.disconnect(document);
|
|
88 }
|
|
89
|
|
90 /*
|
|
91 * @see IAnnotationModel#getAnnotationIterator()
|
|
92 */
|
|
93 public Iterator getAnnotationIterator() {
|
|
94
|
|
95 if (fModel is null)
|
|
96 return super.getAnnotationIterator();
|
|
97
|
|
98 ArrayList a= new ArrayList(20);
|
|
99
|
|
100 Iterator e= fModel.getAnnotationIterator();
|
|
101 while (e.hasNext())
|
|
102 a.add(e.next());
|
|
103
|
|
104 e= super.getAnnotationIterator();
|
|
105 while (e.hasNext())
|
|
106 a.add(e.next());
|
|
107
|
|
108 return a.iterator();
|
|
109 }
|
|
110
|
|
111 /*
|
|
112 * @see IAnnotationModel#getPosition(Annotation)
|
|
113 */
|
|
114 public Position getPosition(Annotation annotation) {
|
|
115
|
|
116 Position p= (Position) getAnnotationMap().get(annotation);
|
|
117 if (p !is null)
|
|
118 return p;
|
|
119
|
|
120 if (fModel !is null)
|
|
121 return fModel.getPosition(annotation);
|
|
122
|
|
123 return null;
|
|
124 }
|
|
125
|
|
126 /*
|
|
127 * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
|
|
128 */
|
|
129 public void modelChanged(IAnnotationModel model) {
|
|
130 if (model is fModel) {
|
|
131 Iterator iter= new ArrayList(fAnnotationModelListeners).iterator();
|
|
132 while (iter.hasNext()) {
|
|
133 IAnnotationModelListener l= (IAnnotationModelListener)iter.next();
|
|
134 l.modelChanged(this);
|
|
135 }
|
|
136 }
|
|
137 }
|
|
138
|
|
139 /*
|
|
140 * @see IAnnotationModel#removeAnnotationModelListener(IAnnotationModelListener)
|
|
141 */
|
|
142 public void removeAnnotationModelListener(IAnnotationModelListener listener) {
|
|
143 super.removeAnnotationModelListener(listener);
|
|
144
|
|
145 if (fModel !is null && fAnnotationModelListeners.isEmpty())
|
|
146 fModel.removeAnnotationModelListener(this);
|
|
147 }
|
|
148 }
|