[jboss-cvs] jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils ...

Max Rydahl Andersen mandersen at jboss.com
Fri Dec 22 10:39:48 EST 2006


  User: mandersen
  Date: 06/12/22 10:39:48

  Modified:    hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils 
                        ProjectUtils.java
  Log:
  HBX-844 auto enable support projects linked to console configuration
  
  Revision  Changes    Path
  1.10      +37 -0     jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ProjectUtils.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- ProjectUtils.java	23 Oct 2006 13:22:55 -0000	1.9
  +++ ProjectUtils.java	22 Dec 2006 15:39:48 -0000	1.10
  @@ -25,17 +25,22 @@
   import org.eclipse.core.resources.IProject;
   import org.eclipse.core.resources.IProjectDescription;
   import org.eclipse.core.resources.IWorkspaceRoot;
  +import org.eclipse.core.resources.ProjectScope;
   import org.eclipse.core.resources.ResourcesPlugin;
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IProgressMonitor;
   import org.eclipse.core.runtime.NullProgressMonitor;
   import org.eclipse.core.runtime.OperationCanceledException;
  +import org.eclipse.core.runtime.preferences.IScopeContext;
   import org.eclipse.jdt.core.IJavaProject;
   import org.eclipse.jdt.core.JavaCore;
   import org.eclipse.ui.IEditorInput;
   import org.eclipse.ui.IEditorPart;
   import org.eclipse.ui.IFileEditorInput;
  +import org.hibernate.eclipse.console.HibernateConsolePlugin;
   import org.hibernate.util.StringHelper;
  +import org.osgi.service.prefs.BackingStoreException;
  +import org.osgi.service.prefs.Preferences;
   
   public class ProjectUtils {
   
  @@ -43,6 +48,38 @@
   		
   	}
   	
  +	public static boolean toggleHibernateOnProject(IProject project, boolean enable,String defaultConsoleName) {
  +		IScopeContext scope = new ProjectScope(project);
  +		
  +		Preferences node = scope.getNode("org.hibernate.eclipse.console");
  +		
  +		if(node!=null) {
  +			node.putBoolean("hibernate3.enabled", enable );
  +			node.put("default.configuration", defaultConsoleName );
  +			try {
  +				node.flush();
  +			} catch (BackingStoreException e) {
  +				HibernateConsolePlugin.getDefault().logErrorMessage("Could not save changes to preferences", e);
  +				return false;
  +			}
  +		} else {
  +			return false;
  +		}
  +		
  +		try {
  +			if(enable) {
  +				return ProjectUtils.addProjectNature(project, "org.hibernate.eclipse.console.hibernateNature", new NullProgressMonitor() );
  +			} else {
  +				return ProjectUtils.removeProjectNature(project, "org.hibernate.eclipse.console.hibernateNature", new NullProgressMonitor() );
  +			}
  +		} catch(CoreException ce) {
  +			HibernateConsolePlugin.getDefault().logErrorMessage("Could not activate Hibernate nature on project " + project.getName(), ce);
  +			HibernateConsolePlugin.getDefault().log(ce.getStatus() );
  +			return false;
  +		}
  +		
  +	}
  +	
   	/**
   	 * Add the given project nature to the given project (if it isn't already added).
   	 * @return true if nature where added, false if not
  
  
  



More information about the jboss-cvs-commits mailing list