Added default world files to examples.

This saves a step and prevents one of the biggest user errors with the
pacgoat example.

Change-Id: Icdceb1da37c4b456f1a34daa815f3bbe2a47e18e
This commit is contained in:
Alex Henning
2014-08-14 18:05:45 -04:00
parent da0cc0c83f
commit 08fdf45f6e
13 changed files with 109 additions and 24 deletions

View File

@@ -36,10 +36,10 @@ public abstract class ExampleWizard extends Wizard implements INewWizard {
*/
protected abstract void doFinish(IExampleProject ex, String teamNumber) throws CoreException;
protected abstract IWizardPage getDetailsPage();
protected abstract IWizardPage getDetailsPage(INewProjectInfo info);
public abstract IExampleProject makeExampleProject(String name, String description,
List<String> tags, List<String> folders, List<IExampleProject.ExportFile> files);
List<String> tags, String world, List<String> folders, List<IExampleProject.ExportFile> files);
public abstract URL getResourceURL();
@@ -60,7 +60,7 @@ public abstract class ExampleWizard extends Wizard implements INewWizard {
}
page1 = new ExampleWizardChoicePage(this, selection);
addPage(page1);
page2 = getDetailsPage();
page2 = getDetailsPage(page1);
addPage(page2);
}

View File

@@ -6,6 +6,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.swing.event.ChangeListener;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -36,11 +37,12 @@ import edu.wpi.first.wpilib.plugins.core.WPILibCore;
* OR with the extension that matches the expected one (mpe).
*/
public class ExampleWizardChoicePage extends WizardPage {
public class ExampleWizardChoicePage extends WizardPage implements INewProjectInfo {
private Tree exampleTree;
private Browser descriptionText;
private IExampleProject selectedExample;
private ExampleWizard parent;
private ChangeListener listener;
/**
* Constructor for SampleNewWizardPage.
@@ -89,6 +91,20 @@ public class ExampleWizardChoicePage extends WizardPage {
dialogChanged();
setControl(container);
}
public String getName() {
if (selectedExample != null) {
return selectedExample.getName();
}
return "";
}
public String getWorld() {
if (selectedExample != null) {
return selectedExample.getWorld();
}
return "";
}
/**
* Tests if the current workbench selection is a suitable container to use.
@@ -137,7 +153,6 @@ public class ExampleWizardChoicePage extends WizardPage {
/**
* Ensures that both text fields are set.
*/
private void dialogChanged() {
if (exampleTree.getSelection().length > 0) {
Object selectedData = exampleTree.getSelection()[0].getData();
@@ -157,6 +172,7 @@ public class ExampleWizardChoicePage extends WizardPage {
return;
}
listener.stateChanged(null);
updateStatus(null);
}
@@ -211,6 +227,11 @@ public class ExampleWizardChoicePage extends WizardPage {
tags.add(tagElementList.item(i).getTextContent());
}
}
String world = "";
if (element.getElementsByTagName("world") != null &&
element.getElementsByTagName("world").item(0) != null) {
world = element.getElementsByTagName("world").item(0).getTextContent();
}
List<String> packages = new ArrayList<String>();
tagsElement = element.getElementsByTagName("packages").item(0);
if (tagsElement.getNodeType() == Node.ELEMENT_NODE) {
@@ -231,10 +252,15 @@ public class ExampleWizardChoicePage extends WizardPage {
}
}
}
return parent.makeExampleProject(name, description, tags, packages, files);
return parent.makeExampleProject(name, description, tags, world, packages, files);
}
public IExampleProject getExampleProject() {
return selectedExample;
}
@Override
public void registerChangeListener(ChangeListener listener) {
this.listener = listener;
}
}

View File

@@ -14,4 +14,10 @@ public interface IExampleProject extends ProjectType {
this.destination = destination;
}
}
/**
* @return The world file to use for simulation, if empty
* the default is used.
*/
String getWorld();
}

View File

@@ -0,0 +1,24 @@
package edu.wpi.first.wpilib.plugins.core.wizards;
import javax.swing.event.ChangeListener;
public interface INewProjectInfo {
String getName();
String getWorld();
void registerChangeListener(ChangeListener changeListener);
public static INewProjectInfo Null = new INewProjectInfo() {
@Override
public String getWorld() {
return "";
}
@Override
public String getName() {
return "";
}
@Override
public void registerChangeListener(ChangeListener changeListener) {}
};
}

View File

