73498c78c764bef6cf310e1d8e47fb57cfb0bafd
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / wizards / importtrace / FileSystemObjectImportStructureProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;
14
15 import java.io.File;
16 import java.io.InputStream;
17 import java.util.ArrayList;
18 import java.util.List;
19 import java.util.zip.ZipEntry;
20
21 import org.eclipse.ui.internal.wizards.datatransfer.TarEntry;
22 import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
23
24 /**
25 * An import provider that makes use of the IFileSystemObject abstraction
26 * instead of using plain file system objects (File, TarEntry, ZipEntry, etc)
27 */
28 @SuppressWarnings("restriction")
29 public class FileSystemObjectImportStructureProvider implements IImportStructureProvider {
30
31 private IImportStructureProvider fImportProvider;
32 private String fArchivePath;
33
34 FileSystemObjectImportStructureProvider(IImportStructureProvider importStructureProvider, String archivePath) {
35 fImportProvider = importStructureProvider;
36 fArchivePath = archivePath;
37 }
38
39 @Override
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));
46 }
47 return adapted;
48 }
49
50 /**
51 * Get the IFileSystemObject corresponding to the specified raw object
52 *
53 * @param o
54 * the raw object
55 * @return the corresponding IFileSystemObject
56 */
57 public IFileSystemObject getIFileSystemObject(Object o) {
58 if (o == null) {
59 return null;
60 }
61
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);
70 }
71
72 throw new IllegalArgumentException("Object type not handled"); //$NON-NLS-1$
73 }
74
75 @Override
76 public InputStream getContents(Object fileSystemObject) {
77 return fImportProvider.getContents(((IFileSystemObject) fileSystemObject).getRawFileSystemObject());
78 }
79
80 @Override
81 public String getFullPath(Object element) {
82 return fImportProvider.getFullPath(((IFileSystemObject) element).getRawFileSystemObject());
83 }
84
85 @Override
86 public String getLabel(Object element) {
87 return fImportProvider.getLabel(((IFileSystemObject) element).getRawFileSystemObject());
88 }
89
90 @Override
91 public boolean isFolder(Object element) {
92 return fImportProvider.isFolder(((IFileSystemObject) element).getRawFileSystemObject());
93 }
94
95 /**
96 * Disposes of the resources associated with the provider.
97 */
98 public void dispose() {
99 }
100 }
This page took 0.032721 seconds and 5 git commands to generate.