View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: BaseProjectUtil.java
13   * Created: 2008-10-09
14   * Author: awos
15   * $Id: BaseProjectUtil.java 2308 2009-01-12 22:33:45Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.resources;
19  
20  import org.apache.log4j.Logger;
21  import org.eclipse.core.resources.IProject;
22  import org.eclipse.core.resources.ProjectScope;
23  import org.eclipse.core.runtime.preferences.IEclipsePreferences;
24  import org.osgi.service.prefs.BackingStoreException;
25  
26  import pl.edu.agh.cast.model.base.BasePlugin;
27  
28  /**
29   * Utility methods for operating on projects. Uses Eclipse Preferences mechanism to fetch project properties.
30   * 
31   * @author AGH CAST Team
32   */
33  public class BaseProjectUtil {
34  
35  	/**
36  	 * Project display name property used.
37  	 */
38  	public static final String PROJECT_DISPLAY_NAME_PROPERTY = "project.displayName"; //$NON-NLS-1$
39  
40  	/**
41  	 * Project id property.
42  	 */
43  	public static final String PROJECT_ID_PROPERTY = "project.id"; //$NON-NLS-1$
44  
45  	/**
46  	 * Reads projects properties using Eclipse Preferences mechanism.
47  	 * 
48  	 * @param project
49  	 *            project which properties are read
50  	 * @param propertyId
51  	 *            id of property to read
52  	 * @return property with given id found for specified project
53  	 */
54  	public static String getProperty(IProject project, String propertyId) {
55  		ProjectScope ps = new ProjectScope(project);
56  		return ps.getNode(BasePlugin.PLUGIN_ID).get(propertyId, null);
57  	}
58  
59  	/**
60  	 * Sets property for given project.
61  	 * 
62  	 * @param project
63  	 *            project which property is to be set
64  	 * @param propertyId
65  	 *            property id
66  	 * @param value
67  	 *            new value of property
68  	 */
69  	public static void setProperty(IProject project, String propertyId, String value) {
70  		ProjectScope ps = new ProjectScope(project);
71  		IEclipsePreferences node = ps.getNode(BasePlugin.PLUGIN_ID);
72  		node.put(propertyId, value);
73  		try {
74  			node.flush();
75  		} catch (BackingStoreException e) {
76  			Logger.getLogger(BaseProjectUtil.class).error("Failed to save property " + propertyId, e); //$NON-NLS-1$
77  		}
78  	}
79  
80  }