mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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) {}
|
||||
};
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user