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
.List
;
19 import java
.util
.zip
.ZipEntry
;
21 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.TarEntry
;
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 @SuppressWarnings("restriction")
29 public class FileSystemObjectImportStructureProvider
implements IImportStructureProvider
{
31 private IImportStructureProvider fImportProvider
;
32 private String fArchivePath
;
34 FileSystemObjectImportStructureProvider(IImportStructureProvider importStructureProvider
, String archivePath
) {
35 fImportProvider
= importStructureProvider
;
36 fArchivePath
= archivePath
;
40 public List
<IFileSystemObject
> getChildren(Object element
) {
41 @SuppressWarnings("rawtypes")
42 List children
= fImportProvider
.getChildren(((IFileSystemObject
) element
).getRawFileSystemObject());
43 List
<IFileSystemObject
> adapted
= new ArrayList
<>(children
.size());
44 for (Object o
: children
) {
45 adapted
.add(getIFileSystemObject(o
));
51 * Get the IFileSystemObject corresponding to the specified raw object
55 * @return the corresponding IFileSystemObject
57 public IFileSystemObject
getIFileSystemObject(Object o
) {
62 if (o
instanceof File
) {
63 return new FileFileSystemObject((File
) o
);
64 } else if (o
instanceof TarEntry
) {
65 return new TarFileSystemObject((TarEntry
) o
, fArchivePath
);
66 } else if (o
instanceof ZipEntry
) {
67 return new ZipFileSystemObject((ZipEntry
) o
, fArchivePath
);
68 } else if (o
instanceof GzipEntry
) {
69 return new GzipFileSystemObject((GzipEntry
) o
, fArchivePath
);
72 throw new IllegalArgumentException("Object type not handled"); //$NON-NLS-1$
76 public InputStream
getContents(Object fileSystemObject
) {
77 return fImportProvider
.getContents(((IFileSystemObject
) fileSystemObject
).getRawFileSystemObject());
81 public String
getFullPath(Object element
) {
82 return fImportProvider
.getFullPath(((IFileSystemObject
) element
).getRawFileSystemObject());
86 public String
getLabel(Object element
) {
87 return fImportProvider
.getLabel(((IFileSystemObject
) element
).getRawFileSystemObject());
91 public boolean isFolder(Object element
) {
92 return fImportProvider
.isFolder(((IFileSystemObject
) element
).getRawFileSystemObject());
96 * Disposes of the resources associated with the provider.
98 public void dispose() {