1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
;
16 import java
.io
.InputStream
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Comparator
;
19 import java
.util
.List
;
20 import java
.util
.zip
.ZipEntry
;
22 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.TarEntry
;
23 import org
.eclipse
.ui
.wizards
.datatransfer
.IImportStructureProvider
;
26 * An import provider that makes use of the IFileSystemObject abstraction
27 * instead of using plain file system objects (File, TarEntry, ZipEntry, etc)
29 @SuppressWarnings("restriction")
30 public class FileSystemObjectImportStructureProvider
implements IImportStructureProvider
{
32 private IImportStructureProvider fImportProvider
;
33 private String fArchivePath
;
38 * @param importStructureProvider
39 * the {@link IImportStructureProvider}
41 * the path of the archive file
43 public FileSystemObjectImportStructureProvider(IImportStructureProvider importStructureProvider
, String archivePath
) {
44 fImportProvider
= importStructureProvider
;
45 fArchivePath
= archivePath
;
49 * This orders by files first then the folders. Then by lexical order.
51 private final class FileObjectPathComparator
implements Comparator
<IFileSystemObject
> {
53 public int compare(IFileSystemObject o1
, IFileSystemObject o2
) {
54 if (o1
.isDirectory() != o2
.isDirectory()) {
55 if (o1
.isDirectory()) {
61 return o1
.getName().compareToIgnoreCase(o2
.getName());
66 public List
<IFileSystemObject
> getChildren(Object element
) {
67 @SuppressWarnings("rawtypes")
68 List children
= fImportProvider
.getChildren(((IFileSystemObject
) element
).getRawFileSystemObject());
69 List
<IFileSystemObject
> adapted
= new ArrayList
<>(children
.size());
70 for (Object o
: children
) {
71 adapted
.add(getIFileSystemObject(o
));
74 adapted
.sort(new FileObjectPathComparator());
79 * Get the IFileSystemObject corresponding to the specified raw object
83 * @return the corresponding IFileSystemObject
85 public IFileSystemObject
getIFileSystemObject(Object o
) {
90 if (o
instanceof File
) {
91 return new FileFileSystemObject((File
) o
);
92 } else if (o
instanceof TarEntry
) {
93 return new TarFileSystemObject((TarEntry
) o
, fArchivePath
);
94 } else if (o
instanceof ZipEntry
) {
95 return new ZipFileSystemObject((ZipEntry
) o
, fArchivePath
);
96 } else if (o
instanceof GzipEntry
) {
97 return new GzipFileSystemObject((GzipEntry
) o
, fArchivePath
);
100 throw new IllegalArgumentException("Object type not handled"); //$NON-NLS-1$
104 public InputStream
getContents(Object fileSystemObject
) {
105 return fImportProvider
.getContents(((IFileSystemObject
) fileSystemObject
).getRawFileSystemObject());
109 public String
getFullPath(Object element
) {
110 return fImportProvider
.getFullPath(((IFileSystemObject
) element
).getRawFileSystemObject());
114 public String
getLabel(Object element
) {
115 return fImportProvider
.getLabel(((IFileSystemObject
) element
).getRawFileSystemObject());
119 public boolean isFolder(Object element
) {
120 return fImportProvider
.isFolder(((IFileSystemObject
) element
).getRawFileSystemObject());
124 * Disposes of the resources associated with the provider.
126 public void dispose() {