Defining file wizard content
From Aptana Development
This page describes how to define the content for a New File wizard.
Contents |
Instructions
This example uses a hypothetical SQL editor to demonstrate the procedure.
Project File Content
To define the file content for a New File wizard:
- Set the title of the window displayed when you name the target file by adding the following line to your constructor, where "SQL" will be replaced with your editor's type:
setWindowTitle("New SQL File"); - Create the page in the dialog displayed when we name the target file. Use the createNewFilePage method. Replace all instances of "sql" as is appropriate for your language.
protected SimpleNewWizardPage createNewFilePage(ISelection selection) { SimpleNewWizardPage page = new SimpleNewWizardPage(selection); page.setRequiredFileExtensions(new String[] { "sql" }); page.setTitle("SQL File"); page.setDescription("Create a SQL File"); page.setDefaultFileName("new_file.sql"); return page; } - Finally, we need to define the actual content for the newly create file. This is done in the getInitialFileContents method. This sample simply uses a StringWriter to build the text, but other options are available including grabbing the value from a preference.
protected String getInitialFileContents() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("INSERT INTO table() VALUES();"); pw.close(); return sw.toString(); }
Untitled File Content
The definition of a new untitled file instance is similar to a project file. However, we do need to provide a bit more information via getters.
- Define the "friendly name" which is used to name the file.
protected String getFriendlyName() { return "SQL"; } - Define the file's extension. This definition of file extension includes the leading period.
protected String getFileExtension() { return ".sql"; } - Define the file content like you did with the project file.
protected String getInitialFileContents() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("INSERT INTO table() VALUES();"); pw.close(); return sw.toString(); }


