*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / JavaReconciler.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.internal.ui.text;
13
14
15 import net.sourceforge.phpdt.internal.ui.text.java.JavaReconcilingStrategy;
16
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.ITextViewer;
19 import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
20 import org.eclipse.jface.text.reconciler.MonoReconciler;
21 import org.eclipse.ui.IPartListener;
22 import org.eclipse.ui.IWorkbenchPart;
23 import org.eclipse.ui.IWorkbenchPartSite;
24 import org.eclipse.ui.IWorkbenchWindow;
25 import org.eclipse.ui.texteditor.ITextEditor;
26
27
28  
29 /**
30  * A reconciler that is also activated on editor activation.
31  */
32 public class JavaReconciler extends MonoReconciler {
33         
34         /**
35          * Internal part listener for activating the reconciler.
36          */
37         class PartListener implements IPartListener {
38                 
39                 /*
40                  * @see IPartListener#partActivated(IWorkbenchPart)
41                  */
42                 public void partActivated(IWorkbenchPart part) {
43                         if (part == fTextEditor)
44                                 JavaReconciler.this.forceReconciling();
45                 }
46
47                 /*
48                  * @see IPartListener#partBroughtToTop(IWorkbenchPart)
49                  */
50                 public void partBroughtToTop(IWorkbenchPart part) {
51                 }
52
53                 /*
54                  * @see IPartListener#partClosed(IWorkbenchPart)
55                  */
56                 public void partClosed(IWorkbenchPart part) {
57                 }
58
59                 /*
60                  * @see IPartListener#partDeactivated(IWorkbenchPart)
61                  */
62                 public void partDeactivated(IWorkbenchPart part) {
63                 }
64
65                 /*
66                  * @see IPartListener#partOpened(IWorkbenchPart)
67                  */
68                 public void partOpened(IWorkbenchPart part) {
69                 }
70         };
71         
72         
73         /** The reconciler's editor */
74         private ITextEditor fTextEditor;
75         /** The part listener */
76         private IPartListener fPartListener;
77         
78         
79         /**
80          * Creates a new reconciler.
81          */
82         public JavaReconciler(ITextEditor editor, IReconcilingStrategy strategy, boolean isIncremental) {
83                 super(strategy, isIncremental);
84                 fTextEditor= editor;
85         }
86         
87         /*
88          * @see IReconciler#install(ITextViewer)
89          */
90         public void install(ITextViewer textViewer) {
91                 super.install(textViewer);
92                 
93                 fPartListener= new PartListener();
94                 IWorkbenchPartSite site= fTextEditor.getSite();
95                 IWorkbenchWindow window= site.getWorkbenchWindow();
96                 window.getPartService().addPartListener(fPartListener);
97         }
98
99         /*
100          * @see IReconciler#uninstall()
101          */
102         public void uninstall() {
103                 
104                 IWorkbenchPartSite site= fTextEditor.getSite();
105                 IWorkbenchWindow window= site.getWorkbenchWindow();
106                 window.getPartService().removePartListener(fPartListener);
107                 fPartListener= null;
108                 
109                 super.uninstall();
110         }
111         
112     /*
113          * @see AbstractReconciler#forceReconciling()
114          */
115         protected void forceReconciling() {
116                 super.forceReconciling();
117         IReconcilingStrategy strategy= getReconcilingStrategy(IDocument.DEFAULT_CONTENT_TYPE);
118         if (strategy instanceof JavaReconcilingStrategy) {
119                         JavaReconcilingStrategy java= (JavaReconcilingStrategy) strategy;
120                         java.notifyParticipants(false);
121                 }
122         }
123     
124         /*
125          * @see AbstractReconciler#reconcilerReset()
126          */
127         protected void reconcilerReset() {
128                 super.reconcilerReset();
129         IReconcilingStrategy strategy= getReconcilingStrategy(IDocument.DEFAULT_CONTENT_TYPE);
130         if (strategy instanceof JavaReconcilingStrategy) {
131                         JavaReconcilingStrategy java= (JavaReconcilingStrategy) strategy;
132                         java.notifyParticipants(true);
133                 }
134         }
135 }