Commit | Line | Data |
---|---|---|
76fccfb0 | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 Ericsson |
76fccfb0 MK |
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 | * Matthew Khouzam - Initial API and implementation | |
11 | **********************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.internal.tmf.ui.project.model; | |
14 | ||
15 | import java.io.File; | |
16 | ||
17 | import org.eclipse.core.resources.IFile; | |
18 | import org.eclipse.core.resources.IFolder; | |
19 | import org.eclipse.core.resources.IResource; | |
20 | import org.eclipse.core.resources.IWorkspace; | |
21 | import org.eclipse.core.resources.ResourcesPlugin; | |
22 | import org.eclipse.core.runtime.CoreException; | |
23 | import org.eclipse.core.runtime.IPath; | |
24 | import org.eclipse.core.runtime.IStatus; | |
25 | import org.eclipse.core.runtime.NullProgressMonitor; | |
26 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; | |
76fccfb0 MK |
27 | |
28 | /** | |
29 | * Import helper used to import traces | |
30 | * | |
31 | * It has two purposes: - import files and directories into projects - set the | |
32 | * resource types | |
33 | * | |
34 | * @author Matthew Khouzam | |
35 | */ | |
36 | public class TmfImportHelper { | |
37 | ||
38 | /** | |
39 | * Create a link and replace what was already there. | |
40 | * | |
41 | * @param parentFolder | |
42 | * the resource to import to, does not contain the element name | |
43 | * @param location | |
44 | * where the resource (file/directory) is located | |
45 | * @param targetName | |
46 | * the name to display | |
47 | * @return the resource created. Should not be null | |
48 | * @throws CoreException | |
49 | * an exception made by createLink. | |
50 | */ | |
51 | public static IResource createLink(IFolder parentFolder, IPath location, String targetName) throws CoreException { | |
52 | File source = new File(location.toString()); | |
53 | IResource res = null; | |
54 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
55 | if (source.isDirectory()) { | |
56 | IFolder folder = parentFolder.getFolder(targetName); | |
57 | IStatus result = workspace.validateLinkLocation(folder, location); | |
977ca87f | 58 | if (result.isOK() || result.matches(IStatus.INFO | IStatus.WARNING)) { |
76fccfb0 MK |
59 | folder.createLink(location, IResource.REPLACE, new NullProgressMonitor()); |
60 | } else { | |
61 | Activator.getDefault().logError(result.getMessage()); | |
62 | } | |
63 | } else { | |
64 | IFile file = parentFolder.getFile(targetName); | |
65 | IStatus result = workspace.validateLinkLocation(file, location); | |
977ca87f | 66 | if (result.isOK() || result.matches(IStatus.INFO | IStatus.WARNING)) { |
76fccfb0 MK |
67 | file.createLink(location, IResource.REPLACE, |
68 | new NullProgressMonitor()); | |
69 | } else { | |
70 | Activator.getDefault().logError(result.getMessage()); | |
71 | } | |
72 | } | |
82cefbfe | 73 | res = parentFolder.findMember(targetName); |
76fccfb0 MK |
74 | return res; |
75 | } | |
76fccfb0 | 76 | } |