From 1816180094d14b12df54f9c079d059d1996250b6 Mon Sep 17 00:00:00 2001 From: YoonKi Park Date: Sun, 18 Sep 2011 15:10:45 +0900 Subject: [PATCH] [Title] support drop on folder or file as well --- .../slp/common/connection/ConnectionActivator.java | 2 +- .../connection/ddmuilib/FileDialogUtils.java | 57 +++++++ .../sdblib/dnd/FileEntryDropAdapter.java | 188 +++++++++------------ 3 files changed, 135 insertions(+), 112 deletions(-) create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ddmuilib/FileDialogUtils.java diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ConnectionActivator.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ConnectionActivator.java index 873eb75..c125885 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ConnectionActivator.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ConnectionActivator.java @@ -58,7 +58,7 @@ public class ConnectionActivator extends AbstractUIPlugin { plugin = this; AndroidDebugBridge.init(false); - AndroidDebugBridge.createBridge("/home/kenoz/sdb/adb",true); + AndroidDebugBridge.createBridge("/home/mustafa/mywork/source/sdb/bin/adb",true); // get the eclipse store final IPreferenceStore eclipseStore = getPreferenceStore(); diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ddmuilib/FileDialogUtils.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ddmuilib/FileDialogUtils.java new file mode 100644 index 0000000..134bcd5 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ddmuilib/FileDialogUtils.java @@ -0,0 +1,57 @@ +package com.samsung.slp.common.connection.ddmuilib; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.ui.PlatformUI; + +import com.samsung.slp.common.connection.ui.Messages; + +public class FileDialogUtils { + private static FileDialogUtils instance; + + private FileDialogUtils() {} + + public static FileDialogUtils getInstance() { + if (instance == null) + instance = new FileDialogUtils(); + return instance; + } + + public int checkOverwrite(final String filename) { + 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 msg = NLS.bind(Messages.getString("FileEntryDropAdapter.overrite.message"), filename); + MessageDialog dialog = new MessageDialog( + PlatformUI.getWorkbench().getDisplay().getActiveShell(), + Messages.getString("FileEntryDropAdapter.overrite.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]; + } +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryDropAdapter.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryDropAdapter.java index 7b1fa15..8d1cbb8 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryDropAdapter.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryDropAdapter.java @@ -4,143 +4,109 @@ import java.io.File; import java.io.IOException; import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.IDropActionDelegate; +import com.samsung.slp.common.connection.ConnectionActivator; import com.samsung.slp.common.connection.ddmlib.AdbCommandRejectedException; -import com.samsung.slp.common.connection.ddmlib.AndroidDebugBridge; -import com.samsung.slp.common.connection.ddmlib.IDevice; import com.samsung.slp.common.connection.ddmlib.SyncService; import com.samsung.slp.common.connection.ddmlib.SyncService.ISyncProgressMonitor; import com.samsung.slp.common.connection.ddmlib.SyncService.SyncResult; import com.samsung.slp.common.connection.ddmlib.TimeoutException; +import com.samsung.slp.common.connection.ddmuilib.FileDialogUtils; import com.samsung.slp.common.connection.ddmuilib.console.DdmConsole; -import com.samsung.slp.common.connection.ui.Messages; public class FileEntryDropAdapter implements IDropActionDelegate { @Override public boolean run(Object source, Object target) { - - if (target instanceof IContainer) { - - String[] entries = FileEntryTransfer.getInstance().fromByteArray( - (byte[]) source); - - if (entries.length < 1) - return false; - - IContainer parent = (IContainer) target; - - if (parent.getType() == IResource.FILE) - return false; - - // FIXME : how to know the current selected device?? - IDevice[] device = AndroidDebugBridge.getBridge().getDevices(); - SyncService sync = null; - try { - sync = device[0].getSyncService(); - } catch (TimeoutException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (AdbCommandRejectedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + IResource resource = null; + +// if (target instanceof IResource) { +// resource = (IResource) target; +// localPath = resource.getLocation().toOSString(); +// } + if (target instanceof IAdaptable) { + target = ((IAdaptable) target).getAdapter(IResource.class); + if (target != null && target instanceof IResource) { + resource = (IResource) target; + if (resource.getType() == IResource.FILE && resource.getParent() != null) + resource = resource.getParent(); } - if (sync != null) { - ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor(); - boolean isAlwayCopy = false; - - IWorkspaceRoot root = parent.getWorkspace().getRoot(); - - for (int i = 0; i < entries.length; i++) { - File f = new File(entries[i]); - IPath destPath = parent.getFullPath().append(f.getName()); - IResource newRes = root.findMember(destPath); - String localFilePath = parent.getLocation().append(f.getName()).toOSString(); - if (newRes != null) { - if (isAlwayCopy == false) { - int ret = checkOverwrite(f.getName()); - switch (ret) { - case IDialogConstants.CANCEL_ID : - return false; - case IDialogConstants.YES_TO_ALL_ID : - isAlwayCopy = true; - break; - case IDialogConstants.NO_ID : - continue; - } - } - } - - SyncResult result = sync.pullFile(entries[i],localFilePath , monitor); - - if (result.getCode() != SyncService.RESULT_OK) { - DdmConsole.printErrorToConsole(String.format( - "Failed to pull %1$s: %2$s", - localFilePath, result.getMessage())); - continue; - } else { - if (ResourcesPlugin.getWorkspace().isTreeLocked() == false) { - try { - parent.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - } - } - return false; - } - private int checkOverwrite(final String filename) { - final int[] result = new int[1]; // using array since you can't change a final int + + String[] entries = FileEntryTransfer.getInstance().fromByteArray( + (byte[]) source); + + if (entries.length < 1) + return false; + + SyncService sync = null; + try { + sync = ConnectionActivator.getDefault().getCurrentDevice().getSyncService(); + } catch (TimeoutException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (AdbCommandRejectedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (sync != null) { + ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor(); + boolean isAlwayCopy = false; + + for (int i = 0; i < entries.length; i++) { + File f = new File(entries[i]); + IPath localPath = resource.getFullPath().append(f.getName()); + IResource newRes = resource.getWorkspace().getRoot().findMember(localPath); - Runnable query = new Runnable() { - public void run() { - int resultId[] = { - IDialogConstants.YES_ID, - IDialogConstants.YES_TO_ALL_ID, - IDialogConstants.NO_ID, - IDialogConstants.CANCEL_ID }; + String localFilePath = resource.getLocation().append(f.getName()).toOSString(); + + if (newRes != null) { + if (isAlwayCopy == false) { + int ret = FileDialogUtils.getInstance().checkOverwrite(f.getName()); + switch (ret) { + case IDialogConstants.CANCEL_ID : + return false; + case IDialogConstants.YES_TO_ALL_ID : + isAlwayCopy = true; + break; + case IDialogConstants.NO_ID : + continue; + } + } + } + SyncResult result = sync.pullFile(entries[i],localFilePath , monitor); - String labels[] = new String[] { - IDialogConstants.YES_LABEL, - IDialogConstants.YES_TO_ALL_LABEL, - IDialogConstants.NO_LABEL, - IDialogConstants.CANCEL_LABEL }; - - String msg = NLS.bind(Messages.getString("FileEntryDropAdapter.overrite.message"), filename); - MessageDialog dialog = new MessageDialog( - PlatformUI.getWorkbench().getDisplay().getActiveShell(), - Messages.getString("FileEntryDropAdapter.overrite.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; + if (result.getCode() != SyncService.RESULT_OK) { + DdmConsole.printErrorToConsole(String.format( + "Failed to pull %1$s: %2$s", + localFilePath, result.getMessage())); + continue; } else { - result[0] = resultId[dialog.getReturnCode()]; + if (ResourcesPlugin.getWorkspace().isTreeLocked() == false) { + try { + resource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } } - }; + } - PlatformUI.getWorkbench().getDisplay().syncExec(query); - return result[0]; + return false; } + } -- 2.7.4