headerItem.setValue(MSG.view_summaryOverviewForm_header_summary());
formItems.add(headerItem);
}
// Type
StaticTextItem typeItem = new StaticTextItem("type", MSG.view_summaryOverviewForm_field_type());
typeItem.setTooltip(MSG.common_title_plugin() + ": " + type.getPlugin() + "\n<br>" + MSG.common_title_type()
+ ": " + type.getName());
typeItem.setValue(AncestryUtil.getFormattedType(type));
formItems.add(typeItem);
final Resource resource = this.resourceComposite.getResource();
// Key
StaticTextItem keyItem = new StaticTextItem(ResourceDataSourceField.KEY.propertyName(),
ResourceDataSourceField.KEY.title());
keyItem.setAttribute(OUTPUT_AS_HTML_ATTRIBUTE, true);
keyItem.setValue(resource.getResourceKey());
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;
}
resource.setLocation(newLocation);
OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_summaryOverviewForm_error_locationChangeFailure(
String.valueOf(resource.getId()), oldLocation, newLocation), caught);
// We failed to update it on the Server, so change back the Resource and the form item to
// the original value.
resource.setLocation(oldLocation);
locationItem.setValue(oldLocation);
}
public void onSuccess(Void result) {
CoreGUI.getMessageCenter()
.notify(
new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(
String.valueOf(resource.getId()), oldLocation, newLocation),
Message.Severity.Info));
}
});
}
});
}
formItems.add(locationItem);
// Version
StaticTextItem versionItem = new StaticTextItem("version", MSG.view_summaryOverviewForm_field_version());
String version = (resource.getVersion() != null) ? resource.getVersion() : "<i>" + MSG.common_label_none()
+ "</i>";
versionItem.setValue(version);
formItems.add(versionItem);
// Timestamps
StaticTextItem ctimeItem = new StaticTextItem(ResourceDataSourceField.CTIME.propertyName(),
ResourceDataSourceField.CTIME.title());
String ctime = TimestampCellFormatter.format(resource.getCtime());
ctimeItem.setValue(ctime);
formItems.add(ctimeItem);
StaticTextItem itimeItem = new StaticTextItem(ResourceDataSourceField.ITIME.propertyName(),
ResourceDataSourceField.ITIME.title());
String itime = TimestampCellFormatter.format(resource.getItime());
itimeItem.setValue(itime);
formItems.add(itimeItem);
StaticTextItem mtimeItem = new StaticTextItem(ResourceDataSourceField.MTIME.propertyName(),
ResourceDataSourceField.MTIME.title());
String mtime = TimestampCellFormatter.format(resource.getMtime());
mtimeItem.setValue(mtime);
formItems.add(mtimeItem);
StaticTextItem modifierItem = new StaticTextItem(ResourceDataSourceField.MODIFIER.propertyName(),
ResourceDataSourceField.MODIFIER.title());
modifierItem.setValue(resource.getModifiedBy());
formItems.add(modifierItem);
// Traits
List<MeasurementDefinition> summaryTraitDefs = new ArrayList<MeasurementDefinition>();
for (MeasurementDefinition measurementDef : type.getMetricDefinitions()) {
if (measurementDef.getDataType() == DataType.TRAIT
&& measurementDef.getDisplayType() == DisplayType.SUMMARY) {
summaryTraitDefs.add(measurementDef);
}
}
Collections.sort(summaryTraitDefs, new Comparator<MeasurementDefinition>() {
public int compare(MeasurementDefinition md1, MeasurementDefinition md2) {
return Integer.valueOf(md1.getDisplayOrder()).compareTo(md2.getDisplayOrder());
}
});
for (MeasurementDefinition trait : summaryTraitDefs) {
String formItemId = buildFormItemIdFromTraitDisplayName(trait.getDisplayName());
StaticTextItem formItem = new StaticTextItem(formItemId, trait.getDisplayName());
formItem.setTooltip(trait.getDescription());
formItems.add(formItem);
// item.setValue("?");
}
// SectionItem section = new SectionItem("Summary", "Summary");