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();
}
}
}