KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > snippeteditor > SnippetEditorActionContributor


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.debug.ui.snippeteditor;
12
13  
14 import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
15 import org.eclipse.jdt.internal.ui.javaeditor.BasicCompilationUnitEditorActionContributor;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.IToolBarManager;
18 import org.eclipse.jface.action.Separator;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IWorkbenchActionConstants;
21
22 /**
23  * Contributions of the Java Snippet Editor to the Workbench's tool and menu bar.
24  */

25 public class SnippetEditorActionContributor extends BasicCompilationUnitEditorActionContributor {
26     
27     protected JavaSnippetEditor fSnippetEditor;
28     
29     private StopAction fStopAction;
30     private SelectImportsAction fSelectImportsAction;
31     private SnippetOpenOnSelectionAction fOpenOnSelectionAction;
32     private SnippetOpenHierarchyOnSelectionAction fOpenOnTypeSelectionAction;
33     
34     public SnippetEditorActionContributor() {
35         super();
36     }
37     
38     /* (non-Javadoc)
39      * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(org.eclipse.jface.action.IToolBarManager)
40      */

41     public void contributeToToolBar(IToolBarManager toolBarManager) {
42         
43         if (fStopAction == null) {
44             toolBarManager.add(new Separator(IJavaDebugUIConstants.EVALUATION_GROUP));
45             return;
46         }
47         toolBarManager.add(fStopAction);
48         toolBarManager.add(fSelectImportsAction);
49         toolBarManager.update(false);
50     }
51             
52     /* (non-Javadoc)
53      * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
54      */

55     public void contributeToMenu(IMenuManager menu) {
56         if (fOpenOnSelectionAction == null) {
57             return;
58         }
59         super.contributeToMenu(menu);
60         
61         IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
62         if (navigateMenu != null) {
63             navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenOnSelectionAction);
64             navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenOnTypeSelectionAction);
65             navigateMenu.setVisible(true);
66         }
67     }
68     
69     /* (non-Javadoc)
70      * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
71      */

72     public void setActiveEditor(IEditorPart part) {
73         
74         super.setActiveEditor(part);
75         fSnippetEditor= null;
76         if (part instanceof JavaSnippetEditor) {
77             fSnippetEditor= (JavaSnippetEditor) part;
78             if (fOpenOnSelectionAction == null) {
79                 initializeActions();
80                 contributeToMenu(getActionBars().getMenuManager());
81                 contributeToToolBar(getActionBars().getToolBarManager());
82             }
83         }
84
85         if (fOpenOnSelectionAction != null) {
86             fStopAction.setEditor(fSnippetEditor);
87             fSelectImportsAction.setEditor(fSnippetEditor);
88             fOpenOnSelectionAction.setEditor(fSnippetEditor);
89             fOpenOnTypeSelectionAction.setEditor(fSnippetEditor);
90         }
91             
92         updateStatus(fSnippetEditor);
93     }
94      
95     protected void initializeActions() {
96          
97         fOpenOnSelectionAction= new SnippetOpenOnSelectionAction(fSnippetEditor);
98         fOpenOnTypeSelectionAction= new SnippetOpenHierarchyOnSelectionAction(fSnippetEditor);
99         fStopAction= new StopAction(fSnippetEditor);
100         
101         fSelectImportsAction= new SelectImportsAction(fSnippetEditor);
102         if (fSnippetEditor.getFile() == null) {
103             fSelectImportsAction.setEnabled(false);
104         }
105     }
106     
107     protected void updateStatus(JavaSnippetEditor editor) {
108         String JavaDoc message= ""; //$NON-NLS-1$
109
if (editor != null && editor.isEvaluating()) {
110             message= SnippetMessages.getString("SnippetActionContributor.evalMsg"); //$NON-NLS-1$
111
}
112         getActionBars().getStatusLineManager().setMessage(message);
113     }
114 }
115
Popular Tags