01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.views.navigator;
11:
12: import org.eclipse.core.resources.IResource;
13: import org.eclipse.core.resources.IWorkspaceRoot;
14: import org.eclipse.core.runtime.IPath;
15: import org.eclipse.jface.viewers.StructuredSelection;
16: import org.eclipse.jface.viewers.TreeViewer;
17: import org.eclipse.swt.SWT;
18: import org.eclipse.swt.events.KeyEvent;
19: import org.eclipse.swt.widgets.Shell;
20: import org.eclipse.ui.PlatformUI;
21: import org.eclipse.ui.actions.RenameResourceAction;
22:
23: /**
24: * The ResourceNavigatorRenameAction is the rename action used by the
25: * ResourceNavigator that also allows updating after rename.
26: * @since 2.0
27: */
28: public class ResourceNavigatorRenameAction extends RenameResourceAction {
29: private TreeViewer viewer;
30:
31: /**
32: * Create a ResourceNavigatorRenameAction and use the tree of the supplied viewer
33: * for editing.
34: * @param shell Shell
35: * @param treeViewer TreeViewer
36: */
37: public ResourceNavigatorRenameAction(Shell shell,
38: TreeViewer treeViewer) {
39: super (shell, treeViewer.getTree());
40: PlatformUI
41: .getWorkbench()
42: .getHelpSystem()
43: .setHelp(
44: this ,
45: INavigatorHelpContextIds.RESOURCE_NAVIGATOR_RENAME_ACTION);
46: this .viewer = treeViewer;
47: }
48:
49: /* (non-Javadoc)
50: * Run the action to completion using the supplied path.
51: */
52: protected void runWithNewPath(IPath path, IResource resource) {
53: IWorkspaceRoot root = resource.getProject().getWorkspace()
54: .getRoot();
55: super .runWithNewPath(path, resource);
56: if (this .viewer != null) {
57: IResource newResource = root.findMember(path);
58: if (newResource != null) {
59: this .viewer.setSelection(new StructuredSelection(
60: newResource), true);
61: }
62: }
63: }
64:
65: /**
66: * Handle the key release
67: */
68: public void handleKeyReleased(KeyEvent event) {
69: if (event.keyCode == SWT.F2 && event.stateMask == 0
70: && isEnabled()) {
71: run();
72: }
73: }
74: }
|