import org.eclipse.ui.wizards.datatransfer.ImportOperation;
/**
- * A variant of the standard resource import wizard for importing traces
- * to given tracing project. If no project or tracing project was selected
- * the wizard imports it to the default tracing project which is created
- * if necessary.
+ * A variant of the standard resource import wizard for importing traces to
+ * given tracing project. If no project or tracing project was selected the
+ * wizard imports it to the default tracing project which is created if
+ * necessary.
*
* In our case traces could be files or a directory structure. This wizard
- * supports both cases. It imports traces for a selected trace type or, if
- * no trace type is selected, it tries to detect the trace type automatically.
- * However, the automatic detection is a best-effort and cannot guarantee
- * that the detection is successful. The reason for this is that there might
- * be multiple trace types that can be assigned to a single trace.
+ * supports both cases. It imports traces for a selected trace type or, if no
+ * trace type is selected, it tries to detect the trace type automatically.
+ * However, the automatic detection is a best-effort and cannot guarantee that
+ * the detection is successful. The reason for this is that there might be
+ * multiple trace types that can be assigned to a single trace.
*
*
* @author Francois Chouinard
}
}
- // If no tracing project was selected or trace folder doesn't exist use
- // default tracing project
+ // If no tracing project was selected or trace folder doesn't exist use
+ // default tracing project
if (traceFolder == null) {
IProject project = TmfProjectRegistry.createProject(
TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, new NullProgressMonitor());
if (element.isPopulated()) {
return getChildren(element).length > 0;
}
- //If we have not populated then wait until asked
+ // If we have not populated then wait until asked
return true;
}
return false;
String archivePath = getSourceArchiveFile() != null ? getSourceArchiveFile().getAbsolutePath() : ""; //$NON-NLS-1$
if (ArchiveFileManipulations.isTarFile(archivePath)) {
if (ensureTarSourceIsValid(archivePath)) {
- // We close the file when we dispose the import provider, see disposeSelectionGroupRoot
+ // We close the file when we dispose the import provider,
+ // see disposeSelectionGroupRoot
TarFile tarFile = getSpecifiedTarSourceFile(archivePath);
leveledImportStructureProvider = new FileSystemObjectLeveledImportStructureProvider(new TarLeveledStructureProvider(tarFile), archivePath);
}
} else if (ensureZipSourceIsValid(archivePath)) {
- // We close the file when we dispose the import provider, see disposeSelectionGroupRoot
+ // We close the file when we dispose the import provider, see
+ // disposeSelectionGroupRoot
@SuppressWarnings("resource")
ZipFile zipFile = getSpecifiedZipSourceFile(archivePath);
leveledImportStructureProvider = new FileSystemObjectLeveledImportStructureProvider(new ZipLeveledStructureProvider(zipFile), archivePath);
private IImportStructureProvider fImportProvider;
private String fArchivePath;
+
private FileSystemObjectImportStructureProvider(IImportStructureProvider importStructureProvider, String archivePath) {
fImportProvider = importStructureProvider;
fArchivePath = archivePath;
@Override
public List<IFileSystemObject> getChildren(Object element) {
@SuppressWarnings("rawtypes")
- List children = fImportProvider.getChildren(((IFileSystemObject)element).getRawFileSystemObject());
+ List children = fImportProvider.getChildren(((IFileSystemObject) element).getRawFileSystemObject());
List<IFileSystemObject> adapted = new ArrayList<>(children.size());
for (Object o : children) {
adapted.add(getIFileSystemObject(o));
@Override
public InputStream getContents(Object element) {
- return fImportProvider.getContents(((IFileSystemObject)element).getRawFileSystemObject());
+ return fImportProvider.getContents(((IFileSystemObject) element).getRawFileSystemObject());
}
@Override
public String getFullPath(Object element) {
- return fImportProvider.getFullPath(((IFileSystemObject)element).getRawFileSystemObject());
+ return fImportProvider.getFullPath(((IFileSystemObject) element).getRawFileSystemObject());
}
@Override
public String getLabel(Object element) {
- return fImportProvider.getLabel(((IFileSystemObject)element).getRawFileSystemObject());
+ return fImportProvider.getLabel(((IFileSystemObject) element).getRawFileSystemObject());
}
@Override
public boolean isFolder(Object element) {
- return fImportProvider.isFolder(((IFileSystemObject)element).getRawFileSystemObject());
+ return fImportProvider.isFolder(((IFileSystemObject) element).getRawFileSystemObject());
}
/**
elementLabel, dummyParent, isContainer, provider);
result.setFileSystemObject(element);
- //Get the files for the element so as to build the first level
+ // Get the files for the element so as to build the first level
result.getFiles();
return dummyParent;
status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ImportTraceWizard_ImportProblem, e);
} catch (InterruptedException e) {
status = Status.CANCEL_STATUS;
- } finally {
- if (!status.isOK()) {
- if (status.getSeverity() == IStatus.CANCEL) {
- setMessage(Messages.ImportTraceWizard_ImportOperationCancelled);
- setErrorMessage(null);
- } else {
- if (status.getException() != null) {
- displayErrorDialog(status.getMessage() + ": " + status.getException()); //$NON-NLS-1$
- }
- setMessage(null);
- setErrorMessage(Messages.ImportTraceWizard_ImportProblem);
+ }
+ if (!status.isOK()) {
+ if (status.getSeverity() == IStatus.CANCEL) {
+ setMessage(Messages.ImportTraceWizard_ImportOperationCancelled);
+ setErrorMessage(null);
+ } else {
+ if (status.getException() != null) {
+ displayErrorDialog(status.getMessage() + ": " + status.getException()); //$NON-NLS-1$
}
- return false;
+ setMessage(null);
+ setErrorMessage(Messages.ImportTraceWizard_ImportProblem);
}
+ return false;
}
setErrorMessage(null);
return true;
public void filterElements(Collection elements, IProgressMonitor monitor) {
fileSystemElements.addAll(elements);
}
+
@Override
public void filterElements(Object[] elements, IProgressMonitor monitor) {
for (int i = 0; i < elements.length; i++) {
- fileSystemElements.add((TraceFileSystemElement)elements[i]);
+ fileSystemElements.add((TraceFileSystemElement) elements[i]);
}
}
};
- // List fileSystemElements will be filled using the passThroughFilter
+ // List fileSystemElements will be filled using the
+ // passThroughFilter
SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 1);
fSelectionGroup.getAllCheckedListItems(passThroughFilter, subMonitor);
}
}
} else {
- TraceFileSystemElement parentElement = (TraceFileSystemElement)element.getParent();
+ TraceFileSystemElement parentElement = (TraceFileSystemElement) element.getParent();
String parentPath = parentElement.getFileSystemObject().getAbsolutePath(fBaseSourceContainerPath.toOSString());
parentElement.setDestinationContainerPath(computeDestinationContainerPath(new Path(parentPath)));
currentPath = parentPath;
String errorMessage = Messages.ImportTraceWizard_ImportProblem + ": " + //$NON-NLS-1$
(currentPath != null ? currentPath : ""); //$NON-NLS-1$
Activator.getDefault().logError(errorMessage, e);
- setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMessage , e));
+ setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMessage, e));
}
}
private Iterator<TraceFileSystemElement> extractSelectedFiles(Iterator<TraceFileSystemElement> fileSystemElementsIter, IFolder tempFolder, IProgressMonitor progressMonitor) throws InterruptedException,
InvocationTargetException {
List<TraceFileSystemElement> subList = new ArrayList<>();
+ Map<IPath, String> sourceLocationMap = new HashMap<>();
// Collect all the elements
while (fileSystemElementsIter.hasNext()) {
ModalContext.checkCanceled(progressMonitor);
TraceFileSystemElement element = fileSystemElementsIter.next();
+ sourceLocationMap.put(new Path(element.getFileSystemObject().getName()).removeTrailingSeparator(), element.getSourceLocation());
+ TraceFileSystemElement parentElement = (TraceFileSystemElement) element.getParent();
+ sourceLocationMap.put(new Path(parentElement.getFileSystemObject().getName()).removeTrailingSeparator(), parentElement.getSourceLocation());
if (element.isDirectory()) {
Object[] array = element.getFiles().getChildren();
for (int i = 0; i < array.length; i++) {
- subList.add((TraceFileSystemElement)array[i]);
+ subList.add((TraceFileSystemElement) array[i]);
}
}
subList.add(element);
operation.run(new SubProgressMonitor(progressMonitor, subList.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
- // Create the new import provider and root element based on the extracted temp folder
+ // Create the new import provider and root element based on the
+ // extracted temp folder
FileSystemObjectImportStructureProvider importStructureProvider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null);
IFileSystemObject rootElement = importStructureProvider.getIFileSystemObject(new File(tempFolder.getLocation().toOSString()));
TraceFileSystemElement createRootElement = createRootElement(rootElement, importStructureProvider);
List<TraceFileSystemElement> list = new ArrayList<>();
getAllChildren(list, createRootElement);
Iterator<TraceFileSystemElement> extractedElementsIter = list.iterator();
+ IPath tempPath = new Path(tempFolder.getLocation().toOSString());
+ for (TraceFileSystemElement element : list) {
+ IPath path = new Path(((File) element.getFileSystemObject().getRawFileSystemObject()).getAbsolutePath()).makeRelativeTo(tempPath);
+ element.setSourceLocation(sourceLocationMap.get(path));
+ TraceFileSystemElement parentElement = (TraceFileSystemElement) element.getParent();
+ IPath parentPath = new Path(((File) parentElement.getFileSystemObject().getRawFileSystemObject()).getAbsolutePath()).makeRelativeTo(tempPath);
+ parentElement.setSourceLocation(sourceLocationMap.get(parentPath));
+ }
return extractedElementsIter;
}
AdaptableList folders = rootElement.getFolders();
for (Object folder : folders.getChildren()) {
- getAllChildren(result, (TraceFileSystemElement)folder);
+ getAllChildren(result, (TraceFileSystemElement) folder);
}
}
private IPath computeDestinationContainerPath(Path resourcePath) {
IPath destinationContainerPath = fDestinationContainerPath;
- // We need to figure out the new destination path relative to the selected "base" source directory.
+ // We need to figure out the new destination path relative to the
+ // selected "base" source directory.
// Here for example, the selected source directory is /home/user
if ((fImportOptionFlags & OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
// /home/user/bar/foo/trace -> /home/user/bar/foo
IPath sourceContainerPath = resourcePath.removeLastSegments(1);
if (fBaseSourceContainerPath.equals(resourcePath)) {
- // Use resourcePath directory if fBaseSourceContainerPath points to a directory trace
+ // Use resourcePath directory if fBaseSourceContainerPath
+ // points to a directory trace
sourceContainerPath = resourcePath;
}
// /home/user/bar/foo, /home/user -> bar/foo
Object[] array = fileSystemElement.getFiles().getChildren();
for (int i = 0; i < array.length; i++) {
- subList.add((TraceFileSystemElement)array[i]);
+ subList.add((TraceFileSystemElement) array[i]);
}
parentFolder = fileSystemElement;
subList.add(fileSystemElement);
}
-
ImportProvider fileSystemStructureProvider = new ImportProvider();
IOverwriteQuery myQueryImpl = new IOverwriteQuery() {
operation.setVirtualFolders(false);
operation.run(new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
- String sourceLocation = fileSystemElement.getFileSystemObject().getSourceLocation();
+ String sourceLocation = fileSystemElement.getSourceLocation();
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(tracePath);
if (sourceLocation != null) {
resource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
// handle rename
if (getExistingTrace(tracePath) != null) {
if ((fConfirmationMode == ImportConfirmation.RENAME_ALL) ||
- (fConfirmationMode == ImportConfirmation.OVERWRITE_ALL) ||
- (fConfirmationMode == ImportConfirmation.SKIP_ALL)) {
+ (fConfirmationMode == ImportConfirmation.OVERWRITE_ALL) ||
+ (fConfirmationMode == ImportConfirmation.SKIP_ALL)) {
return fConfirmationMode;
}
final MessageDialog dialog = new MessageDialog(getContainer()
.getShell(), null, null, NLS.bind(Messages.ImportTraceWizard_TraceAlreadyExists, tracePath.makeRelativeTo(fTraceFolderElement.getProject().getPath())),
MessageDialog.QUESTION, new String[] {
- ImportConfirmation.RENAME.getInName(),
- ImportConfirmation.RENAME_ALL.getInName(),
- ImportConfirmation.OVERWRITE.getInName(),
- ImportConfirmation.OVERWRITE_ALL.getInName(),
- ImportConfirmation.SKIP.getInName(),
- ImportConfirmation.SKIP_ALL.getInName(),
+ ImportConfirmation.RENAME.getInName(),
+ ImportConfirmation.RENAME_ALL.getInName(),
+ ImportConfirmation.OVERWRITE.getInName(),
+ ImportConfirmation.OVERWRITE_ALL.getInName(),
+ ImportConfirmation.SKIP.getInName(),
+ ImportConfirmation.SKIP_ALL.getInName(),
}, 4) {
@Override
protected int getShellStyle() {
return;
}
- // Not using IFolder on purpose to leave the door open to import directly into an IProject
+ // Not using IFolder on purpose to leave the door open to import
+ // directly into an IProject
IContainer folder = (IContainer) trace.getParent().getResource();
int i = 2;
while (true) {
}
/**
- * The <code>TraceFileSystemElement</code> is a <code>FileSystemElement</code> that knows
- * if it has been populated or not.
+ * The <code>TraceFileSystemElement</code> is a
+ * <code>FileSystemElement</code> that knows if it has been populated or
+ * not.
*/
private static class TraceFileSystemElement extends FileSystemElement {
private String fLabel = null;
private IPath fDestinationContainerPath;
private FileSystemObjectImportStructureProvider fProvider;
+ private String fSourceLocation;
public TraceFileSystemElement(String name, FileSystemElement parent, boolean isDirectory, FileSystemObjectImportStructureProvider provider) {
super(name, parent, isDirectory);
@Override
public AdaptableList getFiles() {
- if(!fIsPopulated) {
+ if (!fIsPopulated) {
populateElementChildren();
}
return super.getFiles();
@Override
public AdaptableList getFolders() {
- if(!fIsPopulated) {
+ if (!fIsPopulated) {
populateElementChildren();
}
return super.getFolders();
/**
* Sets the label for the trace to be used when importing at trace.
+ *
* @param name
* the label for the trace
*/
}
/**
- * Populates the children of the specified parent <code>FileSystemElement</code>
+ * Populates the children of the specified parent
+ * <code>FileSystemElement</code>
*/
private void populateElementChildren() {
List<IFileSystemObject> allchildren = fProvider.getChildren(this.getFileSystemObject());
Object child = null;
TraceFileSystemElement newelement = null;
Iterator<IFileSystemObject> iter = allchildren.iterator();
- while(iter.hasNext()) {
+ while (iter.hasNext()) {
child = iter.next();
newelement = new TraceFileSystemElement(fProvider.getLabel(child), this, fProvider.isFolder(child), fProvider);
newelement.setFileSystemObject(child);
Object fileSystemObject = super.getFileSystemObject();
return (IFileSystemObject) fileSystemObject;
}
+
+ public String getSourceLocation() {
+ if (fSourceLocation == null) {
+ fSourceLocation = getFileSystemObject().getSourceLocation();
+ }
+ return fSourceLocation;
+ }
+
+ public void setSourceLocation(String sourceLocation) {
+ fSourceLocation = sourceLocation;
+ }
}
/**
*/
private interface IFileSystemObject {
String getLabel();
+
+ String getName();
+
String getAbsolutePath(String parentContainerPath);
+
String getSourceLocation();
+
Object getRawFileSystemObject();
+
boolean exists();
}
return name;
}
+ @Override
+ public String getName() {
+ return fFileSystemObject.getName();
+ }
+
@Override
public String getAbsolutePath(String parentContainerPath) {
return fFileSystemObject.getAbsolutePath();
return new Path(fFileSystemObject.getName()).lastSegment();
}
+ @Override
+ public String getName() {
+ return fFileSystemObject.getName();
+ }
+
@Override
public String getAbsolutePath(String parentContainerPath) {
return new Path(parentContainerPath).append(fFileSystemObject.getName()).toOSString();
return new Path(fFileSystemObject.getName()).lastSegment();
}
+ @Override
+ public String getName() {
+ return fFileSystemObject.getName();
+ }
+
@Override
public String getAbsolutePath(String parentContainerPath) {
return new Path(parentContainerPath).append(fFileSystemObject.getName()).toOSString();
@Override
public String getLabel(Object element) {
- TraceFileSystemElement resource = (TraceFileSystemElement)element;
+ TraceFileSystemElement resource = (TraceFileSystemElement) element;
return resource.getLabel();
}
@Override
public List getChildren(Object element) {
- TraceFileSystemElement resource = (TraceFileSystemElement)element;
+ TraceFileSystemElement resource = (TraceFileSystemElement) element;
Object[] array = resource.getFiles().getChildren();
- List<Object> list = new ArrayList<>();
- for (int i = 0; i < array.length; i++) {
- list.add(array[i]);
- }
+ List<Object> list = new ArrayList<>();
+ for (int i = 0; i < array.length; i++) {
+ list.add(array[i]);
+ }
return list;
}
@Override
public InputStream getContents(Object element) {
- TraceFileSystemElement resource = (TraceFileSystemElement)element;
+ TraceFileSystemElement resource = (TraceFileSystemElement) element;
return resource.getProvider().getContents(resource.getFileSystemObject());
}
@Override
public String getFullPath(Object element) {
- TraceFileSystemElement resource = (TraceFileSystemElement)element;
+ TraceFileSystemElement resource = (TraceFileSystemElement) element;
return resource.getProvider().getFullPath(resource.getFileSystemObject());
}
@Override
public boolean isFolder(Object element) {
- TraceFileSystemElement resource = (TraceFileSystemElement)element;
+ TraceFileSystemElement resource = (TraceFileSystemElement) element;
return resource.isDirectory();
}
}
/**
* Private constructor
- * @param name the name of state
+ *
+ * @param name
+ * the name of state
*/
private ImportConfirmation(String name) {
fInName = name;