Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Chen2012-02-22 22:02:12 -0500
committerWilliam Chen2012-02-22 22:05:26 -0500
commitc91d020c98b9bdf3d76c599bcec3b0412d1f46b0 (patch)
treeb43a3ef527a62d135593790d5920f42558f0a7ec
parent3d557ba75c9d6914620d352384fb9820a740ea88 (diff)
downloadorg.eclipse.tcf-c91d020c98b9bdf3d76c599bcec3b0412d1f46b0.tar.gz
org.eclipse.tcf-c91d020c98b9bdf3d76c599bcec3b0412d1f46b0.tar.xz
org.eclipse.tcf-c91d020c98b9bdf3d76c599bcec3b0412d1f46b0.zip
Target Explorer: Add confirmation for overwriting during uploading
files.
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IConfirmCallback.java42
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IUIConstants.java12
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java55
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java34
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.java6
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.properties6
6 files changed, 149 insertions, 6 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IConfirmCallback.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IConfirmCallback.java
new file mode 100644
index 000000000..062c9dc63
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IConfirmCallback.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.filesystem.interfaces;
+
+/**
+ * A confirmation callback used to get UI confirmation from user for a long process
+ */
+public interface IConfirmCallback {
+ // Yes button ID.
+ int YES = 0;
+ // Yes to All button ID.
+ int YES_TO_ALL = 1;
+ // No to All button ID.
+ int NO = 2;
+ // Cancel button ID.
+ int CANCEL = 3;
+ // OK button ID.
+ int OK = YES;
+ // No to all button ID.
+ int NO_TO_ALL = 4;
+ /**
+ * Test if the given object requires confirmation.
+ *
+ * @param object The object being tested.
+ * @return true if it requires confirmation.
+ */
+ boolean requires(Object object);
+ /**
+ * Confirm with the user weather the process should continue, continue for all, skip or cancel.
+ *
+ * @param object The object being tested.
+ * @return a button ID the user selects during confirmation.
+ */
+ int confirms(Object object);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IUIConstants.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IUIConstants.java
index 6c0298f44..bebc5a8ff 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IUIConstants.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/interfaces/IUIConstants.java
@@ -1,5 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
package org.eclipse.tcf.te.tcf.filesystem.interfaces;
+/**
+ * UIConstants for file system.
+ */
public interface IUIConstants extends org.eclipse.tcf.te.ui.interfaces.IUIConstants {
/**
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java
index 76963e6a9..f31a5b537 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java
@@ -12,25 +12,36 @@ package org.eclipse.tcf.te.tcf.filesystem.internal.operations;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
+import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
+import org.eclipse.tcf.te.tcf.filesystem.activator.UIPlugin;
+import org.eclipse.tcf.te.tcf.filesystem.interfaces.IConfirmCallback;
+import org.eclipse.tcf.te.tcf.filesystem.internal.ImageConsts;
import org.eclipse.tcf.te.tcf.filesystem.internal.utils.CacheManager;
import org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode;
import org.eclipse.tcf.te.tcf.filesystem.nls.Messages;
+import org.eclipse.ui.PlatformUI;
/**
* Upload multiple files from local system to a remote system.
*/
-public class FSUpload extends FSUIOperation {
+public class FSUpload extends FSUIOperation implements IConfirmCallback {
// The source files to be uploaded.
String[] sourceFiles;
// The target folder to which these files are moved to.
FSTreeNode targetFolder;
// The callback invoked after uploading.
ICallback callback;
+ // The current children
+ List<FSTreeNode> targetChildren;
/**
* Create an instance with specified files, target folder and a callback.
@@ -66,9 +77,8 @@ public class FSUpload extends FSUIOperation {
files[i] = new File(sourceFiles[i]);
urls[i] = new URL(folderURL, files[i].getName());
}
- CacheManager.getInstance().uploadFiles(monitor, files, urls);
- if (monitor.isCanceled())
- throw new InterruptedException();
+ this.targetChildren = getChildren(targetFolder);
+ CacheManager.getInstance().uploadFiles(monitor, files, urls, this);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
@@ -88,4 +98,41 @@ public class FSUpload extends FSUIOperation {
}
return status;
}
+
+ @Override
+ public boolean requires(Object object) {
+ File file = (File) object;
+ String name = file.getName();
+ for(FSTreeNode child:targetChildren) {
+ if(name.equals(child.name))
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public int confirms(Object object) {
+ final int[] results = new int[1];
+ final File file = (File) object;
+ Display display = PlatformUI.getWorkbench().getDisplay();
+ display.syncExec(new Runnable() {
+ @Override
+ public void run() {
+ Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ String title = Messages.FSUpload_OverwriteTitle;
+ String message = NLS.bind(Messages.FSUpload_OverwriteConfirmation, file.getName());
+ final Image titleImage = UIPlugin.getImage(ImageConsts.DELETE_READONLY_CONFIRM);
+ MessageDialog qDialog = new MessageDialog(parent, title, null, message,
+ MessageDialog.QUESTION, new String[] {Messages.FSUpload_Yes,
+ Messages.FSUpload_YesToAll, Messages.FSUpload_No, Messages.FSUpload_Cancel}, 0) {
+ @Override
+ public Image getQuestionImage() {
+ return titleImage;
+ }
+ };
+ results[0] = qDialog.open();
+ }
+ });
+ return results[0];
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java
index 419f0e6b0..4b40647f6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java
@@ -36,6 +36,7 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tcf.te.tcf.filesystem.activator.UIPlugin;
import org.eclipse.tcf.te.tcf.filesystem.dialogs.TimeTriggeredProgressMonitorDialog;
+import org.eclipse.tcf.te.tcf.filesystem.interfaces.IConfirmCallback;
import org.eclipse.tcf.te.tcf.filesystem.internal.url.TcfURLConnection;
import org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode;
import org.eclipse.tcf.te.tcf.filesystem.nls.Messages;
@@ -345,7 +346,7 @@ public class CacheManager {
}
try {
// Upload the files to the remote location by the specified URLs.
- uploadFiles(monitor, files, urls);
+ uploadFiles(monitor, files, urls, null);
}
finally {
// Once upload is successful, synchronize the modified time.
@@ -377,9 +378,10 @@ public class CacheManager {
* @param files The local file objects.
* @param urls The remote file's URL location.
* @param monitor The monitor used to report the progress.
+ * @param callback confirmation callback.
* @throws Exception an Exception thrown during downloading and storing data.
*/
- public void uploadFiles(IProgressMonitor monitor, File[] files, URL[] urls) throws IOException {
+ public void uploadFiles(IProgressMonitor monitor, File[] files, URL[] urls, IConfirmCallback callback) throws IOException {
BufferedInputStream input = null;
BufferedOutputStream output = null;
// The buffer used to download the file.
@@ -395,8 +397,36 @@ public class CacheManager {
int percentRead = 0;
// The current length of read bytes.
long bytesRead = 0;
+ boolean yes2all = false;
for (int i = 0; i < files.length && !monitor.isCanceled(); i++) {
File file = files[i];
+ if(callback != null && !yes2all) {
+ if(callback.requires(file)) {
+ int result = callback.confirms(file);
+ switch(result) {
+ case IConfirmCallback.YES:
+ break;
+ case IConfirmCallback.YES_TO_ALL:
+ yes2all = true;
+ break;
+ case IConfirmCallback.NO:
+ bytesRead += file.length();
+ if (chunk_size != 0) {
+ int percent = (int) bytesRead / chunk_size;
+ if (percent != percentRead) { // Update the progress.
+ monitor.worked(percent - percentRead);
+ percentRead = percent; // Remember the percentage.
+ // Report the progress.
+ monitor.subTask(NLS.bind(Messages.CacheManager_UploadingProgress, new Object[]{file.getName(), formatSize(bytesRead), formatSize(file.length())}));
+ }
+ }
+ continue;
+ case IConfirmCallback.CANCEL:
+ monitor.setCanceled(true);
+ continue;
+ }
+ }
+ }
try {
URL url = urls[i];
TcfURLConnection connection = (TcfURLConnection) url.openConnection();
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.java
index 912f21a2f..50ae55802 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.java
@@ -252,7 +252,13 @@ public class Messages extends NLS {
public static String FSRenamingAssistant_SpecifyNonEmptyName;
public static String FSRenamingAssistant_UnixIllegalCharacters;
public static String FSRenamingAssistant_WinIllegalCharacters;
+ public static String FSUpload_Cancel;
+ public static String FSUpload_No;
+ public static String FSUpload_OverwriteConfirmation;
+ public static String FSUpload_OverwriteTitle;
public static String FSUpload_UploadTitle;
+ public static String FSUpload_Yes;
+ public static String FSUpload_YesToAll;
public static String SaveAllListener_Cancel;
public static String SaveAllListener_Merge;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.properties
index 7fc78eba4..ed0ec32d0 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/nls/Messages.properties
@@ -247,7 +247,13 @@ UserManager_UserAccountTitle=User Account
FSOperation_CannotOpenDir=Cannot open directory {0} because {1}
FSOperation_CannotReadDir=Cannot read directory {0} because {1}
FSOperation_TimedOutWhenOpening=it has timed out when opening the directory\!
+FSUpload_Cancel=Cancel
+FSUpload_No=No
+FSUpload_OverwriteConfirmation=A file with a same name already exists. Are you sure to overwrite {0}?
+FSUpload_OverwriteTitle=Confirm Overwrite
FSUpload_UploadTitle=Upload Files
+FSUpload_Yes=Yes
+FSUpload_YesToAll=Yes to All
MergeEditorInput_CompareLeftAndRight=Compare {0} and {1}
MergeEditorInput_CompareWithLocalCache=Compare {0} with Local Cache
MergeEditorInput_LocalFile=Local: {0}

Back to the top