() {
+ @Override
+ public String getValue(T object) {
+ if (object == null)
+ return "";
+ return ((CatalogueDataset) object).getType();
+ }
+
+ // ADDING TOOLTIP
+ @Override
+ public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
+ if (object == null)
+ return;
+ sb.appendHtmlConstant("");
+ super.render(context, object, sb);
+ sb.appendHtmlConstant("
");
+ };
+ };
+
+ sortedCellTable.addColumn(name, "Type", true);
+
+ if (!isAsyncronusTable) {
+ Comparator c = new Comparator() {
+ @Override
+ public int compare(T o1, T o2) {
+ return ((CatalogueDataset) o1).getType().compareTo(((CatalogueDataset) o2).getType());
+ }
+ };
+
+ sortedCellTable.setComparator(type, c);
+ }
+
+ }
+
+// if (this.displayFields.contains(DISPLAY_FIELD.ICON)) {
+// // ICONS
+// ImageResourceCell iconResourceCell = new ImageResourceCell() {
+// public Set getConsumedEvents() {
+// HashSet events = new HashSet();
+// events.add("click");
+// return events;
+// }
+// };
+//
+// icon = new Column(iconResourceCell) {
+// @Override
+// public ImageResource getValue(T dataObj) {
+// return Util.getImage(dataObj);
+// }
+//
+// /*
+// * (non-Javadoc)
+// *
+// * @see
+// * com.google.gwt.user.cellview.client.Column#render(com.google.gwt.cell.client.
+// * Cell.Context, java.lang.Object,
+// * com.google.gwt.safehtml.shared.SafeHtmlBuilder)
+// */
+// @Override
+// public void render(Context context, T object, SafeHtmlBuilder sb) {
+// super.render(context, object, sb);
+//
+// }
+// };
+//// icon.setSortable(false);
+// sortedCellTable.addColumn(icon, "", false);
+// sortedCellTable.setColumnWidth(icon, 32.0, Unit.PX);
+// }
+
+ if (this.displayFields.contains(DISPLAY_FIELD.NAME)) {
+
+ // NAME
+ name = new TextColumn() {
+ @Override
+ public String getValue(T object) {
+ if (object == null)
+ return "";
+ return ((CatalogueDataset) object).getName();
+ }
+
+ // ADDING TOOLTIP
+ @Override
+ public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
+ if (object == null)
+ return;
+ sb.appendHtmlConstant("");
+ super.render(context, object, sb);
+ sb.appendHtmlConstant("
");
+ };
+ };
+
+ sortedCellTable.addColumn(name, "Name", true);
+
+ if (!isAsyncronusTable) {
+ Comparator c = new Comparator() {
+ @Override
+ public int compare(T o1, T o2) {
+ return ((CatalogueDataset) o1).getName().compareTo(((CatalogueDataset) o2).getName());
+ }
+ };
+
+ sortedCellTable.setComparator(name, c);
+ }
+
+ }
+
+ if (this.displayFields.contains(DISPLAY_FIELD.TITLE)) {
+
+ title = new TextColumn() {
+ @Override
+ public String getValue(T object) {
+ if (object == null)
+ return "";
+ return ((CatalogueDataset) object).getTitle() != null ? ((CatalogueDataset) object).getTitle() : "";
+ }
+ };
+
+ sortedCellTable.addColumn(title, "Title", true);
+
+ if (!isAsyncronusTable) {
+ Comparator c = new Comparator() {
+ @Override
+ public int compare(T o1, T o2) {
+ return ((CatalogueDataset) o1).getTitle().compareTo(((CatalogueDataset) o2).getTitle());
+ }
+ };
+ sortedCellTable.setComparator(title, c);
+ }
+
+ }
+
+ if (this.displayFields.contains(DISPLAY_FIELD.AUTHOR)) {
+
+ author = new TextColumn() {
+ @Override
+ public String getValue(T object) {
+ if (object == null)
+ return "";
+ return ((CatalogueDataset) object).getAuthor() != null ? ((CatalogueDataset) object).getAuthor()
+ : "";
+ }
+ };
+
+ sortedCellTable.addColumn(author, "Title", true);
+
+ if (!isAsyncronusTable) {
+ Comparator c = new Comparator() {
+ @Override
+ public int compare(T o1, T o2) {
+ return ((CatalogueDataset) o1).getAuthor().compareTo(((CatalogueDataset) o2).getAuthor());
+ }
+ };
+ sortedCellTable.setComparator(author, c);
+ }
+
+ }
+
+ if (this.displayFields.contains(DISPLAY_FIELD.AUTHOR)) {
+
+ DateCell date = new DateCell(dtformat);
+ dateColumn = new Column(date) {
+
+ @Override
+ public Date getValue(T object) {
+ if (object == null)
+ return null;
+
+ return new Date(((CatalogueDataset) object).getCreated());
+ }
+ };
+ sortedCellTable.addColumn(dateColumn, "Created", true);
+
+ if (!isAsyncronusTable) {
+ Comparator c = new Comparator() {
+ @Override
+ public int compare(T o1, T o2) {
+ if (o1 == null || o1.getCreated() == 0)
+ return -1;
+
+ if (o2 == null || o2.getCreated() == 0)
+ return 1;
+
+ Date d1 = new Date(((CatalogueDataset) o1).getCreated());
+ Date d2 = new Date(((CatalogueDataset) o2).getCreated());
+
+ // GWT.log(d1.toString() + "is after "+d2.toString() +" ? "+d2.after(d1));
+
+ if (d1.after(d2))
+ return 1;
+ else
+ return -1;
+ }
+ };
+ GWT.log("date colum sortable");
+ sortedCellTable.setComparator(dateColumn, c);
+ }
+
+ }
+
+ GWT.log("startSortByColumn: " + startSortByColumn);
+
+ if (startSortByColumn != null)
+ switch (startSortByColumn) {
+ case NAME:
+ if (this.displayFields.contains(DISPLAY_FIELD.NAME)) {
+ sortedCellTable.setInitialSortColumn(name);
+ }
+ break;
+ case TITLE:
+ if (this.displayFields.contains(DISPLAY_FIELD.TITLE)) {
+ sortedCellTable.setInitialSortColumn(title);
+ }
+ break;
+ case AUTHOR:
+ if (this.displayFields.contains(DISPLAY_FIELD.AUTHOR)) {
+ sortedCellTable.setDefaultSortOrder(dateColumn, false); // sorts ascending on first click
+ sortedCellTable.setInitialSortColumn(dateColumn);
+ GWT.log("sortedCellTable: " + sortedCellTable);
+ }
+ break;
+ default:
+ break;
+ }
+
+ /*
+ * final SingleSelectionModel- selectionModel = new
+ * SingleSelectionModel
- (); selectionModel.addSelectionChangeHandler(new
+ * Handler() {
+ *
+ * @Override public void onSelectionChange(SelectionChangeEvent event) { } });
+ */
+ }
+
+ /**
+ * 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
true
for ascending icon, false
+ * for descending icon
+ */
+ public void setSortedColumn(int columnIndex, boolean ascending) {
+ GWT.log("Column index: " + columnIndex);
+ GWT.log("ascending: " + ascending);
+ Column 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());
+ }
+ }
+ }
+
+ /**
+ * Sets the display fields.
+ *
+ * @param fields the new display fields
+ */
+ public void setDisplayFields(DISPLAY_FIELD[] fields) {
+ this.displayFields = fields != null && fields.length > 0 ? Arrays.asList(fields)
+ : Arrays.asList(DISPLAY_FIELD.values());
+ }
+
+ /**
+ * 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
+ */
+ public List getDisplayFields() {
+ 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
+ */
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.gcube.portlets.widgets.wsexplorer.client.notification.
+ * SelectionItemHandler#getSelectionItem()
+ */
+ @Override
+ public T getSelectedItem() {
+ return ssm.getSelectedObject();
+ }
+
+ /**
+ * Sets the empty table message.
+ *
+ * @param msg the new empty table message
+ */
+ public void setEmptyTableMessage(String msg) {
+ msg = msg != null ? msg : ContentModeratorWidgetConstants.NO_DATA;
+ if (sortedCellTable != null)
+ sortedCellTable.setEmptyTableWidget(new Label(msg));
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/MyToolTipColumn.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/MyToolTipColumn.java
new file mode 100644
index 0000000..92e359b
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/MyToolTipColumn.java
@@ -0,0 +1,83 @@
+/**
+ *
+ */
+
+package org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table;
+
+import com.google.gwt.cell.client.Cell;
+import com.google.gwt.cell.client.Cell.Context;
+import com.google.gwt.core.client.GWT;
+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.user.cellview.client.Column;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class MyToolTipColumn.
+ *
+ * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
+ *
+ * Jun 15, 2021
+ * @param the generic type
+ * @param the generic type
+ */
+public abstract class MyToolTipColumn extends Column {
+
+ /**
+ * The Interface Templates.
+ *
+ * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
+ *
+ * Jun 15, 2021
+ */
+ interface Templates extends SafeHtmlTemplates {
+
+ /**
+ * Start tool tip.
+ *
+ * @param toolTipText the tool tip text
+ * @return the safe html
+ */
+ @Template("")
+ SafeHtml startToolTip(String toolTipText);
+
+ /**
+ * End tool tip.
+ *
+ * @return the safe html
+ */
+ @Template("
")
+ SafeHtml endToolTip();
+ }
+
+ private static final Templates TEMPLATES = GWT.create(Templates.class);
+ private final String toolTipText;
+
+ /**
+ * Instantiates a new my tool tip column.
+ *
+ * @param cell the cell
+ * @param toolTipText the tool tip text
+ */
+ public MyToolTipColumn(final Cell cell, final String toolTipText) {
+
+ super(cell);
+ this.toolTipText = toolTipText;
+ }
+
+ /**
+ * Render.
+ *
+ * @param context the context
+ * @param object the object
+ * @param sb the sb
+ */
+ @Override
+ public void render(final Context context, final T object, final SafeHtmlBuilder sb) {
+
+ sb.append(TEMPLATES.startToolTip(toolTipText));
+ super.render(context, object, sb);
+ sb.append(TEMPLATES.endToolTip());
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/SortedCellTable.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/SortedCellTable.java
new file mode 100644
index 0000000..951a137
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/SortedCellTable.java
@@ -0,0 +1,260 @@
+/**
+ *
+ */
+
+package org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.gcube.portlets.widgets.ckancontentmoderator.client.resources.CellTableResources;
+
+import com.github.gwtbootstrap.client.ui.CellTable;
+import com.google.gwt.user.cellview.client.Column;
+import com.google.gwt.user.cellview.client.ColumnSortEvent;
+import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
+import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
+import com.google.gwt.user.cellview.client.Header;
+import com.google.gwt.view.client.AbstractDataProvider;
+import com.google.gwt.view.client.ListDataProvider;
+
+
+/**
+ * The Class SortedCellTable.
+ *
+ * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
+ *
+ * Jun 15, 2021
+ * @param the generic type
+ */
+public class SortedCellTable extends CellTable {
+
+ /**
+ * To keep track of the currently sorted column
+ */
+ private Column currentlySortedColumn;
+ /**
+ * Tells us which way to sort a column initially
+ */
+ private Map, Boolean> defaultSortOrderMap = new HashMap, Boolean>();
+ /**
+ * Comparators associated with their columns
+ */
+ private Map, Comparator> comparators = new HashMap, Comparator>();
+ /**
+ * Column to sort when the data provider's list is refreshed using
+ * {@link SortedCellTable#setList(List)}
+ */
+ private Column initialSortColumn;
+ /**
+ * Data provider we will attach to this table
+ */
+ private AbstractDataProvider dataProvider;
+
+ /**
+ * Special column sorting handler that will allow us to do more controlled
+ * sorting
+ */
+ private ListHandler columnSortHandler;
+
+
+ /**
+ * Instantiates a new sorted cell table.
+ *
+ * @param pageSize the page size
+ * @param dataProv the data prov
+ */
+ public SortedCellTable(int pageSize, AbstractDataProvider dataProv) {
+ super(1,CellTableResources.INSTANCE);
+ this.dataProvider = dataProv;
+
+ if(this.dataProvider instanceof ListDataProvider){
+ columnSortHandler = new ListHandler(((ListDataProvider) this.dataProvider).getList()) {
+
+ @Override
+ public void onColumnSort(ColumnSortEvent event) {
+
+ @SuppressWarnings("unchecked")
+ Column column = (Column) event.getColumn();
+ if (column == null) {
+ return;
+ }
+ if (column.equals(currentlySortedColumn)) {
+ // Default behavior
+ super.onColumnSort(event);
+ }
+ else {
+ // Initial sort; look up which direction we need
+ final Comparator comparator = comparators.get(column);
+ if (comparator == null) {
+ return;
+ }
+ Boolean ascending = defaultSortOrderMap.get(column);
+ if (ascending == null || ascending) {
+ // Default behavior
+ super.onColumnSort(event);
+ }
+ else {
+ // Sort the column descending
+ Collections.sort(getList(), new Comparator() {
+
+ public int compare(T o1, T o2) {
+
+ return -comparator.compare(o1, o2);
+ }
+ });
+ // Set the proper arrow in the header
+ getColumnSortList().push(new ColumnSortInfo(column, false));
+ }
+ currentlySortedColumn = column;
+ }
+ }
+
+ @Override
+ public void setComparator(Column column, Comparator comparator) {
+
+ comparators.put(column, comparator);
+ super.setComparator(column, comparator);
+ }
+ };
+
+ addColumnSortHandler(columnSortHandler);
+ }
+
+
+ }
+
+ /**
+ * Adds a column to the table and sets its sortable state.
+ *
+ * @param column the column
+ * @param headerName the header name
+ * @param sortable the sortable
+ */
+ public void addColumn(Column column, String headerName, boolean sortable) {
+
+ addColumn(column, headerName);
+ column.setSortable(sortable);
+ if (sortable) {
+ defaultSortOrderMap.put(column, true);
+ }
+ }
+
+ /**
+ * Adds the column.
+ *
+ * @param column the column
+ * @param headerName the header name
+ */
+ /* (non-Javadoc)
+ * @see com.google.gwt.user.cellview.client.AbstractCellTable#addColumn(com.google.gwt.user.cellview.client.Column, java.lang.String)
+ */
+ public void addColumn(Column column, String headerName) {
+
+ super.addColumn(column, headerName);
+ }
+
+ /**
+ * Adds a column to the table and sets its sortable state.
+ *
+ * @param column the column
+ * @param header the header
+ * @param sortable the sortable
+ */
+ public void addColumn(Column column, Header> header, boolean sortable) {
+
+ addColumn(column, header);
+ column.setSortable(sortable);
+ if (sortable) {
+ defaultSortOrderMap.put(column, true);
+ }
+ }
+
+ /**
+ * Sets the column to sort when the data list is reset using
+ * {@link SortedCellTable#setList(List)}.
+ *
+ * @param column the column
+ */
+ public void setInitialSortColumn(Column column) {
+
+ initialSortColumn = column;
+ }
+
+ /**
+ * Sets a comparator to use when sorting the given column.
+ *
+ * @param column the column
+ * @param comparator the comparator
+ */
+ public void setComparator(Column column, Comparator comparator) {
+
+ columnSortHandler.setComparator(column, comparator);
+ }
+
+ /**
+ * Sets the sort order to use when this column is clicked and it was not
+ * previously sorted.
+ *
+ * @param column the column
+ * @param ascending the ascending
+ */
+ public void setDefaultSortOrder(Column column, boolean ascending) {
+
+ defaultSortOrderMap.put(column, ascending);
+ }
+
+ /**
+ * Sets the table's data provider list and sorts the table based on the
+ * column given in {@link SortedCellTable#setInitialSortColumn(Column)}.
+ *
+ * @param list the new list
+ */
+ public void setList(List list) {
+
+ if(dataProvider instanceof ListDataProvider){
+ List myData = ((ListDataProvider) dataProvider).getList();
+ myData.clear();
+ if (list != null) {
+ /*for (T t : list) {
+ dataProvider.getList().add(t);
+ }*/
+ myData.addAll(list);
+ }
+ // Do a first-time sort based on which column was set in
+ // setInitialSortColumn()
+ if (initialSortColumn != null) {
+ Collections.sort(myData, new Comparator() {
+
+ @Override
+ public int compare(T o1, T o2) {
+
+ return (defaultSortOrderMap.get(initialSortColumn) ? 1 : -1) * comparators.get(initialSortColumn).compare(o1, o2);
+ }
+ });
+ // Might as well get the little arrow on the header to make it
+ // official
+ getColumnSortList().push(
+ new ColumnSortInfo(
+ initialSortColumn,
+ defaultSortOrderMap.get(initialSortColumn)));
+
+ currentlySortedColumn = initialSortColumn;
+ }
+ }
+ }
+
+
+ /**
+ * Gets the data provider.
+ *
+ * @return the data provider
+ */
+ public AbstractDataProvider getDataProvider() {
+
+ return dataProvider;
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/public/content-moderator-widget.css b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/public/content-moderator-widget.css
new file mode 100644
index 0000000..e6acdcf
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/public/content-moderator-widget.css
@@ -0,0 +1,25 @@
+@charset "UTF-8";
+
+/*** TABLE ***/
+.table-cms-widget {
+ word-wrap: break-word;
+}
+
+.table-cms-widget td, th {
+ overflow: hidden !important;
+}
+
+.table-cms-widget th {
+ text-align: center !important;
+}
+
+.table-cms-widget-vertical-middle td, th {
+ height: 50%;
+ vertical-align: middle !important;
+}
+
+/***** WS EXPLORER DOCK PANEL - CENTER FLOW PANEL *****/
+.we-dock-center-panel {
+ overflow-y: auto !important;
+ /* border: 1px solid #DDD; */
+}
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CatalogueBeansConverter.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CatalogueBeansConverter.java
index d244184..8929790 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CatalogueBeansConverter.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CatalogueBeansConverter.java
@@ -35,6 +35,7 @@ public class CatalogueBeansConverter {
myDataset.setTitle(t.getTitle());
myDataset.setType(t.getType());
myDataset.setUrl(t.getUrl());
+ myDataset.setCreated(t.getMetadataCreated().getTime());
return myDataset;
}
};
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/shared/CatalogueDataset.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/shared/CatalogueDataset.java
index 06d9de7..3cbec96 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/shared/CatalogueDataset.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/shared/CatalogueDataset.java
@@ -35,6 +35,7 @@ public class CatalogueDataset implements Serializable, IsSerializable {
private String url;
private String version;
private String ckanDatasetURL;
+ private long created;
/**
* Instantiates a new ckan dataset base.
@@ -161,6 +162,14 @@ public class CatalogueDataset implements Serializable, IsSerializable {
public void setCkanDatasetURL(String ckanDatasetURL) {
this.ckanDatasetURL = ckanDatasetURL;
}
+
+ public void setCreated(long creationTime) {
+ this.created = creationTime;
+ }
+
+ public long getCreated() {
+ return created;
+ }
@Override
public String toString() {
@@ -195,6 +204,8 @@ public class CatalogueDataset implements Serializable, IsSerializable {
builder.append(version);
builder.append(", ckanDatasetURL=");
builder.append(ckanDatasetURL);
+ builder.append(", created=");
+ builder.append(created);
builder.append("]");
return builder.toString();
}
diff --git a/src/main/resources/org/gcube/portlets/widgets/ckancontentmoderator/CkanContentModeratorWidget.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/ckancontentmoderator/CkanContentModeratorWidget.gwt.xml
index 00b14f8..4fdac16 100644
--- a/src/main/resources/org/gcube/portlets/widgets/ckancontentmoderator/CkanContentModeratorWidget.gwt.xml
+++ b/src/main/resources/org/gcube/portlets/widgets/ckancontentmoderator/CkanContentModeratorWidget.gwt.xml
@@ -3,21 +3,16 @@
-
-
-
-
-
-
-
-
+
+
+
-
+