1 /**********************************************************************
2 * Copyright (c) 2013, 2014 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
.tracecompass
.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
.tracecompass
.internal
.tmf
.ui
.Activator
;
29 * Import helper used to import traces
31 * It has two purposes: - import files and directories into projects - set the
34 * @author Matthew Khouzam
36 public class TmfImportHelper
{
39 * Create a link and replace what was already there.
42 * the resource to import to, does not contain the element name
44 * where the resource (file/directory) is located
47 * @return the resource created. Should not be null
48 * @throws CoreException
49 * an exception made by createLink.
51 public static IResource
createLink(IFolder parentFolder
, IPath location
, String targetName
) throws CoreException
{
52 File source
= new File(location
.toString());
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());
61 Activator
.getDefault().logError(result
.getMessage());
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());
70 Activator
.getDefault().logError(result
.getMessage());
73 res
= parentFolder
.findMember(targetName
);
This page took 0.032424 seconds and 5 git commands to generate.