Commit | Line | Data |
---|---|---|
05e0d2e9 | 1 | /******************************************************************************* |
339d539c | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal and others |
05e0d2e9 GB |
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 | * Geneviève Bastien - Initial API and implementation | |
d600c18f | 11 | * Marc-Andre Laperle - Add method to get opened tmf projects |
339d539c | 12 | * Patrick Tasse - Add support for folder elements |
05e0d2e9 GB |
13 | *******************************************************************************/ |
14 | ||
2bdf0193 | 15 | package org.eclipse.tracecompass.tmf.ui.project.model; |
05e0d2e9 | 16 | |
d600c18f MAL |
17 | import java.util.ArrayList; |
18 | import java.util.List; | |
19 | ||
339d539c | 20 | import org.eclipse.core.resources.IFolder; |
d600c18f MAL |
21 | import org.eclipse.core.resources.IProject; |
22 | import org.eclipse.core.resources.ResourcesPlugin; | |
23 | import org.eclipse.core.runtime.CoreException; | |
339d539c | 24 | import org.eclipse.core.runtime.IProgressMonitor; |
bfe971e1 | 25 | import org.eclipse.jface.dialogs.MessageDialog; |
05e0d2e9 | 26 | import org.eclipse.swt.widgets.Display; |
bfe971e1 | 27 | import org.eclipse.swt.widgets.Shell; |
2bdf0193 AM |
28 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
29 | import org.eclipse.tracecompass.tmf.core.TmfProjectNature; | |
05e0d2e9 GB |
30 | import org.eclipse.ui.PlatformUI; |
31 | ||
32 | /** | |
33 | * Utility class for common tmf.ui functionalities | |
05e0d2e9 GB |
34 | */ |
35 | public class TraceUtils { | |
36 | ||
37 | /** | |
38 | * Displays an error message in a box | |
39 | * | |
40 | * @param boxTitle | |
41 | * The message box title | |
42 | * @param errorMsg | |
43 | * The error message to display | |
44 | */ | |
45 | public static void displayErrorMsg(final String boxTitle, final String errorMsg) { | |
46 | Display.getDefault().asyncExec(new Runnable() { | |
47 | @Override | |
48 | public void run() { | |
bfe971e1 MK |
49 | final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
50 | MessageDialog.openError(shell, boxTitle, errorMsg); | |
05e0d2e9 GB |
51 | } |
52 | }); | |
53 | } | |
d600c18f MAL |
54 | |
55 | /** | |
56 | * Get the opened (accessible) projects with Tmf nature | |
57 | * | |
58 | * @return the Tmf projects | |
d600c18f MAL |
59 | */ |
60 | public static List<IProject> getOpenedTmfProjects() { | |
61 | IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); | |
507b1336 | 62 | List<IProject> tmfProjects = new ArrayList<>(); |
d600c18f MAL |
63 | for (IProject project : projects) { |
64 | try { | |
65 | if (project.isAccessible() && project.getNature(TmfProjectNature.ID) != null) { | |
66 | tmfProjects.add(project); | |
67 | } | |
68 | } catch (CoreException e) { | |
69 | Activator.getDefault().logError("Error getting opened tmf projects", e); //$NON-NLS-1$ | |
70 | } | |
71 | } | |
72 | return tmfProjects; | |
73 | } | |
339d539c PT |
74 | |
75 | /** | |
76 | * Create a folder, ensuring all parent folders are also created. | |
77 | * | |
78 | * @param folder | |
79 | * the folder to create | |
80 | * @param monitor | |
81 | * the progress monitor | |
82 | * @throws CoreException | |
83 | * if the folder cannot be created | |
339d539c PT |
84 | */ |
85 | public static void createFolder(IFolder folder, IProgressMonitor monitor) throws CoreException { | |
86 | if (!folder.exists()) { | |
87 | if (folder.getParent() instanceof IFolder) { | |
88 | createFolder((IFolder) folder.getParent(), monitor); | |
89 | } | |
90 | folder.create(true, true, monitor); | |
91 | } | |
92 | } | |
93 | ||
05e0d2e9 | 94 | } |