1 /**********************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.model
;
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
;
30 * Import helper used to import traces
32 * It has two purposes: - import files and directories into projects - set the
35 * @author Matthew Khouzam
37 public class TmfImportHelper
{
40 * Create a link and replace what was already there.
43 * the resource to import to, does not contain the element name
45 * where the resource (file/directory) is located
48 * @return the resource created. Should not be null
49 * @throws CoreException
50 * an exception made by createLink.
52 public static IResource
createLink(IFolder parentFolder
, IPath location
, String targetName
) throws CoreException
{
53 File source
= new File(location
.toString());
55 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
56 if (source
.isDirectory()) {
57 IFolder folder
= parentFolder
.getFolder(targetName
);
58 IStatus result
= workspace
.validateLinkLocation(folder
, location
);
60 folder
.createLink(location
, IResource
.REPLACE
, new NullProgressMonitor());
62 Activator
.getDefault().logError(result
.getMessage());
65 IFile file
= parentFolder
.getFile(targetName
);
66 IStatus result
= workspace
.validateLinkLocation(file
, location
);
68 file
.createLink(location
, IResource
.REPLACE
,
69 new NullProgressMonitor());
71 Activator
.getDefault().logError(result
.getMessage());
74 forceFolderRefresh(parentFolder
);
75 res
= parentFolder
.findMember(location
.lastSegment());
80 * Refresh the folders to have sub-folders
83 * the folder to refresh
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());