Disable "Refresh PHP Browser view when opening editor" and "Show PHP
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / ui / overlaypages / ProjectPrefUtil.java
1 package net.sourceforge.phpeclipse.ui.overlaypages;
2
3 import java.io.File;
4 import java.util.ArrayList;
5 import java.util.List;
6 import java.util.StringTokenizer;
7
8 import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
9 import net.sourceforge.phpeclipse.ui.WebUI;
10 import net.sourceforge.phpeclipse.ui.preferences.PHPMiscProjectPreferences;
11 import net.sourceforge.phpeclipse.ui.preferences.PHPPreviewProjectPreferences;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.core.runtime.Path;
18 import org.eclipse.core.runtime.QualifiedName;
19
20 public class ProjectPrefUtil {
21         public static String getMiscProjectsPreferenceValue(IResource resource,
22                         String key) {
23                 return getOverlayedPrefProjectValue(resource,
24                                 PHPMiscProjectPreferences.PREF_ID, key);
25         }
26
27         public static List getIncludePaths(IResource resource) {
28                 String includePaths = getMiscProjectsPreferenceValue(resource,
29                                 IPreferenceConstants.PHP_INCLUDE_PATHS);
30                 ArrayList list = new ArrayList();
31                 if (includePaths != null) {
32                         StringTokenizer st = new StringTokenizer(includePaths,
33                                         File.pathSeparator + "\n\r");//$NON-NLS-1$
34                         while (st.hasMoreElements()) {
35                                 list.add(st.nextElement());
36                         }
37                 }
38                 return list;
39         }
40
41         public static IPath getDocumentRoot(IResource resource) {
42                 String documentRoot = getMiscProjectsPreferenceValue(resource,
43                                 IPreferenceConstants.PHP_DOCUMENTROOT_PREF);
44                 IPath path = new Path(documentRoot);
45                 // documentRoot = documentRoot.replace('\\', '/');
46                 return path;
47         }
48
49         public static String getOverlayedPrefProjectValue(IResource resource,
50                         String pageId, String key) {
51                 IProject project = resource.getProject();
52                 String value = null;
53                 if (useProjectSettings(project, pageId)) {
54                         value = getProperty(resource, pageId, key);
55                 }
56                 if (value != null)
57                         return value;
58                 return WebUI.getDefault().getPreferenceStore().getString(key);
59         }
60
61         public static String getOverlayedPrefResourceValue(IResource resource,
62                         String pageId, String key) {
63                 String value = null;
64                 if (useProjectSettings(resource, pageId)) {
65                         value = getProperty(resource, pageId, key);
66                 }
67                 if (value != null)
68                         return value;
69                 return WebUI.getDefault().getPreferenceStore().getString(key);
70         }
71
72         public static boolean getPreviewBooleanValue(IResource resource, String key) {
73                 return getOverlayedPrefResourceValue(resource,
74                                 PHPPreviewProjectPreferences.PREF_ID, key).equals("true");
75         }
76
77         public static String getPreviewStringValue(IResource resource, String key) {
78                 return getOverlayedPrefResourceValue(resource,
79                                 PHPPreviewProjectPreferences.PREF_ID, key);
80         }
81
82         private static String getProperty(IResource resource, String pageId,
83                         String key) {
84                 try {
85                         return resource
86                                         .getPersistentProperty(new QualifiedName(pageId, key));
87                 } catch (CoreException e) {
88                 }
89                 return null;
90         }
91
92         private static boolean useProjectSettings(IResource resource, String pageId) {
93                 String use = getProperty(resource, pageId,
94                                 FieldEditorOverlayPage.USEPROJECTSETTINGS);
95                 return "true".equals(use);
96         }
97 }