lttng rcp: add tracing rcp "file->open" buttons
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / model / TmfImportHelper.java
1 /**********************************************************************
2 * Copyright (c) 2013 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.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;
27 import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider;
28
29 /**
30 * Import helper used to import traces
31 *
32 * It has two purposes: - import files and directories into projects - set the
33 * resource types
34 *
35 * @author Matthew Khouzam
36 */
37 public class TmfImportHelper {
38
39 /**
40 * Create a link and replace what was already there.
41 *
42 * @param parentFolder
43 * the resource to import to, does not contain the element name
44 * @param location
45 * where the resource (file/directory) is located
46 * @param targetName
47 * the name to display
48 * @return the resource created. Should not be null
49 * @throws CoreException
50 * an exception made by createLink.
51 */
52 public static IResource createLink(IFolder parentFolder, IPath location, String targetName) throws CoreException {
53 File source = new File(location.toString());
54 IResource res = null;
55 IWorkspace workspace = ResourcesPlugin.getWorkspace();
56 if (source.isDirectory()) {
57 IFolder folder = parentFolder.getFolder(targetName);
58 IStatus result = workspace.validateLinkLocation(folder, location);
59 if (result.isOK()) {
60 folder.createLink(location, IResource.REPLACE, new NullProgressMonitor());
61 } else {
62 Activator.getDefault().logError(result.getMessage());
63 }
64 } else {
65 IFile file = parentFolder.getFile(targetName);
66 IStatus result = workspace.validateLinkLocation(file, location);
67 if (result.isOK()) {
68 file.createLink(location, IResource.REPLACE,
69 new NullProgressMonitor());
70 } else {
71 Activator.getDefault().logError(result.getMessage());
72 }
73 }
74 forceFolderRefresh(parentFolder);
75 res = parentFolder.findMember(location.lastSegment());
76 return res;
77 }
78
79 /**
80 * Refresh the folders to have sub-folders
81 *
82 * @param parentFolder
83 * the folder to refresh
84 */
85 public static void forceFolderRefresh(IFolder parentFolder) {
86 final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
87 // force the model to be populated
88 ncp.getChildren(parentFolder.getProject());
89 }
90 }
This page took 0.039406 seconds and 5 git commands to generate.