ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TraceUtils.java
CommitLineData
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
15package org.eclipse.linuxtools.tmf.ui.project.model;
16
d600c18f
MAL
17import java.util.ArrayList;
18import java.util.List;
19
339d539c 20import org.eclipse.core.resources.IFolder;
d600c18f
MAL
21import org.eclipse.core.resources.IProject;
22import org.eclipse.core.resources.ResourcesPlugin;
23import org.eclipse.core.runtime.CoreException;
339d539c 24import org.eclipse.core.runtime.IProgressMonitor;
d600c18f
MAL
25import org.eclipse.linuxtools.internal.tmf.ui.Activator;
26import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
05e0d2e9
GB
27import org.eclipse.swt.widgets.Display;
28import org.eclipse.swt.widgets.MessageBox;
29import org.eclipse.ui.PlatformUI;
30
31/**
32 * Utility class for common tmf.ui functionalities
33 *
34 * @since 2.1
35 */
36public class TraceUtils {
37
38 /**
39 * Displays an error message in a box
40 *
41 * @param boxTitle
42 * The message box title
43 * @param errorMsg
44 * The error message to display
45 */
46 public static void displayErrorMsg(final String boxTitle, final String errorMsg) {
47 Display.getDefault().asyncExec(new Runnable() {
48 @Override
49 public void run() {
50 final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
51 mb.setText(boxTitle);
52 mb.setMessage(errorMsg);
53 mb.open();
54 }
55 });
56 }
d600c18f
MAL
57
58 /**
59 * Get the opened (accessible) projects with Tmf nature
60 *
61 * @return the Tmf projects
62 * @since 2.2
63 */
64 public static List<IProject> getOpenedTmfProjects() {
65 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
507b1336 66 List<IProject> tmfProjects = new ArrayList<>();
d600c18f
MAL
67 for (IProject project : projects) {
68 try {
69 if (project.isAccessible() && project.getNature(TmfProjectNature.ID) != null) {
70 tmfProjects.add(project);
71 }
72 } catch (CoreException e) {
73 Activator.getDefault().logError("Error getting opened tmf projects", e); //$NON-NLS-1$
74 }
75 }
76 return tmfProjects;
77 }
339d539c
PT
78
79 /**
80 * Create a folder, ensuring all parent folders are also created.
81 *
82 * @param folder
83 * the folder to create
84 * @param monitor
85 * the progress monitor
86 * @throws CoreException
87 * if the folder cannot be created
88 * @since 3.0
89 */
90 public static void createFolder(IFolder folder, IProgressMonitor monitor) throws CoreException {
91 if (!folder.exists()) {
92 if (folder.getParent() instanceof IFolder) {
93 createFolder((IFolder) folder.getParent(), monitor);
94 }
95 folder.create(true, true, monitor);
96 }
97 }
98
05e0d2e9 99}
This page took 0.054664 seconds and 5 git commands to generate.