1 11 package org.eclipse.ui.views.navigator; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.resources.IWorkspaceRoot; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.jface.viewers.StructuredSelection; 17 import org.eclipse.jface.viewers.TreeViewer; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.events.KeyEvent; 20 import org.eclipse.swt.widgets.Shell; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.actions.RenameResourceAction; 23 24 29 public class ResourceNavigatorRenameAction extends RenameResourceAction { 30 private TreeViewer viewer; 31 32 38 public ResourceNavigatorRenameAction(Shell shell, TreeViewer treeViewer) { 39 super(shell, treeViewer.getTree()); 40 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 41 INavigatorHelpContextIds.RESOURCE_NAVIGATOR_RENAME_ACTION); 42 this.viewer = treeViewer; 43 } 44 45 48 protected void runWithNewPath(IPath path, IResource resource) { 49 IWorkspaceRoot root = resource.getProject().getWorkspace().getRoot(); 50 super.runWithNewPath(path, resource); 51 if (this.viewer != null) { 52 IResource newResource = root.findMember(path); 53 if (newResource != null) { 54 this.viewer.setSelection(new StructuredSelection(newResource), 55 true); 56 } 57 } 58 } 59 60 63 public void handleKeyReleased(KeyEvent event) { 64 if (event.keyCode == SWT.F2 && event.stateMask == 0 && isEnabled()) { 65 run(); 66 } 67 } 68 } 69 | Popular Tags |