mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-02 22:55:26 +02:00
[248922] [dnd] Remote to local overwrite copy does not work
This commit is contained in:
parent
bae435497e
commit
2fcf4227a4
2 changed files with 115 additions and 4 deletions
|
@ -26,6 +26,7 @@
|
|||
# David Dykstal (IBM) - [231943] Make true and false translatable on SystemTypeFieldEditor
|
||||
# David Dykstal (IBM) - [188150] adding "go up one level" tooltip
|
||||
# David Dykstal (IBM) - [233678] title string is constructed by concatenation, should be substituted
|
||||
# David McKnight (IBM) - [248922] [dnd] Remote to local overwrite copy does not work
|
||||
################################################################################
|
||||
|
||||
# NLS_MESSAGEFORMAT_VAR
|
||||
|
@ -189,7 +190,7 @@ RESID_MOVE_TARGET_FILTERPOOL_PROMPT=Select the filter pool to move into
|
|||
# GENERIC COPY/MOVE NAME-COLLISION DIALOG...
|
||||
#=============================================================
|
||||
RESID_COLLISION_RENAME_TITLE=Duplicate Name Collision
|
||||
RESID_COLLISION_RENAME_VERBIAGE=A resource named "&1" already exists.
|
||||
RESID_COLLISION_RENAME_VERBIAGE=A resource named "{0}" already exists.
|
||||
RESID_COLLISION_RENAME_LABEL=Rename to
|
||||
RESID_COLLISION_COPY_VERBIAGE=The following resources already exist. Would you like to overwrite all of the existing resources or cancel the operation?
|
||||
RESID_COLLISION_COPY_COLHDG_OLDNAME=Resource
|
||||
|
@ -1091,3 +1092,7 @@ SystemImportConnectionAction_UnexpectedException=unexpected exception
|
|||
SystemTableViewPart_title={0} {1}
|
||||
SystemTypeFieldEditor_false=false
|
||||
SystemTypeFieldEditor_true=true
|
||||
|
||||
# collision dialog when copying from RSE to eclipse workspace
|
||||
RESID_COLLISION_DUPLICATE_RESOURCE_TITLE=Resource Exists
|
||||
RESID_COLLISION_OVERWRITE_RESOURCE_MESSAGE=The resource {0} already exists. Do you want to overwrite it?
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* David McKnight (IBM) - [228587] [dnd] NPE From Refresh on Copy/Paste
|
||||
* David McKnight (IBM) - [232889] Dragging and dropping files from a remote unix system to a local project does not work
|
||||
* David McKnight (IBM) - [234721] [dnd] When dragging a file from windows file explorer into RSE, a refresh error is given.
|
||||
* David McKnight (IBM) - [248922] [dnd] Remote to local overwrite copy does not work
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.ui.view;
|
||||
|
@ -29,16 +30,22 @@ package org.eclipse.rse.internal.ui.view;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.WorkspaceJob;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.rse.core.RSECorePlugin;
|
||||
import org.eclipse.rse.core.events.ISystemRemoteChangeEvents;
|
||||
import org.eclipse.rse.core.events.ISystemResourceChangeEvents;
|
||||
|
@ -53,14 +60,19 @@ import org.eclipse.rse.core.subsystems.ISubSystem;
|
|||
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
|
||||
import org.eclipse.rse.core.subsystems.ISystemDragDropAdapter;
|
||||
import org.eclipse.rse.internal.ui.GenericMessages;
|
||||
import org.eclipse.rse.internal.ui.SystemResources;
|
||||
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
|
||||
import org.eclipse.rse.ui.ISystemMessages;
|
||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||
import org.eclipse.rse.ui.SystemBasePlugin;
|
||||
import org.eclipse.rse.ui.internal.model.SystemScratchpad;
|
||||
import org.eclipse.rse.ui.messages.SystemMessageDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.undo.CopyResourcesOperation;
|
||||
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
|
||||
import org.eclipse.ui.progress.UIJob;
|
||||
|
||||
|
||||
|
@ -87,6 +99,7 @@ public class SystemDNDTransferRunnable extends WorkspaceJob
|
|||
private int _sourceType;
|
||||
private Viewer _originatingViewer;
|
||||
private boolean _ok;
|
||||
private Shell _shell;
|
||||
|
||||
public SystemDNDTransferRunnable(Object target, ArrayList srcObjects, Viewer originatingViewer, int sourceType)
|
||||
{
|
||||
|
@ -99,6 +112,7 @@ public class SystemDNDTransferRunnable extends WorkspaceJob
|
|||
_resultTgtObjects = new ArrayList();
|
||||
_setList = new ArrayList();
|
||||
this.setUser(true);
|
||||
_shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
|
||||
}
|
||||
|
||||
protected SystemRemoteResourceSet getSetFor(ISubSystem subSystem, ISystemDragDropAdapter adapter)
|
||||
|
@ -309,6 +323,10 @@ public class SystemDNDTransferRunnable extends WorkspaceJob
|
|||
|
||||
protected boolean transferRSEResourcesToEclipseResource(IResource target, ISubSystem targetSubSystem, IProgressMonitor monitor)
|
||||
{
|
||||
boolean alwaysOverwrite = false;
|
||||
|
||||
List resourcesToCopy = new ArrayList();
|
||||
IWorkspaceRoot root = target.getWorkspace().getRoot();
|
||||
for (int i = 0; i < _srcObjects.size() && _ok; i++)
|
||||
{
|
||||
Object srcObject = _srcObjects.get(i);
|
||||
|
@ -322,28 +340,116 @@ public class SystemDNDTransferRunnable extends WorkspaceJob
|
|||
}
|
||||
else if (srcObject != null)
|
||||
{
|
||||
// find all the files to copy and check that they don't exist first
|
||||
ISystemDragDropAdapter srcAdapter = (ISystemDragDropAdapter) ((IAdaptable) srcObject).getAdapter(ISystemDragDropAdapter.class);
|
||||
Object tempFile = srcAdapter.doDrag(srcObject, true, monitor);
|
||||
if (tempFile instanceof IResource)
|
||||
{
|
||||
boolean canCopy = true;
|
||||
IResource res = (IResource)tempFile;
|
||||
try
|
||||
{
|
||||
{
|
||||
IPath destPath = target.getFullPath();
|
||||
destPath = destPath.append(res.getName());
|
||||
res.copy(destPath, false, monitor);
|
||||
|
||||
IResource newResource = root.findMember(destPath);
|
||||
|
||||
// check for existing files
|
||||
if (!alwaysOverwrite){
|
||||
if (newResource != null && newResource.exists()){
|
||||
int result = checkOverwrite(res, newResource);
|
||||
if (result != IDialogConstants.YES_ID && result != IDialogConstants.YES_TO_ALL_ID){
|
||||
canCopy = false;
|
||||
if (result == IDialogConstants.CANCEL_ID){
|
||||
// cancel the whole operation
|
||||
monitor.setCanceled(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
_resultSrcObjects.remove(srcObject);
|
||||
}
|
||||
else if (result == IDialogConstants.YES_TO_ALL_ID){
|
||||
alwaysOverwrite = true; // don't ask anymore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add to the list of files to copy
|
||||
if (canCopy){
|
||||
resourcesToCopy.add(res);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
operationFailed(monitor);
|
||||
SystemBasePlugin.logError(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now doing the actual copy
|
||||
if (!resourcesToCopy.isEmpty()) {
|
||||
IResource[] resources = (IResource[])resourcesToCopy.toArray(new IResource[resourcesToCopy.size()]);
|
||||
IPath destinationPath = target.getFullPath();
|
||||
CopyResourcesOperation op = new CopyResourcesOperation(resources, destinationPath,
|
||||
SystemResources.RESID_COPY_TITLE);
|
||||
|
||||
|
||||
IAdaptable adaptable = WorkspaceUndoUtil.getUIInfoAdapter(_shell);
|
||||
try {
|
||||
PlatformUI.getWorkbench().getOperationSupport()
|
||||
.getOperationHistory().execute(op, monitor,adaptable);
|
||||
} catch (ExecutionException e) {
|
||||
if (e.getCause() instanceof CoreException) {
|
||||
SystemBasePlugin.logError(e.getMessage(), e);
|
||||
} else {
|
||||
SystemBasePlugin.logError(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private int checkOverwrite(final IResource source, final IResource destination) {
|
||||
final int[] result = new int[1]; // using array since you can't change a final int
|
||||
|
||||
Runnable query = new Runnable() {
|
||||
public void run() {
|
||||
int resultId[] = {
|
||||
IDialogConstants.YES_ID,
|
||||
IDialogConstants.YES_TO_ALL_ID,
|
||||
IDialogConstants.NO_ID,
|
||||
IDialogConstants.CANCEL_ID };
|
||||
|
||||
String labels[] = new String[] {
|
||||
IDialogConstants.YES_LABEL,
|
||||
IDialogConstants.YES_TO_ALL_LABEL,
|
||||
IDialogConstants.NO_LABEL,
|
||||
IDialogConstants.CANCEL_LABEL };
|
||||
|
||||
String title = SystemResources.RESID_COLLISION_DUPLICATE_RESOURCE_TITLE;
|
||||
String msg = NLS.bind(SystemResources.RESID_COLLISION_OVERWRITE_RESOURCE_MESSAGE, destination.getFullPath().makeRelative());
|
||||
|
||||
MessageDialog dialog = new MessageDialog(
|
||||
PlatformUI.getWorkbench().getDisplay().getActiveShell(),
|
||||
title,
|
||||
null, msg, MessageDialog.QUESTION, labels, 0);
|
||||
dialog.open();
|
||||
if (dialog.getReturnCode() == SWT.DEFAULT) {
|
||||
// A window close returns SWT.DEFAULT - mapped to a cancel
|
||||
result[0] = IDialogConstants.CANCEL_ID;
|
||||
} else {
|
||||
result[0] = resultId[dialog.getReturnCode()];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PlatformUI.getWorkbench().getDisplay().syncExec(query);
|
||||
return result[0];
|
||||
}
|
||||
|
||||
protected boolean transferNonRSEResources(Object target, ISubSystem targetSubSystem, ISystemDragDropAdapter targetAdapter, IProgressMonitor monitor)
|
||||
{
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue