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