KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > CompareEditorContributor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.compare.internal;
12
13 import java.util.ResourceBundle JavaDoc;
14
15 import org.eclipse.jface.action.*;
16
17 import org.eclipse.ui.*;
18 import org.eclipse.ui.actions.ActionFactory;
19 import org.eclipse.ui.help.IWorkbenchHelpSystem;
20 import org.eclipse.ui.part.EditorActionBarContributor;
21 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
22
23 import org.eclipse.compare.*;
24
25
26 public class CompareEditorContributor extends EditorActionBarContributor {
27     
28     private IEditorPart fActiveEditorPart= null;
29
30     private ChangePropertyAction fIgnoreWhitespace;
31     private NavigationAction fNext;
32     private NavigationAction fPrevious;
33     
34     private NavigationAction fToolbarNext;
35     private NavigationAction fToolbarPrevious;
36
37     public CompareEditorContributor() {
38         ResourceBundle JavaDoc bundle= CompareUI.getResourceBundle();
39         
40         IWorkbenchHelpSystem helpSystem= PlatformUI.getWorkbench().getHelpSystem();
41         
42         fIgnoreWhitespace= ChangePropertyAction.createIgnoreWhiteSpaceAction(bundle, null);
43         helpSystem.setHelp(fIgnoreWhitespace, ICompareContextIds.IGNORE_WHITESPACE_ACTION);
44         
45         fNext= new NavigationAction(bundle, true);
46         helpSystem.setHelp(fNext, ICompareContextIds.GLOBAL_NEXT_DIFF_ACTION);
47         
48         fPrevious= new NavigationAction(bundle, false);
49         helpSystem.setHelp(fPrevious, ICompareContextIds.GLOBAL_PREVIOUS_DIFF_ACTION);
50         
51         fToolbarNext= new NavigationAction(bundle, true);
52         helpSystem.setHelp(fToolbarNext, ICompareContextIds.NEXT_DIFF_ACTION);
53         
54         fToolbarPrevious= new NavigationAction(bundle, false);
55         helpSystem.setHelp(fToolbarPrevious, ICompareContextIds.PREVIOUS_DIFF_ACTION);
56     }
57
58     /*
59      * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
60      */

61     public void contributeToToolBar(IToolBarManager tbm) {
62         tbm.add(new Separator());
63         tbm.add(fIgnoreWhitespace);
64         tbm.add(fToolbarNext);
65         tbm.add(fToolbarPrevious);
66     }
67     
68     /*
69      * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
70      */

71     public void contributeToMenu(IMenuManager menuManager) {
72         // empty implementation
73
}
74
75     public void setActiveEditor(IEditorPart targetEditor) {
76                 
77         if (fActiveEditorPart == targetEditor)
78             return;
79             
80         fActiveEditorPart= targetEditor;
81         
82         if (fActiveEditorPart != null) {
83             IEditorInput input= fActiveEditorPart.getEditorInput();
84             if (input instanceof CompareEditorInput) {
85                 CompareEditorInput compareInput= (CompareEditorInput) input;
86                 fNext.setCompareEditorInput(compareInput);
87                 fPrevious.setCompareEditorInput(compareInput);
88                 // Begin fix http://bugs.eclipse.org/bugs/show_bug.cgi?id=20105
89
fToolbarNext.setCompareEditorInput(compareInput);
90                 fToolbarPrevious.setCompareEditorInput(compareInput);
91                 // End fix http://bugs.eclipse.org/bugs/show_bug.cgi?id=20105
92
}
93         }
94             
95         if (targetEditor instanceof CompareEditor) {
96             IActionBars actionBars= getActionBars();
97         
98             CompareEditor editor= (CompareEditor) targetEditor;
99             editor.setActionBars(actionBars);
100         
101             actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fNext);
102             actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPrevious);
103
104             actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNext);
105             actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPrevious);
106             
107             CompareConfiguration cc= editor.getCompareConfiguration();
108             fIgnoreWhitespace.setCompareConfiguration(cc);
109         } else {
110             IActionBars actionBars= getActionBars();
111             actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), null);
112             actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), null);
113             actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, null);
114             actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, null);
115         }
116     }
117     
118     public void dispose() {
119         setActiveEditor(null);
120         super.dispose();
121         fIgnoreWhitespace.dispose();
122     }
123 }
124
Popular Tags