01: /*******************************************************************************
02: * Copyright (c) 2003, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.text;
11:
12: import java.util.ArrayList;
13:
14: import org.eclipse.jface.text.IDocument;
15: import org.eclipse.jface.text.IRegion;
16: import org.eclipse.jface.text.reconciler.DirtyRegion;
17: import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
18: import org.eclipse.pde.internal.core.text.IReconcilingParticipant;
19:
20: public class ReconcilingStrategy implements IReconcilingStrategy {
21:
22: private IDocument fDocument;
23: private ArrayList fParticipants = new ArrayList();
24:
25: public ReconcilingStrategy() {
26: }
27:
28: /* (non-Javadoc)
29: * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument)
30: */
31: public void setDocument(IDocument document) {
32: fDocument = document;
33: }
34:
35: /* (non-Javadoc)
36: * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
37: */
38: public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
39: if (fDocument != null)
40: notifyParticipants();
41: }
42:
43: /* (non-Javadoc)
44: * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
45: */
46: public void reconcile(IRegion partition) {
47: if (fDocument != null)
48: notifyParticipants();
49: }
50:
51: private synchronized void notifyParticipants() {
52: for (int i = 0; i < fParticipants.size(); i++) {
53: ((IReconcilingParticipant) fParticipants.get(i))
54: .reconciled(fDocument);
55: }
56: }
57:
58: public void addParticipant(IReconcilingParticipant participant) {
59: fParticipants.add(participant);
60: }
61:
62: public void removeParticipant(IReconcilingParticipant participant) {
63: fParticipants.remove(participant);
64: }
65: }
|