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

Max Rydahl Andersen mandersen at jboss.com
Thu Feb 15 07:20:45 EST 2007


  User: mandersen
  Date: 07/02/15 07:20:45

  Added:       seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions               
                        DeployAction.java ExplodeAction.java
                        GenerateEntitiesAction.java NewActionAction.java
                        NewConversationAction.java NewEntityAction.java
                        NewFormAction.java NewProjectAction.java
                        RestartAction.java SampleAction.java
                        SeamGenAction.java SetupAction.java
                        UndeployAction.java UnexplodeAction.java
                        UpdateProjectAction.java
  Log:
  first cut at seamgen eclipse integration
  
  Revision  Changes    Path
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/DeployAction.java
  
  Index: DeployAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class DeployAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "deploy";
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/ExplodeAction.java
  
  Index: ExplodeAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class ExplodeAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "explode";
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/GenerateEntitiesAction.java
  
  Index: GenerateEntitiesAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class GenerateEntitiesAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "generate-entities";
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/NewActionAction.java
  
  Index: NewActionAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  import java.util.LinkedHashMap;
  import java.util.Map;
  import java.util.Properties;
  
  import org.jboss.ide.seam.gen.SeamGenProperty;
  
  public class NewActionAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "new-action";
  	}
  
  	public String getTitle() {
  		return "Create new Action";
  	}
  	
  	public String getDescription() {
  		return "Create a new Java interface and SLSB\n with key Seam/EJB3 annotations.";
  	}
  	
  	protected Map getQuestions() {
  		Map properties = new LinkedHashMap();
  		properties.put( "component.name", new SeamGenProperty("Seam component name") );
  		properties.put( "interface.name", new SeamGenProperty("Local interface name") {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "component.name", "" );
  				return upper(property);
  			}
  		});
  		properties.put( "bean.name", new SeamGenProperty("Bean name") {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "component.name", "" );
  				return upper(property + "Bean");
  			}
  		});
  		properties.put( "method.name", new SeamGenProperty("Method name") {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "component.name", "" );
  				return lower(property);
  			}
  		});
  		
  		properties.put( "page.name", new SeamGenProperty("Page name") {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "component.name", "" );
  				return lower(property);
  			}
  		});
  		return properties;
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/NewConversationAction.java
  
  Index: NewConversationAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class NewConversationAction extends NewActionAction {
  
  	protected String getTarget() {
  		return "new-conversation";
  	}
  	
  
  	public String getTitle() {
  		return "Create new conversation";
  	}
  	
  	public String getDescription() {
  		return "Create a set of classes managing a conversation.\n";
  		        
  	}
  
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/NewEntityAction.java
  
  Index: NewEntityAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  import java.util.LinkedHashMap;
  import java.util.Map;
  import java.util.Properties;
  
  import org.jboss.ide.seam.gen.SeamGenProperty;
  
  public class NewEntityAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "new-entity";
  	}
  
  	public String getTitle() {
  		return "New entity";
  	}
  	
  	public String getDescription() {
  		return "Create a new entity bean\nwith key Seam/EJB3 annotations and example attributes.";
  	}
  	
  	protected Map getQuestions() {
  		Map properties = new LinkedHashMap();
  		properties.put( "entity.name", new SeamGenProperty("Entity class name") );
  		properties.put( "masterPage.name", new SeamGenProperty("Master page name") {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "entity.name", "" );
  				return lower(property) + "List";
  			}
  		});
  			
  		properties.put( "page.name", new SeamGenProperty("Page name") {
  			public String getDefaultValue(Properties others) {
  				String property = others.getProperty( "entity.name", "" );
  				return lower(property);
  			}
  		});
  		return properties;
  	}
  
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/NewFormAction.java
  
  Index: NewFormAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class NewFormAction extends NewActionAction {
  	/**
  	 * The constructor.
  	 */
  	public NewFormAction() {
  	}
  	
  	protected String getTarget() {
  		return "new-form";
  	}
  	
  	public String getTitle() {
  		return "Create new form";
  	}
  	
  	public String getDescription() {
  		return "Create a form with a single input field and related\n" +
  				"Java interface, SLSB with key Seam/EJB3 annotations.";
  	}
  
  
  }
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/NewProjectAction.java
  
  Index: NewProjectAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class NewProjectAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "new-project";
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/RestartAction.java
  
  Index: RestartAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class RestartAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "restart";
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SampleAction.java
  
  Index: SampleAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  import org.eclipse.jface.action.IAction;
  import org.eclipse.jface.viewers.ISelection;
  import org.eclipse.ui.IWorkbenchWindow;
  import org.eclipse.ui.IWorkbenchWindowActionDelegate;
  import org.eclipse.jface.dialogs.MessageDialog;
  
  /**
   * Our sample action implements workbench action delegate.
   * The action proxy will be created by the workbench and
   * shown in the UI. When the user tries to use the action,
   * this delegate will be created and execution will be 
   * delegated to it.
   * @see IWorkbenchWindowActionDelegate
   */
  public class SampleAction implements IWorkbenchWindowActionDelegate {
  	private IWorkbenchWindow window;
  	/**
  	 * The constructor.
  	 */
  	public SampleAction() {
  	}
  
  	/**
  	 * The action has been activated. The argument of the
  	 * method represents the 'real' action sitting
  	 * in the workbench UI.
  	 * @see IWorkbenchWindowActionDelegate#run
  	 */
  	public void run(IAction action) {
  		MessageDialog.openInformation(
  			window.getShell(),
  			"JBoss Seam-gen Plug-in",
  			"Hello, Eclipse world");
  	}
  
  	/**
  	 * Selection in the workbench has been changed. We 
  	 * can change the state of the 'real' action here
  	 * if we want, but this can only happen after 
  	 * the delegate has been created.
  	 * @see IWorkbenchWindowActionDelegate#selectionChanged
  	 */
  	public void selectionChanged(IAction action, ISelection selection) {
  	}
  
  	/**
  	 * We can use this method to dispose of any system
  	 * resources we previously allocated.
  	 * @see IWorkbenchWindowActionDelegate#dispose
  	 */
  	public void dispose() {
  	}
  
  	/**
  	 * We will cache window object in order to
  	 * be able to provide parent shell for the message dialog.
  	 * @see IWorkbenchWindowActionDelegate#init
  	 */
  	public void init(IWorkbenchWindow window) {
  		this.window = window;
  	}
  }
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SeamGenAction.java
  
  Index: SeamGenAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.net.URI;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Properties;
  
  import org.eclipse.ant.internal.ui.IAntUIConstants;
  import org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants;
  import org.eclipse.core.resources.IProject;
  import org.eclipse.core.resources.IProjectDescription;
  import org.eclipse.core.resources.ResourcesPlugin;
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IPath;
  import org.eclipse.debug.core.DebugPlugin;
  import org.eclipse.debug.core.ILaunch;
  import org.eclipse.debug.core.ILaunchConfiguration;
  import org.eclipse.debug.core.ILaunchConfigurationType;
  import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
  import org.eclipse.debug.core.ILaunchManager;
  import org.eclipse.debug.core.ILaunchesListener2;
  import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
  import org.eclipse.jface.action.IAction;
  import org.eclipse.jface.dialogs.MessageDialog;
  import org.eclipse.jface.viewers.ISelection;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.widgets.FileDialog;
  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.jboss.ide.seam.gen.QuestionDialog;
  import org.jboss.ide.seam.gen.SeamGenPlugin;
  
  public abstract class SeamGenAction implements IWorkbenchWindowActionDelegate {
  
  	private final class LaunchListener implements ILaunchesListener2 {
  		public void launchesRemoved(ILaunch[] launches) {
  			
  		}
  
  		public void launchesChanged(ILaunch[] launches) {
  			
  		}
  
  		public void launchesAdded(ILaunch[] launches) {
  			
  		
  		}
  
  		public void launchesTerminated(ILaunch[] launches) {
  			for (int i = 0; i < launches.length; i++) {
  				ILaunch launch2 = launches[i];
  				if("seamgen".equals( launch2.getLaunchConfiguration().getName() )) {
  					try {
  						//							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" );
  							String projectName = p.getProperty( "project.name" );
  							
  							IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
  							
  							if(!project.exists()) {
  								SeamGenPlugin.logInfo( "project " + projectName + " does not exist");
  								IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
  								URI uri = new File(workspace, projectName).toURI();
  								description.setLocationURI(uri);
  								SeamGenPlugin.logInfo( "project location should be " + uri);
  								project.create(description, null);
  								project.open( null );
  								SeamGenPlugin.logInfo( "project " + projectName + " created ");
  							} else {
  								SeamGenPlugin.logInfo( "project " + projectName + " already exists");
  							}
  							//project.refreshLocal( IResource.DEPTH_INFINITE, null );
  
  						} else {
  							SeamGenPlugin.logInfo( "build.properties not found");
  						}
  					}
  					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 {
  
  					}
  				}
  
  			}
  
  		}
  	}
  
  	protected IWorkbenchWindow window;
  	private LaunchListener launchListener = new LaunchListener();
  
  	public SeamGenAction() {
  		super();
  	}
  
  	public void run(IAction action) {
  		
  		try {
  			
  			ILaunchConfiguration launchConfiguration = findLaunchConfig( "seamgen" );		
  			
  			ILaunchConfigurationWorkingCopy wc = null;
  			if(launchConfiguration==null) {
  				SeamGenPlugin.logInfo( "seamgen launch config not found. Creating one automatically." );
  				FileDialog fileDialog = new FileDialog(window.getShell(), SWT.NONE);
  				fileDialog.setText( "Select Seam Gen build.xml..." );
  				fileDialog.setFileName("build.xml");
  				String text=fileDialog.open();
  				if (text != null) {
  					SeamGenPlugin.logInfo( "User selected: " + text + " as build.xml" );
  					ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  					ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType( "org.eclipse.ant.AntLaunchConfigurationType" );
  					wc = launchConfigurationType.newInstance( null, "seamgen" );
  					wc.setAttribute( "process_factory_id", "org.eclipse.ant.ui.remoteAntProcessFactory" );
  					wc.setAttribute(IAntUIConstants.ATTR_DEFAULT_VM_INSTALL, true);
  					wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.ant.internal.ui.antsupport.InternalAntRunner");
  					
  					wc.setAttribute("org.eclipse.debug.core.appendEnvironmentVariables", true);
  					
  					wc.setAttribute( "org.eclipse.jdt.launching.CLASSPATH_PROVIDER", "org.eclipse.ant.ui.AntClasspathProvider" );
  					wc.setAttribute( "org.eclipse.jdt.launching.SOURCEPATH_PROVIDER", "org.eclipse.ant.ui.AntClasspathProvider" );
  					
  					wc.setAttribute( "org.eclipse.jdt.launching.VM_INSTALL_TYPE_ID", "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType");
  					
  					wc.setAttribute( IExternalToolConstants.ATTR_LOCATION, text );
  					
  					wc.doSave();
  					SeamGenPlugin.logInfo( "seamgen launch config saved" );
  				} else {
  					MessageDialog.openError( window.getShell(), "No build.xml selected", "You have to select the build.xml to be used by Seam Gen." );
  					return;
  				}
  			} else {
  				wc = launchConfiguration.getWorkingCopy();				
  			}			
  			
  			wc.setAttribute(IAntUIConstants.SET_INPUTHANDLER, true);
  			Map userProperties = Collections.EMPTY_MAP;
  			Map questions = getQuestions();
  			if(!questions.isEmpty()) {
  				QuestionDialog questionDialog = new QuestionDialog(window.getShell(), getTitle(), getDescription(), questions);
  				if(questionDialog.open()!= QuestionDialog.OK) {
  					SeamGenPlugin.logInfo( "User cancelled dialog" );
  					return;
  				} else {
  					userProperties = questionDialog.getPropertiesResult();
  				}
  			}
  			wc.setAttribute( IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, userProperties);
  
  			wc.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, getTarget());
  
  
  			ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  
  			launchManager.addLaunchListener( launchListener );
  
  //			launchConfiguration = wc.doSave();
  			SeamGenPlugin.logInfo( "launching seamgen " + getTarget() );
  			ILaunch launch = wc.launch( ILaunchManager.RUN_MODE, null );
  			
  		} catch (CoreException e) {			
  			SeamGenPlugin.logError( "Exception when trying to launch seamgen", e );
  		}
  	
  	}
  
  	public String getDescription() {
  		return "Seam Gen " + getTarget();
  	}
  
  	public String getTitle() {
  		return getDescription();
  	}
  
  	protected Map getQuestions() {		
  		return Collections.EMPTY_MAP;
  	}
  
  	protected abstract String getTarget();
  	
  	private ILaunchConfiguration findLaunchConfig(String name) throws CoreException {
  		ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  		ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType( "org.eclipse.ant.AntLaunchConfigurationType" );
  		ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations( launchConfigurationType );
  	
  		for (int i = 0; i < launchConfigurations.length; i++) { // can't believe there is no look up by name API
  			ILaunchConfiguration launchConfiguration = launchConfigurations[i];
  			if(launchConfiguration.getName().equals(name)) {
  				return launchConfiguration;
  			}
  		} 
  		return null;
  	}
  
  	/**
  	 * Selection in the workbench has been changed. We 
  	 * can change the state of the 'real' action here
  	 * if we want, but this can only happen after 
  	 * the delegate has been created.
  	 * @see IWorkbenchWindowActionDelegate#selectionChanged
  	 */
  	public void selectionChanged(IAction action, ISelection selection) {
  	}
  
  	/**
  	 * We can use this method to dispose of any system
  	 * resources we previously allocated.
  	 * @see IWorkbenchWindowActionDelegate#dispose
  	 */
  	public void dispose() {
  	}
  
  	/**
  	 * We will cache window object in order to
  	 * be able to provide parent shell for the message dialog.
  	 * @see IWorkbenchWindowActionDelegate#init
  	 */
  	public void init(IWorkbenchWindow window) {
  		this.window = window;
  	}
  
  }
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SetupAction.java
  
  Index: SetupAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class SetupAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "setup";
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/UndeployAction.java
  
  Index: UndeployAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class UndeployAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "undeploy";
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/UnexplodeAction.java
  
  Index: UnexplodeAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class UnexplodeAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "unexplode";
  	}
  
  }
  
  
  
  1.1      date: 2007/02/15 12:20:44;  author: mandersen;  state: Exp;jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/UpdateProjectAction.java
  
  Index: UpdateProjectAction.java
  ===================================================================
  package org.jboss.ide.seam.gen.actions;
  
  public class UpdateProjectAction extends SeamGenAction {
  
  	protected String getTarget() {
  		return "update-project";
  	}
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list