Mercurial > projects > dwt-addons
annotate dwtx/jface/text/projection/ProjectionDocumentManager.d @ 140:26688fec6d23
Following dsss compile errors
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 03:23:46 +0200 |
parents | b6bad70d540a |
children | f70d9508c95c |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 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.projection.ProjectionDocumentManager; | |
14 | |
131 | 15 import dwtx.jface.text.projection.ProjectionMapping; // packageimport |
16 import dwtx.jface.text.projection.ChildDocumentManager; // packageimport | |
17 import dwtx.jface.text.projection.SegmentUpdater; // packageimport | |
18 import dwtx.jface.text.projection.Segment; // packageimport | |
19 import dwtx.jface.text.projection.ProjectionDocument; // packageimport | |
20 import dwtx.jface.text.projection.FragmentUpdater; // packageimport | |
21 import dwtx.jface.text.projection.ProjectionDocumentEvent; // packageimport | |
22 import dwtx.jface.text.projection.ChildDocument; // packageimport | |
23 import dwtx.jface.text.projection.IMinimalMapping; // packageimport | |
24 import dwtx.jface.text.projection.Fragment; // packageimport | |
25 import dwtx.jface.text.projection.ProjectionTextStore; // packageimport | |
26 | |
27 | |
129 | 28 import dwt.dwthelper.utils; |
29 | |
30 import java.util.ArrayList; | |
31 import java.util.HashMap; | |
32 import java.util.Iterator; | |
33 import java.util.List; | |
34 import java.util.Map; | |
35 | |
36 import dwtx.jface.text.DocumentEvent; | |
37 import dwtx.jface.text.IDocument; | |
38 import dwtx.jface.text.IDocumentInformationMapping; | |
39 import dwtx.jface.text.IDocumentListener; | |
40 import dwtx.jface.text.ISlaveDocumentManager; | |
41 import dwtx.jface.text.ISlaveDocumentManagerExtension; | |
42 | |
43 | |
44 /** | |
45 * A <code>ProjectionDocumentManager</code> is one particular implementation | |
46 * of {@link dwtx.jface.text.ISlaveDocumentManager}. This manager | |
47 * creates so called projection documents (see | |
48 * {@link dwtx.jface.text.projection.ProjectionDocument}as slave | |
49 * documents for given master documents. | |
50 * <p> | |
51 * A projection document represents a particular projection of the master | |
52 * document and is accordingly adapted to changes of the master document. Vice | |
53 * versa, the master document is accordingly adapted to changes of its slave | |
54 * documents. The manager does not maintain any particular management structure | |
55 * but utilizes mechanisms given by {@link dwtx.jface.text.IDocument} | |
56 * such as position categories and position updaters. | |
57 * <p> | |
58 * Clients can instantiate this class. This class is not intended to be | |
59 * subclassed.</p> | |
60 * | |
61 * @since 3.0 | |
62 * @noextend This class is not intended to be subclassed by clients. | |
63 */ | |
64 public class ProjectionDocumentManager : IDocumentListener, ISlaveDocumentManager, ISlaveDocumentManagerExtension { | |
65 | |
66 /** Registry for master documents and their projection documents. */ | |
67 private Map fProjectionRegistry= new HashMap(); | |
68 | |
69 /** | |
70 * Registers the given projection document for the given master document. | |
71 * | |
72 * @param master the master document | |
73 * @param projection the projection document | |
74 */ | |
75 private void add(IDocument master, ProjectionDocument projection) { | |
134 | 76 List list= cast(List) fProjectionRegistry.get(master); |
129 | 77 if (list is null) { |
78 list= new ArrayList(1); | |
79 fProjectionRegistry.put(master, list); | |
80 } | |
81 list.add(projection); | |
82 } | |
83 | |
84 /** | |
85 * Unregisters the given projection document from its master. | |
86 * | |
87 * @param master the master document | |
88 * @param projection the projection document | |
89 */ | |
90 private void remove(IDocument master, ProjectionDocument projection) { | |
134 | 91 List list= cast(List) fProjectionRegistry.get(master); |
129 | 92 if (list !is null) { |
93 list.remove(projection); | |
94 if (list.size() is 0) | |
95 fProjectionRegistry.remove(master); | |
96 } | |
97 } | |
98 | |
99 /** | |
100 * Returns whether the given document is a master document. | |
101 * | |
102 * @param master the document | |
103 * @return <code>true</code> if the given document is a master document known to this manager | |
104 */ | |
105 private bool hasProjection(IDocument master) { | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
106 return (cast(List)fProjectionRegistry.get(master) ); |
129 | 107 } |
108 | |
109 /** | |
110 * Returns an iterator enumerating all projection documents registered for the given document or | |
111 * <code>null</code> if the document is not a known master document. | |
112 * | |
113 * @param master the document | |
114 * @return an iterator for all registered projection documents or <code>null</code> | |
115 */ | |
116 private Iterator getProjectionsIterator(IDocument master) { | |
134 | 117 List list= cast(List) fProjectionRegistry.get(master); |
129 | 118 if (list !is null) |
119 return list.iterator(); | |
120 return null; | |
121 } | |
122 | |
123 /** | |
124 * Informs all projection documents of the master document that issued the given document event. | |
125 * | |
126 * @param about indicates whether the change is about to happen or happened already | |
127 * @param masterEvent the document event which will be processed to inform the projection documents | |
128 */ | |
129 protected void fireDocumentEvent(bool about, DocumentEvent masterEvent) { | |
130 IDocument master= masterEvent.getDocument(); | |
131 Iterator e= getProjectionsIterator(master); | |
132 if (e is null) | |
133 return; | |
134 | |
135 while (e.hasNext()) { | |
134 | 136 ProjectionDocument document= cast(ProjectionDocument) e.next(); |
129 | 137 if (about) |
138 document.masterDocumentAboutToBeChanged(masterEvent); | |
139 else | |
140 document.masterDocumentChanged(masterEvent); | |
141 } | |
142 } | |
143 | |
144 /* | |
145 * @see dwtx.jface.text.IDocumentListener#documentChanged(dwtx.jface.text.DocumentEvent) | |
146 */ | |
147 public void documentChanged(DocumentEvent event) { | |
148 fireDocumentEvent(false, event); | |
149 } | |
150 | |
151 /* | |
152 * @see dwtx.jface.text.IDocumentListener#documentAboutToBeChanged(dwtx.jface.text.DocumentEvent) | |
153 */ | |
154 public void documentAboutToBeChanged(DocumentEvent event) { | |
155 fireDocumentEvent(true, event); | |
156 } | |
157 | |
158 /* | |
159 * @see dwtx.jface.text.ISlaveDocumentManager#createMasterSlaveMapping(dwtx.jface.text.IDocument) | |
160 */ | |
161 public IDocumentInformationMapping createMasterSlaveMapping(IDocument slave) { | |
138 | 162 if ( cast(ProjectionDocument)slave ) { |
134 | 163 ProjectionDocument projectionDocument= cast(ProjectionDocument) slave; |
129 | 164 return projectionDocument.getDocumentInformationMapping(); |
165 } | |
166 return null; | |
167 } | |
168 | |
169 /* | |
170 * @see dwtx.jface.text.ISlaveDocumentManager#createSlaveDocument(dwtx.jface.text.IDocument) | |
171 */ | |
172 public IDocument createSlaveDocument(IDocument master) { | |
173 if (!hasProjection(master)) | |
174 master.addDocumentListener(this); | |
175 ProjectionDocument slave= createProjectionDocument(master); | |
176 add(master, slave); | |
177 return slave; | |
178 } | |
179 | |
180 /** | |
181 * Factory method for projection documents. | |
182 * | |
183 * @param master the master document | |
184 * @return the newly created projection document | |
185 */ | |
186 protected ProjectionDocument createProjectionDocument(IDocument master) { | |
187 return new ProjectionDocument(master); | |
188 } | |
189 | |
190 /* | |
191 * @see dwtx.jface.text.ISlaveDocumentManager#freeSlaveDocument(dwtx.jface.text.IDocument) | |
192 */ | |
193 public void freeSlaveDocument(IDocument slave) { | |
138 | 194 if ( cast(ProjectionDocument)slave ) { |
134 | 195 ProjectionDocument projectionDocument= cast(ProjectionDocument) slave; |
129 | 196 IDocument master= projectionDocument.getMasterDocument(); |
197 remove(master, projectionDocument); | |
198 projectionDocument.dispose(); | |
199 if (!hasProjection(master)) | |
200 master.removeDocumentListener(this); | |
201 } | |
202 } | |
203 | |
204 /* | |
205 * @see dwtx.jface.text.ISlaveDocumentManager#getMasterDocument(dwtx.jface.text.IDocument) | |
206 */ | |
207 public IDocument getMasterDocument(IDocument slave) { | |
138 | 208 if ( cast(ProjectionDocument)slave ) |
134 | 209 return (cast(ProjectionDocument) slave).getMasterDocument(); |
129 | 210 return null; |
211 } | |
212 | |
213 /* | |
214 * @see dwtx.jface.text.ISlaveDocumentManager#isSlaveDocument(dwtx.jface.text.IDocument) | |
215 */ | |
216 public bool isSlaveDocument(IDocument document) { | |
138 | 217 return ( cast(ProjectionDocument)document ); |
129 | 218 } |
219 | |
220 /* | |
221 * @see dwtx.jface.text.ISlaveDocumentManager#setAutoExpandMode(dwtx.jface.text.IDocument, bool) | |
222 */ | |
223 public void setAutoExpandMode(IDocument slave, bool autoExpanding) { | |
138 | 224 if ( cast(ProjectionDocument)slave ) |
134 | 225 (cast(ProjectionDocument) slave).setAutoExpandMode(autoExpanding); |
129 | 226 } |
227 | |
228 /* | |
229 * @see dwtx.jface.text.ISlaveDocumentManagerExtension#getSlaveDocuments(dwtx.jface.text.IDocument) | |
230 */ | |
231 public IDocument[] getSlaveDocuments(IDocument master) { | |
134 | 232 List list= cast(List) fProjectionRegistry.get(master); |
129 | 233 if (list !is null) { |
234 IDocument[] result= new IDocument[list.size()]; | |
235 list.toArray(result); | |
236 return result; | |
237 } | |
238 return null; | |
239 } | |
240 } |