eclipse plugin: schema-based wizards - step 4...
...actual implementation for multiple tags
This commit is contained in:
parent
174d5e4dfc
commit
5928cee62f
12 changed files with 521 additions and 52 deletions
|
@ -34,6 +34,8 @@ public abstract class NewWizardTemplate extends Wizard implements INewWizard
|
|||
@Override
|
||||
public void addPages()
|
||||
{
|
||||
if (getPageCount() == 0)
|
||||
return;
|
||||
lastPageHashCode_ = getPages()[getPageCount() - 1].hashCode();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* @author Timotei Dolean
|
||||
*
|
||||
*/
|
||||
package wesnoth_eclipse_plugin.wizards;
|
||||
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import wesnoth_eclipse_plugin.Activator;
|
||||
|
||||
public class WizardUtils
|
||||
{
|
||||
public static void launchWizard(NewWizardTemplate wizard, Shell shell, IStructuredSelection selection)
|
||||
{
|
||||
wizard.init(Activator.getDefault().getWorkbench(), selection);
|
||||
wizard.setForcePreviousAndNextButtons(true);
|
||||
|
||||
WizardDialog wizardDialog = new WizardDialog(shell, wizard);
|
||||
wizardDialog.create();
|
||||
wizardDialog.getShell().setLocation(shell.getBounds().x, shell.getBounds().y);
|
||||
Activator.getDefault().getWorkbench().getHelpSystem().setHelp(wizardDialog.getShell(),
|
||||
"org.eclipse.ui.new_wizard_context");
|
||||
|
||||
wizardDialog.open();
|
||||
}
|
||||
}
|
|
@ -75,7 +75,7 @@ public class SchemaParser
|
|||
}
|
||||
else
|
||||
{
|
||||
Tag tag = new Tag(simpleTagName, extendedTagName);
|
||||
Tag tag = new Tag(simpleTagName, extendedTagName, '_');
|
||||
currentTag = tag;
|
||||
currentTag.NeedsExpanding = false;
|
||||
tags_.put(simpleTagName, tag);
|
||||
|
@ -149,7 +149,7 @@ public class SchemaParser
|
|||
else
|
||||
// tag wasn't created yet
|
||||
{
|
||||
targetTag = new Tag(value[1]);
|
||||
targetTag = new Tag(value[1], getCardinality(value[0]));
|
||||
System.err.println("creating missing tag: " + value[1]);
|
||||
tags_.put(value[1], targetTag);
|
||||
}
|
||||
|
|
|
@ -13,26 +13,30 @@ class Tag
|
|||
public String ExtendedTagName = "";
|
||||
public List<Tag> TagChildren;
|
||||
public List<TagKey> KeyChildren;
|
||||
public char Cardinality;
|
||||
|
||||
public boolean NeedsExpanding = false;
|
||||
|
||||
public Tag(String name, List<Tag> tagChildren, List<TagKey> keyChildren) {
|
||||
public Tag(String name, List<Tag> tagChildren, List<TagKey> keyChildren, char cardinality) {
|
||||
Name = name;
|
||||
TagChildren = tagChildren;
|
||||
KeyChildren = keyChildren;
|
||||
Cardinality = cardinality;
|
||||
}
|
||||
|
||||
public Tag(String name) {
|
||||
public Tag(String name, char cardinality) {
|
||||
Name = name;
|
||||
TagChildren = new ArrayList<Tag>();
|
||||
KeyChildren = new ArrayList<TagKey>();
|
||||
Cardinality = cardinality;
|
||||
}
|
||||
|
||||
public Tag(String name, String extendedTagName) {
|
||||
public Tag(String name, String extendedTagName, char cardinality) {
|
||||
Name = name;
|
||||
ExtendedTagName = extendedTagName;
|
||||
TagChildren = new ArrayList<Tag>();
|
||||
KeyChildren = new ArrayList<TagKey>();
|
||||
Cardinality = cardinality;
|
||||
}
|
||||
|
||||
public void addTag(Tag tag)
|
||||
|
|
|
@ -7,6 +7,13 @@ package wesnoth_eclipse_plugin.wizards.generator;
|
|||
public class TagKey
|
||||
{
|
||||
public String Name;
|
||||
/**
|
||||
* Cardinality can be:
|
||||
* 1 = required
|
||||
* ? = optional
|
||||
* * = repeated
|
||||
* - = forbidden
|
||||
*/
|
||||
public char Cardinality;
|
||||
public String Regex;
|
||||
|
||||
|
|
|
@ -12,11 +12,13 @@ import wesnoth_eclipse_plugin.wizards.WizardsConstants;
|
|||
public class WizardGenerator extends NewWizardTemplate
|
||||
{
|
||||
List<WizardGeneratorPageKey> pagesList_;
|
||||
private String tagName_;
|
||||
|
||||
public WizardGenerator(String title, String tagName) {
|
||||
SchemaParser.getInstance().parseSchema(false);
|
||||
setWindowTitle(title);
|
||||
Tag tagContent = SchemaParser.getInstance().getTags().get(tagName);
|
||||
tagName_ = tagName;
|
||||
|
||||
// keys section
|
||||
int keysNr = tagContent.KeyChildren.size();
|
||||
|
@ -51,6 +53,11 @@ public class WizardGenerator extends NewWizardTemplate
|
|||
tempPageTag = new WizardGeneratorPageTag(tagName, tagContent.TagChildren, startTag, tagsNr - 1);
|
||||
addPage(tempPageTag);
|
||||
}
|
||||
|
||||
if (getPageCount() == 0)
|
||||
{
|
||||
addPage(new WizardGeneratorPage404(tagName));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,7 +71,10 @@ public class WizardGenerator extends NewWizardTemplate
|
|||
{
|
||||
// logic
|
||||
|
||||
data_ = null;
|
||||
data_ = "temp";
|
||||
|
||||
// for now let's just return tag's name
|
||||
objectName_ = tagName_;
|
||||
isFinished_ = true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* @author Timotei Dolean
|
||||
*
|
||||
*/
|
||||
package wesnoth_eclipse_plugin.wizards.generator;
|
||||
|
||||
import com.swtdesigner.SWTResourceManager;
|
||||
|
||||
import org.eclipse.jface.wizard.WizardPage;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
public class WizardGeneratorPage404 extends WizardPage
|
||||
{
|
||||
public WizardGeneratorPage404(String tag) {
|
||||
super("wizardGeneratorPage404");
|
||||
setErrorMessage("content not found for tag '" + tag + "'");
|
||||
setTitle("404 Not Found");
|
||||
setDescription("Ooops!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControl(Composite parent)
|
||||
{
|
||||
Composite container = new Composite(parent, SWT.NULL);
|
||||
|
||||
setControl(container);
|
||||
|
||||
Label lblThisIsSooo = new Label(container, SWT.WRAP);
|
||||
lblThisIsSooo.setFont(SWTResourceManager.getFont("Segoe UI", 13, SWT.NORMAL));
|
||||
lblThisIsSooo.setBounds(82, 65, 415, 132);
|
||||
lblThisIsSooo.setText("This is embarassing. It shouldn't happen. \r\nIt seems something is missing from the schema.cfg");
|
||||
}
|
||||
}
|
|
@ -42,7 +42,8 @@ public class WizardGeneratorPageKey extends WizardPage
|
|||
TagKey key = keys_.get(i);
|
||||
Label label = new Label(container_, SWT.NONE);
|
||||
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
||||
label.setText(key.Name);
|
||||
// add star to required items
|
||||
label.setText(key.Name + (key.Cardinality == '1' ? "*" : "") + ":");
|
||||
|
||||
Text textBox = new Text(container_, SWT.BORDER);
|
||||
textBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||
|
@ -50,6 +51,8 @@ public class WizardGeneratorPageKey extends WizardPage
|
|||
textBox.setData("name", key.Name);
|
||||
textBox.setData("regex", key.Regex);
|
||||
textBox.setData("card", key.Cardinality);
|
||||
|
||||
//TODO: check for regex/cardinality
|
||||
}
|
||||
setPageComplete(true);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,13 @@
|
|||
*/
|
||||
package wesnoth_eclipse_plugin.wizards.generator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.jface.wizard.WizardPage;
|
||||
import org.eclipse.swt.SWT;
|
||||
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;
|
||||
|
@ -13,11 +18,15 @@ import org.eclipse.swt.widgets.Composite;
|
|||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.List;
|
||||
|
||||
import wesnoth_eclipse_plugin.utils.GUIUtils;
|
||||
import wesnoth_eclipse_plugin.wizards.WizardUtils;
|
||||
|
||||
public class WizardGeneratorPageTag extends WizardPage
|
||||
{
|
||||
private java.util.List<Tag> tags_;
|
||||
private int startIndex_, endIndex_;
|
||||
private Composite container_;
|
||||
private java.util.List<Tag> tags_;
|
||||
private HashMap<String, java.util.List<String>> content_;
|
||||
private int startIndex_, endIndex_;
|
||||
private Composite container_;
|
||||
|
||||
public WizardGeneratorPageTag(String tagName, java.util.List<Tag> tags, int startIndex, int endIndex) {
|
||||
super("wizardPageTag" + startIndex);
|
||||
|
@ -27,6 +36,7 @@ public class WizardGeneratorPageTag extends WizardPage
|
|||
startIndex_ = startIndex;
|
||||
endIndex_ = endIndex;
|
||||
tags_ = tags;
|
||||
content_ = new HashMap<String, java.util.List<String>>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,7 +48,9 @@ public class WizardGeneratorPageTag extends WizardPage
|
|||
|
||||
for (int i = startIndex_; i <= endIndex_; i++)
|
||||
{
|
||||
Tag tag = tags_.get(i);
|
||||
final Tag tag = tags_.get(i);
|
||||
java.util.List<String> tmp = new ArrayList<String>();
|
||||
|
||||
Group tagGroup = new Group(container_, SWT.NONE);
|
||||
tagGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
||||
tagGroup.setText("[" + tag.Name + "]");
|
||||
|
@ -55,11 +67,59 @@ public class WizardGeneratorPageTag extends WizardPage
|
|||
gd_btnAdd.heightHint = 40;
|
||||
btnAdd.setLayoutData(gd_btnAdd);
|
||||
btnAdd.setText("Add");
|
||||
btnAdd.setData("list", list);
|
||||
btnAdd.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e)
|
||||
{
|
||||
if (!(e.getSource() instanceof Button))
|
||||
return;
|
||||
addNewItem((List) ((Button) e.getSource()).getData("list"), tag.Name);
|
||||
}
|
||||
});
|
||||
|
||||
Button btnRemove = new Button(tagGroup, SWT.NONE);
|
||||
btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
|
||||
btnRemove.setText("Remove");
|
||||
btnRemove.setData("list", list);
|
||||
btnRemove.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e)
|
||||
{
|
||||
if (!(e.getSource() instanceof Button))
|
||||
return;
|
||||
removeItem((List) ((Button) e.getSource()).getData("list"), tag.Name);
|
||||
}
|
||||
});
|
||||
|
||||
content_.put(tag.Name, tmp);
|
||||
}
|
||||
setPageComplete(true);
|
||||
|
||||
//TODO: add checks for list's count
|
||||
}
|
||||
|
||||
private void addNewItem(List targetList, String tagName)
|
||||
{
|
||||
//TODO: check for multiple addings
|
||||
WizardGenerator wizard = new WizardGenerator("Create a new " + tagName, tagName);
|
||||
WizardUtils.launchWizard(wizard, getShell(), null);
|
||||
if (wizard.isFinished())
|
||||
{
|
||||
targetList.add(wizard.getObjectName() + targetList.getItemCount());
|
||||
content_.get(tagName).add(wizard.getData().toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void removeItem(List targetList, String tagName)
|
||||
{
|
||||
if (targetList.getSelectionCount() == 0 || targetList.getItemCount() == 0)
|
||||
{
|
||||
GUIUtils.showMessageBox("Please select an item before removing it.");
|
||||
return;
|
||||
}
|
||||
|
||||
content_.get(tagName).remove(targetList.getSelectionIndex());
|
||||
targetList.remove(targetList.getSelectionIndex());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,41 +4,37 @@
|
|||
*/
|
||||
package wesnoth_eclipse_plugin.wizards.generator;
|
||||
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
|
||||
import wesnoth_eclipse_plugin.Activator;
|
||||
import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
|
||||
import wesnoth_eclipse_plugin.wizards.WizardUtils;
|
||||
|
||||
public class WizardLauncher extends NewWizardTemplate
|
||||
{
|
||||
WizardLauncherPage0 page0_;
|
||||
WizardLauncherPage1 page1_;
|
||||
|
||||
public WizardLauncher() {
|
||||
setWindowTitle("Wizard launcher");
|
||||
page0_ = new WizardLauncherPage0();
|
||||
addPage(page0_);
|
||||
setNeedsProgressMonitor(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages()
|
||||
{
|
||||
page0_ = new WizardLauncherPage0(selection_);
|
||||
addPage(page0_);
|
||||
|
||||
page1_ = new WizardLauncherPage1();
|
||||
addPage(page1_);
|
||||
|
||||
super.addPages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performFinish()
|
||||
{
|
||||
WizardGenerator wizard = new WizardGenerator(page0_.getTagDescription() + " new wizard", page0_.getTagName());
|
||||
wizard.init(Activator.getDefault().getWorkbench(), selection_);
|
||||
wizard.setForcePreviousAndNextButtons(true);
|
||||
WizardGenerator wizard = new WizardGenerator(page1_.getTagDescription() + " new wizard", page1_.getTagName());
|
||||
WizardUtils.launchWizard(wizard, getShell(), selection_);
|
||||
|
||||
WizardDialog wizardDialog = new WizardDialog(getShell(), wizard);
|
||||
wizardDialog.create();
|
||||
wizardDialog.getShell().setLocation(getShell().getBounds().x, getShell().getBounds().y);
|
||||
Activator.getDefault().getWorkbench().getHelpSystem().setHelp(wizardDialog.getShell(),
|
||||
"org.eclipse.ui.new_wizard_context");
|
||||
|
||||
wizardDialog.open();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,30 +4,47 @@
|
|||
*/
|
||||
package wesnoth_eclipse_plugin.wizards.generator;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
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.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.Combo;
|
||||
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.IEditorInput;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
|
||||
|
||||
import wesnoth_eclipse_plugin.Activator;
|
||||
|
||||
public class WizardLauncherPage0 extends WizardPage
|
||||
{
|
||||
private HashMap<String, String> list_;
|
||||
private Combo cmbWizardName_;
|
||||
private IStructuredSelection selection_;
|
||||
|
||||
public WizardLauncherPage0() {
|
||||
super("wizardPage");
|
||||
setTitle("Wizard Launcher");
|
||||
setDescription("Launch a wizard");
|
||||
list_ = new HashMap<String, String>();
|
||||
list_.put("Campaign", "campaign");
|
||||
list_.put("Game config", "game_config");
|
||||
list_.put("AIs", "ais");
|
||||
//TODO: read the list-tag from file!
|
||||
private Text txtDirectory_;
|
||||
private Text txtFileName_;
|
||||
private Button radioNewFile;
|
||||
private Label lblCurrentFileOpened;
|
||||
private Label lblDirectory;
|
||||
private Button btnBrowse;
|
||||
private Label lblFileName;
|
||||
|
||||
public WizardLauncherPage0(IStructuredSelection selection) {
|
||||
super("wizardLauncherPage0");
|
||||
setTitle("Wizard launcher");
|
||||
setDescription("Select destination");
|
||||
selection_ = selection;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,25 +53,248 @@ public class WizardLauncherPage0 extends WizardPage
|
|||
Composite container = new Composite(parent, SWT.NULL);
|
||||
|
||||
setControl(container);
|
||||
container.setLayout(new GridLayout(2, false));
|
||||
container.setLayout(new GridLayout(4, false));
|
||||
|
||||
Label lblSelectAWizard = new Label(container, SWT.NONE);
|
||||
lblSelectAWizard.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
||||
lblSelectAWizard.setText("Select a Wizard: ");
|
||||
radioNewFile = new Button(container, SWT.RADIO);
|
||||
radioNewFile.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e)
|
||||
{
|
||||
updateEnabledStatus();
|
||||
}
|
||||
});
|
||||
radioNewFile.setSelection(true);
|
||||
radioNewFile.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
|
||||
radioNewFile.setText("New file");
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
cmbWizardName_ = new Combo(container, SWT.NONE);
|
||||
cmbWizardName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||
String[] items = new String[0];
|
||||
cmbWizardName_.setItems(list_.keySet().toArray(items));
|
||||
lblDirectory = new Label(container, SWT.NONE);
|
||||
lblDirectory.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
||||
lblDirectory.setText("Directory* :");
|
||||
|
||||
txtDirectory_ = new Text(container, SWT.BORDER);
|
||||
txtDirectory_.addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e)
|
||||
{
|
||||
updatePageIsComplete();
|
||||
}
|
||||
});
|
||||
txtDirectory_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||
|
||||
btnBrowse = new Button(container, SWT.NONE);
|
||||
btnBrowse.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e)
|
||||
{
|
||||
handleBrowse();
|
||||
}
|
||||
});
|
||||
btnBrowse.setText("Browse...");
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
lblFileName = new Label(container, SWT.NONE);
|
||||
lblFileName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
||||
lblFileName.setText("File name* :");
|
||||
|
||||
txtFileName_ = new Text(container, SWT.BORDER);
|
||||
txtFileName_.addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e)
|
||||
{
|
||||
updatePageIsComplete();
|
||||
}
|
||||
});
|
||||
txtFileName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
Button radioCurrentFile = new Button(container, SWT.RADIO);
|
||||
radioCurrentFile.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e)
|
||||
{
|
||||
updateEnabledStatus();
|
||||
}
|
||||
});
|
||||
radioCurrentFile.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
|
||||
radioCurrentFile.setText("In current edited file");
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
lblCurrentFileOpened = new Label(container, SWT.NONE);
|
||||
lblCurrentFileOpened.setEnabled(false);
|
||||
lblCurrentFileOpened.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
|
||||
lblCurrentFileOpened.setText("Current file opened: ");
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
Label label = new Label(container, SWT.NONE);
|
||||
label.setText(" ");
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
initialize();
|
||||
updatePageIsComplete();
|
||||
}
|
||||
|
||||
public String getTagName()
|
||||
private void updatePageIsComplete()
|
||||
{
|
||||
return list_.get(cmbWizardName_.getText());
|
||||
setPageComplete(false);
|
||||
if (radioNewFile.getSelection())
|
||||
{
|
||||
IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getDirectoryName()));
|
||||
String fileName = getFileName();
|
||||
|
||||
if (getDirectoryName().isEmpty())
|
||||
{
|
||||
setErrorMessage("You need to specify a valid directory path first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (container == null || !container.exists() || !(container instanceof IContainer))
|
||||
{
|
||||
setErrorMessage("The directory must be created first and the selected folder to exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileName.isEmpty())
|
||||
{
|
||||
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 || fileName.substring(dotLoc + 1).equalsIgnoreCase("cfg") == false)
|
||||
{
|
||||
setErrorMessage("File extension must be 'cfg'.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// current file checking
|
||||
if (selection_ != null && selection_.isEmpty() == false &&
|
||||
selection_ instanceof IStructuredSelection && selection_.size() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
IEditorReference[] references =
|
||||
Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getPages()[0].getEditorReferences();
|
||||
if (references.length > 0)
|
||||
{
|
||||
IEditorInput input = references[0].getEditorInput();
|
||||
lblCurrentFileOpened.setText("File " + input.getName() + " opened.");
|
||||
}
|
||||
else
|
||||
{
|
||||
lblCurrentFileOpened.setText("No file opened.");
|
||||
setErrorMessage("No file opened.");
|
||||
return;
|
||||
}
|
||||
} catch (PartInitException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
setPageComplete(true);
|
||||
setErrorMessage(null);
|
||||
}
|
||||
|
||||
public String getTagDescription()
|
||||
public void updateEnabledStatus()
|
||||
{
|
||||
return cmbWizardName_.getText();
|
||||
// new file section
|
||||
btnBrowse.setEnabled(radioNewFile.getSelection());
|
||||
lblDirectory.setEnabled(radioNewFile.getSelection());
|
||||
lblFileName.setEnabled(radioNewFile.getSelection());
|
||||
txtDirectory_.setEnabled(radioNewFile.getSelection());
|
||||
txtFileName_.setEnabled(radioNewFile.getSelection());
|
||||
|
||||
// opened file
|
||||
lblCurrentFileOpened.setEnabled(!radioNewFile.getSelection());
|
||||
|
||||
updatePageIsComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the current workbench selection is a suitable directory to use.
|
||||
*/
|
||||
private void initialize()
|
||||
{
|
||||
if (selection_ != null && selection_.isEmpty() == false &&
|
||||
selection_ instanceof IStructuredSelection && selection_.size() > 0)
|
||||
{
|
||||
Object obj = selection_.getFirstElement();
|
||||
if (obj instanceof IResource)
|
||||
{
|
||||
IContainer container;
|
||||
if (obj instanceof IContainer)
|
||||
{
|
||||
container = (IContainer) obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
container = ((IResource) obj).getParent();
|
||||
}
|
||||
txtDirectory_.setText(container.getFullPath().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the standard container selection dialog to choose the new value for
|
||||
* the the directory 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)
|
||||
{
|
||||
txtDirectory_.setText(((Path) result[0]).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileName()
|
||||
{
|
||||
return radioNewFile.getSelection() == true ? txtFileName_.getText() : "";
|
||||
}
|
||||
|
||||
public String getDirectoryName()
|
||||
{
|
||||
return radioNewFile.getSelection() == true ? txtDirectory_.getText() : "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* @author Timotei Dolean
|
||||
*
|
||||
*/
|
||||
package wesnoth_eclipse_plugin.wizards.generator;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.jface.wizard.WizardPage;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
public class WizardLauncherPage1 extends WizardPage
|
||||
{
|
||||
private HashMap<String, String> list_;
|
||||
private Combo cmbWizardName_;
|
||||
|
||||
public WizardLauncherPage1() {
|
||||
super("wizardLauncherPage1");
|
||||
setTitle("Wizard Launcher");
|
||||
setDescription("Select wizard to launch");
|
||||
list_ = new HashMap<String, String>();
|
||||
list_.put("Campaign", "campaign");
|
||||
list_.put("Game config", "game_config");
|
||||
list_.put("AIs", "ais");
|
||||
//TODO: read the list-tag from file!
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControl(Composite parent)
|
||||
{
|
||||
Composite container = new Composite(parent, SWT.NULL);
|
||||
|
||||
setControl(container);
|
||||
container.setLayout(new GridLayout(3, false));
|
||||
String[] items = new String[0];
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
Label label = new Label(container, SWT.NONE);
|
||||
GridData gd_label = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
|
||||
gd_label.widthHint = 141;
|
||||
label.setLayoutData(gd_label);
|
||||
label.setText(" ");
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
Label label_1 = new Label(container, SWT.NONE);
|
||||
GridData gd_label_1 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
|
||||
gd_label_1.widthHint = 146;
|
||||
label_1.setLayoutData(gd_label_1);
|
||||
label_1.setText(" ");
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
Label lblSelectAWizard = new Label(container, SWT.NONE);
|
||||
lblSelectAWizard.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
||||
lblSelectAWizard.setText("Select a Wizard and then press finish: ");
|
||||
new Label(container, SWT.NONE);
|
||||
new Label(container, SWT.NONE);
|
||||
|
||||
cmbWizardName_ = new Combo(container, SWT.READ_ONLY);
|
||||
cmbWizardName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||
cmbWizardName_.setItems(list_.keySet().toArray(items));
|
||||
cmbWizardName_.select(0);
|
||||
new Label(container, SWT.NONE);
|
||||
}
|
||||
|
||||
public String getTagName()
|
||||
{
|
||||
return list_.get(cmbWizardName_.getText());
|
||||
}
|
||||
|
||||
public String getTagDescription()
|
||||
{
|
||||
return cmbWizardName_.getText();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue