eclipse plugin - update the new scenario wizard

This commit is contained in:
Timotei Dolean 2010-05-15 19:27:54 +00:00
parent f75cdf8d99
commit ae7fc60abb
6 changed files with 468 additions and 292 deletions

View file

@ -7,6 +7,8 @@ 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.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.Label;
@ -47,83 +49,88 @@ public class CampaignPage1 extends WizardPage {
updateIsPageComplete();
}
};
txtCampaignName_ = new Text(container, SWT.BORDER);
txtCampaignName_.setBounds(122, 7, 206, 21);
txtCampaignName_.addModifyListener(updatePageCompleteListener);
container.setLayout(new GridLayout(3, false));
Label _lblCampaignName = new Label(container, SWT.NONE);
_lblCampaignName.setBounds(10, 10, 96, 15);
_lblCampaignName.setText("Campaign name* :");
txtCampaignName_ = new Text(container, SWT.BORDER);
GridData gd_txtCampaignName_ = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_txtCampaignName_.heightHint = 15;
txtCampaignName_.setLayoutData(gd_txtCampaignName_);
txtCampaignName_.addModifyListener(updatePageCompleteListener);
new Label(container, SWT.NONE);
Label lblVersion = new Label(container, SWT.NONE);
lblVersion.setText("Version* :");
lblVersion.setBounds(10, 37, 96, 15);
txtVersion_ = new Text(container, SWT.BORDER);
txtVersion_.setBounds(122, 34, 206, 21);
txtVersion_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
txtVersion_.addModifyListener(updatePageCompleteListener);
Label lblTranslationsDir = new Label(container, SWT.NONE);
lblTranslationsDir.setText("Translations folder:");
lblTranslationsDir.setBounds(10, 64, 106, 15);
txtTranslationDir_ = new Text(container, SWT.BORDER);
txtTranslationDir_.setBounds(122, 61, 206, 21);
Label lblRelativeToThe = new Label(container, SWT.NONE);
lblRelativeToThe.setBounds(334, 64, 174, 15);
lblRelativeToThe.setText("Relative to the data folder");
txtAuthor_ = new Text(container, SWT.BORDER);
txtAuthor_.setBounds(122, 121, 206, 21);
Label lblAuthor = new Label(container, SWT.NONE);
lblAuthor.setText("Author:");
lblAuthor.setBounds(10, 124, 96, 15);
txtEmail_ = new Text(container, SWT.BORDER);
txtEmail_.setBounds(122, 148, 206, 21);
Label lblDescription = new Label(container, SWT.NONE);
lblDescription.setText("Email:");
lblDescription.setBounds(10, 151, 96, 15);
txtDescription_ = new Text(container, SWT.BORDER);
txtDescription_.setBounds(122, 175, 206, 21);
Label lblDescription_1 = new Label(container, SWT.NONE);
lblDescription_1.setText("Description:");
lblDescription_1.setBounds(10, 178, 96, 15);
txtPassphrase_ = new Text(container, SWT.BORDER);
txtPassphrase_.setBounds(122, 202, 206, 21);
Label lblIcon = new Label(container, SWT.NONE);
lblIcon.setText("Passphrase:");
lblIcon.setBounds(10, 205, 96, 15);
Label lblFormat = new Label(container, SWT.NONE);
lblFormat.setToolTipText("Displayed to the right of the title, it is just text. However,\r\nstarting with Wesnoth 1.6, the required format is x.y.z \r\nwhere x, y and z are numbers and a value for x greater than 0 \r\nimplies the campaign is complete and balanced. \r\nTrailing non-numeric elements are ok, but nothing should\r\nappear before the numbers. This is necessary for the Update \r\nadd-ons button to work correctly.");
lblFormat.setBounds(334, 37, 72, 15);
lblFormat.setText("Format: x.y.z");
Label lblTranslationsDir = new Label(container, SWT.NONE);
lblTranslationsDir.setText("Translations folder:");
txtTranslationDir_ = new Text(container, SWT.BORDER);
txtTranslationDir_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Label lblRelativeToThe = new Label(container, SWT.NONE);
lblRelativeToThe.setText("Relative to the data folder");
chkMultiCampaign_ = new Button(container, SWT.CHECK);
GridData gd_chkMultiCampaign_ = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
gd_chkMultiCampaign_.widthHint = 236;
chkMultiCampaign_.setLayoutData(gd_chkMultiCampaign_);
chkMultiCampaign_.setText("This is a multiplayer campaign");
new Label(container, SWT.NONE);
Label lblAuthor = new Label(container, SWT.NONE);
lblAuthor.setText("Author:");
txtAuthor_ = new Text(container, SWT.BORDER);
txtAuthor_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
new Label(container, SWT.NONE);
Label lblDescription = new Label(container, SWT.NONE);
lblDescription.setText("Email:");
txtEmail_ = new Text(container, SWT.BORDER);
txtEmail_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
new Label(container, SWT.NONE);
Label lblDescription_1 = new Label(container, SWT.NONE);
lblDescription_1.setText("Description:");
txtDescription_ = new Text(container, SWT.BORDER);
txtDescription_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
new Label(container, SWT.NONE);
Label lblIcon = new Label(container, SWT.NONE);
lblIcon.setText("Passphrase:");
txtPassphrase_ = new Text(container, SWT.BORDER);
txtPassphrase_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
new Label(container, SWT.NONE);
Label lblIcon_1 = new Label(container, SWT.NONE);
lblIcon_1.setText("Icon:");
lblIcon_1.setBounds(10, 232, 96, 15);
txtIcon_ = new Text(container, SWT.BORDER);
txtIcon_.setBounds(122, 229, 206, 21);
GridData gd_txtIcon_ = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_txtIcon_.widthHint = 163;
txtIcon_.setLayoutData(gd_txtIcon_);
Label lblRelativeToThe_1 = new Label(container, SWT.NONE);
GridData gd_lblRelativeToThe_1 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_lblRelativeToThe_1.widthHint = 285;
lblRelativeToThe_1.setLayoutData(gd_lblRelativeToThe_1);
lblRelativeToThe_1.setToolTipText("An image, displayed leftmost on the \"download campaigns\" screen.\r\nIt must be a standard Wesnoth graphic and not a custom one. \r\n(Well, a custom graphic will work if the user already has the campaign \r\ninstalled, or if it is a custom graphic from a different campaign that the \r\nuser has installed but others won't see it!) (Note that the icon used to \r\ndisplay your campaign for when it is played can be custom; for more\r\ninformation see CampaignWML.) If the icon is a unit with magenta color,\r\nplease use ImagePathFunctionWML to team-color it. ");
lblRelativeToThe_1.setBounds(334, 232, 230, 15);
lblRelativeToThe_1.setText("Relative to the data/core/images folder");
chkMultiCampaign_ = new Button(container, SWT.CHECK);
chkMultiCampaign_.setBounds(10, 86, 181, 16);
chkMultiCampaign_.setText("This is a multiplayer campaign");
updateIsPageComplete();
}
/* (non-Javadoc)

View file

@ -1,20 +1,39 @@
package wesnoth_eclipse_plugin.wizards;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.operation.*;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import java.io.*;
import org.eclipse.ui.*;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWizard;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import wesnoth_eclipse_plugin.ReplaceableParameter;
import wesnoth_eclipse_plugin.TemplateProvider;
/**
* This is a sample new wizard. Its role is to create a new file
* resource in the provided container. If the container resource
@ -27,9 +46,12 @@ import org.eclipse.ui.ide.IDE;
*/
public class ScenarioNewWizard extends Wizard implements INewWizard {
private ScenarioNewWizardPage page;
private ScenarioPage0 page0_;
private ScenarioPage1 page1_;
private ISelection selection;
protected int lastPageHashCode_;
/**
* Constructor for ScenarioNewWizard.
*/
@ -41,21 +63,35 @@ public class ScenarioNewWizard extends Wizard implements INewWizard {
/**
* Adding the page to the wizard.
*/
@Override
public void addPages() {
page = new ScenarioNewWizardPage(selection);
addPage(page);
}
page0_ = new ScenarioPage0(selection);
addPage(page0_);
page1_ = new ScenarioPage1();
//addPage(page1_);
lastPageHashCode_ = getPages()[getPageCount()-1].hashCode();
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#canFinish()
*/
@Override
public boolean canFinish() {
IWizardPage page = getContainer().getCurrentPage();
return super.canFinish() && page.hashCode() == lastPageHashCode_ && page.isPageComplete();
}
/**
* This method is called when 'Finish' button is pressed in
* the wizard. We will create an operation and run it
* using wizard as execution context.
*/
@Override
public boolean performFinish() {
final String containerName = page.getContainerName();
final String fileName = page.getFileName();
final String containerName = page0_.getProjectName();
final String fileName = page0_.getFileName();
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException {
try {
doFinish(containerName, fileName, monitor);
@ -67,7 +103,7 @@ public class ScenarioNewWizard extends Wizard implements INewWizard {
}
};
try {
getContainer().run(true, false, op);
getContainer().run(false, false, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
@ -83,12 +119,11 @@ public class ScenarioNewWizard extends Wizard implements INewWizard {
* file if missing or just replace its contents, and open
* the editor on the newly created file.
*/
private void doFinish(
String containerName,
String fileName,
IProgressMonitor monitor)
throws CoreException {
String containerName,
String fileName,
IProgressMonitor monitor)
throws CoreException {
// create a sample file
monitor.beginTask("Creating " + fileName, 2);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
@ -98,8 +133,14 @@ public class ScenarioNewWizard extends Wizard implements INewWizard {
}
IContainer container = (IContainer) resource;
final IFile file = container.getFile(new Path(fileName));
try {
InputStream stream = openContentStream();
InputStream stream = getScenarioStream();
if (stream == null) {
return;
}
if (file.exists()) {
file.setContents(stream, true, true, monitor);
} else {
@ -107,6 +148,7 @@ public class ScenarioNewWizard extends Wizard implements INewWizard {
}
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
monitor.worked(1);
monitor.setTaskName("Opening file for editing...");
@ -124,13 +166,28 @@ public class ScenarioNewWizard extends Wizard implements INewWizard {
}
/**
* We will initialize file contents with a sample text.
* Returns the scenario file contents as an InputStream
*/
private InputStream getScenarioStream() {
ArrayList<ReplaceableParameter> params = new ArrayList<ReplaceableParameter>();
private InputStream openContentStream() {
String contents =
"This is the initial file contents for *.cfg file that should be word-sorted in the Preview page of the multi-page editor";
return new ByteArrayInputStream(contents.getBytes());
params.add(new ReplaceableParameter("$$scenario_id", page0_.getScenarioId()));
params.add(new ReplaceableParameter("$$next_scenario_id", page0_.getNextScenarioId()));
params.add(new ReplaceableParameter("$$scenario_name", page0_.getScenarioName()));
params.add(new ReplaceableParameter("$$turns_number", String.valueOf(page0_.getTurnsNumber())));
String template = TemplateProvider.getProcessedTemplate("scenario", params);
if (template == null)
{
MessageBox box = new MessageBox(this.getShell());
box.setMessage(String.format("Template for \"scenario\" not found."));
box.open();
return null;
}
return new ByteArrayInputStream(template.getBytes());
}
private void throwCoreException(String message) throws CoreException {

View file

@ -1,210 +0,0 @@
package wesnoth_eclipse_plugin.wizards;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
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.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
/**
* The "New" wizard page allows setting the container for the new file as well
* as the file name. The page will only accept file name without the extension
* OR with the extension that matches the expected one (cfg).
*/
public class ScenarioNewWizardPage extends WizardPage {
private Text containerText;
private Text fileText;
private Text scenarioIdText;
private Text scenarioNameText;
private ISelection selection;
/**
* Constructor for SampleNewWizardPage.
*
* @param pageName
*/
public ScenarioNewWizardPage(ISelection selection) {
super("wizardPage");
setTitle("Scenario File");
setDescription("This wizard creates a new file with *.cfg extension that can be opened by a multi-page editor.");
this.selection = selection;
}
/**
* @see IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 3;
layout.verticalSpacing = 9;
Label label = new Label(container, SWT.NULL);
label.setText("&Container:");
containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
containerText.setLayoutData(gd);
containerText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
}
});
Button button = new Button(container, SWT.PUSH);
button.setText("Browse...");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
handleBrowse();
}
});
label = new Label(container, SWT.NULL);
label.setText("&File name:");
fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
gd = new GridData(GridData.FILL_HORIZONTAL);
fileText.setLayoutData(gd);
fileText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
}
});
label = new Label(container, SWT.NULL);
label.setText("&Scenario Id:");
scenarioIdText = new Text(container, SWT.BORDER | SWT.SINGLE);
gd = new GridData(GridData.FILL_HORIZONTAL);
scenarioIdText.setLayoutData(gd);
scenarioIdText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
}
});
label = new Label(container, SWT.NULL);
label.setText("&Scenario name:");
scenarioNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
gd = new GridData(GridData.FILL_HORIZONTAL);
scenarioNameText.setLayoutData(gd);
scenarioNameText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
}
});
initialize();
dialogChanged();
setControl(container);
}
/**
* Tests if the current workbench selection is a suitable container to use.
*/
private void initialize() {
if (selection != null && selection.isEmpty() == false
&& selection instanceof IStructuredSelection) {
IStructuredSelection ssel = (IStructuredSelection) selection;
if (ssel.size() > 1)
return;
Object obj = ssel.getFirstElement();
if (obj instanceof IResource) {
IContainer container;
if (obj instanceof IContainer)
container = (IContainer) obj;
else
container = ((IResource) obj).getParent();
containerText.setText(container.getFullPath().toString());
}
}
fileText.setText("new_scenario.cfg");
}
/**
* Uses the standard container selection dialog to choose the new value for
* the container field.
*/
private void handleBrowse() {
ContainerSelectionDialog dialog = new ContainerSelectionDialog(
getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
"Select new file container");
if (dialog.open() == ContainerSelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result.length == 1) {
containerText.setText(((Path) result[0]).toString());
}
}
}
/**
* Ensures that both text fields are set.
*/
private void dialogChanged() {
IResource container = ResourcesPlugin.getWorkspace().getRoot()
.findMember(new Path(getContainerName()));
String fileName = getFileName();
if (getContainerName().length() == 0) {
updateStatus("File container must be specified");
return;
}
if (container == null
|| (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
updateStatus("File container must exist");
return;
}
if (!container.isAccessible()) {
updateStatus("Project must be writable");
return;
}
if (fileName.length() == 0) {
updateStatus("File name must be specified");
return;
}
if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
updateStatus("File name must be valid");
return;
}
int dotLoc = fileName.lastIndexOf('.');
if (dotLoc != -1) {
String ext = fileName.substring(dotLoc + 1);
if (ext.equalsIgnoreCase("cfg") == false) {
updateStatus("File extension must be \"cfg\"");
return;
}
}
updateStatus(null);
}
private void updateStatus(String message) {
setErrorMessage(message);
setPageComplete(message == null);
}
public String getContainerName() {
return containerText.getText();
}
public String getFileName() {
return fileText.getText();
}
}

View file

@ -0,0 +1,285 @@
package wesnoth_eclipse_plugin.wizards;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
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.Label;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
/**
* The "New" wizard page allows setting the container for the new file as well
* as the file name. The page will only accept file name without the extension
* OR with the extension that matches the expected one (cfg).
*/
public class ScenarioPage0 extends WizardPage {
private Text txtProject_;
private Text txtFileName_;
private Text txtScenarioId_;
private Text txtScenarioName_;
private ISelection selection;
private GridData gd_txtProject_;
private Label lblproject;
private GridData gd_txtFileName_;
private GridData gd_txtScenarioId_;
private GridData gd_txtScenarioName_;
private Label lblFileName;
private Label lblScenarioId;
private Label lblScenarioName;
private Label lblNextScenarioId;
private Text txtNextScenarioId_;
private Label lblNumberOfTurns;
private Spinner txtTurns_;
private Label lblMapData;
private Text txtMapData_;
/**
* Constructor for SampleNewWizardPage.
*
* @param pageName
*/
public ScenarioPage0(ISelection selection) {
super("wizardPage");
setTitle("Scenario File");
setDescription("Create a new scenario file.");
this.selection = selection;
}
/**
* @see IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 3;
layout.verticalSpacing = 9;
ModifyListener modifyListener =new ModifyListener() {
public void modifyText(ModifyEvent e) {
updatePageIsComplete();
}
};
Label label;
lblproject = new Label(container, SWT.NULL);
lblproject.setText("Project* :");
txtProject_ = new Text(container, SWT.BORDER | SWT.SINGLE);
GridData gd;
gd_txtProject_ = new GridData(GridData.FILL_HORIZONTAL);
txtProject_.setLayoutData(gd_txtProject_);
txtProject_.addModifyListener(modifyListener);
Button btnBrowse_ = new Button(container, SWT.PUSH);
btnBrowse_.setText("Browse...");
btnBrowse_.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleBrowse();
}
});
lblFileName = new Label(container, SWT.NULL);
lblFileName.setText("File name* :");
txtFileName_ = new Text(container, SWT.BORDER | SWT.SINGLE);
gd_txtFileName_ = new GridData(GridData.FILL_HORIZONTAL);
txtFileName_.setLayoutData(gd_txtFileName_);
txtFileName_.addModifyListener(modifyListener);
new Label(container, SWT.NONE);
lblScenarioId = new Label(container, SWT.NULL);
lblScenarioId.setText("Scenario Id* :");
txtScenarioId_ = new Text(container, SWT.BORDER | SWT.SINGLE);
gd_txtScenarioId_ = new GridData(GridData.FILL_HORIZONTAL);
txtScenarioId_.setLayoutData(gd_txtScenarioId_);
txtScenarioId_.addModifyListener(modifyListener);
initialize();
setControl(container);
new Label(container, SWT.NONE);
lblScenarioName = new Label(container, SWT.NULL);
lblScenarioName.setText("Scenario name:");
txtScenarioName_ = new Text(container, SWT.BORDER | SWT.SINGLE);
gd_txtScenarioName_ = new GridData(GridData.FILL_HORIZONTAL);
txtScenarioName_.setLayoutData(gd_txtScenarioName_);
txtScenarioName_.addModifyListener(modifyListener);
new Label(container, SWT.NONE);
lblNextScenarioId = new Label(container, SWT.NONE);
lblNextScenarioId.setText("Next scenario Id :");
txtNextScenarioId_ = new Text(container, SWT.BORDER);
txtNextScenarioId_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(container, SWT.NONE);
lblNumberOfTurns = new Label(container, SWT.NONE);
lblNumberOfTurns.setText("Number of turns:");
txtTurns_ = new Spinner(container, SWT.BORDER);
GridData gd_txtTurns_ = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_txtTurns_.widthHint = 60;
txtTurns_.setLayoutData(gd_txtTurns_);
new Label(container, SWT.NONE);
lblMapData = new Label(container, SWT.NONE);
lblMapData.setText("Map data:");
txtMapData_ = new Text(container, SWT.BORDER);
txtMapData_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(container, SWT.NONE);
updatePageIsComplete();
}
/**
* Tests if the current workbench selection is a suitable campaign to use.
*/
private void initialize() {
if (selection != null && selection.isEmpty() == false
&& selection instanceof IStructuredSelection) {
IStructuredSelection ssel = (IStructuredSelection) selection;
if (ssel.size() > 1) {
return;
}
Object obj = ssel.getFirstElement();
if (obj instanceof IResource) {
IContainer container;
if (obj instanceof IContainer) {
container = (IContainer) obj;
} else {
container = ((IResource) obj).getParent();
}
txtProject_.setText(container.getFullPath().toString());
}
}
}
/**
* Uses the standard container selection dialog to choose the new value for
* the project field.
*/
private void handleBrowse() {
ContainerSelectionDialog dialog = new ContainerSelectionDialog(
getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
"Select a campaign project");
if (dialog.open() == ContainerSelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result.length == 1) {
txtProject_.setText(((Path) result[0]).toString());
}
}
}
/**
* Checks the mandatory fields and updates the isPageComplete status
*/
private void updatePageIsComplete() {
setPageComplete(false);
IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getProjectName()));
String fileName = getFileName();
String warningMessage = "";
if (getProjectName().length() == 0) {
setErrorMessage("An existing campaign must be specified");
return;
}
if (container == null ||
(container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
setErrorMessage("The campaign must be created first and the selected folder to exist.");
return;
}
if (!container.isAccessible()) {
setErrorMessage("The campaign project must be writable");
return;
}
if (!getProjectName().contains("scenarios"))
{
warningMessage += "The scenario *should* be created in the \"campaign_project/scenarios\" folder.";
}
if (fileName.length() == 0) {
setErrorMessage("File name must be specified.");
return;
}
if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
setErrorMessage("File name must be valid.");
return;
}
int dotLoc = fileName.lastIndexOf('.');
if (dotLoc != -1) {
String ext = fileName.substring(dotLoc + 1);
if (ext.equalsIgnoreCase("cfg") == false) {
setErrorMessage("File extension must be \"cfg\".");
return;
}
}
if (txtScenarioId_.getText().length() == 0)
{
setErrorMessage("The scenario ID cannot be empty.");
return;
}
setErrorMessage(null);
setMessage(warningMessage == "" ? null : warningMessage, WARNING);
setPageComplete(true);
}
/**
* @return the project this new scenario will belong to
*/
public String getProjectName() {
return txtProject_.getText();
}
/**
* @return the file name of the scenario
*/
public String getFileName() {
return txtFileName_.getText();
}
/**
* @return the scenario id
*/
public String getScenarioId() {
return txtScenarioId_.getText();
}
/**
* @return the scenario name
*/
public String getScenarioName() {
return txtScenarioName_.getText();
}
/**
* @return the next scenario's id
*/
public String getNextScenarioId() {
return txtNextScenarioId_.getText();
}
/**
* @return the number of scenario's turns
*/
public int getTurnsNumber() {
return txtTurns_.getSelection();
}
}

View file

@ -0,0 +1,31 @@
/**
* @author Timotei Dolean
*/
package wesnoth_eclipse_plugin.wizards;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
public class ScenarioPage1 extends WizardPage {
/**
* Create the wizard.
*/
public ScenarioPage1() {
super("wizardPage");
setTitle("Scenario file");
setDescription("Set scenario details");
}
/**
* Create contents of the wizard.
* @param parent
*/
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
}
}

View file

@ -1,2 +1,8 @@
[scenario]
id=$$scenario_id
next_scenario=$$next_scenario_id
name=$$scenario_name
map_data="$$map_data"
turns=$$turns_number
[/scenario]