Mercurial > projects > dwt-addons
comparison dwtx/jface/text/link/LinkedModeModel.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | f70d9508c95c |
children |
comparison
equal
deleted
inserted
replaced
161:f8d52b926852 | 162:1a5b8f8129df |
---|---|
22 import dwtx.jface.text.link.LinkedPositionAnnotations; // packageimport | 22 import dwtx.jface.text.link.LinkedPositionAnnotations; // packageimport |
23 import dwtx.jface.text.link.ProposalPosition; // packageimport | 23 import dwtx.jface.text.link.ProposalPosition; // packageimport |
24 | 24 |
25 | 25 |
26 import dwt.dwthelper.utils; | 26 import dwt.dwthelper.utils; |
27 | |
28 import dwtx.dwtxhelper.Collection; | 27 import dwtx.dwtxhelper.Collection; |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | 28 |
36 import dwtx.core.runtime.Assert; | 29 import dwtx.core.runtime.Assert; |
37 import dwtx.jface.text.BadLocationException; | 30 import dwtx.jface.text.BadLocationException; |
38 import dwtx.jface.text.BadPositionCategoryException; | 31 import dwtx.jface.text.BadPositionCategoryException; |
39 import dwtx.jface.text.DocumentEvent; | 32 import dwtx.jface.text.DocumentEvent; |
40 import dwtx.jface.text.IDocument; | 33 import dwtx.jface.text.IDocument; |
41 import dwtx.jface.text.IDocumentExtension; | 34 import dwtx.jface.text.IDocumentExtension; |
42 import dwtx.jface.text.IDocumentListener; | 35 import dwtx.jface.text.IDocumentListener; |
43 import dwtx.jface.text.IPositionUpdater; | 36 import dwtx.jface.text.IPositionUpdater; |
44 import dwtx.jface.text.Position; | 37 import dwtx.jface.text.Position; |
45 import dwtx.jface.text.IDocumentExtension.IReplace; | 38 import dwtx.jface.text.IDocumentExtension; |
46 import dwtx.text.edits.MalformedTreeException; | 39 import dwtx.text.edits.MalformedTreeException; |
47 import dwtx.text.edits.TextEdit; | 40 import dwtx.text.edits.TextEdit; |
48 | 41 |
49 | 42 |
50 /** | 43 /** |
140 | 133 |
141 /** | 134 /** |
142 * Encapsulates the edition triggered by a change to a linking position. Can | 135 * Encapsulates the edition triggered by a change to a linking position. Can |
143 * be applied to a document as a whole. | 136 * be applied to a document as a whole. |
144 */ | 137 */ |
145 private class Replace : IReplace { | 138 private class Replace : IDocumentExtension.IReplace { |
146 | 139 |
147 /** The edition to apply on a document. */ | 140 /** The edition to apply on a document. */ |
148 private TextEdit fEdit; | 141 private TextEdit fEdit; |
149 | 142 |
150 /** | 143 /** |
238 | 231 |
239 if (result !is null) { | 232 if (result !is null) { |
240 // edit all documents | 233 // edit all documents |
241 for (Iterator it2= result.keySet().iterator(); it2.hasNext(); ) { | 234 for (Iterator it2= result.keySet().iterator(); it2.hasNext(); ) { |
242 IDocument doc= cast(IDocument) it2.next(); | 235 IDocument doc= cast(IDocument) it2.next(); |
243 TextEdit edit= cast(TextEdit) result.get(doc); | 236 TextEdit edit= cast(TextEdit) result.get(cast(Object)doc); |
244 Replace replace= new Replace(edit); | 237 Replace replace= new Replace(edit); |
245 | 238 |
246 // apply the edition, either as post notification replace | 239 // apply the edition, either as post notification replace |
247 // on the calling document or directly on any other | 240 // on the calling document or directly on any other |
248 // document | 241 // document |
260 } | 253 } |
261 | 254 |
262 } | 255 } |
263 | 256 |
264 /** The set of linked position groups. */ | 257 /** The set of linked position groups. */ |
265 private const List fGroups= new ArrayList(); | 258 private const List fGroups; |
266 /** The set of documents spanned by this group. */ | 259 /** The set of documents spanned by this group. */ |
267 private const Set fDocuments= new HashSet(); | 260 private const Set fDocuments; |
268 /** The position updater for linked positions. */ | 261 /** The position updater for linked positions. */ |
269 private const IPositionUpdater fUpdater= new InclusivePositionUpdater(getCategory()); | 262 private const IPositionUpdater fUpdater; |
270 /** The document listener on the documents affected by this model. */ | 263 /** The document listener on the documents affected by this model. */ |
271 private const DocumentListener fDocumentListener= new DocumentListener(); | 264 private const DocumentListener fDocumentListener; |
272 /** The parent model for a hierarchical set up, or <code>null</code>. */ | 265 /** The parent model for a hierarchical set up, or <code>null</code>. */ |
273 private LinkedModeModel fParentEnvironment; | 266 private LinkedModeModel fParentEnvironment; |
274 /** | 267 /** |
275 * The position in <code>fParentEnvironment</code> that includes all | 268 * The position in <code>fParentEnvironment</code> that includes all |
276 * positions in this object, or <code>null</code> if there is no parent | 269 * positions in this object, or <code>null</code> if there is no parent |
283 */ | 276 */ |
284 private bool fIsSealed= false; | 277 private bool fIsSealed= false; |
285 /** <code>true</code> when this model is changing documents. */ | 278 /** <code>true</code> when this model is changing documents. */ |
286 private bool fIsChanging= false; | 279 private bool fIsChanging= false; |
287 /** The linked listeners. */ | 280 /** The linked listeners. */ |
288 private const List fListeners= new ArrayList(); | 281 private const List fListeners; |
289 /** Flag telling whether we have exited: */ | 282 /** Flag telling whether we have exited: */ |
290 private bool fIsActive= true; | 283 private bool fIsActive= true; |
291 /** | 284 /** |
292 * The sequence of document positions as we are going to iterate through | 285 * The sequence of document positions as we are going to iterate through |
293 * them. | 286 * them. |
294 */ | 287 */ |
295 private List fPositionSequence= new ArrayList(); | 288 private List fPositionSequence; |
296 | 289 |
297 /** | 290 /** |
298 * Whether we are in the process of editing documents (set by <code>Replace</code>, | 291 * Whether we are in the process of editing documents (set by <code>Replace</code>, |
299 * read by <code>DocumentListener</code>. | 292 * read by <code>DocumentListener</code>. |
300 * | 293 * |
377 * category. | 370 * category. |
378 * | 371 * |
379 * @param document the new document | 372 * @param document the new document |
380 */ | 373 */ |
381 private void manageDocument(IDocument document) { | 374 private void manageDocument(IDocument document) { |
382 if (!fDocuments.contains(document)) { | 375 if (!fDocuments.contains(cast(Object)document)) { |
383 fDocuments.add(document); | 376 fDocuments.add(cast(Object)document); |
384 document.addPositionCategory(getCategory()); | 377 document.addPositionCategory(getCategory()); |
385 document.addPositionUpdater(fUpdater); | 378 document.addPositionUpdater(fUpdater); |
386 document.addDocumentListener(fDocumentListener); | 379 document.addDocumentListener(fDocumentListener); |
387 } | 380 } |
388 | 381 |
436 /** | 429 /** |
437 * Creates a new model. | 430 * Creates a new model. |
438 * @since 3.1 | 431 * @since 3.1 |
439 */ | 432 */ |
440 public this() { | 433 public this() { |
434 // DWT inst init | |
435 fGroups= new ArrayList(); | |
436 fDocuments= new HashSet(); | |
437 fUpdater= new InclusivePositionUpdater(getCategory()); | |
438 fDocumentListener= new DocumentListener(); | |
439 fListeners= new ArrayList(); | |
440 fPositionSequence= new ArrayList(); | |
441 | |
441 } | 442 } |
442 | 443 |
443 /** | 444 /** |
444 * Installs this model, which includes registering as document | 445 * Installs this model, which includes registering as document |
445 * listener on all involved documents and storing global information about | 446 * listener on all involved documents and storing global information about |
554 */ | 555 */ |
555 private IDocument[] getDocuments() { | 556 private IDocument[] getDocuments() { |
556 Set docs= new HashSet(); | 557 Set docs= new HashSet(); |
557 for (Iterator it= fGroups.iterator(); it.hasNext(); ) { | 558 for (Iterator it= fGroups.iterator(); it.hasNext(); ) { |
558 LinkedPositionGroup group= cast(LinkedPositionGroup) it.next(); | 559 LinkedPositionGroup group= cast(LinkedPositionGroup) it.next(); |
559 docs.addAll(Arrays.asList(group.getDocuments())); | 560 docs.addAll(Arrays.asList(arraycast!(Object)(group.getDocuments()))); |
560 } | 561 } |
561 return (IDocument[]) docs.toArray(new IDocument[docs.size()]); | 562 return arraycast!(IDocument)( docs.toArray()); |
562 } | 563 } |
563 | 564 |
564 /** | 565 /** |
565 * Returns whether the receiver can be nested into the given <code>parent</code> | 566 * Returns whether the receiver can be nested into the given <code>parent</code> |
566 * model. If yes, the parent model and its position that the receiver | 567 * model. If yes, the parent model and its position that the receiver |
650 * upon state changes. | 651 * upon state changes. |
651 * | 652 * |
652 * @param listener the new listener | 653 * @param listener the new listener |
653 */ | 654 */ |
654 public void addLinkingListener(ILinkedModeListener listener) { | 655 public void addLinkingListener(ILinkedModeListener listener) { |
655 Assert.isNotNull(listener); | 656 Assert.isNotNull(cast(Object)listener); |
656 if (!fListeners.contains(listener)) | 657 if (!fListeners.contains(cast(Object)listener)) |
657 fListeners.add(listener); | 658 fListeners.add(cast(Object)listener); |
658 } | 659 } |
659 | 660 |
660 /** | 661 /** |
661 * Removes <code>listener</code> from the set of listeners that are | 662 * Removes <code>listener</code> from the set of listeners that are |
662 * informed upon state changes. | 663 * informed upon state changes. |
663 * | 664 * |
664 * @param listener the new listener | 665 * @param listener the new listener |
665 */ | 666 */ |
666 public void removeLinkingListener(ILinkedModeListener listener) { | 667 public void removeLinkingListener(ILinkedModeListener listener) { |
667 fListeners.remove(listener); | 668 fListeners.remove(cast(Object)listener); |
668 } | 669 } |
669 | 670 |
670 /** | 671 /** |
671 * Finds the position in this model that is closest after | 672 * Finds the position in this model that is closest after |
672 * <code>toFind</code>. <code>toFind</code> needs not be a position in | 673 * <code>toFind</code>. <code>toFind</code> needs not be a position in |