@@ -39,6 +39,7 @@ public class NewProjectMainPage extends WizardPage {
private boolean showPackage;
private boolean showProjectTypes;
private TeamNumberPage teamNumberPage;
private INewProjectInfo info;
/**
* Constructor for SampleNewWizardPage.
@@ -46,17 +47,20 @@ public class NewProjectMainPage extends WizardPage {
*
* @param pageName
*/
public NewProjectMainPage(ISelection selection, TeamNumberPage teamNumberPage) {
public NewProjectMainPage(ISelection selection, TeamNumberPage teamNumberPage, INewProjectInfo info) {
super("wizardPage");
this.teamNumberPage = teamNumberPage;
showPackage = true;
showProjectTypes = false;
this.info = info;
}
/**
* @see IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
System.out.println(info.getName() +" -- "+ info.getWorld());
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
@@ -130,7 +134,7 @@ public class NewProjectMainPage extends WizardPage {
comp.setLayout(groupLayout);
worldText = new Text(comp, SWT.BORDER | SWT.SINGLE);
worldText.setLayoutData(gd);
worldText.setText("/usr/share/frcsim/worlds/GearsBotDemo.world");
worldText.setText("/usr/share/frcsim/worlds/GearsBotDemo.world");
worldText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
@@ -161,11 +165,18 @@ public class NewProjectMainPage extends WizardPage {
@Override public void stateChanged(ChangeEvent e) {
String teamNumber = TeamNumberPage.getTeamNumberFromPage(teamNumberPage);
packageText.setText("org.usfirst.frc.team"+teamNumber+".robot");
}
});
}
}
info.registerChangeListener(new ChangeListener() {
@Override public void stateChanged(ChangeEvent e) {
projectNameText.setText(info.getName());
if (!"".equals(info.getWorld())) {
worldText.setText(info.getWorld());
}
}
});
}
/**

View File

@@ -250,6 +250,7 @@
<tag>CommandBased Robot</tag>
<tag>Complete List</tag>
</tags>
<world>/usr/share/frcsim/worlds/GearsBotDemo.world</world>
<packages>
<package>src</package>
<package>src/Commands</package>
@@ -333,7 +334,8 @@
<tags>
<tag>CommandBased Robot</tag>
<tag>Complete List</tag>
</tags>
</tags>
<world>/usr/share/frcsim/worlds/PacGoat2014.world</world>
<packages>
<package>src</package>
<package>src/Commands</package>

View File

@@ -7,16 +7,17 @@ import edu.wpi.first.wpilib.plugins.core.wizards.IExampleProject;
import edu.wpi.first.wpilib.plugins.cpp.wizards.newproject.CPPProjectType;
public class ExampleCPPProject extends CPPProjectType implements IExampleProject {
private String name, description;
private String name, description, world;
private List<String> tags;
private List<String> directories;
private List<ExportFile> files;
public ExampleCPPProject(String name, String description, List<String> tags,
List<String> directories, List<ExportFile> files) {
String world, List<String> directories, List<ExportFile> files) {
this.name = name;
this.description = description;
this.tags = tags;
this.world = world;
this.directories = directories;
this.files = files;
}
@@ -32,6 +33,10 @@ public class ExampleCPPProject extends CPPProjectType implements IExampleProject
public List<String> getTags() {
return tags;
}
public String getWorld() {
return world;
}
@Override
public String[] getFolders(String packageName) {

View File

@@ -11,6 +11,7 @@ import edu.wpi.first.wpilib.plugins.core.WPILibCore;
import edu.wpi.first.wpilib.plugins.core.wizards.ExampleWizard;
import edu.wpi.first.wpilib.plugins.core.wizards.IExampleProject;
import edu.wpi.first.wpilib.plugins.core.wizards.IExampleProject.ExportFile;
import edu.wpi.first.wpilib.plugins.core.wizards.INewProjectInfo;
import edu.wpi.first.wpilib.plugins.core.wizards.NewProjectMainPage;
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectCreationUtils;
import edu.wpi.first.wpilib.plugins.cpp.WPILibCPPPlugin;
@@ -38,9 +39,9 @@ public class ExampleCPPWizard extends ExampleWizard {
}
@Override
protected IWizardPage getDetailsPage() {
protected IWizardPage getDetailsPage(INewProjectInfo info) {
if (detailsPage != null) return detailsPage;
detailsPage = new NewProjectMainPage(selection, getTeamNumberPage());
detailsPage = new NewProjectMainPage(selection, getTeamNumberPage(), info);
detailsPage.setTitle("Create Example Robot C++ Project");
detailsPage.setDescription("This wizard creates a new example project based on your selection.");
detailsPage.setShowPackage(false);
@@ -49,8 +50,8 @@ public class ExampleCPPWizard extends ExampleWizard {
@Override
public IExampleProject makeExampleProject(String name, String description,
List<String> tags, List<String> folders, List<ExportFile> files) {
return new ExampleCPPProject(name, description, tags, folders, files);
List<String> tags, String world, List<String> folders, List<ExportFile> files) {
return new ExampleCPPProject(name, description, tags, world, folders, files);
}
@Override

View File

@@ -15,6 +15,7 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
import edu.wpi.first.wpilib.plugins.core.WPILibCore;
import edu.wpi.first.wpilib.plugins.core.wizards.INewProjectInfo;
import edu.wpi.first.wpilib.plugins.core.wizards.NewProjectMainPage;
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectCreationUtils;
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectType;
@@ -56,7 +57,7 @@ public class NewCPPWizard extends Wizard implements INewWizard {
teamNumberPage = new TeamNumberPage(selection);
addPage(teamNumberPage);
}
page = new NewProjectMainPage(selection, teamNumberPage);
page = new NewProjectMainPage(selection, teamNumberPage, INewProjectInfo.Null);
page.setTitle("Create New Robot C++ Project");
page.setDescription("This wizard creates a new Robot C++ Project configured to use WPILib for programming FRC robots.");
page.setShowPackage(false);

View File

@@ -166,6 +166,7 @@
<tags>
<tag>CommandBased Robot</tag>
</tags>
<world>/usr/share/frcsim/worlds/GearsBotDemo.world</world>
<packages>
<package>src/$package-dir</package>
<package>src/$package-dir/commands</package>
@@ -198,6 +199,7 @@
<tags>
<tag>CommandBased Robot</tag>
</tags>
<world>/usr/share/frcsim/worlds/PacGoat2014.world</world>
<packages>
<package>src/$package-dir</package>
<package>src/$package-dir/commands</package>

View File

@@ -7,16 +7,17 @@ import edu.wpi.first.wpilib.plugins.core.wizards.IExampleProject;
import edu.wpi.first.wpilib.plugins.java.wizards.newproject.JavaProjectType;
public class ExampleJavaProject extends JavaProjectType implements IExampleProject {
private String name, description;
private String name, description, world;
private List<String> tags;
private List<String> packages;
private List<ExportFile> files;
public ExampleJavaProject(String name, String description, List<String> tags,
List<String> packages, List<ExportFile> files) {
String world, List<String> packages, List<ExportFile> files) {
this.name = name;
this.description = description;
this.tags = tags;
this.world = world;
this.packages = packages;
this.files = files;
}
@@ -32,6 +33,10 @@ public class ExampleJavaProject extends JavaProjectType implements IExampleProje
public List<String> getTags() {
return tags;
}
public String getWorld() {
return world;
}
@Override
public String[] getFolders(String packageName) {

View File

@@ -10,6 +10,7 @@ import org.eclipse.jface.wizard.IWizardPage;
import edu.wpi.first.wpilib.plugins.core.WPILibCore;
import edu.wpi.first.wpilib.plugins.core.wizards.ExampleWizard;
import edu.wpi.first.wpilib.plugins.core.wizards.IExampleProject;
import edu.wpi.first.wpilib.plugins.core.wizards.INewProjectInfo;
import edu.wpi.first.wpilib.plugins.core.wizards.IExampleProject.ExportFile;
import edu.wpi.first.wpilib.plugins.core.wizards.NewProjectMainPage;
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectCreationUtils;
@@ -40,9 +41,9 @@ public class ExampleJavaWizard extends ExampleWizard {
}
@Override
protected IWizardPage getDetailsPage() {
protected IWizardPage getDetailsPage(INewProjectInfo info) {
if (detailsPage != null) return detailsPage;
detailsPage = new NewProjectMainPage(selection, getTeamNumberPage());
detailsPage = new NewProjectMainPage(selection, getTeamNumberPage(), info);
detailsPage.setTitle("Create Example Robot Java Project");
detailsPage.setDescription("This wizard creates a new example project based on your selection.");
return detailsPage;
@@ -50,8 +51,8 @@ public class ExampleJavaWizard extends ExampleWizard {
@Override
public IExampleProject makeExampleProject(String name, String description,
List<String> tags, List<String> folders, List<ExportFile> files) {
return new ExampleJavaProject(name, description, tags, folders, files);
List<String> tags, String world, List<String> folders, List<ExportFile> files) {
return new ExampleJavaProject(name, description, tags, world, folders, files);
}
@Override

View File

@@ -15,6 +15,7 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
import edu.wpi.first.wpilib.plugins.core.WPILibCore;
import edu.wpi.first.wpilib.plugins.core.wizards.INewProjectInfo;
import edu.wpi.first.wpilib.plugins.core.wizards.NewProjectMainPage;
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectCreationUtils;
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectType;
@@ -56,7 +57,7 @@ public class NewJavaWizard extends Wizard implements INewWizard {
teamNumberPage = new TeamNumberPage(selection);
addPage(teamNumberPage);
}
page = new NewProjectMainPage(selection, teamNumberPage);
page = new NewProjectMainPage(selection, teamNumberPage, INewProjectInfo.Null);
page.setProjectTypes(JavaProjectType.TYPES);
page.setTitle("Create New Robot Java Project");
page.setDescription("This wizard creates a new Robot Java Project configured to use WPILib for programming FRC robots.");