this.identityStore = new IdentityStore();
this.gridPanel = new GridPanel(this.identityStore, columnModel);
Toolbar toolbar = new Toolbar();
toolbar.addButton(new ToolbarButton(TextProvider.get().identities_panel_new_identity(),
new ButtonListenerAdapter() {
@Override
public void onClick( Button button, EventObject e ) {
Identity newIdentity = new Identity();
newIdentity.setEmail(GWTSessionManager.get().getMailbox().getEmailAddress());
newIdentity.setUserAccount(GWTSessionManager.get().getUserAccount());
Record record = identityStore.createRecord(newIdentity);
identityStore.add(record);
gridPanel.getSelectionModel().selectRecords(record);
userAccount.getIdentities().add(newIdentity);
}
}, ImageProvider.IDENTITY_ADD));
toolbar.addButton(new ToolbarButton(TextProvider.get().identities_panel_delete_identity(),
new ButtonListenerAdapter() {
@Override
public void onClick( Button button, EventObject e ) {
Record record = gridPanel.getSelectionModel().getSelected();
if (record != null) {
Identity identity = (Identity) record
.getAsObject(IdentityListFields.IDENTITY_OBJECT.name());
if (!identity.isStandard()) {
userAccount.getIdentities().remove(identity);
identityStore.remove(record);
} else {
MessageBox.alert(TextProvider.get().identities_panel_altert_delete());
}
}
}
}, ImageProvider.IDENTITY_DELETE));
this.gridPanel.setTopToolbar(toolbar);
this.gridPanel.setBorder(false);
this.gridPanel.setFrame(false);
this.gridPanel.setStripeRows(true);
this.gridPanel.setEnableDragDrop(false);
this.gridPanel.getView().setAutoFill(true);
this.gridPanel.getView().setForceFit(true);
this.gridPanel.setAutoHeight(false);
this.gridPanel.setHeight(200);
this.gridPanel.setSelectionModel(new RowSelectionModel(true)); // single
// select
this.gridPanel.getSelectionModel().addListener(new IdentityRowSelectionListener());
this.gridPanel.addGridCellListener(new GridCellListenerAdapter() {
public void onCellClick( GridPanel grid, int rowIndex, int colIndex, EventObject e ) {
// if already selected, don't deselect
if (grid.getColumnModel().getDataIndex(colIndex).equals(IdentityListFields.STANDARD.name())
&& e.getTarget(".checkbox", 1) != null) {
Record record = grid.getStore().getAt(rowIndex);
boolean isSelected = record.getAsBoolean(IdentityListFields.STANDARD.name());
if (!isSelected) {
Record[] records = grid.getStore().getRecords();
Identity identity = null;
for (int i = 0; i < records.length; i++) {
records[i].set(IdentityListFields.STANDARD.name(), false);
identity = (Identity) records[i].getAsObject(IdentityListFields.IDENTITY_OBJECT.name());
identity.setStandard(false);
}
record.set(IdentityListFields.STANDARD.name(), true);
identity = (Identity) record.getAsObject(IdentityListFields.IDENTITY_OBJECT.name());
identity.setStandard(true);
detailsFormPanel.updateForm();
}
}
}
});
add(this.gridPanel, new BorderLayoutData(RegionPosition.CENTER));
// Identity details
this.detailsFormPanel = new ModelFormPanel<Identity>();
this.detailsFormPanel.setFrame(true);
this.detailsFormPanel.setBorder(false);
this.detailsFormPanel.setLabelAlign(Position.RIGHT);
this.detailsFormPanel.setLabelWidth(110);
this.detailsFormPanel.setButtonAlign(Position.RIGHT);
this.detailsFormPanel.setAutoHeight(true);
Checkbox standardCheckbox = new Checkbox(TextProvider.get().identities_panel_label_standard(), "standard");
standardCheckbox.setDisabled(true);
this.detailsFormPanel.add(standardCheckbox);
TextField textfield = null;
KeyListener keyListener = new KeyListener() {
public void onKey( int key, EventObject e ) {
if (key == KeyboardListener.KEY_ENTER) {
resumeIdentities();
}
}
};
this.formFields = new ArrayList<Component>();
this.detailsFormPanel.add(textfield = new TextField(TextProvider.get().identities_panel_label_name(),
"displayName"), new AnchorLayoutData("80%"));
textfield.addKeyListener(KeyboardListener.KEY_ENTER, keyListener);
this.formFields.add(textfield);
this.detailsFormPanel.add(
textfield = new TextField(TextProvider.get().identities_panel_label_email(), "email"),
new AnchorLayoutData("80%"));
textfield.addKeyListener(KeyboardListener.KEY_ENTER, keyListener);
this.formFields.add(textfield);
this.detailsFormPanel.add(textfield = new TextField(TextProvider.get().identities_panel_label_organisation(),
"organisation"), new AnchorLayoutData("80%"));
textfield.addKeyListener(KeyboardListener.KEY_ENTER, keyListener);
this.formFields.add(textfield);
this.detailsFormPanel.add(textfield = new TextField(TextProvider.get().identities_panel_label_reply(),
"replyTo"), new AnchorLayoutData("80%"));
textfield.addKeyListener(KeyboardListener.KEY_ENTER, keyListener);
this.formFields.add(textfield);
this.detailsFormPanel.add(textfield = new TextField(TextProvider.get().identities_panel_label_bcc(), "bcc"),
new AnchorLayoutData("80%"));
textfield.addKeyListener(KeyboardListener.KEY_ENTER, keyListener);
this.formFields.add(textfield);
this.detailsFormPanel.add(textfield = new TextArea(TextProvider.get().identities_panel_label_signature(),
"signature"), new AnchorLayoutData("60%"));
this.formFields.add(textfield);
// Checkbox checkbox = new Checkbox(
// TextProvider.get().identities_panel_label_htmlsignature(),
// "htmlSignature" );
// this.detailsFormPanel.add( checkbox );
// this.formFields.add( checkbox );
Button button = new Button(TextProvider.get().common_button_apply(), new ButtonListenerAdapter() {
@Override
public void onClick( Button button, EventObject e ) {
resumeIdentities();