[jboss-cvs] jboss-seam-ide/src/org/jboss/seam/ide/wizard ...

Thomas Heute theute at jboss.com
Tue Aug 15 06:14:37 EDT 2006


  User: theute  
  Date: 06/08/15 06:14:37

  Added:       src/org/jboss/seam/ide/wizard   NewSeamProjectWizard.java
                        NewSeamProjectWizardPage.java
  Log:
  Initial for Seam IDE
  
  Revision  Changes    Path
  1.1      date: 2006/08/15 10:14:37;  author: theute;  state: Exp;jboss-seam-ide/src/org/jboss/seam/ide/wizard/NewSeamProjectWizard.java
  
  Index: NewSeamProjectWizard.java
  ===================================================================
  package org.jboss.seam.ide.wizard;
  
  import java.io.IOException;
  import java.lang.reflect.InvocationTargetException;
  import java.util.ArrayList;
  import java.util.List;
  
  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.IProgressMonitor;
  import org.eclipse.jface.operation.IRunnableWithProgress;
  import org.eclipse.jface.viewers.IStructuredSelection;
  import org.eclipse.jface.wizard.Wizard;
  import org.eclipse.ui.INewWizard;
  import org.eclipse.ui.IWorkbench;
  import org.eclipse.ui.IWorkbenchWizard;
  import org.jboss.seam.tools.context.Context;
  import org.jboss.seam.tools.context.EarContext;
  import org.jboss.seam.tools.context.EjbContext;
  import org.jboss.seam.tools.context.WebContext;
  import org.jboss.seam.tools.exporter.wtp.WTPEarProjectExporter;
  import org.jboss.seam.tools.exporter.wtp.WTPEjbProjectExporter;
  import org.jboss.seam.tools.exporter.wtp.WTPSeamExporter;
  import org.jboss.seam.tools.exporter.wtp.WTPWebProjectExporter;
  
  /**
   * This is a sample new wizard. Its role is to create a new file 
   * resource in the provided container. If the container resource
   * (a folder or a project) is selected in the workspace 
   * when the wizard is opened, it will accept it as the target
   * container. The wizard creates one file with the extension
   * "mpe". If a sample multi-page editor (also available
   * as a template) is registered for the same extension, it will
   * be able to open it.
   */
  
  public class NewSeamProjectWizard extends Wizard implements INewWizard {
  
  	private NewSeamProjectWizardPage seamPage;
  
  	/**
  	 * Constructor for NewSeamProjectWizard.
  	 */
  	public NewSeamProjectWizard() {
  		super();
  		setNeedsProgressMonitor(true);
  	}
  
  	/**
  	 * Adding the page to the wizard.
  	 */
  
  	public void addPages() {
  		seamPage = new NewSeamProjectWizardPage();
  		addPage(seamPage);
  	}
  
  	public boolean performFinish() {
  		
  		final String projectName = seamPage.getProjectName();
  		final boolean exampleProject = seamPage.getExampleProject();
  		final String seamLocation = seamPage.getSeamLocation();
  		final String exampleSrcPackage = seamPage.getExampleSrcPackage();
  		final String exampleTestPackage = seamPage.getExampleTestPackage();
  		final boolean faceletsSupport = seamPage.getFaceletsSupport();
  		final boolean testSupport = seamPage.getTestSupport();
  		
  		IRunnableWithProgress op = new IRunnableWithProgress() {
  			public void run(IProgressMonitor monitor) throws InvocationTargetException {
  				try {
  					createProjects(projectName, exampleProject, faceletsSupport, testSupport, seamLocation, exampleSrcPackage, exampleTestPackage, monitor);
  				} catch (Exception e) {
  					e.printStackTrace();
  					throw new InvocationTargetException(e);
  				} finally {
  					monitor.done();
  				}
  			}
  		};
  		try {
  			getContainer().run(true, false, op);
  		} catch (InterruptedException e) {
  			return false;
  		} catch (InvocationTargetException e) {
  			Throwable realException = e.getTargetException();
  			realException.printStackTrace();
  			return false;
  		}
  		return true;
  	}
  	
  	public void createProjects(String projectName, boolean exampleProject, boolean faceletsSupport, boolean testSupport, String seamLocation, String exampleSrcPackage, String exampleTestPackage, IProgressMonitor monitor) throws IOException, CoreException
  	{
  		monitor.beginTask("Creating " + projectName, 5);
  		
  		Context context = new Context();
  		context.setProjectName(projectName);
  		context.setIsolationClassLoadingName("seam.jboss.org:loader=" + projectName);
  		context.setSeamLocation(seamLocation);
  		context.setEclipseSupport(true);
  		context.setBasicProject(exampleProject);
  		context.setTestSupport(testSupport);
  		context.setSrcPackage(exampleSrcPackage);
  		context.setTestPackage(exampleTestPackage);
  		context.setFaceletsSupport(faceletsSupport);
  
  		
  		EarContext earContext = new EarContext();
  		earContext.setProjectName(projectName + "-ear");
  		earContext.setDisplayName(projectName);
  		earContext.setFilename(projectName + ".ear");
  		earContext.setContentDirectory("src");
  		WTPEarProjectExporter wtpEarExporter = new WTPEarProjectExporter(context);
  		wtpEarExporter.setEarContext(earContext);
  		
  		
  		EjbContext ejbContext = new EjbContext();
  		ejbContext.setFilename(projectName + "-ejb.jar");
  		ejbContext.setProjectName(projectName + "-ejb");
  		ejbContext.setId(projectName + "-ejb");
  		ejbContext.setContentDirectory("src");
  		ejbContext.setJtaDataSource("DefaultDS");
  		ejbContext.setPersistenceUnitName(projectName + "Database");
  
  		WTPEjbProjectExporter wtpEjbExporter = new WTPEjbProjectExporter(context);
  		wtpEjbExporter.setEjbContext(ejbContext);
  		List ejbExporters = new ArrayList();
  		ejbExporters.add(wtpEjbExporter);
  		
  		WebContext webContext = new WebContext();
  		webContext.setProjectName(projectName + "-web");
  		webContext.setFilename(projectName + "-web.war");
  		webContext.setContextRoot(projectName);
  		webContext.setId(projectName + "-web.war");
  		webContext.setContentDirectory("web");
  		if (context.isFaceletsSupport())
  		{
  			webContext.setJsfExtension("xhtml");
  		}
  		else
  		{
  			webContext.setJsfExtension("jsp");
  		}
  		WTPWebProjectExporter wtpWebExporter = new WTPWebProjectExporter(context);
  		wtpWebExporter.setWebContext(webContext);
  		List webExporters = new ArrayList();
  		webExporters.add(wtpWebExporter);
  		
  		
  		WTPSeamExporter seamWTPExporter = new WTPSeamExporter(wtpEarExporter, ejbExporters, webExporters);
  		
  		seamWTPExporter.setOutputDirectory(ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toFile());
  		seamWTPExporter.start();
  
  		
  		
  		/*
  		
  		WTPRootProject seamProject = new WTPRootProject();
  
  		// Ear
  		EarContext earContext = new EarContext();
  		earContext.setContentDirectory("src");
  		earContext.setDisplayName(projectName);
  		WTPEarProject wtpEarProject = new WTPEarProject();
  		wtpEarProject.setEarContext(earContext);
  
  		wtpEarProject.setProjectName(projectName + "-ear");
  
  		seamProject.setEarProject(wtpEarProject);
  
  		// Utility Jar
  		UtilityJar seamJar = new UtilityJar();
  		seamJar.setFilename("jboss-seam.jar");
  		wtpEarProject.addUtilityJar(seamJar);
  
  		// War
  		WTPWebContext eContext = new WTPWebContext();
  		eContext.setId(projectName + "-war");
  		eContext.setContentDirectory("web");
  		eContext.setContextRoot("/" + projectName);
  		WTPWebProject wtpWebProject = new WTPWebProject();
  		wtpWebProject.setWebContext(eContext);
  		wtpWebProject.setProjectName(projectName + "-war");
  		wtpWebProject.setFilename(projectName + ".war");
  
  		seamProject.addWebProject(wtpWebProject);
  
  		// EJB
  		WTPEjbContext ejbContext = new WTPEjbContext();
  		ejbContext.setContentDirectory("src");
  		ejbContext.setJtaDataSource(projectName + "Datasource");
  		ejbContext.setPersistenceUnitName(projectName + "Database");
  		ejbContext.setId(projectName + "-ejb");
  		EjbProject ejbProject = new WTPEjbProject();
  		ejbProject.setEjbContext(ejbContext);
  
  		ejbProject.setProjectName(projectName + "-ejb");
  		ejbProject.setFilename(projectName + ".jar");
  		
  		seamProject.addEjbProject(ejbProject);
  
  		// Context
  		Context context = new Context();
  
  		context.setOutputLocation(ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toString());
  		context.setEclipseSupport(true);
  		context.setStructure(Structure.WTP);
  		context.setBasicProject(exampleProject);
  		context.setJsfExtension("jsp");
  		context.setFaceletsSupport(true);
  		context.setTestSupport(true);
  		context.setIsolationClassLoadingName("seam.jboss.org:loader=" + projectName);
  		context.setSeamLocation(seamLocation);
  		context.setSrcPackage(exampleSrcPackage);
  		context.setTestPackage(exampleTestPackage);
  
  		seamProject.generate(context);
  */
  		monitor.worked(2);
  		
  		IProjectDescription descr;
  
  		// Load and open the Web project
  		descr = ResourcesPlugin.getWorkspace().loadProjectDescription(ResourcesPlugin.getWorkspace().getRoot().getRawLocation().append(webContext.getProjectName()).append(".project"));
  		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
  				webContext.getProjectName());
  		project.create(descr, monitor);
  		project.open(monitor);
  
  		monitor.worked(1);
  
  		// Load and open the Ejb project
  		descr = ResourcesPlugin.getWorkspace().loadProjectDescription(ResourcesPlugin.getWorkspace().getRoot().getRawLocation().append(ejbContext.getProjectName()).append(".project"));
  		project = ResourcesPlugin.getWorkspace().getRoot().getProject(
  				ejbContext.getProjectName());
  		project.create(descr, monitor);
  		project.open(monitor);
  		
  		monitor.worked(1);
  
  		// Load and open the Ear project
  		descr = ResourcesPlugin.getWorkspace().loadProjectDescription(ResourcesPlugin.getWorkspace().getRoot().getRawLocation().append(earContext.getProjectName()).append(".project"));
  		project = ResourcesPlugin.getWorkspace().getRoot().getProject(
  				earContext.getProjectName());
  		project.create(descr, monitor);
  		project.open(monitor);
  
  		monitor.worked(1);
  	}
  
  
  
  	/**
  	 * We will accept the selection in the workbench to see if
  	 * we can initialize from it.
  	 * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
  	 */
  	public void init(IWorkbench workbench, IStructuredSelection selection) {
  //		this.selection = selection;
  	}
  }
  
  
  1.1      date: 2006/08/15 10:14:37;  author: theute;  state: Exp;jboss-seam-ide/src/org/jboss/seam/ide/wizard/NewSeamProjectWizardPage.java
  
  Index: NewSeamProjectWizardPage.java
  ===================================================================
  package org.jboss.seam.ide.wizard;
  
  import java.io.File;
  import java.util.regex.Pattern;
  
  import org.eclipse.jface.dialogs.IDialogPage;
  import org.eclipse.jface.wizard.WizardPage;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.events.ModifyEvent;
  import org.eclipse.swt.events.ModifyListener;
  import org.eclipse.swt.events.SelectionAdapter;
  import org.eclipse.swt.events.SelectionEvent;
  import org.eclipse.swt.events.SelectionListener;
  import org.eclipse.swt.layout.GridData;
  import org.eclipse.swt.layout.GridLayout;
  import org.eclipse.swt.widgets.Button;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Control;
  import org.eclipse.swt.widgets.DirectoryDialog;
  import org.eclipse.swt.widgets.Group;
  import org.eclipse.swt.widgets.Label;
  import org.eclipse.swt.widgets.Text;
  
  /**
   *
   */
  public class NewSeamProjectWizardPage extends WizardPage {
  	private Text projectNameText;
  
  	private Text seamLocationText;
  
  	private Text exampleSrcPackageText;
  
  	private Text exampleTestPackageText;
  
  	private Group exampleConfigurationGroup;
  
  	private Button exampleProjectButton;
  
  	private Button testSupportButton;
  
  	private Button faceletsSupportButton;
  
  	public NewSeamProjectWizardPage() {
  		super("seamWizardPage");
  		setTitle("New Seam project wizard");
  		setDescription("This wizard creates a new Seam project composed of an EAR application, an EJB3 application and a WAR application.");
  	}
  
  	/**
  	 * @see IDialogPage#createControl(Composite)
  	 */
  	public void createControl(Composite parent) {
  		
  		Composite container = new Composite(parent, SWT.NULL);
  		GridLayout layout = new GridLayout();
  		container.setLayout(layout);
  		layout.numColumns = 3;
  		layout.verticalSpacing = 9;
  		
  		Label label = new Label(container, SWT.NULL);
  		label.setText("Project name:");
  
  		projectNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
  		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
  		gd.horizontalSpan = 2;
  		projectNameText.setLayoutData(gd);
  		projectNameText.addModifyListener(new ModifyListener() {
  
  			public void modifyText(ModifyEvent e) {
  				checkValidity();
  			}
  			
  		});
  		
  		GridData span3 = new GridData(GridData.FILL_HORIZONTAL);
  		span3.horizontalSpan = 3;
  		
  		testSupportButton = new Button(container, SWT.CHECK);
  		testSupportButton.setText("Create test environment");
  		testSupportButton.setLayoutData(span3);
  		
  		faceletsSupportButton = new Button(container, SWT.CHECK);
  		faceletsSupportButton.setText("Facelets support");
  		faceletsSupportButton.setLayoutData(span3);
  
  		label = new Label(container, SWT.NULL);
  		label.setText("JBoss Seam location:");
  
  		seamLocationText = new Text(container, SWT.BORDER | SWT.SINGLE);
  		GridData seamLocationGd = new GridData(GridData.FILL_HORIZONTAL);
  		seamLocationText.setLayoutData(seamLocationGd);
  		seamLocationText.addModifyListener(new ModifyListener() {
  
  			public void modifyText(ModifyEvent e) {
  				checkValidity();
  			}
  			
  		});
  
  		Button button = new Button(container, SWT.PUSH);
  		button.setText("Browse...");
  		button.addSelectionListener(new SelectionAdapter() {
  			public void widgetSelected(SelectionEvent e) {
  				handleBrowse();
  			}
  		});
  		
  		exampleProjectButton = new Button(container, SWT.CHECK);
  		exampleProjectButton.setText("Example project");
  		exampleProjectButton.setLayoutData(span3);
  		exampleProjectButton.addSelectionListener(new SelectionListener() {
  
  			public void widgetDefaultSelected(SelectionEvent e) {
  
  			}
  
  			public void widgetSelected(SelectionEvent e) {
  				if (exampleConfigurationGroup != null)
  				{
  					if (exampleProjectButton.getSelection())
  					{
  						setEnabledExampleConfigurationGoup(true);
  					}
  					else
  					{
  						setEnabledExampleConfigurationGoup(false);					}
  				}
  			}
  			
  		});
  		
  		exampleConfigurationGroup = new Group(container, SWT.SHADOW_ETCHED_IN);
  		GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL);
  		groupGridData.horizontalSpan = 3;
  		exampleConfigurationGroup.setLayoutData(groupGridData);
  		exampleConfigurationGroup.setText("Example configuration");
  		
  		GridLayout layout2 = new GridLayout();
  		layout2.numColumns = 2;
  		layout2.verticalSpacing = 9;
  		exampleConfigurationGroup.setLayout(layout2);
  
  		GridData groupItemGridData = new GridData(GridData.FILL_HORIZONTAL);
  		
  		label = new Label(exampleConfigurationGroup, SWT.NULL);
  		label.setText("Example main sources package:");
  		
  		exampleSrcPackageText = new Text(exampleConfigurationGroup, SWT.BORDER | SWT.SINGLE);
  		exampleSrcPackageText.setLayoutData(groupItemGridData);
  		
  		label = new Label(exampleConfigurationGroup, SWT.NULL);
  		label.setText("Example test sources package:");
  		
  		exampleTestPackageText = new Text(exampleConfigurationGroup, SWT.BORDER | SWT.SINGLE);
  		exampleTestPackageText.setLayoutData(groupItemGridData);
  		
  		initialize();
  		checkValidity();
  		setControl(container);
  	}
  
  	private void initialize() {
  		exampleProjectButton.setSelection(false);
  		setEnabledExampleConfigurationGoup(false);
  	}
  
  	private void handleBrowse() {
  		DirectoryDialog dialog = new DirectoryDialog(getShell());
  		dialog.setMessage("Select the directory where you installed JBoss Seam");
  		String seamPath = dialog.open();
  		seamLocationText.setText(seamPath);
  	}
  	
  	public boolean checkValidity()
  	{
  		// check projectNameText
  		if ("".equals(projectNameText.getText()))
  		{
  			updateStatus("The project name cannot be empty");
  			return false;
  		}
  		if ( ! Pattern.matches("[a-zA-Z0-9_-]+", projectNameText.getText()))
  		{
  			updateStatus("The project main only contains alphanumerical characters, - and _");
  			return false;
  		}
  
  		// Check seamLocationText
  		File seamJar = new File(seamLocationText.getText() + File.separatorChar + "jboss-seam.jar");
  		if (!seamJar.exists())
  		{
  			String errorMessage = "The Seam installed directory does not contain jboss-seam.jar";
  			updateStatus(errorMessage);
  			return false;
  		}
  		
  		updateStatus(null);
  		return true;
  	}
  	
  	private void updateStatus(String message) {
  		setErrorMessage(message);
  		setPageComplete(message == null);
  	}
  
  
  	public void setEnabledExampleConfigurationGoup(boolean enabled)
  	{
  		exampleConfigurationGroup.setEnabled(enabled);
  		Control[] controls = exampleConfigurationGroup.getChildren();
  		for (int i=0; i<controls.length; i++)
  		{
  			((Control)controls[i]).setEnabled(enabled);
  		}
  	}
  	
  	public String getProjectName()
  	{
  		return projectNameText.getText();
  	}
  
  	public boolean getExampleProject() {
  		return exampleProjectButton.getSelection();
  	}
  
  	public boolean getFaceletsSupport() {
  		return faceletsSupportButton.getSelection();
  	}
  
  	public boolean getTestSupport() {
  		return testSupportButton.getSelection();
  	}
  
  	public String getSeamLocation() {
  		return seamLocationText.getText();
  	}
  
  	public String getExampleSrcPackage() {
  		return exampleSrcPackageText.getText();
  	}
  
  	public String getExampleTestPackage() {
  		return exampleTestPackageText.getText();
  	}
  
  }
  
  
  
  



More information about the jboss-cvs-commits mailing list