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 java.util.ArrayList;
13: import java.util.Iterator;
14: import java.util.List;
15:
16: import org.eclipse.core.resources.IResource;
17: import org.eclipse.core.resources.IWorkspaceRoot;
18: import org.eclipse.core.resources.ResourcesPlugin;
19: import org.eclipse.core.runtime.IPath;
20: import org.eclipse.jface.viewers.IStructuredSelection;
21: import org.eclipse.jface.viewers.StructuredSelection;
22: import org.eclipse.jface.viewers.StructuredViewer;
23: import org.eclipse.swt.widgets.Shell;
24: import org.eclipse.ui.PlatformUI;
25: import org.eclipse.ui.actions.MoveProjectAction;
26: import org.eclipse.ui.actions.MoveResourceAction;
27:
28: /**
29: * The ResourceNavigatorMoveAction is a resource move that aso updates the navigator
30: * to show the result of the move.
31: * It also delegates to MoveProjectAction as needed.
32: *
33: * @since 2.0
34: */
35: public class ResourceNavigatorMoveAction extends MoveResourceAction {
36: private StructuredViewer viewer;
37:
38: private MoveProjectAction moveProjectAction;
39:
40: /**
41: * Create a ResourceNavigatorMoveAction and use the supplied viewer to update the UI.
42: * @param shell Shell
43: * @param structureViewer StructuredViewer
44: */
45: public ResourceNavigatorMoveAction(Shell shell,
46: StructuredViewer structureViewer) {
47: super (shell);
48: PlatformUI
49: .getWorkbench()
50: .getHelpSystem()
51: .setHelp(
52: this ,
53: INavigatorHelpContextIds.RESOURCE_NAVIGATOR_MOVE_ACTION);
54: this .viewer = structureViewer;
55: this .moveProjectAction = new MoveProjectAction(shell);
56: }
57:
58: /* (non-Javadoc)
59: * Method declared on IAction.
60: */
61: public void run() {
62: if (moveProjectAction.isEnabled()) {
63: moveProjectAction.run();
64: return;
65: }
66:
67: super .run();
68: List destinations = getDestinations();
69: if (destinations != null && destinations.isEmpty() == false) {
70: IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
71: .getRoot();
72: List resources = new ArrayList();
73: Iterator iterator = destinations.iterator();
74:
75: while (iterator.hasNext()) {
76: IResource newResource = root
77: .findMember((IPath) iterator.next());
78: if (newResource != null) {
79: resources.add(newResource);
80: }
81: }
82:
83: this .viewer.setSelection(
84: new StructuredSelection(resources), true);
85: }
86:
87: }
88:
89: protected boolean updateSelection(IStructuredSelection selection) {
90: moveProjectAction.selectionChanged(selection);
91: return super.updateSelection(selection)
92: || moveProjectAction.isEnabled();
93: }
94:
95: }
|