Added the start of a wizard that will setup a new processing sketch like the PDE and establish a new project in eclipse for that sketch. All the SWT stuff is done, but no files are actually modified.

This commit is contained in:
lonnen
2010-07-23 01:24:50 +00:00
parent 9fa6ecb0b1
commit 1685eb24fc
5 changed files with 269 additions and 2 deletions
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.processing.editor
Bundle-SymbolicName: org.processing.editor;singleton:=true
Bundle-Version: 0.0.2
Bundle-Version: 0.0.3
Bundle-Activator: org.processing.editor.ProcessingEditorPlugin
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui,
@@ -11,5 +11,6 @@ bin.includes = plugin.xml,\
libs/core.jar,\
libs/ecj.jar,\
libs/jna.jar,\
libs/pde.jar
libs/pde.jar,\
src/
source.. = src/
+8
View File
@@ -74,4 +74,12 @@
natureId="org.processing.editor.processingSketchNature">
</image>
</extension>
<extension
point="org.eclipse.ui.newWizards">
<wizard
class="org.processing.wizards.NewSketchWizard"
id="org.processing.wizards.NewSketchWizard"
name="New Sketch Wizard">
</wizard>
</extension>
</plugin>
@@ -0,0 +1,49 @@
package org.processing.wizards;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
/**
* A wizard to create a new Processing sketch project.
* <p>
* Contains a single page the requests the name of the sketch
* and the sketch book folder to put the sketch in.
*
* @author lonnen
*/
public class NewSketchWizard extends Wizard implements INewWizard {
/** The single page in the wizard */
private NewSketchWizardPage page;
/** Constructor */
public NewSketchWizard(){
}
public void init(IWorkbench workbench, IStructuredSelection selection) {
// init code
}
/**
* Called when the 'Finish' button is pressed in the wizard.
*/
public boolean performFinish() {
// shit it down
return true;
}
/**
* Initializes the single page and adds it to the wizard.
*/
public void addPages(){
setWindowTitle("New Sketch Wizard");
page = new NewSketchWizardPage();
addPage(page);
}
}
@@ -0,0 +1,209 @@
package org.processing.wizards;
import java.io.File;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.preference.IPreferenceStore;
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.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.DirectoryDialog;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class NewSketchWizardPage extends WizardPage {
/** field containg the name of the sketch to be created */
private Text sketchNameField;
/** field containing path of the sketch book folder that will contain the sketch */
private Text sketchbookPathField; // TODO get the default from the plugin preferences
/** the actual path of the sketch book folder */
private IPath initialSketchbookPath;
public NewSketchWizardPage() {
super("selectFiles");
setTitle("New Sketch Wizard");
setDescription("Create a new Processing Sketch");
}
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
container.setLayout(gridLayout);
setControl(container);
final Label label = new Label(container, SWT.NONE);
final GridData gridData = new GridData();
gridData.horizontalSpan = 3;
label.setLayoutData(gridData);
label.setText("Select a name for the new sketch.");
final Label label_1 = new Label(container, SWT.NONE);
final GridData gridData_1 = new GridData(GridData.HORIZONTAL_ALIGN_END);
label_1.setLayoutData(gridData_1);
label_1.setText("Sketch Name:");
sketchNameField = new Text(container, SWT.BORDER);
sketchNameField.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e){
updatePageComplete();
}
});
sketchNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Label label_2 = new Label(container, SWT.NONE);
final GridData gridData_2 = new GridData();
gridData_2.horizontalSpan = 3;
label_2.setLayoutData(gridData_2);
final Label label_3 = new Label(container, SWT.NONE);
final GridData gridData_3 = new GridData();
gridData_3.horizontalSpan = 3;
label_3.setLayoutData(gridData_3);
label_3.setLayoutData(gridData_3);
label_3.setText("Select the sketchbook folder that will contain the sketch:");
final Label label_4 = new Label(container, SWT.NONE);
final GridData gridData_4 = new GridData();
gridData_4.horizontalIndent = 20;
label_4.setLayoutData(gridData_4);
label_4.setText("Sketchbook Folder:");
sketchbookPathField = new Text(container, SWT.BORDER);
sketchbookPathField.addModifyListener(
new ModifyListener() {
public void modifyText(ModifyEvent e){
updatePageComplete();
}
});
sketchbookPathField.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
final Button button_1 = new Button(container, SWT.NONE);
button_1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){browseForDestinationFolder();
}
});
button_1.setText("Browse...");
initContents();
}
/** initialize the contents of the sketch book path */
private void initContents() {
if (initialSketchbookPath == null){
setPageComplete(false);
return;
}
// see if the sketchbook path has been set in the prefs
// IPreferenceStore prefs = ProcessingEditorPlugin.getDefault().getPreferenceStore();
//
// IPath rootLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation();
}
/**
* Browse button functionality to find a destination folder
* <p>
* Prettifies the file path if it happens to be in the workspace
*/
protected void browseForDestinationFolder() {
IPath path = browse(getSketchbookLoc());
if (path == null)
return;
IPath rootLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation();
if (rootLoc.isPrefixOf(path))
path = path.setDevice(null).removeFirstSegments(rootLoc.segmentCount());
sketchbookPathField.setText(path.toString());
}
/**
* Sets up a dialog box allowing you to select a directory to use for the sketchbook
*
* @param path the path to be investigated
* @return the path chosen in the dialog box
*/
private IPath browse(IPath path){
DirectoryDialog dialog = new DirectoryDialog(getShell());
if (path != null){
if(path.segmentCount() > 1)
dialog.setFilterPath(path.toOSString());
}
String result = dialog.open();
if (result == null)
return null;
return new Path(result);
}
/**
* Verifies that the sketchbook path exists and does not already contain a sketch with that name.
*/
private void updatePageComplete() {
setPageComplete(false);
// check the sketchbook path first
IPath sketchbookLoc = getSketchbookLoc();
if (sketchbookLoc == null || !sketchbookLoc.toFile().exists()){
setMessage(null);
setErrorMessage("Please specify a sketchbook folder.");
return;
}
// ensure the sketch isn't already present in the sketchbook
String sketchName = getSketchName();
System.out.println(sketchName);
for( File child : sketchbookLoc.toFile().listFiles()){
if (child.isDirectory() && child.getName().equals(sketchName)){
System.out.println(child.getName() + " is a conflict!");
setMessage(null);
setErrorMessage("A sketch with that name already exists. Please choose another.");
return;
}
}
// if nothing was caught, enable the finish button
setPageComplete(true);
setMessage(null);
setErrorMessage(null);
}
/**
* Trims and returns the sketchNameField contents
*
* @return the contents of the sketchNameField as a string or null
*/
private String getSketchName() {
String text = sketchNameField.getText().trim();
if (text.length() == 0)
return null;
return text;
}
/**
* Tries to resolve the contents of the sketch book path field to an IPath, and returns it.
* If the field contains a relative path it will be resolved relative to the Eclipse workspace folder.
*
* @return an absolute IPath handle to the contents of the sketchbookPathField or null
*/
private IPath getSketchbookLoc() {
String text = sketchbookPathField.getText().trim();
if (text.length() == 0)
return null;
IPath path = new Path(text);
if (!path.isAbsolute()) // relative paths are relative to the Eclipse workspace
path = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(path);
return path;
}
}