1 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 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 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 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 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 message= ""; if (editor != null && editor.isEvaluating()) { 110 message= SnippetMessages.getString("SnippetActionContributor.evalMsg"); } 112 getActionBars().getStatusLineManager().setMessage(message); 113 } 114 } 115 | Popular Tags |