KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > actions > MoveResourceAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.actions;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.resources.IContainer;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
21 import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
22
23 /**
24  * Standard action for moving the currently selected resources elsewhere
25  * in the workspace. All resources being moved as a group must be siblings.
26  * <p>
27  * This class may be instantiated; it is not intended to be subclassed.
28  * </p>
29  */

30 public class MoveResourceAction extends CopyResourceAction {
31
32     /**
33      * The id of this action.
34      */

35     public static final String JavaDoc ID = PlatformUI.PLUGIN_ID
36             + ".MoveResourceAction"; //$NON-NLS-1$
37

38     /**
39      * Keep a list of destinations so that any required update can be done after the
40      * move.
41      */

42     protected List JavaDoc destinations;
43
44     /**
45      * Creates a new action.
46      *
47      * @param shell the shell for any dialogs
48      */

49     public MoveResourceAction(Shell shell) {
50         super(shell, IDEWorkbenchMessages.MoveResourceAction_text);
51         setToolTipText(IDEWorkbenchMessages.MoveResourceAction_toolTip);
52         setId(MoveResourceAction.ID);
53         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
54                 IIDEHelpContextIds.MOVE_RESOURCE_ACTION);
55     }
56
57     /* (non-Javadoc)
58      * Overrides method in CopyResourceAction
59      */

60     protected CopyFilesAndFoldersOperation createOperation() {
61         return new MoveFilesAndFoldersOperation(getShell());
62     }
63
64     /**
65      * Returns the destination resources for the resources that have been moved so far.
66      *
67      * @return list of destination <code>IResource</code>s
68      */

69     protected List JavaDoc getDestinations() {
70         return destinations;
71     }
72
73     /* (non-Javadoc)
74      * Overrides method in CopyResourceAction
75      */

76     protected IResource[] getResources(List JavaDoc resourceList) {
77         ReadOnlyStateChecker checker = new ReadOnlyStateChecker(getShell(),
78                 IDEWorkbenchMessages.MoveResourceAction_title,
79                 IDEWorkbenchMessages.MoveResourceAction_checkMoveMessage);
80         return checker.checkReadOnlyResources(super.getResources(resourceList));
81     }
82
83     /* (non-Javadoc)
84      * Overrides method in CopyResourceAction
85      */

86     protected void runOperation(IResource[] resources, IContainer destination) {
87         //Initialize the destinations
88
destinations = new ArrayList JavaDoc();
89         IResource[] copiedResources = operation.copyResources(resources,
90                 destination);
91
92         for (int i = 0; i < copiedResources.length; i++) {
93             destinations.add(destination.getFullPath().append(
94                     copiedResources[i].getName()));
95         }
96     }
97 }
98
Popular Tags