setPartName(res.getLocaleString("campaign.editor.title.tab") + ": " + ((CampaignEditorInput)getEditorInput()).getCampaign().getName());
}
private Composite createMainPage(Composite parent)
{
final Campaign campaign = ((CampaignEditorInput)getEditorInput()).getCampaign();
Label label;
logger.debug("creating controls");
SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
// have to create the children before setting their weights
Composite leftSide = new Composite(sashForm, SWT.NONE);
new Sash(sashForm, SWT.NONE);
Composite rightSide = new Composite(sashForm, SWT.NONE);
sashForm.setWeights(new int[] { 65, 35 });
// left side of sash
{
leftSide.setLayout(new GridLayout());
// top group
logger.debug("creating general group");
Group generalGroup = new Group(leftSide, SWT.NONE);
generalGroup.setText(res.getLocaleString("campaign.editor.group.general.label"));
generalGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout generalGroupLayout = new GridLayout();
generalGroupLayout.numColumns = 6;
generalGroup.setLayout(generalGroupLayout);
// name
logger.debug("creating name field");
label = new Label(generalGroup, SWT.RIGHT);
label.setText(res.getLocaleString("campaign.editor.name.label"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
name = new Text(generalGroup, SWT.BORDER);
{
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 5;
name.setLayoutData(gd);
}
name.setText(campaign.getName());
name.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event)
{
logger.debug("setting campaign name");
campaign.setName(name.getText());
logger.debug("setting editor as dirty");
dirty = true;
// set editor name
CampaignEditor.this.setPartName(res.getLocaleString("campaign.editor.title.tab") + ": " + name.getText());
}
});
// setting
logger.debug("creating setting chooser");
label = new Label(generalGroup, SWT.RIGHT);
label.setText(res.getLocaleString("campaign.editor.setting.label"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
setting = new Combo(generalGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
{
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
setting.setLayoutData(gd);
}
for(Setting s : DataManager.getDataManager().getSettings())
{
setting.add(s.getName());
}
setting.select(DataManager.getDataManager().getSettingIndex(campaign.getSetting()));
setting.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e)
{
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e)
{
logger.debug("setting campaign setting; index = " + setting.getSelectionIndex());
campaign.setSetting(Application.getApplication().getDataManager().getSetting(setting.getSelectionIndex()));
logger.debug("setting editor as dirty");
dirty = true;
// CampaignEditor.this.
}
});
// edition
logger.debug("creating edition chooser");
label = new Label(generalGroup, SWT.RIGHT);
label.setText(res.getLocaleString("campaign.editor.edition.label"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
edition = new Combo(generalGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
{
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
edition.setLayoutData(gd);
}
// if campaign is deleteable, then it's not the default workspace campaign, and can therefore
// have an edition assigned to it
for(Edition ed : DataManager.getDataManager().getEditions())
{
edition.add(ed.getName());
}
edition.select(DataManager.getDataManager().getEditionIndex(campaign.getEdition()));
edition.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e)
{
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e)
{
logger.debug("setting campaign edition; index = " + edition.getSelectionIndex());
campaign.setEdition(Application.getApplication().getDataManager().getEdition(edition.getSelectionIndex()).getName());
logger.debug("setting editor as dirty");
dirty = true;
// CampaignEditor.this.
}
});
// inception
logger.debug("creating date field");
label = new Label(generalGroup, SWT.RIGHT);
label.setText(res.getLocaleString("campaign.editor.inception.label"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
inception = new Text(generalGroup, SWT.BORDER);
inception.setText(campaign.getInception().toString());
{
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
inception.setLayoutData(gd);
}
inception.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event)
{
logger.debug("modifying inception date");
SimpleDateFormat sdf = new SimpleDateFormat();
String dateText = inception.getText();
try
{
logger.debug("parsing inception date");
Date d = sdf.parse(dateText);
logger.debug("setting inception date");
campaign.setInception(d);
logger.debug("marking editor as dirty");
dirty = true;
}
catch(ParseException e)
{
logger.debug("date is invalid; don't do it");
}
}
});
inception.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent event)
{
logger.debug("verifying date text");
event.doit = true;
SimpleDateFormat sdf = new SimpleDateFormat();
String dateText = inception.getText();
try
{
Date d = sdf.parse(dateText);
}
catch(ParseException e)
{
logger.debug("date is invalid; don't do it");
event.doit = false;
}
}
});
// logger.debug("creating date picker");
// Button datePicker = new Button(generalGroup, SWT.PUSH | SWT.FLAT);
// // datePicker.setText("Choose..."); // TODO: replace with image
// datePicker.setImage(ImageLoader.getImage(Activator.class, "/icons/date-picker.gif"));
// datePicker.setLayoutData(new GridData());
// datePicker.addSelectionListener(new SelectionListener() {
// public void widgetDefaultSelected(SelectionEvent event)
// {
// }
//
// public void widgetSelected(SelectionEvent event)
// {
// }
// });
// starting level
logger.debug("creating starting level field");
label = new Label(generalGroup, SWT.RIGHT);
label.setText(res.getLocaleString("campaign.editor.starting_level.label"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
startingLevel = new Spinner(generalGroup, SWT.BORDER);
{
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
startingLevel.setLayoutData(gd);
}
startingLevel.setSelection(campaign.getStartLevel());
startingLevel.setMinimum(1);
startingLevel.setMaximum(99);
startingLevel.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event)
{
logger.debug("setting campaign starting level");
campaign.setStartLevel(startingLevel.getSelection());
logger.debug("setting editor as dirty");
dirty = true;
}
});
if(!campaign.isDeleteable())
{
logger.debug("marking general group disabled");
generalGroup.setEnabled(false);
}
}
// bottom group: misc.
{
logger.debug("creating misc. group");
Group miscGroup = new Group(leftSide, SWT.NONE);
miscGroup.setText(res.getLocaleString("campaign.editor.group.notes.label"));
miscGroup.setLayout(new FillLayout());
miscGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
// description field
notes = new Text(miscGroup, SWT.MULTI);
notes.setText(campaign.getNotes());
notes.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e)
{
logger.debug("setting notes");
campaign.setNotes(notes.getText());
logger.debug("setting editor as dirty");
dirty = true;
}
});