KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > link > EditorLinkedModeUI


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ui.texteditor.link;
12
13 import org.eclipse.jface.text.ITextViewer;
14 import org.eclipse.jface.text.link.LinkedModeModel;
15 import org.eclipse.jface.text.link.LinkedModeUI;
16 import org.eclipse.jface.text.link.LinkedPosition;
17
18 import org.eclipse.ui.IEditorPart;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.PlatformUI;
22
23 /**
24  * A <code>LinkedModeUI</code> that takes care of updating the focus editor's
25  * navigation history.
26  *
27  * @since 3.0
28  */

29 public class EditorLinkedModeUI extends LinkedModeUI {
30
31     /**
32      * Updates the editor navigation history upon linked focus changes.
33      *
34      * @since 3.0
35      */

36     private static class EditorHistoryUpdater implements ILinkedModeUIFocusListener {
37
38         /*
39          * @see org.eclipse.jface.text.link.LinkedModeUI.ILinkedModeUIFocusListener#linkedFocusLost(org.eclipse.jface.text.link.LinkedPosition, org.eclipse.jface.text.link.LinkedModeUI.LinkedModeUITarget)
40          */

41         public void linkingFocusLost(LinkedPosition position, LinkedModeUITarget target) {
42             // mark navigation history
43
IWorkbenchWindow win= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
44             if (win != null) {
45                 IWorkbenchPage page= win.getActivePage();
46                 if (page != null) {
47                     IEditorPart part= page.getActiveEditor();
48                     page.getNavigationHistory().markLocation(part);
49                 }
50             }
51         }
52
53         /*
54          * @see org.eclipse.jface.text.link.LinkedModeUI.ILinkedModeUIFocusListener#linkedFocusGained(org.eclipse.jface.text.link.LinkedPosition, org.eclipse.jface.text.link.LinkedModeUI.LinkedModeUITarget)
55          */

56         public void linkingFocusGained(LinkedPosition position, LinkedModeUITarget target) {
57             // does nothing
58
}
59     }
60
61
62     /**
63      * @param model
64      * @param viewer
65      */

66     public EditorLinkedModeUI(LinkedModeModel model, ITextViewer viewer) {
67         super(model, viewer);
68         setPositionListener(new EditorHistoryUpdater());
69     }
70
71     /**
72      * @param model
73      * @param viewers
74      */

75     public EditorLinkedModeUI(LinkedModeModel model, ITextViewer[] viewers) {
76         super(model, viewers);
77         setPositionListener(new EditorHistoryUpdater());
78     }
79
80     /**
81      * @param model
82      * @param target
83      */

84     public EditorLinkedModeUI(LinkedModeModel model, LinkedModeUITarget target) {
85         super(model, target);
86         setPositionListener(new EditorHistoryUpdater());
87     }
88
89     /**
90      * @param model
91      * @param targets
92      */

93     public EditorLinkedModeUI(LinkedModeModel model, LinkedModeUITarget[] targets) {
94         super(model, targets);
95         setPositionListener(new EditorHistoryUpdater());
96     }
97 }
98
Popular Tags