1 /******************************************************************************* 2 * Copyright (c) 2003, 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.jdt.internal.ui.navigator; 12 13 import org.eclipse.jface.action.IMenuManager; 14 15 import org.eclipse.ui.IActionBars; 16 import org.eclipse.ui.IViewPart; 17 import org.eclipse.ui.actions.ActionContext; 18 import org.eclipse.ui.navigator.CommonActionProvider; 19 import org.eclipse.ui.navigator.ICommonActionExtensionSite; 20 import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; 21 22 import org.eclipse.jdt.ui.actions.RefactorActionGroup; 23 24 /** 25 * Contributes the following actions to the menu on behalf of the JDT content 26 * extension. 27 * 28 * <ul> 29 * <li>{@link RefactorActionGroup}. Contributes the "Refactor>" and "Source>" submenus to the context menu.</li> 30 * </ul> 31 */ 32 public class JavaNavigatorRefactorActionProvider extends CommonActionProvider { 33 34 private RefactorActionGroup fRefactorGroup; 35 36 public void fillActionBars(IActionBars actionBars) { 37 if (fRefactorGroup != null) { 38 fRefactorGroup.fillActionBars(actionBars); 39 fRefactorGroup.retargetFileMenuActions(actionBars); 40 } 41 } 42 43 public void fillContextMenu(IMenuManager menu) { 44 if (fRefactorGroup != null) { 45 fRefactorGroup.fillContextMenu(menu); 46 } 47 } 48 49 public void init(ICommonActionExtensionSite site) { 50 ICommonViewerWorkbenchSite workbenchSite= null; 51 if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) 52 workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite(); 53 54 // we only initialize the refactor group when in a view part 55 // (required for the constructor) 56 if (workbenchSite != null) { 57 if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { 58 IViewPart viewPart= (IViewPart) workbenchSite.getPart(); 59 60 fRefactorGroup= new RefactorActionGroup(viewPart); 61 } 62 } 63 } 64 65 public void setContext(ActionContext context) { 66 if (fRefactorGroup != null) { 67 fRefactorGroup.setContext(context); 68 } 69 } 70 } 71