Mercurial > projects > dwt-addons
annotate dwtx/jface/text/projection/ProjectionDocumentManager.d @ 200:eb3414669eb0 default tip
fix for dmd 1.041 and tango 0.99.8
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 28 Mar 2009 03:09:57 +0100 |
parents | 1a5b8f8129df |
children |
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 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
140
diff
changeset
|
30 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
140
diff
changeset
|
31 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
140
diff
changeset
|
32 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
140
diff
changeset
|
33 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
140
diff
changeset
|
34 |
129 | 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. */ | |
162 | 67 private Map fProjectionRegistry; |
68 | |
69 this(){ | |
70 fProjectionRegistry= new HashMap(); | |
71 } | |
129 | 72 |
73 /** | |
74 * Registers the given projection document for the given master document. | |
75 * | |
76 * @param master the master document | |
77 * @param projection the projection document | |
78 */ | |
79 private void add(IDocument master, ProjectionDocument projection) { | |
162 | 80 List list= cast(List) fProjectionRegistry.get(cast(Object)master); |
129 | 81 if (list is null) { |
82 list= new ArrayList(1); | |
162 | 83 fProjectionRegistry.put(cast(Object)master, cast(Object)list); |
129 | 84 } |
85 list.add(projection); | |
86 } | |
87 | |
88 /** | |
89 * Unregisters the given projection document from its master. | |
90 * | |
91 * @param master the master document | |
92 * @param projection the projection document | |
93 */ | |
94 private void remove(IDocument master, ProjectionDocument projection) { | |
162 | 95 List list= cast(List) fProjectionRegistry.get(cast(Object)master); |
129 | 96 if (list !is null) { |
97 list.remove(projection); | |
98 if (list.size() is 0) | |
162 | 99 fProjectionRegistry.remove(cast(Object)master); |
129 | 100 } |
101 } | |
102 | |
103 /** | |
104 * Returns whether the given document is a master document. | |
105 * | |
106 * @param master the document | |
107 * @return <code>true</code> if the given document is a master document known to this manager | |
108 */ | |
109 private bool hasProjection(IDocument master) { | |
162 | 110 return ( null !is cast(List)fProjectionRegistry.get(cast(Object)master) ); |
129 | 111 } |
112 | |
113 /** | |
114 * Returns an iterator enumerating all projection documents registered for the given document or | |
115 * <code>null</code> if the document is not a known master document. | |
116 * | |
117 * @param master the document | |
118 * @return an iterator for all registered projection documents or <code>null</code> | |
119 */ | |
120 private Iterator getProjectionsIterator(IDocument master) { | |
162 | 121 List list= cast(List) fProjectionRegistry.get(cast(Object)master); |
129 | 122 if (list !is null) |
123 return list.iterator(); | |
124 return null; | |
125 } | |
126 | |
127 /** | |
128 * Informs all projection documents of the master document that issued the given document event. | |
129 * | |
130 * @param about indicates whether the change is about to happen or happened already | |
131 * @param masterEvent the document event which will be processed to inform the projection documents | |
132 */ | |
133 protected void fireDocumentEvent(bool about, DocumentEvent masterEvent) { | |
134 IDocument master= masterEvent.getDocument(); | |
135 Iterator e= getProjectionsIterator(master); | |
136 if (e is null) | |
137 return; | |
138 | |
139 while (e.hasNext()) { | |
134 | 140 ProjectionDocument document= cast(ProjectionDocument) e.next(); |
129 | 141 if (about) |
142 document.masterDocumentAboutToBeChanged(masterEvent); | |
143 else | |
144 document.masterDocumentChanged(masterEvent); | |
145 } | |
146 } | |
147 | |
148 /* | |
149 * @see dwtx.jface.text.IDocumentListener#documentChanged(dwtx.jface.text.DocumentEvent) | |
150 */ | |
151 public void documentChanged(DocumentEvent event) { | |
152 fireDocumentEvent(false, event); | |
153 } | |
154 | |
155 /* | |
156 * @see dwtx.jface.text.IDocumentListener#documentAboutToBeChanged(dwtx.jface.text.DocumentEvent) | |
157 */ | |
158 public void documentAboutToBeChanged(DocumentEvent event) { | |
159 fireDocumentEvent(true, event); | |
160 } | |
161 | |
162 /* | |
163 * @see dwtx.jface.text.ISlaveDocumentManager#createMasterSlaveMapping(dwtx.jface.text.IDocument) | |
164 */ | |
165 public IDocumentInformationMapping createMasterSlaveMapping(IDocument slave) { | |
138 | 166 if ( cast(ProjectionDocument)slave ) { |
134 | 167 ProjectionDocument projectionDocument= cast(ProjectionDocument) slave; |
129 | 168 return projectionDocument.getDocumentInformationMapping(); |
169 } | |
170 return null; | |
171 } | |
172 | |
173 /* | |
174 * @see dwtx.jface.text.ISlaveDocumentManager#createSlaveDocument(dwtx.jface.text.IDocument) | |
175 */ | |
176 public IDocument createSlaveDocument(IDocument master) { | |
177 if (!hasProjection(master)) | |
178 master.addDocumentListener(this); | |
179 ProjectionDocument slave= createProjectionDocument(master); | |
180 add(master, slave); | |
181 return slave; | |
182 } | |
183 | |
184 /** | |
185 * Factory method for projection documents. | |
186 * | |
187 * @param master the master document | |
188 * @return the newly created projection document | |
189 */ | |
190 protected ProjectionDocument createProjectionDocument(IDocument master) { | |
191 return new ProjectionDocument(master); | |
192 } | |
193 | |
194 /* | |
195 * @see dwtx.jface.text.ISlaveDocumentManager#freeSlaveDocument(dwtx.jface.text.IDocument) | |
196 */ | |
197 public void freeSlaveDocument(IDocument slave) { | |
138 | 198 if ( cast(ProjectionDocument)slave ) { |
134 | 199 ProjectionDocument projectionDocument= cast(ProjectionDocument) slave; |
129 | 200 IDocument master= projectionDocument.getMasterDocument(); |
201 remove(master, projectionDocument); | |
202 projectionDocument.dispose(); | |
203 if (!hasProjection(master)) | |
204 master.removeDocumentListener(this); | |
205 } | |
206 } | |
207 | |
208 /* | |
209 * @see dwtx.jface.text.ISlaveDocumentManager#getMasterDocument(dwtx.jface.text.IDocument) | |
210 */ | |
211 public IDocument getMasterDocument(IDocument slave) { | |
138 | 212 if ( cast(ProjectionDocument)slave ) |
134 | 213 return (cast(ProjectionDocument) slave).getMasterDocument(); |
129 | 214 return null; |
215 } | |
216 | |
217 /* | |
218 * @see dwtx.jface.text.ISlaveDocumentManager#isSlaveDocument(dwtx.jface.text.IDocument) | |
219 */ | |
220 public bool isSlaveDocument(IDocument document) { | |
162 | 221 return ( null !is cast(ProjectionDocument)document ); |
129 | 222 } |
223 | |
224 /* | |
225 * @see dwtx.jface.text.ISlaveDocumentManager#setAutoExpandMode(dwtx.jface.text.IDocument, bool) | |
226 */ | |
227 public void setAutoExpandMode(IDocument slave, bool autoExpanding) { | |
138 | 228 if ( cast(ProjectionDocument)slave ) |
134 | 229 (cast(ProjectionDocument) slave).setAutoExpandMode(autoExpanding); |
129 | 230 } |
231 | |
232 /* | |
233 * @see dwtx.jface.text.ISlaveDocumentManagerExtension#getSlaveDocuments(dwtx.jface.text.IDocument) | |
234 */ | |
235 public IDocument[] getSlaveDocuments(IDocument master) { | |
162 | 236 List list= cast(List) fProjectionRegistry.get(cast(Object)master); |
129 | 237 if (list !is null) { |
162 | 238 return arraycast!(IDocument)(list.toArray()); |
129 | 239 } |
240 return null; | |
241 } | |
242 } |