KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > CompositeReconcilingStrategy


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  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.text;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.IRegion;
17 import org.eclipse.jface.text.reconciler.DirtyRegion;
18 import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
19 import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
20
21 /**
22  * A reconciling strategy consisting of a sequence of internal reconciling strategies.
23  * By default, all requests are passed on to the contained strategies.
24  *
25  * @since 3.0
26  */

27 public class CompositeReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
28
29     /** The list of internal reconciling strategies. */
30     private IReconcilingStrategy[] fStrategies;
31
32     /**
33      * Creates a new, empty composite reconciling strategy.
34      */

35     public CompositeReconcilingStrategy() {
36     }
37
38     /**
39      * Sets the reconciling strategies for this composite strategy.
40      *
41      * @param strategies the strategies to be set or <code>null</code>
42      */

43     public void setReconcilingStrategies(IReconcilingStrategy[] strategies) {
44         fStrategies= strategies;
45     }
46
47     /**
48      * Returns the previously set stratgies or <code>null</code>.
49      *
50      * @return the contained strategies or <code>null</code>
51      */

52     public IReconcilingStrategy[] getReconcilingStrategies() {
53         return fStrategies;
54     }
55
56     /*
57      * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument)
58      */

59     public void setDocument(IDocument document) {
60         if (fStrategies == null)
61             return;
62
63         for (int i= 0; i < fStrategies.length; i++)
64             fStrategies[i].setDocument(document);
65     }
66
67     /*
68      * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
69      */

70     public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
71         if (fStrategies == null)
72             return;
73
74         for (int i= 0; i < fStrategies.length; i++)
75             fStrategies[i].reconcile(dirtyRegion, subRegion);
76     }
77
78     /*
79      * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
80      */

81     public void reconcile(IRegion partition) {
82         if (fStrategies == null)
83             return;
84
85         for (int i= 0; i < fStrategies.length; i++)
86             fStrategies[i].reconcile(partition);
87     }
88
89     /*
90      * @see org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension#setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)
91      */

92     public void setProgressMonitor(IProgressMonitor monitor) {
93         if (fStrategies == null)
94             return;
95
96         for (int i=0; i < fStrategies.length; i++) {
97             if (fStrategies[i] instanceof IReconcilingStrategyExtension) {
98                 IReconcilingStrategyExtension extension= (IReconcilingStrategyExtension) fStrategies[i];
99                 extension.setProgressMonitor(monitor);
100             }
101         }
102     }
103
104     /*
105      * @see org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension#initialReconcile()
106      */

107     public void initialReconcile() {
108         if (fStrategies == null)
109             return;
110
111         for (int i=0; i < fStrategies.length; i++) {
112             if (fStrategies[i] instanceof IReconcilingStrategyExtension) {
113                 IReconcilingStrategyExtension extension= (IReconcilingStrategyExtension) fStrategies[i];
114                 extension.initialReconcile();
115             }
116         }
117     }
118 }
119
Popular Tags