KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > navigator > ResourceNavigatorMoveAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.views.navigator;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.resources.IWorkspaceRoot;
19 import org.eclipse.core.resources.ResourcesPlugin;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.jface.viewers.StructuredSelection;
23 import org.eclipse.jface.viewers.StructuredViewer;
24 import org.eclipse.swt.widgets.Shell;
25 import org.eclipse.ui.PlatformUI;
26 import org.eclipse.ui.actions.MoveProjectAction;
27 import org.eclipse.ui.actions.MoveResourceAction;
28
29 /**
30  * The ResourceNavigatorMoveAction is a resource move that aso updates the navigator
31  * to show the result of the move.
32  * It also delegates to MoveProjectAction as needed.
33  *
34  * @since 2.0
35  */

36 public class ResourceNavigatorMoveAction extends MoveResourceAction {
37     private StructuredViewer viewer;
38
39     private MoveProjectAction moveProjectAction;
40
41     /**
42      * Create a ResourceNavigatorMoveAction and use the supplied viewer to update the UI.
43      * @param shell Shell
44      * @param structureViewer StructuredViewer
45      */

46     public ResourceNavigatorMoveAction(Shell shell,
47             StructuredViewer structureViewer) {
48         super(shell);
49         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
50                 INavigatorHelpContextIds.RESOURCE_NAVIGATOR_MOVE_ACTION);
51         this.viewer = structureViewer;
52         this.moveProjectAction = new MoveProjectAction(shell);
53     }
54
55     /* (non-Javadoc)
56      * Method declared on IAction.
57      */

58     public void run() {
59         if (moveProjectAction.isEnabled()) {
60             moveProjectAction.run();
61             return;
62         }
63
64         super.run();
65         List JavaDoc destinations = getDestinations();
66         if (destinations != null && destinations.isEmpty() == false) {
67             IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
68             List JavaDoc resources = new ArrayList JavaDoc();
69             Iterator JavaDoc iterator = destinations.iterator();
70
71             while (iterator.hasNext()) {
72                 IResource newResource = root
73                         .findMember((IPath) iterator.next());
74                 if (newResource != null) {
75                     resources.add(newResource);
76                 }
77             }
78
79             this.viewer.setSelection(new StructuredSelection(resources), true);
80         }
81
82     }
83
84     protected boolean updateSelection(IStructuredSelection selection) {
85         moveProjectAction.selectionChanged(selection);
86         return super.updateSelection(selection)
87                 || moveProjectAction.isEnabled();
88     }
89
90 }
91
Popular Tags