[jboss-cvs] jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions ...

Max Rydahl Andersen mandersen at jboss.com
Wed Mar 14 05:21:29 EDT 2007


  User: mandersen
  Date: 07/03/14 05:21:29

  Modified:    seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions  
                        SeamGenAction.java
  Added:       seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions  
                        SetupDeluxeAction.java
  Log:
  final eclipsecon + minor improvements for seam presentation
  
  Revision  Changes    Path
  1.2       +165 -23   jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SeamGenAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamGenAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SeamGenAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- SeamGenAction.java	15 Feb 2007 12:20:44 -0000	1.1
  +++ SeamGenAction.java	14 Mar 2007 09:21:29 -0000	1.2
  @@ -3,17 +3,23 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
  +import java.io.FileOutputStream;
   import java.io.IOException;
   import java.net.URI;
   import java.util.Collections;
  -import java.util.HashMap;
  +import java.util.Iterator;
   import java.util.Map;
   import java.util.Properties;
  +import java.util.Set;
  +import java.util.Map.Entry;
   
   import org.eclipse.ant.internal.ui.IAntUIConstants;
   import org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants;
  +import org.eclipse.core.filesystem.URIUtil;
  +import org.eclipse.core.internal.utils.FileUtil;
   import org.eclipse.core.resources.IProject;
   import org.eclipse.core.resources.IProjectDescription;
  +import org.eclipse.core.resources.IResource;
   import org.eclipse.core.resources.ResourcesPlugin;
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IPath;
  @@ -30,10 +36,15 @@
   import org.eclipse.jface.viewers.ISelection;
   import org.eclipse.swt.SWT;
   import org.eclipse.swt.widgets.FileDialog;
  +import org.eclipse.swt.widgets.Shell;
   import org.eclipse.ui.IWorkbenchWindow;
   import org.eclipse.ui.IWorkbenchWindowActionDelegate;
   import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
   import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
  +import org.eclipse.wst.rdb.connection.internal.ui.wizards.shared.NewCWJDBCPage;
  +import org.eclipse.wst.rdb.internal.core.RDBCorePlugin;
  +import org.eclipse.wst.rdb.internal.core.connection.ConnectionInfo;
  +import org.eclipse.wst.rdb.internal.core.definition.DatabaseDefinition;
   import org.jboss.ide.seam.gen.QuestionDialog;
   import org.jboss.ide.seam.gen.SeamGenPlugin;
   
  @@ -55,29 +66,89 @@
   
   		public void launchesTerminated(ILaunch[] launches) {
   			for (int i = 0; i < launches.length; i++) {
  -				ILaunch launch2 = launches[i];
  +				final ILaunch launch2 = launches[i];
   				if("seamgen".equals( launch2.getLaunchConfiguration().getName() )) {
   					try {
  +						String target = launch2.getLaunchConfiguration().getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS,(String)null);
  +						if("setup".equals(target) && launch2.getAttribute( "terminated-done" )==null) {
  +							launch2.setAttribute( "terminated-done", "true" );
  +							SeamGenPlugin.getDefault().getWorkbench().getDisplay().syncExec(
  +									  new Runnable() {
  +									    public void run(){
  +									    	if(MessageDialog.openQuestion( getShell(), "Create new Seam project", "Create new seam project ?" )) {
  +												new NewProjectAction().run( null );												
  +											}
  +									    	
  +									    	if(MessageDialog.openQuestion( getShell(), "Create DB Connection", "Create DB Connection ?"  )) {
  +									    		DatabaseDefinition definition = RDBCorePlugin
  +				                                .getDefault().getDatabaseDefinitionRegistry()
  +				                                .getDefinition( "Generic JDBC", "1.0" );
  +									    		
  +									    		ConnectionInfo connection = RDBCorePlugin.getDefault()
  +								                .getConnectionManager().createConnectionInfo(
  +								                        definition,
  +								                        NewCWJDBCPage.createUniqueConnectionName( NewCWJDBCPage.getExistingConnectionNamesList(), "seamgen-connection"));
  +									    		
  +							
  +									    		Properties seamGenProperties = getSeamGenProperties( launch2.getLaunchConfiguration() );
  +									    		
  +									    		if(seamGenProperties!=null) {
  +									    			connection.setDatabaseName("SeamGen database");
  +									    			connection.setURL(seamGenProperties.getProperty( "hibernate.connection.url", "" ));
  +									    			connection.setDriverClassName(seamGenProperties.getProperty( "hibernate.connection.driver_class", "" ));
  +									    			connection.setLoadingPath(seamGenProperties.getProperty( "driver.jar", "" ));
  +									    			connection.setUserName( seamGenProperties.getProperty( "hibernate.connection.username", "" ) );
  +									    			connection.setPassword( seamGenProperties.getProperty( "hibernate.connection.password", "" ) );
  +									    			connection.setCustomProperty( "JDBC_DRIVER","Other");
  +									    			try {
  +														connection.saveConnectionInfo();
  +													}
  +													catch (Exception e) {
  +														SeamGenPlugin.logError( "Could not save connection info", e);
  +													}
  +									    		} else {
  +									    			MessageDialog.openError( getShell(), "Could not read database settings", "Could not read database settings. See Error log for details" );
  +									    		}
  +
  +									            
  +
  +									    	}
  +									    }
  +									  });
  +							return;
  +						}
  +						
  +						
   						//							org.eclipse.ui.externaltools.internal.launchConfigurations
  -						SeamGenPlugin.logInfo( "launch completed...auto detecting project" );
  -						IPath location = ExternalToolsUtil.getLocation( launch2.getLaunchConfiguration() );
  -						SeamGenPlugin.logInfo( "location: " + location );
  -						File file = new File(location.toFile().getParentFile(), "build.properties");
  -						SeamGenPlugin.logInfo( "build.properties: " + location );
  -						if(file.exists()) {
  -							Properties p = new Properties();
  -							p.load( new FileInputStream(file) );
  -							String workspace = p.getProperty( "workspace.home" );
  +						Properties p = getSeamGenProperties( launch2.getLaunchConfiguration() );
  +						if(p!=null) {
  +							String seamWorkspace = p.getProperty( "workspace.home" );
   							String projectName = p.getProperty( "project.name" );
   							
   							IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
   							
  +							if(!"new-project".equals(target)) {
  +								if(project.exists()) {
  +									project.refreshLocal( IResource.DEPTH_INFINITE, null );
  +								}
  +								return; // only autodetect for new-project stuff.
  +							}
  +							
   							if(!project.exists()) {
   								SeamGenPlugin.logInfo( "project " + projectName + " does not exist");
   								IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
  -								URI uri = new File(workspace, projectName).toURI();
  +								URI uri = new File(seamWorkspace, projectName).toURI();
  +								
  +								IPath locationPath = URIUtil.toPath(uri);
  +								IPath defaultDefaultLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
  +								IPath parentPath = locationPath.removeLastSegments(1);
  +								if (FileUtil.isPrefixOf(parentPath, defaultDefaultLocation) && FileUtil.isPrefixOf(defaultDefaultLocation, parentPath)) {
  +									SeamGenPlugin.logInfo( "seam workspace overlaps with eclipse. Opening project directly." );
  +								} else {
   								description.setLocationURI(uri);
   								SeamGenPlugin.logInfo( "project location should be " + uri);
  +									
  +								}
   								project.create(description, null);
   								project.open( null );
   								SeamGenPlugin.logInfo( "project " + projectName + " created ");
  @@ -92,12 +163,6 @@
   					}
   					catch (CoreException e) {
   						SeamGenPlugin.logError( "Error when seam-gen terminated", e );
  -					}
  -					catch (FileNotFoundException e) {
  -						SeamGenPlugin.logError( "Error when seam-gen terminated", e );
  -					}
  -					catch (IOException e) {
  -						SeamGenPlugin.logError( "Error when seam-gen terminated", e );
   					} finally {
   
   					}
  @@ -160,7 +225,7 @@
   			Map userProperties = Collections.EMPTY_MAP;
   			Map questions = getQuestions();
   			if(!questions.isEmpty()) {
  -				QuestionDialog questionDialog = new QuestionDialog(window.getShell(), getTitle(), getDescription(), questions);
  +				QuestionDialog questionDialog = new QuestionDialog(window.getShell(), getTitle(), getDescription(), questions,getGroups());
   				if(questionDialog.open()!= QuestionDialog.OK) {
   					SeamGenPlugin.logInfo( "User cancelled dialog" );
   					return;
  @@ -168,11 +233,42 @@
   					userProperties = questionDialog.getPropertiesResult();
   				}
   			}
  +			
  +			Properties empties = new Properties();
  +			Iterator iterator = userProperties.entrySet().iterator();
  +			while(iterator.hasNext()) {
  +				Map.Entry element = (Entry) iterator.next();
  +				String value = (String) element.getValue();
  +				if(value==null || value.trim().length()==0) {
  +					iterator.remove();
  +					empties.setProperty( (String) element.getKey(), value );
  +				}
  +			}
  +			
  +			if(!empties.isEmpty()) {
  +				File createTempFile = null;
  +				try {				
  +					createTempFile = File.createTempFile( "seamgenempty", "properties" );
  +					empties.store( new FileOutputStream(createTempFile), "File used to send intentionally empty valued properties" );
  +				}
  +				catch (FileNotFoundException e) {
  +					SeamGenPlugin.logError( "Error while running " + getTarget(), e );
  +				}
  +				catch (IOException e) {
  +					SeamGenPlugin.logError( "Error while running " + getTarget(), e );
  +				}
  +
  +				if(createTempFile!=null) {
  +					wc.setAttribute( IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, createTempFile.toString() );
  +				}
  +			}
  +			
   			wc.setAttribute( IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, userProperties);
   
   			wc.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, getTarget());
   
   
  +
   			ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
   
   			launchManager.addLaunchListener( launchListener );
  @@ -187,6 +283,10 @@
   	
   	}
   
  +	public Set getGroups() {
  +		return Collections.EMPTY_SET;
  +	}
  +
   	public String getDescription() {
   		return "Seam Gen " + getTarget();
   	}
  @@ -201,7 +301,7 @@
   
   	protected abstract String getTarget();
   	
  -	private ILaunchConfiguration findLaunchConfig(String name) throws CoreException {
  +	static public ILaunchConfiguration findLaunchConfig(String name) throws CoreException {
   		ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
   		ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType( "org.eclipse.ant.AntLaunchConfigurationType" );
   		ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations( launchConfigurationType );
  @@ -242,4 +342,46 @@
   		this.window = window;
   	}
   
  +	public static Properties getSeamGenProperties(ILaunchConfiguration lc) {
  +		SeamGenPlugin.logInfo( "launch completed...auto detecting project" );
  +		IPath location;
  +		try {
  +			location = ExternalToolsUtil.getLocation( lc );
  +		}
  +		catch (CoreException e2) {
  +			SeamGenPlugin.logError( "Error while loading seamgen properties", e2 );
  +			return null;
  +		}
  +		
  +		SeamGenPlugin.logInfo( "location: " + location );
  +		File file = new File(location.toFile().getParentFile(), "build.properties");
  +		SeamGenPlugin.logInfo( "build.properties: " + location );
  +		
  +		if(file.exists()) {
  +			Properties p = new Properties();
  +			FileInputStream fileInputStream = null;
  +			try {
  +				fileInputStream = new FileInputStream(file);
  +				p.load( fileInputStream );
  +			}
  +			catch (Exception e) {
  +				SeamGenPlugin.logError( "Error while loading seamgen properties", e );
  +				if(fileInputStream!=null)
  +					try {
  +						fileInputStream.close();
  +					}
  +					catch (IOException e1) {
  +						SeamGenPlugin.logError( "Error while closing seamgen properties", e );
  +					}
  +			}
  +			return p;
  +		} else {
  +			return null;
  +		}
  +		
  +	}
  +
  +	private Shell getShell() {
  +		return SeamGenPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
  +	}
   }
  \ No newline at end of file
  
  
  
  1.1      date: 2007/03/14 09:21:29;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SetupDeluxeAction.java
  
  Index: SetupDeluxeAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  import java.io.File;
  import java.util.LinkedHashMap;
  import java.util.LinkedHashSet;
  import java.util.Map;
  import java.util.Properties;
  import java.util.Set;
  
  import org.eclipse.ui.IWorkbenchWindowActionDelegate;
  import org.jboss.ide.seam.gen.SeamGenProperty;
  
  public class SetupDeluxeAction extends SeamGenAction implements
  		IWorkbenchWindowActionDelegate {
  
  	
  	protected static final String DB = "Database";
  	protected static final String CODEGEN = "Code generation";
  	
  	protected String getTarget() {
  		return "setup";
  	}
  
  	public Set getGroups() {
  		LinkedHashSet set = new LinkedHashSet();
  		set.add(SeamGenProperty.GENERAL);
  		set.add(DB);
  		set.add(CODEGEN);
  		return set;
  	}
  	protected Map getQuestions() {
  		Map properties = new LinkedHashMap();
  
  		properties.put( "project.name.new",
  				new SeamGenProperty( "Project name", "project.name" ) {
  					public String getDefaultValue(Properties others) {
  						String property = others.getProperty(
  								"project.name.new", "" );
  						return property;
  					}
  					
  					public String getGroup() {
  						return GENERAL; 
  					}
  				}
  
  				
  		);
  
  		properties.put( "workspace.home.new", new SeamGenProperty(
  				"Seam project workspace", "workspace.home" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "workspace.home",
  						"c:/projects" );
  				return property;
  			}
  			
  			public int getInputType() {
  				return DIR;
  			};
  			
  			public String valid(String string) {
  				if(string==null) return null;
  				File file = new File(string);
  				if (file.exists() && file.isDirectory()) {
  					return null;
  				} else {
  					return string + " does not exist or is not a directory";
  				}
  			}
  			
  			
  			
  		} );
  
  		properties.put( "jboss.home.new", new SeamGenProperty(
  				"JBoss AS home directory", "jboss.home" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "jboss.home.new",
  						"C:/Program Files/jboss-4.0.5.GA" );
  				return property;
  			}
  			
  			public int getInputType() {
  				return DIR;
  			};
  
  			public String valid(String string) {
  				if(string==null) return null;
  				File file = new File(string);
  				if (file.exists() && file.isDirectory()) {
  					return null;
  				} else {
  					return string + " does not exist or is not a directory";
  				}
  			}
  		} );
  
  		properties.put( "project.type.new", new SeamGenProperty(
  				"Deploy as an EAR or a WAR", "project.type" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "project.type", "ear" );
  				return property; // ear,war
  			}
  			
  			public String getGroup() {
  				return GENERAL; 
  			}
  		} );
  
  		properties.put( "action.package.new", new SeamGenProperty(
  				"Session beans package name", "action.package" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "project.name.new", "" );
  				return "com.mydomain." + property;
  			}
  			
  			public String getGroup() {
  				return CODEGEN; 
  			}
  		} );
  
  		properties.put( "model.package.new", new SeamGenProperty(
  				"Entity beans package name", "model.package" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "action.package.new", "" );
  				return property;
  			}
  			
  			public String getGroup() {
  				return CODEGEN; 
  			}
  		} );
  
  		properties.put( "test.package.new", new SeamGenProperty(
  				"Test cases package name", "test.package" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "action.package.new", "" );
  				return property + ".test";
  			}
  			
  			public String getGroup() {
  				return CODEGEN; 
  			}
  		} );
  
  		properties.put( "database.type.new", new SeamGenProperty(
  				"Database type", "database.type" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "database.type.new",
  						"hql" );
  				return property; // hsql,mysql,oracle,postgres,mssql,db2,sybase,enterprisedb
  			}
  			
  			public String getGroup() {
  				return DB; 
  			}
  					
  		} );
  
  		properties.put( "hibernate.dialect.new", new SeamGenProperty(
  				"Hibernate dialect", "hibernate.dialect" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "hibernate.dialect.new",
  						"org.hibernate.dialect.HSQLDialect" );
  				return property;
  			}
  			public String getGroup() {
  				return DB; 
  			}
  		} );
  
  		properties.put( "driver.jar.new", new SeamGenProperty(
  				"Filesystem path to the JDBC driver jar", "driver.jar" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "driver.jar.new",
  						"lib/hsqldb.jar" );
  				return property;
  			}
  			
  			public int getInputType() {
  				return JAR;
  			};
  
  			public String valid(String string) {
  				if(string==null) return null;
  				File file = new File(string);
  				if (file.exists() && file.isFile()) {
  					return null;
  				} else {
  					return string + " does not exist or is not a file";
  				}
  			}
  		} );
  
  		properties.put( "hibernate.connection.driver_class.new",
  				new SeamGenProperty( "JDBC driver class for your database", "hibernate.connection.driver_class" ) {
  					public String getDefaultValue(Properties others) {
  						String property = others.getProperty(
  								"hibernate.connection.driver_class",
  								"org.hsqldb.jdbcDriver" );
  						return property;
  					}
  					public String getGroup() {
  						return DB; 
  					}
  				} );
  
  		properties.put( "hibernate.connection.url.new", new SeamGenProperty(
  				"JDBC URL for your database", "hibernate.connection.url" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty(
  						"hibernate.connection.url",
  						"jdbc:hsqldb:hsql://localhost:1701" );
  				return property;				
  			}
  			public String getGroup() {
  				return DB; 
  			}
  		} );
  
  		properties.put( "hibernate.connection.username.new",
  				new SeamGenProperty( "Database username", "hibernate.connection.username" ) {
  					public String getDefaultValue(Properties others) {
  						String property = others.getProperty(
  								"hibernate.connection.username", "sa" );
  						return property;
  					}
  					public String getGroup() {
  						return DB; 
  					}
  				} );
  
  		properties.put( "hibernate.connection.password.new",
  				new SeamGenProperty( "Database password", "hibernate.connection.password" ) {
  					public String getDefaultValue(Properties others) {
  						String property = others.getProperty(
  								"hibernate.connection.password", "" );
  						return property;
  					}
  
  					public boolean isRequired() {
  						return false;
  					}
  					public String getGroup() {
  						return DB; 
  					}
  				} );
  
  		properties.put( "hibernate.default_schema.new", new SeamGenProperty(
  				"Database schema name", "hibernate.default_schema" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty(
  						"hibernate.default_schema", "" );
  				return property;
  			}
  
  			public boolean isRequired() {
  				return false;
  			}
  			
  			public String getGroup() {
  				return DB; 
  			}
  		} );
  
  		properties.put( "hibernate.default_catalog.new", new SeamGenProperty(
  				"Database catalog name", "hibernate.default_catalog" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty(
  						"hibernate.default_catalog", "" );
  				return property;
  			}
  
  			public boolean isRequired() {
  				return false;
  			}
  			
  			public String getGroup() {
  				return DB; 
  			}
  		}
  
  		);
  
  		properties.put( "database.exists.new", new SeamGenProperty(
  				"Does tables already exist in the database?", "database.exists" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "database.exists", "y" );
  				return property; // yn
  			}
  			
  			public String getGroup() {
  				return DB; 
  			}
  			
  			public int getInputType() {
  				return YES_NO;
  			};
  			
  			
  		} );
  
  		properties.put( "database.drop.new", new SeamGenProperty(
  				"Recreate database tables + data on deploy?", "database.drop" ) {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "database.drop", "n" );
  				return property; // yn
  			}
  			
  			public String getGroup() {
  				return DB; 
  			}
  			
  			public int getInputType() {
  				return YES_NO;
  			};
  		} );
  
  		return properties;
  	}
  }
  
  
  



More information about the jboss-cvs-commits mailing list