Improved display of results on multiple fields #26372
This commit is contained in:
parent
c16bcdbc76
commit
9ca7b52b60
|
@ -4,6 +4,10 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v3.2.2-SNAPSHOT] - 2024-01-11
|
||||
|
||||
- Improved display of results on multiple fields (in the table) [#26372]
|
||||
|
||||
## [v3.2.1] - 2023-06-16
|
||||
|
||||
- Fixed issue in the Search facility [#25265]
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -14,7 +14,7 @@
|
|||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>geoportal-data-entry-app</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>3.2.1</version>
|
||||
<version>3.2.2-SNAPSHOT</version>
|
||||
<name>GeoPortal Data Entry App</name>
|
||||
<description>The GeoPortal Data Entry App is an application to build the web forms for data entries needed to create projects/documents (based on UCD) in the D4Science Geoportal service</description>
|
||||
<scm>
|
||||
|
|
|
@ -188,6 +188,16 @@ public class GeonaRecordsPaginatedView {
|
|||
}
|
||||
// initFirstRangeChanged = false;
|
||||
|
||||
//printData((List<DocumentDV>) result.getData());
|
||||
}
|
||||
|
||||
private void printData(List<DocumentDV> data) {
|
||||
GWT.log("printData");
|
||||
int i = 0;
|
||||
for (DocumentDV documentDV : data) {
|
||||
GWT.log(++i + ") json: " + documentDV.getDocumentAsJSON());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.google.gwt.core.shared.GWT;
|
|||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
|
||||
import com.google.gwt.safehtml.shared.SafeHtml;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
|
||||
|
@ -102,6 +103,127 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
|||
super.addItems(items);
|
||||
}
|
||||
|
||||
class CellRender {
|
||||
|
||||
String tooltip;
|
||||
String value;
|
||||
|
||||
public CellRender() {
|
||||
}
|
||||
|
||||
public String getTooltip() {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setTooltip(String tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CellRender toCellRender(ItemFieldDV itemField, DocumentDV documentDV) {
|
||||
|
||||
StringBuilder tooltipBuilder = new StringBuilder();
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
String newLine = "<br>";
|
||||
String newLineTxt = "\n";
|
||||
String bullet = "• "; // it is the dot. As <li> rendered in the <ul> tag
|
||||
|
||||
String newBullet = newLine + bullet;
|
||||
|
||||
List<String> listJsonFields = itemField.getJsonFields();
|
||||
|
||||
int numberOfFields = listJsonFields.size();
|
||||
|
||||
if (numberOfFields > 1) {
|
||||
valueBuilder.append(bullet);
|
||||
}
|
||||
|
||||
for (String jsonKey : listJsonFields) {
|
||||
|
||||
try {
|
||||
String objectToRender = "";
|
||||
// removing the '_theDocument.' prefix for searching in the Document Map
|
||||
String key = jsonKey.replace(ConstantsGeoPortalDataEntryApp.DEFAULT_DOCUMENT_PROJECTION_NAME + ".", "");
|
||||
Object value = documentDV.getDocumentAsMap().get(key);
|
||||
// GWT.log("key: "+key+" is instance of: "+value.getClass());
|
||||
|
||||
if (value == null)
|
||||
continue;
|
||||
|
||||
GWT.log("value instance: " + value.getClass());
|
||||
|
||||
if (value instanceof ArrayList) {
|
||||
ArrayList<Object> arrayValues = (ArrayList<Object>) value;
|
||||
String toReturn = "<ul>";
|
||||
for (Object arrayValue : arrayValues) {
|
||||
toReturn += "<li>" + arrayValue + "</li>";
|
||||
}
|
||||
toReturn += "</ul>";
|
||||
GWT.log("Array returning: " + key + " is instance of: " + value.getClass() + " to return: "
|
||||
+ toReturn);
|
||||
objectToRender = StringUtil.ellipsize(toReturn, MAX_TEXT_DIMENSION);
|
||||
} else {
|
||||
objectToRender = StringUtil.ellipsize(value.toString(), MAX_TEXT_DIMENSION);
|
||||
}
|
||||
|
||||
valueBuilder.append(objectToRender);
|
||||
valueBuilder.append(newBullet);
|
||||
|
||||
if (numberOfFields > 1) {
|
||||
tooltipBuilder.append("* " + key + newLineTxt);
|
||||
}else {
|
||||
tooltipBuilder.append(key);
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
GWT.log("Error e: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
CellRender cellRender = new CellRender();
|
||||
|
||||
String toRender = valueBuilder.toString();
|
||||
cellRender.setValue(toRender.substring(0, toRender.length() - newBullet.length()));
|
||||
|
||||
String toTooltip = tooltipBuilder.toString();
|
||||
toTooltip = numberOfFields > 1 ? toTooltip.substring(0, toTooltip.length() - newLineTxt.length())
|
||||
: toTooltip;
|
||||
cellRender.setTooltip(toTooltip);
|
||||
|
||||
return cellRender;
|
||||
|
||||
}
|
||||
|
||||
interface Templates extends SafeHtmlTemplates {
|
||||
|
||||
/**
|
||||
* Start tool tip.
|
||||
*
|
||||
* @param toolTipText the tool tip text
|
||||
* @return the safe html
|
||||
*/
|
||||
@Template("<span title=\"{0}\">")
|
||||
SafeHtml startToolTip(String toolTipText);
|
||||
|
||||
/**
|
||||
* End tool tip.
|
||||
*
|
||||
* @return the safe html
|
||||
*/
|
||||
@Template("</span>")
|
||||
SafeHtml endToolTip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the table.
|
||||
*
|
||||
|
@ -130,27 +252,10 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
|||
String displayName = itemField.getDisplayName();
|
||||
|
||||
TextColumn<T> col = new TextColumn<T>() {
|
||||
|
||||
@Override
|
||||
public String getValue(T object) {
|
||||
|
||||
if (object == null)
|
||||
return "";
|
||||
|
||||
DocumentDV documentDV = (DocumentDV) object;
|
||||
|
||||
try {
|
||||
// removing the '_theDocument.' prefix for searching in the Document Map
|
||||
String key = itemField.getJsonFields().get(0)
|
||||
.replace(ConstantsGeoPortalDataEntryApp.DEFAULT_DOCUMENT_PROJECTION_NAME + ".", "");
|
||||
Object value = documentDV.getDocumentAsMap().get(key);
|
||||
if(value==null)
|
||||
return "";
|
||||
|
||||
return value.toString();
|
||||
} catch (Exception e) {
|
||||
GWT.log("Error e: " + e);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -158,39 +263,12 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
|||
public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
|
||||
if (object == null)
|
||||
return;
|
||||
Templates TEMPLATES = GWT.create(Templates.class);
|
||||
|
||||
DocumentDV documentDV = (DocumentDV) object;
|
||||
String objectToRender = "";
|
||||
try {
|
||||
// removing the '_theDocument.' prefix for searching in the Document Map
|
||||
String key = itemField.getJsonFields().get(0)
|
||||
.replace(ConstantsGeoPortalDataEntryApp.DEFAULT_DOCUMENT_PROJECTION_NAME + ".", "");
|
||||
Object value = documentDV.getDocumentAsMap().get(key);
|
||||
// GWT.log("key: "+key+" is instance of: "+value.getClass());
|
||||
|
||||
if(value==null)
|
||||
return;
|
||||
|
||||
if (value instanceof ArrayList) {
|
||||
ArrayList<Object> arrayValues = (ArrayList<Object>) value;
|
||||
String toReturn = "<ul>";
|
||||
for (Object arrayValue : arrayValues) {
|
||||
toReturn += "<li>" + arrayValue + "</li>";
|
||||
}
|
||||
toReturn += "</ul>";
|
||||
GWT.log("Array returning: " + key + " is instance of: " + value.getClass() + " to return: "
|
||||
+ toReturn);
|
||||
objectToRender = StringUtil.ellipsize(toReturn, MAX_TEXT_DIMENSION);
|
||||
} else {
|
||||
objectToRender = StringUtil.ellipsize(value.toString(), MAX_TEXT_DIMENSION);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
GWT.log("Error e: " + e);
|
||||
}
|
||||
sb.appendHtmlConstant(objectToRender);
|
||||
// super.render(context, object, sb);
|
||||
// sb.appendHtmlConstant("</span>");
|
||||
CellRender cellRender = toCellRender(itemField, object);
|
||||
sb.append(TEMPLATES.startToolTip(cellRender.getTooltip()));
|
||||
sb.appendHtmlConstant(cellRender.getValue());
|
||||
sb.append(TEMPLATES.endToolTip());
|
||||
|
||||
};
|
||||
|
||||
|
@ -198,7 +276,7 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
|||
sortedCellTable.addColumn(col, displayName, true);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
// COL RELATIONS
|
||||
TextColumn<T> colRelationship = new TextColumn<T>() {
|
||||
@Override
|
||||
|
@ -231,7 +309,7 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
|||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
colRelationship.setCellStyleNames(CSS_CLASS_BACK_SYSTEM_CELL_B);
|
||||
sortedCellTable.addColumn(colRelationship, DEFAULT_DISPLAYING_COLUMN_NAME.RELATIONSHIPS.getTitle(), true);
|
||||
mapColumns.put(DEFAULT_DISPLAYING_COLUMN_NAME.RELATIONSHIPS, colRelationship);
|
||||
|
@ -258,7 +336,7 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
colCreated.setCellStyleNames(CSS_CLASS_BACK_SYSTEM_CELL_O);
|
||||
sortedCellTable.addColumn(colCreated, DEFAULT_DISPLAYING_COLUMN_NAME.CREATED.getTitle(), true);
|
||||
sortedCellTable.setColumnWidth(colCreated, 130, Unit.PX);
|
||||
|
@ -286,7 +364,7 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
colPublisher.setCellStyleNames(CSS_CLASS_BACK_SYSTEM_CELL_O);
|
||||
sortedCellTable.addColumn(colPublisher, DEFAULT_DISPLAYING_COLUMN_NAME.CREATED_BY.getTitle(), true);
|
||||
mapColumns.put(DEFAULT_DISPLAYING_COLUMN_NAME.CREATED_BY, colPublisher);
|
||||
|
@ -363,7 +441,7 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
|||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
colOperationStatus.setCellStyleNames(CSS_CLASS_BACK_SYSTEM_CELL_Y);
|
||||
sortedCellTable.addColumn(colOperationStatus, DEFAULT_DISPLAYING_COLUMN_NAME.STATUS.getTitle(), true);
|
||||
sortedCellTable.setColumnWidth(colOperationStatus, 120, Unit.PX);
|
||||
|
|
Loading…
Reference in New Issue