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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.internal.ui.text;
15 import net.sourceforge.phpdt.internal.ui.text.java.JavaReconcilingStrategy;
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;
30 * A reconciler that is also activated on editor activation.
32 public class JavaReconciler extends MonoReconciler {
35 * Internal part listener for activating the reconciler.
37 class PartListener implements IPartListener {
40 * @see IPartListener#partActivated(IWorkbenchPart)
42 public void partActivated(IWorkbenchPart part) {
43 if (part == fTextEditor)
44 JavaReconciler.this.forceReconciling();
48 * @see IPartListener#partBroughtToTop(IWorkbenchPart)
50 public void partBroughtToTop(IWorkbenchPart part) {
54 * @see IPartListener#partClosed(IWorkbenchPart)
56 public void partClosed(IWorkbenchPart part) {
60 * @see IPartListener#partDeactivated(IWorkbenchPart)
62 public void partDeactivated(IWorkbenchPart part) {
66 * @see IPartListener#partOpened(IWorkbenchPart)
68 public void partOpened(IWorkbenchPart part) {
73 /** The reconciler's editor */
74 private ITextEditor fTextEditor;
75 /** The part listener */
76 private IPartListener fPartListener;
80 * Creates a new reconciler.
82 public JavaReconciler(ITextEditor editor, IReconcilingStrategy strategy, boolean isIncremental) {
83 super(strategy, isIncremental);
88 * @see IReconciler#install(ITextViewer)
90 public void install(ITextViewer textViewer) {
91 super.install(textViewer);
93 fPartListener= new PartListener();
94 IWorkbenchPartSite site= fTextEditor.getSite();
95 IWorkbenchWindow window= site.getWorkbenchWindow();
96 window.getPartService().addPartListener(fPartListener);
100 * @see IReconciler#uninstall()
102 public void uninstall() {
104 IWorkbenchPartSite site= fTextEditor.getSite();
105 IWorkbenchWindow window= site.getWorkbenchWindow();
106 window.getPartService().removePartListener(fPartListener);
113 * @see AbstractReconciler#forceReconciling()
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);
125 * @see AbstractReconciler#reconcilerReset()
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);