KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > EditorHighlightingSynchronizer


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.jdt.internal.ui.javaeditor;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jface.text.link.ILinkedModeListener;
16 import org.eclipse.jface.text.link.LinkedModeModel;
17
18
19 /**
20  * Turns off occurrences highlighting on a java editor until linked mode is
21  * left.
22  *
23  * @since 3.0
24  */

25 public class EditorHighlightingSynchronizer implements ILinkedModeListener {
26
27     private final JavaEditor fEditor;
28     private final boolean fWasOccurrencesOn;
29
30     /**
31      * Creates a new synchronizer.
32      *
33      * @param editor the java editor the occurrences markers of which will be
34      * synchronized with the linked mode
35      *
36      */

37     public EditorHighlightingSynchronizer(JavaEditor editor) {
38         Assert.isLegal(editor != null);
39         fEditor= editor;
40         fWasOccurrencesOn= fEditor.isMarkingOccurrences();
41
42         if (fWasOccurrencesOn && !isEditorDisposed())
43             fEditor.uninstallOccurrencesFinder();
44     }
45
46     /*
47      * @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int)
48      */

49     public void left(LinkedModeModel environment, int flags) {
50         if (fWasOccurrencesOn && !isEditorDisposed())
51             fEditor.installOccurrencesFinder(true);
52     }
53
54     /*
55      * @since 3.2
56      */

57     private boolean isEditorDisposed() {
58         return fEditor == null || fEditor.getSelectionProvider() == null;
59     }
60
61     /*
62      * @see org.eclipse.jface.text.link.ILinkedModeListener#suspend(org.eclipse.jface.text.link.LinkedModeModel)
63      */

64     public void suspend(LinkedModeModel environment) {
65     }
66
67     /*
68      * @see org.eclipse.jface.text.link.ILinkedModeListener#resume(org.eclipse.jface.text.link.LinkedModeModel, int)
69      */

70     public void resume(LinkedModeModel environment, int flags) {
71     }
72
73 }
74
Popular Tags