tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / model / TmfImportHelper.java
1 /**********************************************************************
2 * Copyright (c) 2013, 2014 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 * Matthew Khouzam - Initial API and implementation
11 **********************************************************************/
12
13 package org.eclipse.tracecompass.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.tracecompass.internal.tmf.ui.Activator;
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);
58 if (result.isOK() || result.matches(IStatus.INFO | IStatus.WARNING)) {
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);
66 if (result.isOK() || result.matches(IStatus.INFO | IStatus.WARNING)) {
67 file.createLink(location, IResource.REPLACE,
68 new NullProgressMonitor());
69 } else {
70 Activator.getDefault().logError(result.getMessage());
71 }
72 }
73 res = parentFolder.findMember(targetName);
74 return res;
75 }
76 }
This page took 0.036984 seconds and 5 git commands to generate.