tmf: Switch tmf.ui to Java 7 + fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TraceUtils.java
1 /*******************************************************************************
2 * Copyright (c) 2013 É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 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.ui.project.model;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.resources.ResourcesPlugin;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
23 import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.swt.widgets.MessageBox;
26 import org.eclipse.ui.PlatformUI;
27
28 /**
29 * Utility class for common tmf.ui functionalities
30 *
31 * @since 2.1
32 */
33 public class TraceUtils {
34
35 /**
36 * Displays an error message in a box
37 *
38 * @param boxTitle
39 * The message box title
40 * @param errorMsg
41 * The error message to display
42 */
43 public static void displayErrorMsg(final String boxTitle, final String errorMsg) {
44 Display.getDefault().asyncExec(new Runnable() {
45 @Override
46 public void run() {
47 final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
48 mb.setText(boxTitle);
49 mb.setMessage(errorMsg);
50 mb.open();
51 }
52 });
53 }
54
55 /**
56 * Get the opened (accessible) projects with Tmf nature
57 *
58 * @return the Tmf projects
59 * @since 2.2
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 }
This page took 0.036551 seconds and 5 git commands to generate.