KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > reconciler > MonoReconciler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11 package org.eclipse.jface.text.reconciler;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.IProgressMonitor;
15
16 import org.eclipse.jface.text.IDocument;
17 import org.eclipse.jface.text.Region;
18
19
20 /**
21  * Standard implementation of {@link org.eclipse.jface.text.reconciler.IReconciler}.
22  * The reconciler is configured with a single {@linkplain org.eclipse.jface.text.reconciler.IReconcilingStrategy reconciling strategy}
23  * that is used independently from where a dirty region is located in the reconciler's
24  * document.
25  * <p>
26  * Usually, clients instantiate this class and configure it before using it.
27  * </p>
28  *
29  * @see org.eclipse.jface.text.IDocumentListener
30  * @see org.eclipse.jface.text.ITextInputListener
31  * @see org.eclipse.jface.text.reconciler.DirtyRegion
32  * @since 2.0
33  */

34 public class MonoReconciler extends AbstractReconciler {
35
36
37     /** The reconciling strategy. */
38     private IReconcilingStrategy fStrategy;
39
40
41     /**
42      * Creates a new reconciler that uses the same reconciling strategy to
43      * reconcile its document independent of the type of the document's contents.
44      *
45      * @param strategy the reconciling strategy to be used
46      * @param isIncremental the indication whether strategy is incremental or not
47      */

48     public MonoReconciler(IReconcilingStrategy strategy, boolean isIncremental) {
49         super();
50
51         Assert.isNotNull(strategy);
52
53         fStrategy= strategy;
54         setIsIncrementalReconciler(isIncremental);
55     }
56
57     /*
58      * @see IReconciler#getReconcilingStrategy(String)
59      */

60     public IReconcilingStrategy getReconcilingStrategy(String JavaDoc contentType) {
61         Assert.isNotNull(contentType);
62         return fStrategy;
63     }
64
65     /*
66      * @see AbstractReconciler#process(DirtyRegion)
67      */

68     protected void process(DirtyRegion dirtyRegion) {
69
70         if(dirtyRegion != null)
71             fStrategy.reconcile(dirtyRegion, dirtyRegion);
72         else {
73             IDocument document= getDocument();
74             if (document != null)
75                 fStrategy.reconcile(new Region(0, document.getLength()));
76         }
77     }
78
79     /*
80      * @see AbstractReconciler#reconcilerDocumentChanged(IDocument)
81      */

82     protected void reconcilerDocumentChanged(IDocument document) {
83         fStrategy.setDocument(document);
84     }
85
86     /*
87      * @see AbstractReconciler#setProgressMonitor(IProgressMonitor)
88      */

89     public void setProgressMonitor(IProgressMonitor monitor) {
90         super.setProgressMonitor(monitor);
91         if (fStrategy instanceof IReconcilingStrategyExtension) {
92             IReconcilingStrategyExtension extension= (IReconcilingStrategyExtension) fStrategy;
93             extension.setProgressMonitor(monitor);
94         }
95     }
96
97     /*
98      * @see AbstractReconciler#initialProcess()
99      */

100     protected void initialProcess() {
101         if (fStrategy instanceof IReconcilingStrategyExtension) {
102             IReconcilingStrategyExtension extension= (IReconcilingStrategyExtension) fStrategy;
103             extension.initialReconcile();
104         }
105     }
106 }
107
Popular Tags