1 11 package org.eclipse.ui.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.net.URI ; 15 16 import org.eclipse.core.commands.ExecutionException; 17 import org.eclipse.core.filesystem.URIUtil; 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.jface.dialogs.ErrorDialog; 22 import org.eclipse.jface.operation.IRunnableWithProgress; 23 import org.eclipse.osgi.util.NLS; 24 import org.eclipse.swt.widgets.Shell; 25 import org.eclipse.ui.PlatformUI; 26 import org.eclipse.ui.dialogs.ProjectLocationMoveDialog; 27 import org.eclipse.ui.ide.undo.MoveProjectOperation; 28 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; 29 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 30 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 31 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 32 import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog; 33 34 38 public class MoveProjectAction extends CopyProjectAction { 39 private static String MOVE_TOOL_TIP = IDEWorkbenchMessages.MoveProjectAction_toolTip; 40 41 private static String MOVE_TITLE = IDEWorkbenchMessages.MoveProjectAction_text; 42 43 private static String PROBLEMS_TITLE = IDEWorkbenchMessages.MoveProjectAction_dialogTitle; 44 45 48 public static final String ID = PlatformUI.PLUGIN_ID + ".MoveProjectAction"; 50 56 public MoveProjectAction(Shell shell) { 57 super(shell, MOVE_TITLE); 58 setToolTipText(MOVE_TOOL_TIP); 59 setId(MoveProjectAction.ID); 60 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 61 IIDEHelpContextIds.MOVE_PROJECT_ACTION); 62 } 63 64 72 protected String getErrorsTitle() { 73 return PROBLEMS_TITLE; 74 } 75 76 86 boolean performMove(final IProject project, 87 final URI newLocation) { 88 89 IRunnableWithProgress op = new IRunnableWithProgress() { 90 public void run(IProgressMonitor monitor) { 91 MoveProjectOperation op = new MoveProjectOperation(project, newLocation, IDEWorkbenchMessages.MoveProjectAction_moveTitle); 92 op.setModelProviderIds(getModelProviderIds()); 93 try { 94 PlatformUI.getWorkbench().getOperationSupport() 95 .getOperationHistory().execute(op, monitor, 96 WorkspaceUndoUtil.getUIInfoAdapter(shell)); 97 } catch (ExecutionException e) { 98 if (e.getCause() instanceof CoreException) { 99 recordError((CoreException)e.getCause()); 100 } else { 101 IDEWorkbenchPlugin.log(e.getMessage(), e); 102 displayError(e.getMessage()); 103 } 104 } 105 } 106 }; 107 108 try { 109 new ProgressMonitorJobsDialog(shell).run(true, true, op); 110 } catch (InterruptedException e) { 111 return false; 112 } catch (InvocationTargetException e) { 113 IDEWorkbenchPlugin.log(getClass(), 116 "performMove()", e.getTargetException()); displayError(NLS.bind(IDEWorkbenchMessages.MoveProjectAction_internalError, e.getTargetException().getMessage())); 118 return false; 119 } 120 121 return true; 122 } 123 124 132 protected Object [] queryDestinationParameters(IProject project) { 133 ProjectLocationMoveDialog dialog = new ProjectLocationMoveDialog(shell, 134 project); 135 dialog.setTitle(IDEWorkbenchMessages.MoveProjectAction_moveTitle); 136 dialog.open(); 137 return dialog.getResult(); 138 } 139 140 143 public void run() { 144 145 errorStatus = null; 146 147 IProject project = (IProject) getSelectedResources().get(0); 148 149 Object [] destinationPaths = queryDestinationParameters(project); 151 if (destinationPaths == null) { 152 return; 153 } 154 155 URI newLocation = URIUtil.toURI((String )destinationPaths[1]); 159 160 161 boolean completed = performMove(project, newLocation); 162 163 if (!completed) { 164 return; } 166 167 if (errorStatus != null) { 169 ErrorDialog 170 .openError(this.shell, PROBLEMS_TITLE, null, errorStatus); 171 errorStatus = null; 172 } 173 } 174 } 175 | Popular Tags |