public Widget asWidget() {
ToolStrip toolStrip = new ToolStrip();
if (providesEditSaveOp) {
editBtn = new ToolButton(Console.CONSTANTS.common_label_edit());
ClickHandler editHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if(null == form.getEditedEntity())
{
Log.warn("Empty form!");
return;
}
if(editBtn.getText().equals(Console.CONSTANTS.common_label_edit()))
{
editBtn.setText(Console.CONSTANTS.common_label_save());
form.setEnabled(true);
cancelBtn.setVisible(true);
}
else
{
if(!form.validate().hasErrors())
{
boolean preValidationIsSuccess = preValidation != null && preValidation.isValid();
if(preValidation==null || preValidationIsSuccess)
{
cancelBtn.setVisible(false);
editBtn.setText(Console.CONSTANTS.common_label_edit());
form.setEnabled(false);
Map<String, Object> changedValues = form.getChangedValues();
if(!changedValues.isEmpty())
callback.onSave(changedValues);
else
Log.warn("Empty changeset!");
}
}
}
}
};
editBtn.addClickHandler(editHandler);
toolStrip.addToolButton(editBtn);
}
editBtn.ensureDebugId(Console.DEBUG_CONSTANTS.debug_label_edit_formToolStrip());
for(ToolButton btn : additionalButtons)
toolStrip.addToolButtonRight(btn);
if(providesDeleteOp)
{
ClickHandler clickHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if(null == form.getEditedEntity()) return;
Feedback.confirm(
Console.MESSAGES.deleteTitle(Console.CONSTANTS.common_label_item()),
Console.MESSAGES.deleteConfirm(Console.CONSTANTS.common_label_item()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed) {
callback.onDelete(form.getEditedEntity());
}
}
});
}
};
String title = deleteOpName!=null ? deleteOpName : Console.CONSTANTS.common_label_delete();
ToolButton deleteBtn = new ToolButton(title);
deleteBtn.ensureDebugId(Console.DEBUG_CONSTANTS.debug_label_delete_formToolStrip());
deleteBtn.addClickHandler(clickHandler);
toolStrip.addToolButtonRight(deleteBtn);
}
final ClickHandler cancelHandler = new ClickHandler() {