/* * Created on May 26, 2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package CDBuilder; import java.io.FileWriter; import java.util.Calendar; import java.util.Date; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; /** * * @author Lucie Zhao and Sherwin Sim * * @version 1 May - August 2003 * Creates the GUI for inputing author's name * This class also generates a notes file for the project * which includes the date, name and version 1 as default text */ public class CDProjectCreationPage extends WizardPage { /** a constant to name the file with */ private static int nameCounter = 1; /** the workbench */ private IWorkbench workbench; /** the path of the project to store the file*/ public IPath newPath; /** the text field for filling in the author's name */ private Text toText; /** the author's name */ private String name; /** the selection */ private IStructuredSelection selection; /** a new file writer to make the notes file */ private FileWriter write = null; /** the composite to create the interface */ public Composite composite = null; /** * Initializes the workbench and selection * Also sets the title and description of the page * @param workbench the default workbench * @param selection the selected window */ public CDProjectCreationPage (IWorkbench workbench, IStructuredSelection selection){ super("CD++Builder"); setTitle("CD++ Notes"); setDescription("Notes"); this.workbench = workbench; this.selection = selection; } /** * Creates the interface for entering the author's name * @param parent the composite to set the gui on */ public void createControl(Composite parent) { try { GridData gd; composite = new Composite(parent, SWT.NONE); // create the desired layout for this wizard page GridLayout gl = new GridLayout(); int ncol = 1; gl.numColumns = ncol; composite.setLayout(gl); // create the widgets. If the appearance of the widget is different from the default, // create a GridData for it to set the alignment and define how much space it will occupy new Label (composite, SWT.NONE).setText("Author's Name:"); toText = new Text(composite, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = ncol ; toText.setLayoutData(gd); // set the composite as the control for this page setControl(composite); setPageComplete(true); } catch (Exception e) { System.out.println(e); } } /** * Creates a new file resource as requested by the user. If everything * is OK then answer true. If not, false will cause the dialog * to stay open. Initializes the files with name, version 1 and date * * @return whether creation was successful * @see CDWizard#performFinish() */ public boolean finish() { try { write = new FileWriter (newPath + "/notes" + nameCounter +".txt"); } catch (Exception e){ System.out.println(e); } name = toText.getText(); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); int month = cal.get(Calendar.MONTH); int year = cal.get(Calendar.YEAR); try { write.write("Date: " + dayOfMonth +"/" + month + "/"+year +"\n"); write.write("Name: " + name +" \n"); write.write("Version 1 \n"); write.close(); } catch (Exception e){ System.out.println(e); } nameCounter++; return true; } }