*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / preferences / ProjectProperties.java
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/preferences/ProjectProperties.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/preferences/ProjectProperties.java
new file mode 100644 (file)
index 0000000..68761fe
--- /dev/null
@@ -0,0 +1,102 @@
+package net.sourceforge.phpeclipse.preferences;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.QualifiedName;
+
+
+public class ProjectProperties
+   implements IObfuscatorPreferences
+{
+   private IProject project;
+
+  // private static final String DEFAULT_BUILD = String.valueOf(DEFAULT_BUILD_VALUE);
+
+   public ProjectProperties(IProject project)
+   {
+      this.project = project;
+   }
+   
+   
+   public String getPublish()
+      throws CoreException
+   {
+      return getProperty(PUBLISH_PROPERTY_NAME,DEFAULT_PUBLISH_DIR);
+   }
+
+   public boolean hasNature()
+      throws CoreException
+   {
+      return project.hasNature(PHPeclipsePlugin.PHP_NATURE_ID);
+   }
+   
+   public void setPublish(String publish)
+      throws CoreException
+   {
+      setProperty(PUBLISH_PROPERTY_NAME,publish,DEFAULT_PUBLISH_DIR);
+   }
+
+   
+   public void setNature(boolean nature)
+      throws CoreException
+   {
+      if(nature)
+      {
+         if(!hasNature())
+         {
+            IProjectDescription description = project.getDescription();
+            String[] old = description.getNatureIds(),
+                     natures= new String[old.length + 1];
+            System.arraycopy(old,0,natures,0,old.length);
+            natures[old.length] = PHPeclipsePlugin.PHP_NATURE_ID;
+            description.setNatureIds(natures);
+            project.setDescription(description,new NullProgressMonitor());
+         }
+      }
+      else
+      {
+         if(hasNature())
+         {
+            IProjectDescription description = project.getDescription();
+            String[] old = description.getNatureIds(),
+                     natures= new String[old.length - 1];
+            int i = 0,
+                 j = 0;
+            while(i < old.length)
+            {
+               if(!old[i].equals(PHPeclipsePlugin.PHP_NATURE_ID))
+                  natures[j++] = old[i];
+               i++;
+            }
+            description.setNatureIds(natures);
+            project.setDescription(description,new NullProgressMonitor());
+         }
+      }
+   }
+
+   protected String getProperty(QualifiedName key,String def)
+      throws CoreException
+   {
+      String value = project.getPersistentProperty(key);
+      if(value == null || value.length() == 0)
+         return def;
+      else
+         return value;
+   }
+
+   protected void setProperty(QualifiedName key,String value,String def)
+      throws CoreException
+   {
+       if(value != null && value.length() != 0 && hasNature())
+       {
+          if(value.equals(def))
+             project.setPersistentProperty(key,null);
+          else
+             project.setPersistentProperty(key,value);
+       }
+   }
+}
\ No newline at end of file