X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tmf%2Forg.eclipse.tracecompass.tmf.ui%2Fsrc%2Forg%2Feclipse%2Ftracecompass%2Finternal%2Ftmf%2Fui%2Fproject%2Fwizards%2Fimporttrace%2FTraceValidateAndImportOperation.java;h=6a90871db160b94382506aaaed8dcd85635cfd73;hb=6120dc638d8ea1aaca8dee3b4a0244d582c4b241;hp=22e476cb1c11709c39335cfc0394f79a8f203cd3;hpb=6cfa77db1c9ece0dcc0a2df51e98c1387c2c05c8;p=deliverable%2Ftracecompass.git diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceValidateAndImportOperation.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceValidateAndImportOperation.java index 22e476cb1c..6a90871db1 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceValidateAndImportOperation.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceValidateAndImportOperation.java @@ -17,6 +17,7 @@ import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -38,10 +39,10 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.URIUtil; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.ModalContext; import org.eclipse.swt.widgets.Shell; import org.eclipse.tracecompass.internal.tmf.ui.Activator; +import org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation; import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; @@ -62,7 +63,7 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation; * control * */ -public class TraceValidateAndImportOperation implements IRunnableWithProgress { +public class TraceValidateAndImportOperation extends TmfWorkspaceModifyOperation { private static final String TRACE_IMPORT_TEMP_FOLDER = ".traceImport"; //$NON-NLS-1$ @@ -133,8 +134,53 @@ public class TraceValidateAndImportOperation implements IRunnableWithProgress { fSelectedFileSystemElements = traceFileSystemElements; } + /** + * This orders by files first then the folders. Then by lexical order. + * This comparator handles full paths. + * Example of ordering: + * + * /trace.txt + * /folderA/trace.txt + * /folderA/folderB/trace.txt + * /folderZ/trace.txt + */ + private final class FileObjectPathComparator implements Comparator { + @Override + public int compare(TraceFileSystemElement e1, TraceFileSystemElement e2) { + IFileSystemObject o1 = e1.getFileSystemObject(); + IFileSystemObject o2 = e2.getFileSystemObject(); + IPath p1 = new Path(e1.getProvider().getFullPath(o1)); + IPath p2 = new Path(e2.getProvider().getFullPath(o2)); + int segmentCount1 = p1.segmentCount(); + int segmentCount2 = p2.segmentCount(); + + int commonParentSegmentCount = Math.min(segmentCount1, segmentCount2) - 1; + // Compare parents that are common (in terms of segment number). + // If one of them is different, we do not need to worry about any + // children, we already know in which order they are going to be. + for (int i = 0; i < commonParentSegmentCount; i++) { + int compare = p1.segment(i).compareToIgnoreCase(p2.segment(i)); + if (compare != 0) { + return compare; + } + } + + // At this point, we know all the common parent folders are the same. + // Either: + // - One of them is shorter which means it should be processed first because files are processed before sub-folders. + // or + // - They are the same level so only the name matters. + if (segmentCount1 != segmentCount2) { + return Integer.compare(segmentCount1, segmentCount2); + } + + // + return o1.getName().compareToIgnoreCase(o2.getName()); + } + } + @Override - public void run(IProgressMonitor progressMonitor) { + protected void execute(IProgressMonitor progressMonitor) throws CoreException, InvocationTargetException, InterruptedException { try { final int ARCHIVE_OR_DIRECTORY_PROGRESS = 45; final int EXTRA_IMPORT_OPERATION_PROGRESS = 45; @@ -246,6 +292,10 @@ public class TraceValidateAndImportOperation implements IRunnableWithProgress { private void importFileSystemElements(IProgressMonitor monitor, List fileSystemElements) throws InterruptedException, TmfTraceImportException, CoreException, InvocationTargetException { SubMonitor subMonitor = SubMonitor.convert(monitor, fileSystemElements.size()); + // Sort the elements in a sensible order to make it more predictable to + // the user when there can be name clashes. Otherwise, the order can + // seem pretty random depending on the OS/Filesystem. + fileSystemElements.sort(new FileObjectPathComparator()); ListIterator fileSystemElementsIter = fileSystemElements.listIterator(); @@ -534,7 +584,7 @@ public class TraceValidateAndImportOperation implements IRunnableWithProgress { // Finally import trace IResource importedResource = importResource(fileSystemElement, monitor); if (importedResource != null) { - TmfTraceTypeUIUtils.setTraceType(importedResource, traceTypeHelper); + TmfTraceTypeUIUtils.setTraceType(importedResource, traceTypeHelper, false); fImportedResources.add(importedResource); }