{
Label label;
logger.debug("creating controls");
final Participant p = ((ParticipantEditorInput)getEditorInput()).getParticipant();
SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
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 });
// create a generic focus listener that saves the object when focus is lost
FocusListener saveObjectFocusListener = new FocusListener() {
public void focusGained(FocusEvent event)
{
logger.trace("focus gained: " + event);
}
public void focusLost(FocusEvent event)
{
logger.debug("focus lost: " + event);
try
{
Participant p = ((ParticipantEditorInput)getEditorInput()).getParticipant();
logger.info("Saving participant: " + p);
DataStore.getDataStore().saveObject(p, null);
}
catch(DataPersistenceException e)
{
logger.error("exception while saving participant: " + e.getLocalizedMessage(), e);
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), res.getLocaleString("campaign.editor.error.save_participant.title"), res.getLocaleString("campaign.editor.error.save_participant.message"));
}
}
};
{
GridLayout layout = new GridLayout();
layout.numColumns = 4;
leftSide.setLayout(layout);
// name
label = new Label(leftSide, SWT.RIGHT);
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
label.setText(res.getLocaleString("participant.editor.name.label"));
name = new Text(leftSide, SWT.BORDER);
name.setText(p.getName());
name.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
name.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e)
{
logger.debug("modifying participant name");
p.setName(name.getText());
dirty = true;
ParticipantEditor.this.setPartName(res.getLocaleString("participant.editor.title.tab") + ": " + ((ParticipantEditorInput)getEditorInput()).getParticipant().getName());
}
});
name.addFocusListener(saveObjectFocusListener);
// role
label = new Label(leftSide, SWT.RIGHT);
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
label.setText(res.getLocaleString("participant.editor.role.label"));
role = new Combo(leftSide, SWT.READ_ONLY | SWT.DROP_DOWN);
role.add(res.getLocaleString("participant.role.player"));
role.add(res.getLocaleString("participant.role.dm"));
role.select(IApplicationConstants.DUNGEON_MASTER_ROLE.equals(p.getRole()) ? 1 : 0);
role.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
role.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e)
{
// do nothing
}
public void widgetSelected(SelectionEvent e)
{
logger.debug("modifying participant role");
int selection = role.getSelectionIndex();
if(selection == 1)
p.setRole(IApplicationConstants.DUNGEON_MASTER_ROLE);
else
p.setRole(IApplicationConstants.PLAYER_ROLE);
dirty = true;
}
});
role.addFocusListener(saveObjectFocusListener);
// address
label = new Label(leftSide, SWT.RIGHT);
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
label.setText(res.getLocaleString("participant.editor.address.label"));
address = new Text(leftSide, SWT.BORDER | SWT.MULTI);
{
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
address.setLayoutData(gd);
}
address.setSize(0, 50); // TODO: better determination?
address.setText(p.getAddress());
address.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e)
{
logger.debug("modifying participant address");
p.setAddress(name.getText());
dirty = true;
}
});
address.addFocusListener(saveObjectFocusListener);
// home phone
label = new Label(leftSide, SWT.RIGHT);
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
label.setText(res.getLocaleString("participant.editor.home_phone.label"));
homePhone = new Text(leftSide, SWT.BORDER);
homePhone.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
homePhone.setText(p.getHomePhone());
homePhone.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e)
{
logger.debug("modifying participant home phone");
p.setHomePhone(name.getText());
dirty = true;
}
});
homePhone.addFocusListener(saveObjectFocusListener);
// mobile phone
label = new Label(leftSide, SWT.RIGHT);
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
label.setText(res.getLocaleString("participant.editor.mobile_phone.label"));
mobilePhone = new Text(leftSide, SWT.BORDER);
mobilePhone.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mobilePhone.setText(p.getMobilePhone());
mobilePhone.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e)
{
logger.debug("modifying participant mobile phone");
p.setMobilePhone(name.getText());
dirty = true;
}
});
mobilePhone.addFocusListener(saveObjectFocusListener);
// email
label = new Label(leftSide, SWT.RIGHT);
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
label.setText(res.getLocaleString("participant.editor.email.label"));
email = new Text(leftSide, SWT.BORDER);
{
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 3;
email.setLayoutData(gd);
}
email.setText(p.getEmail());
email.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e)
{
logger.debug("modifying participant email");
p.setEmail(name.getText());
dirty = true;
}
});
email.addFocusListener(saveObjectFocusListener);
// notes
label = new Label(leftSide, SWT.RIGHT);
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
label.setText(res.getLocaleString("participant.editor.notes.label"));
notes = new Text(leftSide, SWT.BORDER | SWT.MULTI);
{
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
notes.setLayoutData(gd);
}
notes.setText(p.getAddress());
notes.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e)
{
logger.debug("modifying participant notes");
p.setAddress(name.getText());
dirty = true;
}
});
notes.addFocusListener(saveObjectFocusListener);