diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorWidget.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorWidget.java index 70c9c70..4f50bc5 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorWidget.java @@ -5,7 +5,6 @@ import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTabl import com.google.gwt.user.client.Command; import com.google.gwt.user.client.ui.ComplexPanel; -import com.google.gwt.user.client.ui.Composite; /** * The Class CkanContentModeratorWidget. diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorWidgetController.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorWidgetController.java index 18708f9..f9d75e3 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorWidgetController.java +++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorWidgetController.java @@ -5,8 +5,8 @@ import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ClickItemEv import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ClickItemEventHandler; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.CkanFramePanel; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorPaginatedView; -import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorSystemBaseView; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorToolbar; +import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.HomeView; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.MainTabPanel; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD; import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset; @@ -16,9 +16,7 @@ import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.ComplexPanel; -import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; -import com.google.gwt.user.client.ui.VerticalPanel; /** * The Class CkanContentModeratorWidget. @@ -34,13 +32,12 @@ public class CkanContentModeratorWidgetController { private FlowPanel mainPanel = new FlowPanel(); -// private ItemsTable itemsTable; - private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView(); private ContentModeratorToolbar toolbar; private MainTabPanel mainTabPanel = new MainTabPanel(); private Boolean isContentModeratorEnabled = null; private ContentModeratorPaginatedView paginatedView; public final static HandlerManager eventBus = new HandlerManager(null); + private HomeView howeView; /** * Instantiates a new ckan content moderator widget. @@ -51,17 +48,9 @@ public class CkanContentModeratorWidgetController { */ public CkanContentModeratorWidgetController(ItemStatus status, DISPLAY_FIELD[] displayFields, DISPLAY_FIELD sortByField) { -// itemsTable = new ItemsTable(null, displayFields, sortByField); -// itemsTable.initTable(null, null, new ListDataProvider()); -// cmsPanel.add(itemsTable.getCellTable()); - toolbar = new ContentModeratorToolbar(eventBus); - paginatedView = new ContentModeratorPaginatedView(eventBus, status, displayFields, sortByField); - // cmsPanel.addToTop(new LoadingPanel(new HTML("Loading..."))); - //cmsPanel.addToTop(toolbar); - cmsPanel.addToCenter(paginatedView.getCellPanel()); - cmsPanel.addToBottom(paginatedView.getPagerPanel()); - mainTabPanel.addHomeWidget(cmsPanel.getPanel()); + howeView = new HomeView(eventBus, status, displayFields, sortByField); + mainTabPanel.addHomeWidget(howeView.getPanel()); mainPanel.add(toolbar); mainPanel.add(mainTabPanel); bindEvents(); diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/ContentModeratorSystemBaseView.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/ContentModeratorSystemBaseView.java index bdcacc6..0e76c3b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/ContentModeratorSystemBaseView.java +++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/ContentModeratorSystemBaseView.java @@ -4,7 +4,7 @@ import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.Widget; -// TODO: Auto-generated Javadoc + /** * The Class ContentModeratorSystemBaseView. * diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/HomeView.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/HomeView.java new file mode 100644 index 0000000..2719fb5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/HomeView.java @@ -0,0 +1,69 @@ +package org.gcube.portlets.widgets.ckancontentmoderator.client.ui; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; +import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD; + +import com.github.gwtbootstrap.client.ui.CheckBox; +import com.github.gwtbootstrap.client.ui.Dropdown; +import com.github.gwtbootstrap.client.ui.NavLink; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + +public class HomeView extends Composite { + + private static HomeViewUiBinder uiBinder = GWT.create(HomeViewUiBinder.class); + private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView(); + private ContentModeratorPaginatedView paginatedView; + + @UiField + HTMLPanel panelContainer; + + @UiField + CheckBox cbSelectAll; + + @UiField + Dropdown dropdownSetStatus; + + private List setStatusOptions = new ArrayList<>(); + + private ItemStatus displayingItemStatus; + + interface HomeViewUiBinder extends UiBinder { + } + + public HomeView(HandlerManager eventBus, ItemStatus status, DISPLAY_FIELD[] displayFields, + DISPLAY_FIELD sortByField) { + initWidget(uiBinder.createAndBindUi(this)); + this.displayingItemStatus = status; + paginatedView = new ContentModeratorPaginatedView(eventBus, status, displayFields, sortByField); + cmsPanel.addToCenter(paginatedView.getCellPanel()); + cmsPanel.addToBottom(paginatedView.getPagerPanel()); + panelContainer.add(cmsPanel.getPanel()); + + fillSetStatusOptions(); + } + + private void fillSetStatusOptions() { + for (ItemStatus status : ItemStatus.values()) { + if (!status.equals(displayingItemStatus)) { + NavLink nl = new NavLink(status.getLabel()); + dropdownSetStatus.add(nl); + setStatusOptions.add(nl); + } + } + + } + + public Composite getPanel() { + return this; + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/HomeView.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/HomeView.ui.xml new file mode 100644 index 0000000..802c5d3 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/HomeView.ui.xml @@ -0,0 +1,29 @@ + + + + .important { + font-weight: bold; + } + + .margin-left-20 { + margin-left: 20px; + } + + .margin-left-5 { + margin-left: 5px; + } + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/MainTabPanel.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/MainTabPanel.java index 8c82ab9..4b5d21d 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/MainTabPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/MainTabPanel.java @@ -8,7 +8,6 @@ import com.github.gwtbootstrap.client.ui.TabPanel; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.uibinder.client.UiBinder; diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/AbstractItemsCellTable.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/AbstractItemsCellTable.java index a3d1d0b..fcc0da2 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/AbstractItemsCellTable.java +++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/AbstractItemsCellTable.java @@ -14,7 +14,6 @@ import com.google.gwt.event.dom.client.ContextMenuHandler; import com.google.gwt.event.dom.client.DoubleClickEvent; import com.google.gwt.event.dom.client.DoubleClickHandler; import com.google.gwt.event.shared.HandlerManager; -import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; import com.google.gwt.user.cellview.client.SimplePager; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.DialogBox; @@ -146,25 +145,25 @@ public abstract class AbstractItemsCellTable { } - /** - * Update items. - * - * @param items the items - * @param removeOldItems the remove old items - */ - public void updateItems(List items, boolean removeOldItems) { - - if (removeOldItems) { - if (theSelectionModel instanceof SingleSelectionModel) { - ((SingleSelectionModel) theSelectionModel).clear(); - } else if (theSelectionModel instanceof MultiSelectionModel) { - ((MultiSelectionModel) theSelectionModel).clear(); - } - } - sortedCellTable.setList(items); - sortedCellTable.setPageSize(items.size() + 1); - sortedCellTable.redraw(); - } +// /** +// * Update items. +// * +// * @param items the items +// * @param removeOldItems the remove old items +// */ +// public void updateItems(List items, boolean removeOldItems) { +// +// if (removeOldItems) { +// if (theSelectionModel instanceof SingleSelectionModel) { +// ((SingleSelectionModel) theSelectionModel).clear(); +// } else if (theSelectionModel instanceof MultiSelectionModel) { +// ((MultiSelectionModel) theSelectionModel).clear(); +// } +// } +// sortedCellTable.setList(items); +// sortedCellTable.setPageSize(items.size() + 1); +// sortedCellTable.redraw(); +// } /** * Gets the cell tables. diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/ItemsTable.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/ItemsTable.java index a06aa2b..604d17b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/table/ItemsTable.java @@ -19,6 +19,7 @@ import com.github.gwtbootstrap.client.ui.Pagination; import com.google.gwt.cell.client.ButtonCell; import com.google.gwt.cell.client.CheckboxCell; import com.google.gwt.cell.client.DateCell; +import com.google.gwt.cell.client.FieldUpdater; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.shared.HandlerManager; @@ -85,22 +86,22 @@ public class ItemsTable extends AbstractItemsCellTab setDisplayFields(fields); } - /** - * Update items. - * - * @param items the items - * @param removeOldItems the remove old items - */ - /* - * (non-Javadoc) - * - * @see - * org.gcube.portlets.widgets.wsexplorer.client.view.grid.AbstractItemsCellTable - * #updateItems(java.util.List, boolean) - */ - public void updateItems(List items, boolean removeOldItems) { - super.updateItems(items, removeOldItems); - } +// /** +// * Update items. +// * +// * @param items the items +// * @param removeOldItems the remove old items +// */ +// /* +// * (non-Javadoc) +// * +// * @see +// * org.gcube.portlets.widgets.wsexplorer.client.view.grid.AbstractItemsCellTable +// * #updateItems(java.util.List, boolean) +// */ +// public void updateItems(List items, boolean removeOldItems) { +// super.updateItems(items, removeOldItems); +// } /** * Adds the items. @@ -141,6 +142,23 @@ public class ItemsTable extends AbstractItemsCellTab }; sortedCellTable.addColumn(checkColumn, "", false); sortedCellTable.setColumnWidth(checkColumn, 40, Unit.PX); + + ButtonCell previewButton = new ButtonCell(); + Column showdItemColumn = new Column(previewButton) { + public String getValue(T object) { + return "Show"; + } + }; + + showdItemColumn.setFieldUpdater(new FieldUpdater() { + @Override + public void update(int index, T object, String value) { + GWT.log("clicked"); + } + }); + sortedCellTable.addColumn(showdItemColumn); + sortedCellTable.setColumnWidth(showdItemColumn, 80, Unit.PX); + if (this.displayFields.contains(DISPLAY_FIELD.NAME)) { @@ -313,7 +331,8 @@ public class ItemsTable extends AbstractItemsCellTab if (o2 == null || o2.getExtra_SystemType() == null) return 1; - return ((CatalogueDataset) o1).getExtra_SystemType().compareTo(((CatalogueDataset) o2).getExtra_SystemType()); + return ((CatalogueDataset) o1).getExtra_SystemType() + .compareTo(((CatalogueDataset) o2).getExtra_SystemType()); } }; @@ -321,7 +340,7 @@ public class ItemsTable extends AbstractItemsCellTab } } - + GWT.log("startSortByColumn: " + startSortByColumn); if (startSortByColumn != null) 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 index 92e359b..5080d11 100644 --- 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 @@ -12,7 +12,7 @@ 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. * 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 index 10ba428..c18d579 100644 --- 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 @@ -15,19 +15,20 @@ import org.gcube.portlets.widgets.ckancontentmoderator.client.resources.CellTabl 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.AsyncHandler; 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.AsyncDataProvider; import com.google.gwt.view.client.ListDataProvider; - /** * The Class SortedCellTable. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Jun 15, 2021 + * Jun 15, 2021 * @param the generic type */ public class SortedCellTable extends CellTable { @@ -58,8 +59,7 @@ public class SortedCellTable extends CellTable { * Special column sorting handler that will allow us to do more controlled * sorting */ - private ListHandler columnSortHandler; - + private ColumnSortEvent.Handler columnSortHandler; /** * Instantiates a new sorted cell table. @@ -68,11 +68,12 @@ public class SortedCellTable extends CellTable { * @param dataProv the data prov */ public SortedCellTable(int pageSize, AbstractDataProvider dataProv) { - super(pageSize,CellTableResources.INSTANCE); + super(pageSize, CellTableResources.INSTANCE); this.dataProvider = dataProv; - if(this.dataProvider instanceof ListDataProvider){ - columnSortHandler = new ListHandler(((ListDataProvider) this.dataProvider).getList()) { + if (this.dataProvider instanceof ListDataProvider) { + ListDataProvider listDataProvider = (ListDataProvider) this.dataProvider; + ListHandler listSortHandler = new ListHandler((listDataProvider).getList()) { @Override public void onColumnSort(ColumnSortEvent event) { @@ -85,8 +86,7 @@ public class SortedCellTable extends CellTable { if (column.equals(currentlySortedColumn)) { // Default behavior super.onColumnSort(event); - } - else { + } else { // Initial sort; look up which direction we need final Comparator comparator = comparators.get(column); if (comparator == null) { @@ -96,8 +96,7 @@ public class SortedCellTable extends CellTable { if (ascending == null || ascending) { // Default behavior super.onColumnSort(event); - } - else { + } else { // Sort the column descending Collections.sort(getList(), new Comparator() { @@ -120,19 +119,62 @@ public class SortedCellTable extends CellTable { super.setComparator(column, comparator); } }; + addColumnSortHandler(listSortHandler); + columnSortHandler = listSortHandler; + } else if (this.dataProvider instanceof AsyncDataProvider) { + //AsyncDataProvider asyncDataProvider = ((AsyncDataProvider) this.dataProvider); + //asyncDataProvider.get + AsyncHandler asyncSortHandler = new AsyncHandler(this) { + @Override + public void onColumnSort(ColumnSortEvent event) { - addColumnSortHandler(columnSortHandler); + @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(getVisibleItems(), 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; + } + } + }; + +// addColumnSortHandler(asyncSortHandler); +// columnSortHandler = asyncSortHandler; } - } /** * Adds a column to the table and sets its sortable state. * - * @param column the column + * @param column the column * @param headerName the header name - * @param sortable the sortable + * @param sortable the sortable */ public void addColumn(Column column, String headerName, boolean sortable) { @@ -146,11 +188,15 @@ public class SortedCellTable extends CellTable { /** * Adds the column. * - * @param column 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) + /* + * (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) { @@ -160,8 +206,8 @@ public class SortedCellTable extends CellTable { /** * Adds a column to the table and sets its sortable state. * - * @param column the column - * @param header the header + * @param column the column + * @param header the header * @param sortable the sortable */ public void addColumn(Column column, Header header, boolean sortable) { @@ -183,23 +229,22 @@ public class SortedCellTable extends CellTable { 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); - } + + /** + * Set the comparator used to sort the specified column in ascending order. + * + * @param column the {@link Column} + * @param comparator the {@link Comparator} to use for the {@link Column} + */ + public void setComparator(Column column, Comparator comparator) { + comparators.put(column, comparator); + } /** * Sets the sort order to use when this column is clicked and it was not * previously sorted. * - * @param column the column + * @param column the column * @param ascending the ascending */ public void setDefaultSortOrder(Column column, boolean ascending) { @@ -208,20 +253,20 @@ public class SortedCellTable extends CellTable { } /** - * Sets the table's data provider list and sorts the table based on the - * column given in {@link SortedCellTable#setInitialSortColumn(Column)}. + * 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){ + if (dataProvider instanceof ListDataProvider) { List myData = ((ListDataProvider) dataProvider).getList(); myData.clear(); if (list != null) { - /*for (T t : list) { - dataProvider.getList().add(t); - }*/ + /* + * for (T t : list) { dataProvider.getList().add(t); } + */ myData.addAll(list); } // Do a first-time sort based on which column was set in @@ -232,22 +277,19 @@ public class SortedCellTable extends CellTable { @Override public int compare(T o1, T o2) { - return (defaultSortOrderMap.get(initialSortColumn) ? 1 : -1) * comparators.get(initialSortColumn).compare(o1, 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))); + getColumnSortList().push(new ColumnSortInfo(initialSortColumn, defaultSortOrderMap.get(initialSortColumn))); currentlySortedColumn = initialSortColumn; } } } - /** * Gets the data provider. *