01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 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.actions;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: import org.eclipse.core.resources.IContainer;
16: import org.eclipse.core.resources.IResource;
17: import org.eclipse.swt.widgets.Shell;
18: import org.eclipse.ui.PlatformUI;
19: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
20: import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
21:
22: /**
23: * Standard action for moving the currently selected resources elsewhere
24: * in the workspace. All resources being moved as a group must be siblings.
25: * <p>
26: * This class may be instantiated; it is not intended to be subclassed.
27: * </p>
28: */
29: public class MoveResourceAction extends CopyResourceAction {
30:
31: /**
32: * The id of this action.
33: */
34: public static final String ID = PlatformUI.PLUGIN_ID
35: + ".MoveResourceAction"; //$NON-NLS-1$
36:
37: /**
38: * Keep a list of destinations so that any required update can be done after the
39: * move.
40: */
41: protected List destinations;
42:
43: /**
44: * Creates a new action.
45: *
46: * @param shell the shell for any dialogs
47: */
48: public MoveResourceAction(Shell shell) {
49: super (shell, IDEWorkbenchMessages.MoveResourceAction_text);
50: setToolTipText(IDEWorkbenchMessages.MoveResourceAction_toolTip);
51: setId(MoveResourceAction.ID);
52: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
53: IIDEHelpContextIds.MOVE_RESOURCE_ACTION);
54: }
55:
56: /* (non-Javadoc)
57: * Overrides method in CopyResourceAction
58: */
59: protected CopyFilesAndFoldersOperation createOperation() {
60: return new MoveFilesAndFoldersOperation(getShell());
61: }
62:
63: /**
64: * Returns the destination resources for the resources that have been moved so far.
65: *
66: * @return list of destination <code>IResource</code>s
67: */
68: protected List getDestinations() {
69: return destinations;
70: }
71:
72: /* (non-Javadoc)
73: * Overrides method in CopyResourceAction
74: */
75: protected IResource[] getResources(List resourceList) {
76: ReadOnlyStateChecker checker = new ReadOnlyStateChecker(
77: getShell(),
78: IDEWorkbenchMessages.MoveResourceAction_title,
79: IDEWorkbenchMessages.MoveResourceAction_checkMoveMessage);
80: return checker.checkReadOnlyResources(super
81: .getResources(resourceList));
82: }
83:
84: /* (non-Javadoc)
85: * Overrides method in CopyResourceAction
86: */
87: protected void runOperation(IResource[] resources,
88: IContainer destination) {
89: //Initialize the destinations
90: destinations = new ArrayList();
91: IResource[] copiedResources = operation.copyResources(
92: resources, destination);
93:
94: for (int i = 0; i < copiedResources.length; i++) {
95: destinations.add(destination.getFullPath().append(
96: copiedResources[i].getName()));
97: }
98: }
99: }
|