1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-09 10:05:24 +02:00

Bug 163230: Need "cancelAll" functionality in "duplicate name collision" dialog when uploading a directory tree

This commit is contained in:
Kushal Munir 2006-11-02 23:10:31 +00:00
parent 0420688abf
commit 925c5fc987
4 changed files with 171 additions and 23 deletions

View file

@ -37,13 +37,16 @@ import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.rse.core.SystemBasePlugin; import org.eclipse.rse.core.SystemBasePlugin;
import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemRegistry; import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.core.model.SystemWorkspaceResourceSet; import org.eclipse.rse.core.model.SystemWorkspaceResourceSet;
import org.eclipse.rse.core.subsystems.ISubSystem; import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.files.ui.Activator;
import org.eclipse.rse.files.ui.FileResources; import org.eclipse.rse.files.ui.FileResources;
import org.eclipse.rse.model.SystemRemoteResourceSet; import org.eclipse.rse.model.SystemRemoteResourceSet;
import org.eclipse.rse.services.clientserver.SystemEncodingUtil; import org.eclipse.rse.services.clientserver.SystemEncodingUtil;
@ -80,6 +83,22 @@ public class UniversalFileTransferUtility
static final String _rootPath = SystemRemoteEditManager.getDefault().getRemoteEditProjectLocation().makeAbsolute().toOSString(); static final String _rootPath = SystemRemoteEditManager.getDefault().getRemoteEditProjectLocation().makeAbsolute().toOSString();
public static class RenameStatus extends Status {
private static final int CANCEL_ALL = 16;
/**
* @param severity
* @param pluginId
* @param code
* @param message
* @param exception
*/
public RenameStatus(int severity, String pluginId, int code, String message, Throwable exception) {
super(severity, pluginId, code, message, exception);
}
}
/** /**
* Transfer a remote file or folder from one remote location to another. * Transfer a remote file or folder from one remote location to another.
* @param srcFileOrFolder the file or folder to copy * @param srcFileOrFolder the file or folder to copy
@ -962,11 +981,22 @@ public class UniversalFileTransferUtility
String oldPath = newPathBuf.toString() + name; String oldPath = newPathBuf.toString() + name;
if (checkForCollisions) if (checkForCollisions)
{ {
name = checkForCollision(existingFiles, targetFolder, name, oldPath); RenameStatus status = checkForCollision(existingFiles, targetFolder, name, oldPath);
if (name == null) int severity = status.getSeverity();
{
continue; if (severity == IStatus.OK) {
//return null; name = status.getMessage();
}
else if (severity == IStatus.CANCEL) {
int code = status.getCode();
if (code == IStatus.CANCEL) {
continue;
}
else if (code == RenameStatus.CANCEL_ALL) {
break;
}
} }
} }
@ -1894,48 +1924,84 @@ public class UniversalFileTransferUtility
return SystemRemoteEditManager.getDefault().getWorkspacePathFor(hostname, remotePath); return SystemRemoteEditManager.getDefault().getWorkspacePathFor(hostname, remotePath);
} }
protected static String checkForCollision(SystemRemoteResourceSet existingFiles, IRemoteFile targetFolder, String oldName, String oldPath) protected static RenameStatus checkForCollision(SystemRemoteResourceSet existingFiles, IRemoteFile targetFolder, String oldName, String oldPath)
{ {
String newName = oldName; String newName = oldName;
IRemoteFileSubSystem ss = targetFolder.getParentRemoteFileSubSystem(); IRemoteFileSubSystem ss = targetFolder.getParentRemoteFileSubSystem();
IRemoteFile targetFileOrFolder = (IRemoteFile)existingFiles.get(oldPath); IRemoteFile targetFileOrFolder = (IRemoteFile) existingFiles.get(oldPath);
if (targetFileOrFolder != null && targetFileOrFolder.exists()) RenameStatus status = new RenameStatus(IStatus.OK, Activator.getDefault().getBundle().getSymbolicName(), IStatus.OK, newName, null);
{
RenameRunnable rr = new RenameRunnable(targetFileOrFolder); if (targetFileOrFolder != null && targetFileOrFolder.exists()) {
Display.getDefault().syncExec(rr); RenameRunnable rr = new RenameRunnable(targetFileOrFolder);
newName = rr.getNewName(); Display.getDefault().syncExec(rr);
newName = rr.getNewName();
if (newName == null) {
int state = rr.getCancelStatus();
if (state == RenameRunnable.RENAME_DIALOG_CANCELLED_ALL) {
status = new RenameStatus(IStatus.CANCEL, Activator.getDefault().getBundle().getSymbolicName(), RenameStatus.CANCEL_ALL, "", null);
}
else if (state == RenameRunnable.RENAME_DIALOG_CANCELLED) {
status = new RenameStatus(IStatus.CANCEL, Activator.getDefault().getBundle().getSymbolicName(), IStatus.CANCEL, "", null);
}
} }
else {
status = new RenameStatus(IStatus.OK, Activator.getDefault().getBundle().getSymbolicName(), IStatus.OK, newName, null);
}
}
return newName; return status;
} }
public static class RenameRunnable implements Runnable public static class RenameRunnable implements Runnable
{ {
private IRemoteFile _targetFileOrFolder; private IRemoteFile _targetFileOrFolder;
private String _newName; private String _newName;
private int cancelStatus;
public static int RENAME_DIALOG_NOT_CANCELLED = -1;
public static int RENAME_DIALOG_CANCELLED = 0;
public static int RENAME_DIALOG_CANCELLED_ALL = 1;
public RenameRunnable(IRemoteFile targetFileOrFolder) public RenameRunnable(IRemoteFile targetFileOrFolder)
{ {
_targetFileOrFolder = targetFileOrFolder; _targetFileOrFolder = targetFileOrFolder;
cancelStatus = RENAME_DIALOG_NOT_CANCELLED;
} }
public void run() { public void run() {
ValidatorFileUniqueName validator = null; ValidatorFileUniqueName validator = null;
SystemRenameSingleDialog dlg = new SystemRenameSingleDialog(null, true, _targetFileOrFolder, validator); // true => copy-collision-mode SystemRenameSingleDialog dlg = new SystemRenameSingleDialog(null, true, _targetFileOrFolder, validator); // true => copy-collision-mode
dlg.setShowCancelAllButton(true);
dlg.open(); dlg.open();
if (!dlg.wasCancelled()) if (!dlg.wasCancelled() && !dlg.wasCancelledAll())
_newName = dlg.getNewName(); _newName = dlg.getNewName();
else else {
_newName = null; _newName = null;
if (dlg.wasCancelledAll()) {
cancelStatus = RENAME_DIALOG_CANCELLED_ALL;
}
else {
cancelStatus = RENAME_DIALOG_CANCELLED;
}
}
} }
public String getNewName() public String getNewName()
{ {
return _newName; return _newName;
} }
public int getCancelStatus() {
return cancelStatus;
}
} }
protected static String checkForCollision(IRemoteFile targetFolder, String oldName) protected static String checkForCollision(IRemoteFile targetFolder, String oldName)

View file

@ -51,7 +51,8 @@ public class SystemResources extends NLS
public static String BUTTON_APPLY_TOOLTIP; public static String BUTTON_APPLY_TOOLTIP;
public static String BUTTON_RESET_LABEL; public static String BUTTON_RESET_LABEL;
public static String BUTTON_RESET_TOOLTIP; public static String BUTTON_RESET_TOOLTIP;
public static String BUTTON_CANCEL_ALL;
public static String BUTTON_CANCEL_ALL_TOOLTIP;
// THESE TERMS ARE USED POTENTIALLY ANYWHERE // THESE TERMS ARE USED POTENTIALLY ANYWHERE
public static String TERM_YES; public static String TERM_YES;

View file

@ -29,6 +29,8 @@ BUTTON_APPLY_LABEL=Apply
BUTTON_APPLY_TOOLTIP=Press to apply pending changes BUTTON_APPLY_TOOLTIP=Press to apply pending changes
BUTTON_RESET_LABEL=Reset BUTTON_RESET_LABEL=Reset
BUTTON_RESET_TOOLTIP=Press to reset to original values BUTTON_RESET_TOOLTIP=Press to reset to original values
BUTTON_CANCEL_ALL = Cancel All
BUTTON_CANCEL_ALL_TOOLTIP = Cancel for all
TERM_YES=Yes TERM_YES=Yes
TERM_NO=No TERM_NO=No

View file

@ -134,6 +134,7 @@ public abstract class SystemPromptDialog
{ {
protected boolean okPressed = false; protected boolean okPressed = false;
protected boolean cancelAllPressed = false;
protected boolean showBrowseButton = false; protected boolean showBrowseButton = false;
protected boolean showTestButton = false; protected boolean showTestButton = false;
protected boolean showAddButton = false; protected boolean showAddButton = false;
@ -144,12 +145,13 @@ public abstract class SystemPromptDialog
protected boolean initialDetailsButtonEnabledState = true; protected boolean initialDetailsButtonEnabledState = true;
protected boolean detailsButtonHideMode = false; protected boolean detailsButtonHideMode = false;
protected boolean showOkButton = true; protected boolean showOkButton = true;
protected boolean showCancelAllButton = false;
protected Shell overallShell = null; protected Shell overallShell = null;
protected Composite parentComposite, dialogAreaComposite; protected Composite parentComposite, dialogAreaComposite;
protected Composite buttonsComposite; protected Composite buttonsComposite;
protected Button okButton, cancelButton, testButton, browseButton, addButton, detailsButton; protected Button okButton, cancelButton, cancelAllButton, testButton, browseButton, addButton, detailsButton;
protected String title, labelOk, labelBrowse, labelTest, labelCancel, labelAdd, labelDetailsShow, labelDetailsHide; protected String title, labelOk, labelBrowse, labelTest, labelCancel, labelCancelAll, labelAdd, labelDetailsShow, labelDetailsHide;
protected String tipOk, tipBrowse, tipTest, tipCancel, tipAdd, tipDetailsShow, tipDetailsHide; protected String tipOk, tipBrowse, tipTest, tipCancel, tipCancelAll, tipAdd, tipDetailsShow, tipDetailsHide;
protected boolean noShowAgainOption; protected boolean noShowAgainOption;
protected Button noShowAgainButton; protected Button noShowAgainButton;
protected String detailsShowLabel; protected String detailsShowLabel;
@ -191,6 +193,8 @@ public abstract class SystemPromptDialog
protected static final int TEST_ID = 60; protected static final int TEST_ID = 60;
protected static final int ADD_ID = 70; protected static final int ADD_ID = 70;
protected static final int DETAILS_ID = 80; protected static final int DETAILS_ID = 80;
protected static final int CANCEL_ALL_ID = 90;
protected static final boolean BROWSE_BUTTON_YES = true; protected static final boolean BROWSE_BUTTON_YES = true;
protected static final boolean BROWSE_BUTTON_NO = false; protected static final boolean BROWSE_BUTTON_NO = false;
protected static final boolean TEST_BUTTON_YES = true; protected static final boolean TEST_BUTTON_YES = true;
@ -376,12 +380,17 @@ public abstract class SystemPromptDialog
/** /**
* Allow caller to determine if window was cancelled or not. * Allow caller to determine if window was cancelled or not.
* Will return <code>false</code> if Cancel All was pressed.
*/ */
public boolean wasCancelled() public boolean wasCancelled()
{ {
return !okPressed; return !okPressed;
} }
public boolean wasCancelledAll() {
return cancelAllPressed;
}
/** /**
* If validation of the output object is desired, set the validator here. * If validation of the output object is desired, set the validator here.
* It will be used when the child class calls setOutputObject(). * It will be used when the child class calls setOutputObject().
@ -454,6 +463,7 @@ public abstract class SystemPromptDialog
{ {
this.showOkButton = showOk; this.showOkButton = showOk;
} }
/** /**
* For explicitly setting ok button label * For explicitly setting ok button label
*/ */
@ -461,6 +471,7 @@ public abstract class SystemPromptDialog
{ {
this.labelOk = label; this.labelOk = label;
} }
/** /**
* For explicitly setting ok button tooltip text * For explicitly setting ok button tooltip text
*/ */
@ -468,6 +479,7 @@ public abstract class SystemPromptDialog
{ {
this.tipOk = tip; this.tipOk = tip;
} }
/** /**
* For explicitly enabling/disabling ok button. * For explicitly enabling/disabling ok button.
*/ */
@ -545,7 +557,59 @@ public abstract class SystemPromptDialog
protected boolean processCancel() protected boolean processCancel()
{ {
return true; return true;
} }
// ------------------------------
// CANCEL ALL BUTTON CONFIGURATION...
// ------------------------------
/**
* Enable or disable showing of Cancel All button
*/
public void setShowCancelAllButton(boolean showCancelAll)
{
this.showCancelAllButton = showCancelAll;
}
/**
* For explicitly setting cancel button label
*/
public void setCancelAllButtonLabel(String label)
{
this.labelCancelAll = label;
}
/**
* For explicitly setting cancel button tooltip text
*/
public void setCancelAllButtonToolTipText(String tip)
{
this.tipCancelAll = tip;
}
/**
* For explicitly enabling/disabling cancel button.
*/
public void enableCancelAllButton(boolean enable)
{
if (cancelAllButton != null)
cancelAllButton.setEnabled(enable);
}
/**
* Return cancel button widget.
* Be careful <i>not</i> to call the deprecated inherited method getCancelButton()!
*/
public Button getCancelAllButton()
{
return cancelAllButton;
}
/**
* To be overridden by children.
* Called when user presses CANCEL button.
* Return true to close dialog.
* Return false to not close dialog.
*/
protected boolean processCancelAll()
{
return true;
}
// ------------------------------ // ------------------------------
// BROWSE BUTTON CONFIGURATION... // BROWSE BUTTON CONFIGURATION...
@ -894,8 +958,14 @@ public abstract class SystemPromptDialog
else if (!detailsButtonHideMode && (tipDetailsHide != null)) else if (!detailsButtonHideMode && (tipDetailsHide != null))
detailsButton.setToolTipText(tipDetailsHide); detailsButton.setToolTipText(tipDetailsHide);
} }
} }
else if (buttonId == CANCEL_ALL_ID) {
if (processCancelAll()) {
cancelAllPressed = true;
close();
}
}
} }
/** /**
@ -1009,6 +1079,15 @@ public abstract class SystemPromptDialog
} }
}; };
cancelButton.addSelectionListener(cancelListener); cancelButton.addSelectionListener(cancelListener);
if (showCancelAllButton) {
String cancelAllLabel = (labelCancelAll != null) ? labelCancelAll: SystemResources.BUTTON_CANCEL_ALL;
cancelAllButton = createButton(parent, CANCEL_ALL_ID, cancelAllLabel, false);
if (tipCancelAll != null) {
cancelAllButton.setToolTipText(tipCancelAll);
}
}
buttonsComposite = parent; buttonsComposite = parent;
if (helpId != null) if (helpId != null)