formItems.add(keyItem);
boolean modifiable = this.resourceComposite.getResourcePermission().isInventory();
// Name
final FormItem nameItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
nameItem.setName("name");
nameItem.setTitle(MSG.view_summaryOverviewForm_field_name());
nameItem.setValue(resource.getName());
nameItem.setAttribute(OUTPUT_AS_HTML_ATTRIBUTE, true);
if (nameItem instanceof EditableFormItem) {
EditableFormItem togglableNameItem = (EditableFormItem) nameItem;
togglableNameItem.setValidators(notEmptyOrNullValidator);
togglableNameItem.setValueEditedHandler(new ValueEditedHandler() {
public void editedValue(Object newValue) {
final String newName = newValue.toString();
final String oldName = resource.getName();
if (newName.equals(oldName)) {
return;
}
resource.setName(newName);
OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_summaryOverviewForm_error_nameChangeFailure(String.valueOf(resource.getId()),
oldName, newName), caught);
// We failed to update it on the Server, so change back the Resource and the form item to
// the original value.
resource.setName(oldName);
nameItem.setValue(oldName);
}
public void onSuccess(Void result) {
titleBar.displayResourceName(newName);
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(
String.valueOf(resource.getId()), oldName, newName), Message.Severity.Info));
}
});
}
});
}
formItems.add(nameItem);
// Description
final FormItem descriptionItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
descriptionItem.setName("description");
descriptionItem.setTitle(MSG.common_title_description());
descriptionItem.setValue(resource.getDescription());
descriptionItem.setAttribute(OUTPUT_AS_HTML_ATTRIBUTE, true);
if (descriptionItem instanceof EditableFormItem) {
EditableFormItem togglableDescriptionItem = (EditableFormItem) descriptionItem;
togglableDescriptionItem.setValueEditedHandler(new ValueEditedHandler() {
public void editedValue(Object newValue) {
final String newDescription = newValue != null ? newValue.toString() : "";
final String oldDescription = resource.getDescription();
if (newDescription.equals(oldDescription)) {
return;
}
resource.setDescription(newDescription);
OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_summaryOverviewForm_error_descriptionChangeFailure(
String.valueOf(resource.getId()), oldDescription, newDescription), caught);
// We failed to update it on the Server, so change back the Resource and the form item to
// the original value.
resource.setDescription(oldDescription);
descriptionItem.setValue(oldDescription);
}
public void onSuccess(Void result) {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(
String.valueOf(resource.getId()), oldDescription, newDescription),
Message.Severity.Info));
}
});
}
});
}
formItems.add(descriptionItem);
// Location
final FormItem locationItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
locationItem.setName("location");
locationItem.setTitle(MSG.view_summaryOverviewForm_field_location());
locationItem.setValue(resource.getLocation());
locationItem.setAttribute(OUTPUT_AS_HTML_ATTRIBUTE, true);
if (locationItem instanceof EditableFormItem) {
EditableFormItem togglableLocationItem = (EditableFormItem) locationItem;
togglableLocationItem.setValueEditedHandler(new ValueEditedHandler() {
public void editedValue(Object newValue) {
final String newLocation = newValue != null ? newValue.toString() : "";
final String oldLocation = resource.getLocation();
if (newLocation.equals(oldLocation)) {
return;