1 11 package org.eclipse.ui.views.navigator; 12 13 import org.eclipse.core.resources.IFolder; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.jface.action.IMenuManager; 17 import org.eclipse.jface.action.IToolBarManager; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.ui.IActionBars; 20 import org.eclipse.ui.IWorkbenchActionConstants; 21 import org.eclipse.ui.actions.ActionContext; 22 import org.eclipse.ui.actions.ActionFactory; 23 import org.eclipse.ui.internal.views.navigator.ResourceNavigatorMessages; 24 import org.eclipse.ui.views.framelist.BackAction; 25 import org.eclipse.ui.views.framelist.ForwardAction; 26 import org.eclipse.ui.views.framelist.FrameList; 27 import org.eclipse.ui.views.framelist.GoIntoAction; 28 import org.eclipse.ui.views.framelist.UpAction; 29 30 33 public class GotoActionGroup extends ResourceNavigatorActionGroup { 34 35 private BackAction backAction; 36 37 private ForwardAction forwardAction; 38 39 private GoIntoAction goIntoAction; 40 41 private UpAction upAction; 42 43 private GotoResourceAction goToResourceAction; 44 45 public GotoActionGroup(IResourceNavigator navigator) { 46 super(navigator); 47 } 48 49 public void fillContextMenu(IMenuManager menu) { 50 IStructuredSelection selection = (IStructuredSelection) getContext() 51 .getSelection(); 52 if (selection.size() == 1) { 53 if (ResourceSelectionUtil.allResourcesAreOfType(selection, 54 IResource.FOLDER)) { 55 menu.add(goIntoAction); 56 } else { 57 IStructuredSelection resourceSelection = ResourceSelectionUtil 58 .allResources(selection, IResource.PROJECT); 59 if (resourceSelection != null && !resourceSelection.isEmpty()) { 60 IProject project = (IProject) resourceSelection 61 .getFirstElement(); 62 if (project.isOpen()) { 63 menu.add(goIntoAction); 64 } 65 } 66 } 67 } 68 } 69 70 public void fillActionBars(IActionBars actionBars) { 71 actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_INTO, 72 goIntoAction); 73 actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(), 74 backAction); 75 actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(), 76 forwardAction); 77 actionBars.setGlobalActionHandler(IWorkbenchActionConstants.UP, 78 upAction); 79 actionBars.setGlobalActionHandler( 80 IWorkbenchActionConstants.GO_TO_RESOURCE, goToResourceAction); 81 82 IToolBarManager toolBar = actionBars.getToolBarManager(); 83 toolBar.add(backAction); 84 toolBar.add(forwardAction); 85 toolBar.add(upAction); 86 } 87 88 protected void makeActions() { 89 FrameList frameList = navigator.getFrameList(); 90 goIntoAction = new GoIntoAction(frameList); 91 backAction = new BackAction(frameList); 92 forwardAction = new ForwardAction(frameList); 93 upAction = new UpAction(frameList); 94 goToResourceAction = new GotoResourceAction(navigator, 95 ResourceNavigatorMessages.GoToResource_label); 96 } 97 98 public void updateActionBars() { 99 ActionContext context = getContext(); 100 boolean enable = false; 101 102 if (context != null) { 107 IStructuredSelection selection = (IStructuredSelection) context 108 .getSelection(); 109 110 if (selection.size() == 1) { 111 Object object = selection.getFirstElement(); 112 if (object instanceof IProject) { 113 enable = ((IProject) object).isOpen(); 114 } else if (object instanceof IFolder) { 115 enable = true; 116 } 117 } 118 } 119 goIntoAction.setEnabled(enable); 120 } 122 } 123 | Popular Tags |