org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider Java Examples
The following examples show how to use
org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExampleImporter.java From statecharts with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("deprecation") public IProject importExample(ExampleData edata, IProgressMonitor monitor) { try { IProjectDescription original = ResourcesPlugin.getWorkspace() .loadProjectDescription(new Path(edata.getProjectDir().getAbsolutePath()).append("/.project")); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(edata.getProjectDir().getName()); IProjectDescription clone = ResourcesPlugin.getWorkspace().newProjectDescription(original.getName()); clone.setBuildSpec(original.getBuildSpec()); clone.setComment(original.getComment()); clone.setDynamicReferences(original.getDynamicReferences()); clone.setNatureIds(original.getNatureIds()); clone.setReferencedProjects(original.getReferencedProjects()); if (project.exists()) { return project; } project.create(clone, monitor); project.open(monitor); @SuppressWarnings("unchecked") List<IFile> filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(edata.getProjectDir()); ImportOperation io = new ImportOperation(project.getFullPath(), edata.getProjectDir(), FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() { @Override public String queryOverwrite(String pathString) { return IOverwriteQuery.ALL; } }, filesToImport); io.setOverwriteResources(true); io.setCreateContainerStructure(false); io.run(monitor); project.refreshLocal(IProject.DEPTH_INFINITE, monitor); return project; } catch (Exception e) { e.printStackTrace(); } return null; }
Example #2
Source File: TraceValidateAndImportOperation.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Generate a new list of file system elements for the specified folder. */ private static List<TraceFileSystemElement> createElementsForFolder(IFolder folder) { // Create the new import provider and root element based on the // specified folder FileSystemObjectImportStructureProvider importStructureProvider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null); IFileSystemObject rootElement = importStructureProvider.getIFileSystemObject(new File(folder.getLocation().toOSString())); TraceFileSystemElement createRootElement = TraceFileSystemElement.createRootTraceFileElement(rootElement, importStructureProvider); List<TraceFileSystemElement> list = new LinkedList<>(); createRootElement.getAllChildren(list); return list; }
Example #3
Source File: TraceValidateAndImportOperation.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Extract all file system elements (File) to destination folder (typically * workspace/TraceProject/.traceImport) */ private void extractAllArchiveFiles(List<TraceFileSystemElement> fileSystemElements, IFolder destFolder, IPath baseSourceContainerPath, IProgressMonitor progressMonitor) throws InterruptedException, CoreException, InvocationTargetException { SubMonitor subMonitor = SubMonitor.convert(progressMonitor, fileSystemElements.size()); ListIterator<TraceFileSystemElement> fileSystemElementsIter = fileSystemElements.listIterator(); while (fileSystemElementsIter.hasNext()) { ModalContext.checkCanceled(subMonitor); SubMonitor elementProgress = subMonitor.newChild(1); TraceFileSystemElement element = fileSystemElementsIter.next(); elementProgress.setTaskName(Messages.ImportTraceWizard_ExamineOperationTaskName + " " + element.getFileSystemObject().getAbsolutePath()); //$NON-NLS-1$ File archiveFile = (File) element.getFileSystemObject().getRawFileSystemObject(); boolean isArchiveFileElement = element.getFileSystemObject() instanceof FileFileSystemObject && ArchiveUtil.isArchiveFile(archiveFile); if (isArchiveFileElement) { elementProgress = SubMonitor.convert(elementProgress, 4); IPath makeAbsolute = baseSourceContainerPath.makeAbsolute(); IPath relativeToSourceContainer = new Path(element.getFileSystemObject().getAbsolutePath()).makeRelativeTo(makeAbsolute); IFolder folder = safeCreateExtractedFolder(destFolder, relativeToSourceContainer, elementProgress.newChild(1)); extractArchiveToFolder(archiveFile, folder, elementProgress.newChild(1)); // Delete original archive, we don't want to import this, just // the extracted content IFile fileRes = destFolder.getFile(relativeToSourceContainer); fileRes.delete(true, elementProgress.newChild(1)); IPath newPath = destFolder.getFullPath().append(relativeToSourceContainer); // Rename extracted folder (.extract) to original archive name folder.move(newPath, true, elementProgress.newChild(1)); folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(newPath); elementProgress.subTask(""); //$NON-NLS-1$ // Create the new import provider and root element based on // the newly extracted temporary folder FileSystemObjectImportStructureProvider importStructureProvider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null); IFileSystemObject rootElement = importStructureProvider.getIFileSystemObject(new File(folder.getLocation().toOSString())); TraceFileSystemElement newElement = TraceFileSystemElement.createRootTraceFileElement(rootElement, importStructureProvider); List<TraceFileSystemElement> extractedChildren = new ArrayList<>(); newElement.getAllChildren(extractedChildren); extractAllArchiveFiles(extractedChildren, folder, folder.getLocation(), progressMonitor); } } }
Example #4
Source File: HybridProjectImportPage.java From thym with Eclipse Public License 1.0 | 5 votes |
private IProject doCreateProject(ProjectCandidate pc, IProgressMonitor monitor) throws CoreException, InterruptedException { HybridProjectCreator projectCreator = new HybridProjectCreator(); Widget w = pc.getWidget(); String projectName = pc.getProjectName(); URI location = null; if(!copyFiles){ location = pc.wwwLocation.getParentFile().toURI(); } IProject project = projectCreator.createProject(projectName, location, w.getName(), w.getId(), null, monitor); if(copyFiles){ ImportOperation operation = new ImportOperation(project .getFullPath(), pc.wwwLocation.getParentFile(), FileSystemStructureProvider.INSTANCE , this); operation.setContext(getShell()); operation.setOverwriteResources(true); operation.setCreateContainerStructure(false); try { operation.run(monitor); } catch (InvocationTargetException e) { if(e.getCause() != null && e.getCause() instanceof CoreException){ CoreException corex = (CoreException) e.getCause(); throw corex; } } IStatus status = operation.getStatus(); if (!status.isOK()) throw new CoreException(status); } return project; }
Example #5
Source File: HttpTraceImportOperation.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
@Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { int importOptionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE; // Temporary directory to contain any downloaded files IFolder tempDestination = fDestinationFolder.getProject().getResource().getFolder(TRACE_HTTP_IMPORT_TEMP_FOLDER); String tempDestinationFolderPath = tempDestination.getLocation().toOSString(); if (tempDestination.exists()) { tempDestination.delete(true, monitor); } tempDestination.create(IResource.HIDDEN, true, monitor); // Download trace/traces List<File> downloadedTraceList = new ArrayList<>(); TraceDownloadStatus status = DownloadTraceHttpHelper.downloadTraces(fSourceUrl, tempDestinationFolderPath); if (status.isOk()) { List<TraceDownloadStatus> children = status.getChildren(); for (TraceDownloadStatus traceDownloadStatus : children) { downloadedTraceList.add(traceDownloadStatus.getDownloadedFile()); } } else if (status.isTimeout()) { if (tempDestination.exists()) { tempDestination.delete(true, monitor); } throw new InterruptedException(); } boolean isArchive = false; if (!downloadedTraceList.isEmpty()) { isArchive = ArchiveUtil.isArchiveFile(downloadedTraceList.get(0)); } FileSystemObjectImportStructureProvider provider = null; IFileSystemObject object = null; String archiveFolderName = null; if (isArchive) { // If it's an archive there is only 1 element in this list File downloadedTrace = downloadedTraceList.get(0); Pair<IFileSystemObject, FileSystemObjectImportStructureProvider> rootObjectAndProvider = ArchiveUtil.getRootObjectAndProvider(downloadedTrace, null); provider = rootObjectAndProvider.getSecond(); object = rootObjectAndProvider.getFirst(); archiveFolderName = downloadedTrace.getName(); } else { provider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null); object = provider.getIFileSystemObject(new File(tempDestinationFolderPath)); } TraceFileSystemElement root = TraceFileSystemElement.createRootTraceFileElement(object, provider); List<TraceFileSystemElement> fileSystemElements = new ArrayList<>(); root.getAllChildren(fileSystemElements); IPath sourceContainerPath = new Path(tempDestinationFolderPath); IPath destinationContainerPath = fDestinationFolder.getPath(); TraceValidateAndImportOperation validateAndImportOperation = new TraceValidateAndImportOperation(null, fileSystemElements, null, sourceContainerPath, destinationContainerPath, isArchive, importOptionFlags, fDestinationFolder, null, null, archiveFolderName, false); validateAndImportOperation.run(monitor); provider.dispose(); // Clean the temporary directory if (tempDestination.exists()) { tempDestination.delete(true, monitor); } }