Commit | Line | Data |
---|---|---|
12c155f5 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
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 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
14 | ||
15 | import java.util.HashMap; | |
16 | import java.util.Map; | |
17 | ||
18 | import org.eclipse.core.resources.IProject; | |
19 | ||
20 | /** | |
21 | * <b><u>TmfProjectRegistry</u></b> | |
22 | * <p> | |
23 | */ | |
24 | public class TmfProjectRegistry { | |
25 | ||
828e5592 | 26 | // The map of project resource to project model elements |
12c155f5 FC |
27 | private static Map<IProject, TmfProjectElement> registry = new HashMap<IProject, TmfProjectElement>(); |
28 | ||
828e5592 PT |
29 | /** |
30 | * Get the project model element for a project resource | |
31 | * @param project the project resource | |
32 | * @return the project model element or null if it does not exist | |
33 | */ | |
12c155f5 | 34 | public static synchronized TmfProjectElement getProject(IProject project) { |
828e5592 PT |
35 | return getProject(project, false); |
36 | } | |
37 | ||
38 | /** | |
39 | * Get the project model element for a project resource | |
40 | * @param project the project resource | |
41 | * @param force a flag controlling whether a new project should be created if it doesn't exist | |
42 | * @return the project model element | |
43 | */ | |
44 | public static synchronized TmfProjectElement getProject(IProject project, boolean force) { | |
12c155f5 | 45 | TmfProjectElement element = registry.get(project); |
828e5592 | 46 | if (element == null && force) { |
12c155f5 FC |
47 | registry.put(project, new TmfProjectElement(project.getName(), project, null)); |
48 | element = registry.get(project); | |
49 | } | |
50 | return element; | |
51 | } | |
52 | ||
53 | } |