2021-08-04 17:11:46 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.geoportaldataentry.client.ui.table;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
|
2022-08-08 17:43:13 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
|
2021-09-14 17:51:20 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV.ValidationStatus;
|
2021-08-04 17:11:46 +02:00
|
|
|
|
2021-09-14 17:51:20 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.ButtonCell;
|
2021-08-04 17:11:46 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Pagination;
|
|
|
|
import com.google.gwt.core.shared.GWT;
|
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
|
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
|
import com.google.gwt.safehtml.shared.SafeHtml;
|
|
|
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
|
|
|
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
|
|
|
|
import com.google.gwt.user.cellview.client.Column;
|
|
|
|
import com.google.gwt.user.cellview.client.ColumnSortEvent;
|
|
|
|
import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
|
|
|
|
import com.google.gwt.user.cellview.client.SimplePager;
|
|
|
|
import com.google.gwt.user.cellview.client.TextColumn;
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
import com.google.gwt.user.client.ui.Label;
|
|
|
|
import com.google.gwt.view.client.AbstractDataProvider;
|
|
|
|
import com.google.gwt.view.client.ListDataProvider;
|
|
|
|
import com.google.gwt.view.client.MultiSelectionModel;
|
|
|
|
import com.google.gwt.view.client.SelectionModel;
|
|
|
|
import com.google.gwt.view.client.SingleSelectionModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class ItemsTable.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Jun 15, 2021
|
|
|
|
* @param <T> the generic type
|
|
|
|
*/
|
2022-08-08 17:43:13 +02:00
|
|
|
public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T> {
|
2021-08-04 17:11:46 +02:00
|
|
|
|
|
|
|
private static final int ITEMS_PER_PAGE = 10;
|
|
|
|
private static final String NO_DATA = "No data";
|
|
|
|
public static DateTimeFormat dtformat = DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT);
|
|
|
|
private AbstractDataProvider<T> dataProvider;
|
2022-03-17 18:08:58 +01:00
|
|
|
private List<ItemFieldDV> displayFields;
|
2021-08-04 17:11:46 +02:00
|
|
|
private boolean isAsyncronusTable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new items table.
|
|
|
|
*
|
|
|
|
* @param eventBus the event bus
|
2021-08-06 16:23:17 +02:00
|
|
|
* @param displayFields the display fields
|
2021-08-04 17:11:46 +02:00
|
|
|
* @param startSortByColumn the start sort by column
|
|
|
|
*/
|
2022-03-17 18:08:58 +01:00
|
|
|
public ItemsTable(HandlerManager eventBus, List<ItemFieldDV> displayFields) {
|
2021-08-04 17:11:46 +02:00
|
|
|
this.eventBus = eventBus;
|
2021-12-06 17:24:27 +01:00
|
|
|
this.displayFields = displayFields;
|
2021-08-04 17:11:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the items.
|
|
|
|
*
|
|
|
|
* @param items the items
|
|
|
|
*/
|
|
|
|
public void addItems(List<T> items) {
|
|
|
|
super.addItems(items);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits the table.
|
|
|
|
*
|
|
|
|
* @param pager the pager
|
|
|
|
* @param pagination the pagination
|
|
|
|
* @param dataProvider the data provider
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void initTable(final SimplePager pager, final Pagination pagination, AbstractDataProvider<T> dataProvider) {
|
|
|
|
this.dataProvider = dataProvider;
|
|
|
|
this.theSelectionModel = new SingleSelectionModel<T>();
|
|
|
|
initAbstractTable(eventBus, fireEventOnClick, dataProvider, theSelectionModel, ITEMS_PER_PAGE);
|
|
|
|
this.dataProvider.addDataDisplay(sortedCellTable);
|
|
|
|
|
|
|
|
this.isAsyncronusTable = dataProvider instanceof ListDataProvider ? false : true;
|
|
|
|
setEmptyTableMessage(NO_DATA);
|
|
|
|
|
2021-12-06 17:24:27 +01:00
|
|
|
int i = 0;
|
2021-08-04 17:11:46 +02:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
for (ItemFieldDV itemField : displayFields) {
|
2021-12-06 17:24:27 +01:00
|
|
|
String displayName = itemField.getDisplayName();
|
2021-08-04 17:11:46 +02:00
|
|
|
// NAME
|
2021-12-06 17:24:27 +01:00
|
|
|
TextColumn<T> col = new TextColumn<T>() {
|
2021-08-04 17:11:46 +02:00
|
|
|
@Override
|
|
|
|
public String getValue(T object) {
|
|
|
|
|
|
|
|
if (object == null)
|
|
|
|
return "";
|
2022-08-08 17:43:13 +02:00
|
|
|
|
|
|
|
DocumentDV documentDV = (DocumentDV) object;
|
|
|
|
|
|
|
|
try {
|
|
|
|
return documentDV.getDocumentAsMap().get(itemField.getJsonFields().get(0)).toString();
|
|
|
|
}catch (Exception e) {
|
|
|
|
GWT.log("Error e: "+e);
|
|
|
|
}
|
2021-08-04 17:11:46 +02:00
|
|
|
|
2022-08-08 17:43:13 +02:00
|
|
|
/*
|
2021-12-06 17:24:27 +01:00
|
|
|
if (displayName.equalsIgnoreCase("Name")) {
|
|
|
|
return ((ConcessioneDV) object).getNome();
|
|
|
|
} else if (displayName.equalsIgnoreCase("Introduction")) {
|
|
|
|
return ((ConcessioneDV) object).getIntroduzione();
|
|
|
|
} else if (displayName.equalsIgnoreCase("Author/s")) {
|
|
|
|
|
|
|
|
String toDisplay = "";
|
|
|
|
if (object.getAuthors() != null) {
|
|
|
|
toDisplay = toDisplayAuthors(((ConcessioneDV) object).getAuthors());
|
|
|
|
}
|
|
|
|
return toDisplay;
|
|
|
|
} else if (displayName.equalsIgnoreCase("Project Start/End Date")) {
|
|
|
|
|
|
|
|
Date dS = null;
|
|
|
|
Date dE = null;
|
|
|
|
if (object.getDataInizioProgetto() != null) {
|
|
|
|
dS = (((ConcessioneDV) object).getDataInizioProgetto());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object.getDataFineProgetto() != null) {
|
|
|
|
dE = (((ConcessioneDV) object).getDataFineProgetto());
|
|
|
|
}
|
|
|
|
|
|
|
|
String dateFormat = "";
|
|
|
|
if (dS != null) {
|
|
|
|
dateFormat += dtformat.format(dS);
|
|
|
|
}
|
|
|
|
|
|
|
|
dateFormat += " / ";
|
|
|
|
|
|
|
|
if (dE != null) {
|
|
|
|
dateFormat += dtformat.format(dE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dateFormat;
|
|
|
|
} else if (displayName.equalsIgnoreCase("Published with")) {
|
|
|
|
ValidationReportDV vr = ((ConcessioneDV) object).getValidationReport();
|
|
|
|
if (vr != null && vr.getStatus() != null)
|
|
|
|
return vr.getStatus().getLabel();
|
2021-08-04 17:11:46 +02:00
|
|
|
return "";
|
2021-12-06 17:24:27 +01:00
|
|
|
} else if (displayName.equalsIgnoreCase("Created")) {
|
|
|
|
Date cd = ((ConcessioneDV) object).getCreationTime();
|
|
|
|
return dtformat.format(cd);
|
|
|
|
} else if (displayName.equalsIgnoreCase("Created by")) {
|
|
|
|
return ((ConcessioneDV) object).getCreationUser();
|
2022-07-01 15:39:27 +02:00
|
|
|
}else if (displayName.toLowerCase().contains("unpub")) {
|
|
|
|
ValidationReportDV vr = ((ConcessioneDV) object).getValidationReport();
|
|
|
|
if (vr != null && vr.getObjectName() != null)
|
|
|
|
return vr.getObjectName();
|
2022-08-08 17:43:13 +02:00
|
|
|
}*/
|
2021-08-05 11:21:39 +02:00
|
|
|
|
2021-12-06 17:24:27 +01:00
|
|
|
return "";
|
2021-08-04 17:11:46 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 17:24:27 +01:00
|
|
|
// ADDING TOOLTIP
|
2021-08-04 17:11:46 +02:00
|
|
|
@Override
|
2021-12-06 17:24:27 +01:00
|
|
|
public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
|
2021-08-04 17:11:46 +02:00
|
|
|
if (object == null)
|
2021-12-06 17:24:27 +01:00
|
|
|
return;
|
2021-08-04 17:11:46 +02:00
|
|
|
|
2021-12-06 17:24:27 +01:00
|
|
|
if (displayName.equalsIgnoreCase("Published with")) {
|
|
|
|
String value = getValue(object);
|
|
|
|
String color = "#000";
|
|
|
|
if (value.compareTo(ValidationStatus.PASSED.getLabel()) == 0) {
|
|
|
|
color = "#32CD32";
|
|
|
|
} else if (value.compareTo(ValidationStatus.WARNING.getLabel()) == 0) {
|
|
|
|
color = "#FF8000";
|
|
|
|
} else if (value.compareTo(ValidationStatus.ERROR.getLabel()) == 0) {
|
|
|
|
color = "red";
|
|
|
|
}
|
|
|
|
sb.appendHtmlConstant("<span style=\"color:" + color + "\";>");
|
|
|
|
super.render(context, object, sb);
|
|
|
|
sb.appendHtmlConstant("</span>");
|
|
|
|
} else
|
|
|
|
super.render(context, object, sb);
|
2021-08-04 17:11:46 +02:00
|
|
|
|
|
|
|
};
|
2021-08-05 11:21:39 +02:00
|
|
|
};
|
|
|
|
|
2022-08-11 12:07:07 +02:00
|
|
|
// if(i==0) {
|
|
|
|
// //name
|
|
|
|
// sortedCellTable.setColumnWidth(col, 20, Unit.PCT);
|
|
|
|
// }else if (i == 1) {
|
|
|
|
// // intro
|
|
|
|
// sortedCellTable.setColumnWidth(col, 30, Unit.PCT);
|
|
|
|
// } else if (i == 2) {
|
|
|
|
// sortedCellTable.setColumnWidth(col, 15, Unit.PCT);
|
|
|
|
// }else if(i==displayFields.size()-1) {
|
|
|
|
// sortedCellTable.setColumnWidth(col, 120, Unit.PX);
|
|
|
|
// }
|
2021-12-06 17:24:27 +01:00
|
|
|
|
|
|
|
sortedCellTable.addColumn(col, itemField.getDisplayName(), true);
|
2021-09-14 13:08:55 +02:00
|
|
|
|
2021-12-06 17:24:27 +01:00
|
|
|
i++;
|
2021-09-14 13:08:55 +02:00
|
|
|
}
|
2021-08-04 17:11:46 +02:00
|
|
|
}
|
2021-12-06 17:24:27 +01:00
|
|
|
|
2021-09-15 16:14:27 +02:00
|
|
|
public void enableWriteOperations() {
|
2021-12-06 17:24:27 +01:00
|
|
|
|
2021-09-15 16:14:27 +02:00
|
|
|
}
|
2021-08-04 17:11:46 +02:00
|
|
|
|
2021-08-06 16:23:17 +02:00
|
|
|
/**
|
|
|
|
* To display authors.
|
|
|
|
*
|
|
|
|
* @param authors the authors
|
|
|
|
* @return the string
|
|
|
|
*/
|
2021-08-04 17:11:46 +02:00
|
|
|
private String toDisplayAuthors(List<String> authors) {
|
|
|
|
String toDisplay = "";
|
|
|
|
if (authors == null)
|
|
|
|
return toDisplay;
|
|
|
|
|
|
|
|
for (String author : authors) {
|
|
|
|
toDisplay += author + "; ";
|
|
|
|
}
|
|
|
|
return toDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the appropriate sorted icon in the header of the column for the
|
|
|
|
* given index.
|
|
|
|
*
|
|
|
|
* @param columnIndex of the column to mark as sorted
|
|
|
|
* @param ascending <code>true</code> for ascending icon, <code>false</code>
|
|
|
|
* for descending icon
|
|
|
|
*/
|
|
|
|
public void setSortedColumn(int columnIndex, boolean ascending) {
|
|
|
|
GWT.log("Column index: " + columnIndex);
|
|
|
|
GWT.log("ascending: " + ascending);
|
|
|
|
Column<T, ?> column = sortedCellTable.getColumn(columnIndex);
|
|
|
|
if (column != null && column.isSortable()) {
|
|
|
|
ColumnSortInfo info = sortedCellTable.getColumnSortList().push(column);
|
|
|
|
// ColumnSortEvent.fire(cellTable, cellTable.getColumnSortList());
|
|
|
|
GWT.log("info.isAscending(): " + info.isAscending());
|
|
|
|
if (info.isAscending() != ascending) {
|
|
|
|
sortedCellTable.getColumnSortList().push(column);
|
|
|
|
ColumnSortEvent.fire(sortedCellTable, sortedCellTable.getColumnSortList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-06 17:24:27 +01:00
|
|
|
// /**
|
|
|
|
// * Sets the display fields.
|
|
|
|
// *
|
|
|
|
// * @param fields the new display fields
|
|
|
|
// */
|
|
|
|
// public void setDisplayFields(List<ItemField> fields) {
|
|
|
|
// this.displayFields = fields != null && fields.size() > 0 ? Arrays.asList(fields)
|
|
|
|
// : Arrays.asList(RECORD_FIELD.values());
|
|
|
|
// }
|
2021-08-04 17:11:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset columns table.
|
|
|
|
*/
|
|
|
|
public void reInitColumnsTable() {
|
|
|
|
int count = sortedCellTable.getColumnCount();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
sortedCellTable.removeColumn(0);
|
|
|
|
}
|
|
|
|
initTable(null, null, dataProvider);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the display fields.
|
|
|
|
*
|
|
|
|
* @return the displayFields
|
|
|
|
*/
|
2022-03-17 18:08:58 +01:00
|
|
|
public List<ItemFieldDV> getDisplayFields() {
|
2021-08-04 17:11:46 +02:00
|
|
|
return displayFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class ButtonImageCell.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 1, 2016
|
|
|
|
*/
|
|
|
|
public class ButtonImageCell extends ButtonCell {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render.
|
|
|
|
*
|
|
|
|
* @param context the context
|
|
|
|
* @param value the value
|
|
|
|
* @param sb the sb
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see
|
|
|
|
* com.google.gwt.cell.client.AbstractSafeHtmlCell#render(com.google.gwt.cell.
|
|
|
|
* client.Cell.Context, java.lang.Object,
|
|
|
|
* com.google.gwt.safehtml.shared.SafeHtmlBuilder)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
|
|
|
|
SafeHtml html = SafeHtmlUtils.fromTrustedString(new Image(value).toString());
|
|
|
|
sb.append(html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the selected item.
|
|
|
|
*
|
|
|
|
* @return the selected item
|
|
|
|
*/
|
|
|
|
public List<T> getSelectedItems() {
|
|
|
|
if (theSelectionModel instanceof SingleSelectionModel) {
|
|
|
|
T selected = ((SingleSelectionModel<T>) theSelectionModel).getSelectedObject();
|
|
|
|
if (selected != null) {
|
|
|
|
return Arrays.asList(selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (theSelectionModel instanceof MultiSelectionModel) {
|
|
|
|
Set<T> selected = ((MultiSelectionModel<T>) theSelectionModel).getSelectedSet();
|
|
|
|
if (selected != null) {
|
|
|
|
return new ArrayList<T>(selected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the empty table message.
|
|
|
|
*
|
|
|
|
* @param msg the new empty table message
|
|
|
|
*/
|
|
|
|
public void setEmptyTableMessage(String msg) {
|
|
|
|
msg = msg != null ? msg : NO_DATA;
|
|
|
|
if (sortedCellTable != null)
|
|
|
|
sortedCellTable.setEmptyTableWidget(new Label(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the selection model.
|
|
|
|
*
|
|
|
|
* @return the selection model
|
|
|
|
*/
|
|
|
|
public SelectionModel<T> getSelectionModel() {
|
|
|
|
return theSelectionModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|