5b8399f0bbe0b76ae89a250e62c2ba7e64a4fb01
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal and others
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 * 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 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
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
.jface
.dialogs
.MessageDialog
;
26 import org
.eclipse
.swt
.widgets
.Display
;
27 import org
.eclipse
.swt
.widgets
.Shell
;
28 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.TmfProjectNature
;
30 import org
.eclipse
.ui
.PlatformUI
;
33 * Utility class for common tmf.ui functionalities
35 public class TraceUtils
{
37 private TraceUtils() {
41 * Displays an error message in a box
44 * The message box title
46 * The error message to display
48 public static void displayErrorMsg(final String boxTitle
, final String errorMsg
) {
49 Display
.getDefault().asyncExec(new Runnable() {
52 final Shell shell
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell();
53 MessageDialog
.openError(shell
, boxTitle
, errorMsg
);
59 * Get the opened (accessible) projects with Tmf nature
61 * @return the Tmf projects
63 public static List
<IProject
> getOpenedTmfProjects() {
64 IProject
[] projects
= ResourcesPlugin
.getWorkspace().getRoot().getProjects();
65 List
<IProject
> tmfProjects
= new ArrayList
<>();
66 for (IProject project
: projects
) {
68 if (project
.isAccessible() && project
.getNature(TmfProjectNature
.ID
) != null) {
69 tmfProjects
.add(project
);
71 } catch (CoreException e
) {
72 Activator
.getDefault().logError("Error getting opened tmf projects", e
); //$NON-NLS-1$
79 * Create a folder, ensuring all parent folders are also created.
82 * the folder to create
84 * the progress monitor
85 * @throws CoreException
86 * if the folder cannot be created
88 public static void createFolder(IFolder folder
, IProgressMonitor monitor
) throws CoreException
{
89 if (!folder
.exists()) {
90 if (folder
.getParent() instanceof IFolder
) {
91 createFolder((IFolder
) folder
.getParent(), monitor
);
93 folder
.create(true, true, monitor
);
This page took 0.054317 seconds and 4 git commands to generate.