|
Lines 17-23
Link Here
|
| 17 |
import org.eclipse.core.resources.IFile; |
17 |
import org.eclipse.core.resources.IFile; |
| 18 |
import org.eclipse.core.resources.IFolder; |
18 |
import org.eclipse.core.resources.IFolder; |
| 19 |
import org.eclipse.core.resources.IResource; |
19 |
import org.eclipse.core.resources.IResource; |
|
|
20 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 20 |
import org.eclipse.core.runtime.IAdaptable; |
21 |
import org.eclipse.core.runtime.IAdaptable; |
|
|
22 |
import org.eclipse.core.runtime.Path; |
| 21 |
import org.eclipse.hyades.test.ui.UiPlugin; |
23 |
import org.eclipse.hyades.test.ui.UiPlugin; |
| 22 |
import org.eclipse.hyades.test.ui.internal.navigator.action.resources.ActionMessages; |
24 |
import org.eclipse.hyades.test.ui.internal.navigator.action.resources.ActionMessages; |
| 23 |
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache; |
25 |
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache; |
|
Lines 27-42
Link Here
|
| 27 |
import org.eclipse.hyades.test.ui.navigator.IProxyNode; |
29 |
import org.eclipse.hyades.test.ui.navigator.IProxyNode; |
| 28 |
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; |
30 |
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; |
| 29 |
import org.eclipse.swt.dnd.Clipboard; |
31 |
import org.eclipse.swt.dnd.Clipboard; |
|
|
32 |
import org.eclipse.swt.dnd.FileTransfer; |
| 30 |
import org.eclipse.swt.widgets.Shell; |
33 |
import org.eclipse.swt.widgets.Shell; |
| 31 |
import org.eclipse.ui.part.ResourceTransfer; |
34 |
import org.eclipse.ui.part.ResourceTransfer; |
| 32 |
/** |
35 |
/** |
| 33 |
* @author Jerome Bozier |
36 |
* @author Jerome Bozier |
| 34 |
* @version February 26, 2008 |
37 |
* @version April 29, 2008 |
| 35 |
*/ |
38 |
*/ |
| 36 |
public class FileAndFolderPaster implements IPasterExtended { |
39 |
public class FileAndFolderPaster implements IPasterExtended { |
| 37 |
|
40 |
|
| 38 |
private LinkedList folders; |
41 |
private LinkedList folders; |
| 39 |
private LinkedList proxies; |
42 |
private LinkedList proxies; |
|
|
43 |
private LinkedList externalFiles; |
| 40 |
private Clipboard clipboard; |
44 |
private Clipboard clipboard; |
| 41 |
private Shell shell; |
45 |
private Shell shell; |
| 42 |
|
46 |
|
|
Lines 44-49
Link Here
|
| 44 |
folders = new LinkedList(); |
48 |
folders = new LinkedList(); |
| 45 |
clipboard = null; |
49 |
clipboard = null; |
| 46 |
proxies = new LinkedList(); |
50 |
proxies = new LinkedList(); |
|
|
51 |
externalFiles = new LinkedList(); |
| 47 |
shell = null; |
52 |
shell = null; |
| 48 |
} |
53 |
} |
| 49 |
|
54 |
|
|
Lines 55-64
Link Here
|
| 55 |
this.shell = shell; |
60 |
this.shell = shell; |
| 56 |
} |
61 |
} |
| 57 |
|
62 |
|
| 58 |
private void sortClipboardElements() { |
63 |
private void sortClipboardElements(Object selection) { |
| 59 |
folders.clear(); |
64 |
folders.clear(); |
| 60 |
proxies.clear(); |
65 |
proxies.clear(); |
| 61 |
IResource [] res = getResourceFromClipboard(); |
66 |
externalFiles.clear(); |
|
|
67 |
IContainer container = null; |
| 68 |
if (selection instanceof IContainer) { |
| 69 |
container = (IContainer)selection; |
| 70 |
} |
| 71 |
IResource [] res = getResourceFromClipboard(container); |
| 62 |
if (res == null) { |
72 |
if (res == null) { |
| 63 |
return; |
73 |
return; |
| 64 |
} |
74 |
} |
|
Lines 79-91
Link Here
|
| 79 |
} |
89 |
} |
| 80 |
|
90 |
|
| 81 |
|
91 |
|
| 82 |
private IResource [] getResourceFromClipboard() { |
92 |
private IResource [] getResourceFromClipboard(final IContainer container) { |
| 83 |
final IResource[][] clipboardData = new IResource[1][]; |
93 |
final IResource[][] clipboardData = new IResource[1][]; |
| 84 |
shell.getDisplay().syncExec(new Runnable() { |
94 |
shell.getDisplay().syncExec(new Runnable() { |
| 85 |
public void run() { |
95 |
public void run() { |
| 86 |
//- clipboard must have resources or files |
96 |
//- clipboard must have resources or files |
| 87 |
ResourceTransfer resTransfer = ResourceTransfer.getInstance(); |
97 |
ResourceTransfer resTransfer = ResourceTransfer.getInstance(); |
|
|
98 |
// first case : copied inside eclipse |
| 88 |
clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer); |
99 |
clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer); |
|
|
100 |
if (clipboardData[0] == null) { |
| 101 |
// second case : copied outside eclipse |
| 102 |
FileTransfer transfer = FileTransfer.getInstance(); |
| 103 |
String[] res = (String [])clipboard.getContents(transfer); |
| 104 |
IResource[] res2 = new IResource[res.length]; |
| 105 |
for (int i=0; i<res.length; i++) { |
| 106 |
// basic case : resource already inside workspace |
| 107 |
Path path = new Path(res[i]); |
| 108 |
res2[i] = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); |
| 109 |
if (res2[i] == null) { |
| 110 |
// annoying case : resource not inside workspace => add it to external files to be deal separately |
| 111 |
externalFiles.add(res[i]); |
| 112 |
} |
| 113 |
} |
| 114 |
clipboardData[0] = res2; |
| 115 |
} |
| 89 |
} |
116 |
} |
| 90 |
}); |
117 |
}); |
| 91 |
return clipboardData[0]; |
118 |
return clipboardData[0]; |
|
Lines 99-106
Link Here
|
| 99 |
if (! canActivate(shell)) |
126 |
if (! canActivate(shell)) |
| 100 |
return false; |
127 |
return false; |
| 101 |
this.clipboard = clipboard; |
128 |
this.clipboard = clipboard; |
| 102 |
sortClipboardElements(); |
129 |
sortClipboardElements(selection); |
| 103 |
PasteRefactoring refactoring = new PasteRefactoring(folders,proxies); |
130 |
PasteRefactoring refactoring = new PasteRefactoring(folders,proxies,externalFiles); |
| 104 |
PasteRefactoringWizard wizard = new PasteRefactoringWizard(refactoring,selection); |
131 |
PasteRefactoringWizard wizard = new PasteRefactoringWizard(refactoring,selection); |
| 105 |
wizard.setDefaultPageTitle(ActionMessages.PASTE_ACTION_NAME); |
132 |
wizard.setDefaultPageTitle(ActionMessages.PASTE_ACTION_NAME); |
| 106 |
wizard.setNeedsProgressMonitor(true); |
133 |
wizard.setNeedsProgressMonitor(true); |