added "Behaviour" page in Editor Prefernce Page
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / preferences / ProjectProperties.java
1 package net.sourceforge.phpeclipse.preferences;
2
3 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
4
5 import org.eclipse.core.resources.IProject;
6 import org.eclipse.core.resources.IProjectDescription;
7 import org.eclipse.core.runtime.CoreException;
8 import org.eclipse.core.runtime.NullProgressMonitor;
9 import org.eclipse.core.runtime.QualifiedName;
10
11
12 public class ProjectProperties
13    implements IObfuscatorPreferences
14 {
15    private IProject project;
16
17   // private static final String DEFAULT_BUILD = String.valueOf(DEFAULT_BUILD_VALUE);
18
19    public ProjectProperties(IProject project)
20    {
21       this.project = project;
22    }
23    
24    
25    public String getPublish()
26       throws CoreException
27    {
28       return getProperty(PUBLISH_PROPERTY_NAME,DEFAULT_PUBLISH_DIR);
29    }
30
31    public boolean hasNature()
32       throws CoreException
33    {
34       return project.hasNature(PHPeclipsePlugin.PHP_NATURE_ID);
35    }
36    
37    public void setPublish(String publish)
38       throws CoreException
39    {
40       setProperty(PUBLISH_PROPERTY_NAME,publish,DEFAULT_PUBLISH_DIR);
41    }
42
43    
44    public void setNature(boolean nature)
45       throws CoreException
46    {
47       if(nature)
48       {
49          if(!hasNature())
50          {
51             IProjectDescription description = project.getDescription();
52             String[] old = description.getNatureIds(),
53                      natures= new String[old.length + 1];
54             System.arraycopy(old,0,natures,0,old.length);
55             natures[old.length] = PHPeclipsePlugin.PHP_NATURE_ID;
56             description.setNatureIds(natures);
57             project.setDescription(description,new NullProgressMonitor());
58          }
59       }
60       else
61       {
62          if(hasNature())
63          {
64             IProjectDescription description = project.getDescription();
65             String[] old = description.getNatureIds(),
66                      natures= new String[old.length - 1];
67             int i = 0,
68                  j = 0;
69             while(i < old.length)
70             {
71                if(!old[i].equals(PHPeclipsePlugin.PHP_NATURE_ID))
72                   natures[j++] = old[i];
73                i++;
74             }
75             description.setNatureIds(natures);
76             project.setDescription(description,new NullProgressMonitor());
77          }
78       }
79    }
80
81    protected String getProperty(QualifiedName key,String def)
82       throws CoreException
83    {
84       String value = project.getPersistentProperty(key);
85       if(value == null || value.length() == 0)
86          return def;
87       else
88          return value;
89    }
90
91    protected void setProperty(QualifiedName key,String value,String def)
92       throws CoreException
93    {
94        if(value != null && value.length() != 0 && hasNature())
95        {
96           if(value.equals(def))
97              project.setPersistentProperty(key,null);
98           else
99              project.setPersistentProperty(key,value);
100        }
101    }
102 }