1 package $packageName$; 2 3 4 import org.eclipse.ui.IActionBars; 5 import org.eclipse.ui.IEditorPart; 6 import org.eclipse.ui.part.MultiPageEditorActionBarContributor; 7 import org.eclipse.ui.texteditor.ITextEditor; 8 import org.eclipse.ui.texteditor.ITextEditorActionConstants; 9 import org.eclipse.ui.IWorkbenchActionConstants; 10 import org.eclipse.jface.action.*; 11 import org.eclipse.jface.dialogs.MessageDialog; 12 import org.eclipse.ui.PlatformUI; 13 import org.eclipse.ui.ISharedImages; 14 15 20 public class $contributorClassName$ extends MultiPageEditorActionBarContributor { 21 private IEditorPart activeEditorPart; 22 private Action sampleAction; 23 26 public $contributorClassName$() { 27 super(); 28 createActions(); 29 } 30 34 protected IAction getAction(ITextEditor editor, String actionID) { 35 return (editor == null ? null : editor.getAction(actionID)); 36 } 37 40 41 public void setActivePage(IEditorPart part) { 42 if (activeEditorPart == part) 43 return; 44 45 activeEditorPart = part; 46 47 IActionBars actionBars = getActionBars(); 48 if (actionBars != null) { 49 50 ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null; 51 52 actionBars.setGlobalActionHandler( 53 IWorkbenchActionConstants.DELETE, 54 getAction(editor, ITextEditorActionConstants.DELETE)); 55 actionBars.setGlobalActionHandler( 56 IWorkbenchActionConstants.UNDO, 57 getAction(editor, ITextEditorActionConstants.UNDO)); 58 actionBars.setGlobalActionHandler( 59 IWorkbenchActionConstants.REDO, 60 getAction(editor, ITextEditorActionConstants.REDO)); 61 actionBars.setGlobalActionHandler( 62 IWorkbenchActionConstants.CUT, 63 getAction(editor, ITextEditorActionConstants.CUT)); 64 actionBars.setGlobalActionHandler( 65 IWorkbenchActionConstants.COPY, 66 getAction(editor, ITextEditorActionConstants.COPY)); 67 actionBars.setGlobalActionHandler( 68 IWorkbenchActionConstants.PASTE, 69 getAction(editor, ITextEditorActionConstants.PASTE)); 70 actionBars.setGlobalActionHandler( 71 IWorkbenchActionConstants.SELECT_ALL, 72 getAction(editor, ITextEditorActionConstants.SELECT_ALL)); 73 actionBars.setGlobalActionHandler( 74 IWorkbenchActionConstants.FIND, 75 getAction(editor, ITextEditorActionConstants.FIND)); 76 actionBars.setGlobalActionHandler( 77 IWorkbenchActionConstants.BOOKMARK, 78 getAction(editor, ITextEditorActionConstants.BOOKMARK)); 79 actionBars.updateActionBars(); 80 } 81 } 82 private void createActions() { 83 sampleAction = new Action() { 84 public void run() { 85 MessageDialog.openInformation(null, "$pluginName$", "Sample Action Executed"); 86 } 87 }; 88 sampleAction.setText("Sample Action"); 89 sampleAction.setToolTipText("Sample Action tool tip"); 90 sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). 91 getImageDescriptor(ISharedImages.IMG_OBJS_TASK_TSK)); 92 } 93 public void contributeToMenu(IMenuManager manager) { 94 IMenuManager menu = new MenuManager("Editor &Menu"); 95 manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu); 96 menu.add(sampleAction); 97 } 98 public void contributeToToolBar(IToolBarManager manager) { 99 manager.add(new Separator()); 100 manager.add(sampleAction); 101 } 102 } 103 | Popular Tags |