tmf: Make order of files processing more natural during import
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / wizards / importtrace / FileFileSystemObject.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.IOException;
17
18 import org.eclipse.core.resources.IResource;
19 import org.eclipse.core.resources.ResourcesPlugin;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.Path;
22 import org.eclipse.core.runtime.URIUtil;
23 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
24
25 /**
26 * The "File" implementation of an IFileSystemObject
27 */
28 class FileFileSystemObject implements IFileSystemObject {
29
30 private File fFileSystemObject;
31
32 FileFileSystemObject(File fileSystemObject) {
33 fFileSystemObject = fileSystemObject;
34 }
35
36 @Override
37 public String getName() {
38 String name = fFileSystemObject.getName();
39 if (name.length() == 0) {
40 return fFileSystemObject.getPath();
41 }
42 return name;
43 }
44
45 @Override
46 public String getAbsolutePath() {
47 return fFileSystemObject.getAbsolutePath();
48 }
49
50 @Override
51 public boolean exists() {
52 return fFileSystemObject.exists();
53 }
54
55 @Override
56 public String getSourceLocation() {
57 IResource sourceResource;
58 String sourceLocation = null;
59 if (fFileSystemObject.isDirectory()) {
60 sourceResource = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(Path.fromOSString(fFileSystemObject.getAbsolutePath()));
61 } else {
62 sourceResource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(fFileSystemObject.getAbsolutePath()));
63 }
64 if (sourceResource != null && sourceResource.exists()) {
65 try {
66 sourceLocation = sourceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
67 } catch (CoreException e) {
68 // Something went wrong with the already existing resource.
69 // This is not a problem, we'll assign a new location below.
70 }
71 }
72 if (sourceLocation == null) {
73 try {
74 sourceLocation = URIUtil.toUnencodedString(fFileSystemObject.getCanonicalFile().toURI());
75 } catch (IOException e) {
76 // Something went wrong canonicalizing the file. We can still
77 // use the URI but there might be extra ../ in it.
78 sourceLocation = URIUtil.toUnencodedString(fFileSystemObject.toURI());
79 }
80 }
81 return sourceLocation;
82 }
83
84 @Override
85 public Object getRawFileSystemObject() {
86 return fFileSystemObject;
87 }
88
89 @Override
90 public boolean isDirectory() {
91 return fFileSystemObject.isDirectory();
92 }
93 }
This page took 0.032491 seconds and 5 git commands to generate.