下面列出了org.eclipse.ui.wizards.datatransfer.ImportOperation#setVirtualFolders ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Extract all file system elements (Tar, Zip elements) to destination
* folder (typically workspace/TraceProject/.traceImport or a subfolder of
* it)
*/
private void extractArchiveContent(Iterator<TraceFileSystemElement> fileSystemElementsIter, IFolder tempFolder, IProgressMonitor progressMonitor) throws InterruptedException,
InvocationTargetException {
List<TraceFileSystemElement> subList = new ArrayList<>();
// Collect all the elements
while (fileSystemElementsIter.hasNext()) {
ModalContext.checkCanceled(progressMonitor);
TraceFileSystemElement element = fileSystemElementsIter.next();
if (element.isDirectory()) {
Object[] array = element.getFiles().getChildren();
for (int i = 0; i < array.length; i++) {
subList.add((TraceFileSystemElement) array[i]);
}
}
subList.add(element);
}
if (subList.isEmpty()) {
return;
}
TraceFileSystemElement root = getRootElement(subList.get(0));
ImportProvider fileSystemStructureProvider = new ImportProvider();
IOverwriteQuery myQueryImpl = file -> IOverwriteQuery.NO_ALL;
progressMonitor.setTaskName(Messages.ImportTraceWizard_ExtractImportOperationTaskName);
IPath containerPath = tempFolder.getFullPath();
ImportOperation operation = new ImportOperation(containerPath, root, fileSystemStructureProvider, myQueryImpl, subList);
operation.setContext(fShell);
operation.setCreateContainerStructure(true);
operation.setOverwriteResources(false);
operation.setVirtualFolders(false);
operation.run(SubMonitor.convert(progressMonitor).newChild(subList.size()));
}
/**
* Imports a trace resource to project. In case of name collision the user
* will be asked to confirm overwriting the existing trace, overwriting or
* skipping the trace to be imported.
*
* @param fileSystemElement
* trace file system object to import
* @param monitor
* a progress monitor
* @return the imported resource or null if no resource was imported
*
* @throws InvocationTargetException
* if problems during import operation
* @throws InterruptedException
* if cancelled
* @throws CoreException
* if problems with workspace
*/
private IResource importResource(TraceFileSystemElement fileSystemElement, IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException, CoreException {
IPath tracePath = getInitialDestinationPath(fileSystemElement);
String newName = fConflictHandler.checkAndHandleNameClash(tracePath, monitor);
if (newName == null) {
return null;
}
fileSystemElement.setLabel(newName);
List<TraceFileSystemElement> subList = new ArrayList<>();
FileSystemElement parentFolder = fileSystemElement.getParent();
IPath containerPath = fileSystemElement.getDestinationContainerPath();
tracePath = containerPath.addTrailingSeparator().append(fileSystemElement.getLabel());
boolean createLinksInWorkspace = (fImportOptionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0;
if (fileSystemElement.isDirectory() && !createLinksInWorkspace) {
containerPath = tracePath;
Object[] array = fileSystemElement.getFiles().getChildren();
for (int i = 0; i < array.length; i++) {
subList.add((TraceFileSystemElement) array[i]);
}
parentFolder = fileSystemElement;
} else {
if (!fileSystemElement.isDirectory()) {
// File traces
IFileInfo info = EFS.getStore(new File(fileSystemElement.getFileSystemObject().getAbsolutePath()).toURI()).fetchInfo();
if (info.getLength() == 0) {
// Don't import empty traces
return null;
}
}
subList.add(fileSystemElement);
}
ImportProvider fileSystemStructureProvider = new ImportProvider();
IOverwriteQuery myQueryImpl = file -> IOverwriteQuery.NO_ALL;
monitor.setTaskName(Messages.ImportTraceWizard_ImportOperationTaskName + " " + fileSystemElement.getFileSystemObject().getAbsolutePath()); //$NON-NLS-1$
ImportOperation operation = new ImportOperation(containerPath, parentFolder, fileSystemStructureProvider, myQueryImpl, subList);
operation.setContext(fShell);
operation.setCreateContainerStructure(false);
operation.setOverwriteResources(false);
operation.setCreateLinks(createLinksInWorkspace);
operation.setVirtualFolders(false);
operation.run(SubMonitor.convert(monitor).newChild(1));
String sourceLocation = fileSystemElement.getSourceLocation();
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(tracePath);
if ((sourceLocation != null) && (resource != null)) {
resource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
}
return resource;
}