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
.wizards
.datatransfer
.IImportStructureProvider
;
25 * An import provider that makes use of the IFileSystemObject abstraction
26 * instead of using plain file system objects (File, TarEntry, ZipEntry, etc)
28 public class FileSystemObjectImportStructureProvider
implements IImportStructureProvider
{
30 private IImportStructureProvider fImportProvider
;
31 private String fArchivePath
;
36 * @param importStructureProvider
37 * the {@link IImportStructureProvider}
39 * the path of the archive file
41 public FileSystemObjectImportStructureProvider(IImportStructureProvider importStructureProvider
, String archivePath
) {
42 fImportProvider
= importStructureProvider
;
43 fArchivePath
= archivePath
;
47 * This orders by files first then the folders. Then by lexical order.
49 private final class FileObjectPathComparator
implements Comparator
<IFileSystemObject
> {
51 public int compare(IFileSystemObject o1
, IFileSystemObject o2
) {
52 if (o1
.isDirectory() != o2
.isDirectory()) {
53 if (o1
.isDirectory()) {
59 return o1
.getName().compareToIgnoreCase(o2
.getName());
64 public List
<IFileSystemObject
> getChildren(Object element
) {
65 @SuppressWarnings("rawtypes")
66 List children
= fImportProvider
.getChildren(((IFileSystemObject
) element
).getRawFileSystemObject());
67 List
<IFileSystemObject
> adapted
= new ArrayList
<>(children
.size());
68 for (Object o
: children
) {
69 adapted
.add(getIFileSystemObject(o
));
72 adapted
.sort(new FileObjectPathComparator());
77 * Get the IFileSystemObject corresponding to the specified raw object
81 * @return the corresponding IFileSystemObject
83 public IFileSystemObject
getIFileSystemObject(Object o
) {
88 if (o
instanceof File
) {
89 return new FileFileSystemObject((File
) o
);
90 } else if (o
instanceof TarEntry
) {
91 return new TarFileSystemObject((TarEntry
) o
, fArchivePath
);
92 } else if (o
instanceof ZipEntry
) {
93 return new ZipFileSystemObject((ZipEntry
) o
, fArchivePath
);
94 } else if (o
instanceof GzipEntry
) {
95 return new GzipFileSystemObject((GzipEntry
) o
, fArchivePath
);
98 throw new IllegalArgumentException("Object type not handled"); //$NON-NLS-1$
102 public InputStream
getContents(Object fileSystemObject
) {
103 return fImportProvider
.getContents(((IFileSystemObject
) fileSystemObject
).getRawFileSystemObject());
107 public String
getFullPath(Object element
) {
108 return fImportProvider
.getFullPath(((IFileSystemObject
) element
).getRawFileSystemObject());
112 public String
getLabel(Object element
) {
113 return fImportProvider
.getLabel(((IFileSystemObject
) element
).getRawFileSystemObject());
117 public boolean isFolder(Object element
) {
118 return fImportProvider
.isFolder(((IFileSystemObject
) element
).getRawFileSystemObject());
122 * Disposes of the resources associated with the provider.
124 public void dispose() {