01: /*******************************************************************************
02: * Copyright (c) 2000, 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.jdt.internal.ui.javaeditor;
11:
12: import org.eclipse.core.runtime.Assert;
13:
14: import org.eclipse.jface.text.link.ILinkedModeListener;
15: import org.eclipse.jface.text.link.LinkedModeModel;
16:
17: /**
18: * Turns off occurrences highlighting on a java editor until linked mode is
19: * left.
20: *
21: * @since 3.0
22: */
23: public class EditorHighlightingSynchronizer implements
24: ILinkedModeListener {
25:
26: private final JavaEditor fEditor;
27: private final boolean fWasOccurrencesOn;
28:
29: /**
30: * Creates a new synchronizer.
31: *
32: * @param editor the java editor the occurrences markers of which will be
33: * synchronized with the linked mode
34: *
35: */
36: public EditorHighlightingSynchronizer(JavaEditor editor) {
37: Assert.isLegal(editor != null);
38: fEditor = editor;
39: fWasOccurrencesOn = fEditor.isMarkingOccurrences();
40:
41: if (fWasOccurrencesOn && !isEditorDisposed())
42: fEditor.uninstallOccurrencesFinder();
43: }
44:
45: /*
46: * @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int)
47: */
48: public void left(LinkedModeModel environment, int flags) {
49: if (fWasOccurrencesOn && !isEditorDisposed())
50: fEditor.installOccurrencesFinder(true);
51: }
52:
53: /*
54: * @since 3.2
55: */
56: private boolean isEditorDisposed() {
57: return fEditor == null
58: || 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: }
|