1 11 package org.eclipse.ui.views.navigator; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 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 36 public class ResourceNavigatorMoveAction extends MoveResourceAction { 37 private StructuredViewer viewer; 38 39 private MoveProjectAction moveProjectAction; 40 41 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 58 public void run() { 59 if (moveProjectAction.isEnabled()) { 60 moveProjectAction.run(); 61 return; 62 } 63 64 super.run(); 65 List destinations = getDestinations(); 66 if (destinations != null && destinations.isEmpty() == false) { 67 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 68 List resources = new ArrayList (); 69 Iterator 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 |