renamed package

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@150988 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-07-11 08:08:07 +00:00
parent db424b5cc9
commit 75e0c25614
12 changed files with 952 additions and 1958 deletions

View File

@ -17,7 +17,7 @@ import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplor
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener;
import org.gcube.portlets.widgets.wsexplorer.client.view.Breadcrumbs;
import org.gcube.portlets.widgets.wsexplorer.client.view.WorkspaceExplorer;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;

View File

@ -12,7 +12,7 @@ import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEventHandler;
import org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent;
import org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEventHandler;
import org.gcube.portlets.widgets.wsexplorer.client.view.WorkspaceExplorerPaginated;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;

View File

@ -8,8 +8,8 @@ import org.gcube.portlets.widgets.wsexplorer.client.Util;
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
import org.gcube.portlets.widgets.wsexplorer.client.event.RootLoadedEvent;
import org.gcube.portlets.widgets.wsexplorer.client.resources.WorkspaceExplorerResources;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;

View File

@ -8,8 +8,8 @@ import java.util.List;
import org.gcube.portlets.widgets.wsexplorer.client.Util;
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.SortedCellTable;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.SortedCellTable;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;

View File

@ -1,191 +1,185 @@
//package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
//
//import java.util.List;
//
//import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent;
//import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.SortedCellTable;
//
//import com.github.gwtbootstrap.client.ui.Pagination;
//import com.google.gwt.core.client.Scheduler.ScheduledCommand;
//import com.google.gwt.core.shared.GWT;
//import com.google.gwt.dom.client.Style.BorderStyle;
//import com.google.gwt.event.dom.client.ContextMenuEvent;
//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;
//import com.google.gwt.user.client.ui.MenuBar;
//import com.google.gwt.user.client.ui.MenuItem;
//import com.google.gwt.view.client.SelectionChangeEvent;
//import com.google.gwt.view.client.SelectionChangeEvent.Handler;
//import com.google.gwt.view.client.SingleSelectionModel;
//
///**
// * The Class AbstractItemTable.
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 19, 2015
// * @param <T> the generic type
// */
//public abstract class AbstractItemsCellTable<T> {
//
// protected SortedCellTable<T> sortedCellTable;
//// protected ListDataProvider<T> dataProvider = new ListDataProvider<>();
// protected T itemContextMenu = null;
// protected boolean showMoreInfo;
// protected final SingleSelectionModel<T> ssm;
// private final HandlerManager eventBus;
//
// /**
// * Inits the table.
// *
// * @param pager the pager
// * @param pagination the pagination
// */
// public abstract void initTable(final SimplePager pager, final Pagination pagination);
//
//
// /**
// * Instantiates a new abstract items cell table.
// *
// * @param eventBus the event bus
// * @param fireOnClick the fire on click
// */
// public AbstractItemsCellTable(HandlerManager eventBus, boolean fireOnClick) {
// this.eventBus = eventBus;
// this.showMoreInfo = fireOnClick;
// sortedCellTable = new SortedCellTable<T>();
// sortedCellTable.addStyleName("table-explorer");
//// cellTable.getElement().getStyle().setOverflow(Overflow.HIDDEN);
// sortedCellTable.addStyleName("table-explorer-vertical-middle");
// sortedCellTable.setStriped(true);
// sortedCellTable.setCondensed(true);
// sortedCellTable.setWidth("100%", true);
//// dataProvider.addDataDisplay(sortedCellTable);
//// initTable(cellTable, null, null);
// sortedCellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
//
// ssm = new SingleSelectionModel<T>();
// sortedCellTable.setSelectionModel(ssm);
// ssm.addSelectionChangeHandler(new Handler() {
// @Override
// public void onSelectionChange(final SelectionChangeEvent event)
// {
// final T selectedObject = ssm.getSelectedObject();
// if(selectedObject!=null){
// GWT.log("Clicked: "+selectedObject);
//// selectedItem(selectedObject);
// if(showMoreInfo)
// AbstractItemsCellTable.this.eventBus.fireEvent(new ClickItemEvent<T>(selectedObject));
// }
// }
// });
//
// sortedCellTable.addDomHandler(new DoubleClickHandler() {
//
// @Override
// public void onDoubleClick(final DoubleClickEvent event) {
// T selected = ssm.getSelectedObject();
// if (selected != null) {
// GWT.log("Double Click: "+selected);
// AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(selected));
// }
// }
// },
// DoubleClickEvent.getType());
//
// MenuBar options = new MenuBar(true);
// ScheduledCommand openCommand = new ScheduledCommand() {
//
// @Override
// public void execute() {
// AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(itemContextMenu));
// }
// };
//
// MenuItem openItem = new MenuItem("Open", openCommand);
// options.addItem(openItem);
// final DialogBox menuWrapper = new DialogBox(true);
// menuWrapper.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
// menuWrapper.getElement().getStyle().setZIndex(10000);
// menuWrapper.add(options);
// sortedCellTable.sinkEvents(Event.ONCONTEXTMENU);
//
// sortedCellTable.addHandler(new ContextMenuHandler() {
// @Override
// public void onContextMenu(ContextMenuEvent event) {
// /*
// GWT.log("On Context Menu: " + event.getNativeEvent().getEventTarget().toString());
// Item selectedObject = (Item) event.getSource();
// itemContextMenu = selectedObject;
// if (selectedObject != null && selectedObject.isFolder()) {
// event.preventDefault();
// event.stopPropagation();
// menuWrapper.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
// menuWrapper.show();
// }*/
// }
// }, ContextMenuEvent.getType());
//
//// ssm.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
////
//// @Override
//// public void onSelectionChange(SelectionChangeEvent event) {
//// // changed the context menu selection
//// GWT.log("Selected item is" + ssm.getSelectedObject());
////
//// }
//// });
//
// }
//
//
// /**
// * Update items.
// *
// * @param items the items
// * @param removeOldItems the remove old items
// */
// public void updateItems(List<T> items, boolean removeOldItems) {
//
// if(removeOldItems){
//// dataProvider.getList().clear();
// ssm.clear();
// }
//
// sortedCellTable.setList(items);
//// dataProvider.flush();
//// dataProvider.refresh();
//
// sortedCellTable.setPageSize(items.size()+1);
// sortedCellTable.redraw();
// }
//
//
// /**
// * Adds the items.
// *
// * @param items the items
// */
// public void addItems(List<T> items){
//
// for (int i=0; i<items.size(); i++) {
// sortedCellTable.getDataProvider().getList().add(i, items.get(i));
// }
//
// sortedCellTable.setPageSize(items.size()+1);
// sortedCellTable.redraw();
// }
//
// /**
// * Gets the cell tables.
// *
// * @return the cell tables
// */
// public SortedCellTable<T> getCellTable() {
// return sortedCellTable;
// }
//}
package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
import java.util.List;
import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent;
import com.github.gwtbootstrap.client.ui.Pagination;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.event.dom.client.ContextMenuEvent;
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;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.view.client.AbstractDataProvider;
import com.google.gwt.view.client.AsyncDataProvider;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.gwt.view.client.SingleSelectionModel;
/**
* The Class AbstractItemTable.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 19, 2015
* @param <T> the generic type
*/
public abstract class AbstractItemsCellTable<T> {
protected SortedCellTable<T> sortedCellTable;
// protected ListDataProvider<T> dataProvider = new ListDataProvider<>();
protected T itemContextMenu = null;
protected boolean showMoreInfo;
protected SingleSelectionModel<T> ssm;
private HandlerManager eventBus;
/**
* Inits the table.
*
* @param pager the pager
* @param pagination the pagination
*/
public abstract void initTable(final SimplePager pager, final Pagination pagination);
/**
* Inits the abstract table.
*
* @param eventBus the event bus
* @param fireOnClick the fire on click
* @param dataProvider the data provider
*/
public void initAbstractTable(HandlerManager eventBus, boolean fireOnClick, AbstractDataProvider<T> dataProvider){
this.eventBus = eventBus;
this.showMoreInfo = fireOnClick;
sortedCellTable = new SortedCellTable<T>(dataProvider);
sortedCellTable.addStyleName("table-explorer");
// cellTable.getElement().getStyle().setOverflow(Overflow.HIDDEN);
sortedCellTable.addStyleName("table-explorer-vertical-middle");
sortedCellTable.setStriped(true);
sortedCellTable.setCondensed(true);
sortedCellTable.setWidth("100%", true);
// dataProvider.addDataDisplay(sortedCellTable);
// initTable(cellTable, null, null);
sortedCellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
ssm = new SingleSelectionModel<T>();
sortedCellTable.setSelectionModel(ssm);
ssm.addSelectionChangeHandler(new Handler() {
@Override
public void onSelectionChange(final SelectionChangeEvent event)
{
final T selectedObject = ssm.getSelectedObject();
if(selectedObject!=null){
GWT.log("Clicked: "+selectedObject);
// selectedItem(selectedObject);
if(showMoreInfo)
AbstractItemsCellTable.this.eventBus.fireEvent(new ClickItemEvent<T>(selectedObject));
}
}
});
sortedCellTable.addDomHandler(new DoubleClickHandler() {
@Override
public void onDoubleClick(final DoubleClickEvent event) {
T selected = ssm.getSelectedObject();
if (selected != null) {
GWT.log("Double Click: "+selected);
AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(selected));
}
}
},
DoubleClickEvent.getType());
MenuBar options = new MenuBar(true);
ScheduledCommand openCommand = new ScheduledCommand() {
@Override
public void execute() {
AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(itemContextMenu));
}
};
MenuItem openItem = new MenuItem("Open", openCommand);
options.addItem(openItem);
final DialogBox menuWrapper = new DialogBox(true);
menuWrapper.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
menuWrapper.getElement().getStyle().setZIndex(10000);
menuWrapper.add(options);
sortedCellTable.sinkEvents(Event.ONCONTEXTMENU);
sortedCellTable.addHandler(new ContextMenuHandler() {
@Override
public void onContextMenu(ContextMenuEvent event) {
}
}, ContextMenuEvent.getType());
}
/**
* Update items.
*
* @param items the items
* @param removeOldItems the remove old items
*/
public void updateItems(List<T> items, boolean removeOldItems) {
if(removeOldItems){
// dataProvider.getList().clear();
ssm.clear();
}
sortedCellTable.setList(items);
// dataProvider.flush();
// dataProvider.refresh();
sortedCellTable.setPageSize(items.size()+1);
sortedCellTable.redraw();
}
/**
* Gets the cell tables.
*
* @return the cell tables
*/
public SortedCellTable<T> getCellTable() {
return sortedCellTable;
}
/**
* Adds the items.
*
* @param items the items
*/
public void addItems(List<T> items){
AbstractDataProvider<T> dataProvider = sortedCellTable.getDataProvider();
if(dataProvider instanceof ListDataProvider){
List<T> ldp = ((ListDataProvider<T>) dataProvider).getList();
for (int i=0; i<items.size(); i++) {
ldp.add(i, items.get(i));
}
sortedCellTable.setPageSize(items.size()+1);
sortedCellTable.redraw();
}else if (dataProvider instanceof AsyncDataProvider){
//TODO ???
}
}
}

View File

@ -1,41 +1,41 @@
///**
// *
// */
//
//package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
//
//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;
//
//public abstract class MyToolTipColumn<T, C> extends Column<T, C> {
//
// interface Templates extends SafeHtmlTemplates {
//
// @Template("<div title=\"{0}\">")
// SafeHtml startToolTip(String toolTipText);
//
// @Template("</div>")
// SafeHtml endToolTip();
// }
// private static final Templates TEMPLATES = GWT.create(Templates.class);
// private final String toolTipText;
//
// public MyToolTipColumn(final Cell<C> cell, final String toolTipText) {
//
// super(cell);
// this.toolTipText = toolTipText;
// }
//
// @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());
// }
//}
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
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;
public abstract class MyToolTipColumn<T, C> extends Column<T, C> {
interface Templates extends SafeHtmlTemplates {
@Template("<div title=\"{0}\">")
SafeHtml startToolTip(String toolTipText);
@Template("</div>")
SafeHtml endToolTip();
}
private static final Templates TEMPLATES = GWT.create(Templates.class);
private final String toolTipText;
public MyToolTipColumn(final Cell<C> cell, final String toolTipText) {
super(cell);
this.toolTipText = toolTipText;
}
@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());
}
}

View File

@ -1,240 +1,250 @@
///**
// *
// */
//
//package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
//
//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.wsexplorer.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.ListDataProvider;
//
//
///**
// * The Class SortedCellTable.
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
// * Jun 6, 2016
// * @param <T> the generic type
// */
//public class SortedCellTable<T> extends CellTable<T> {
//
// /**
// * To keep track of the currently sorted column
// */
// private Column<T, ?> currentlySortedColumn;
// /**
// * Tells us which way to sort a column initially
// */
// private Map<Column<T, ?>, Boolean> defaultSortOrderMap = new HashMap<Column<T, ?>, Boolean>();
// /**
// * Comparators associated with their columns
// */
// private Map<Column<T, ?>, Comparator<T>> comparators = new HashMap<Column<T, ?>, Comparator<T>>();
// /**
// * Column to sort when the data provider's list is refreshed using
// * {@link SortedCellTable#setList(List)}
// */
// private Column<T, ?> initialSortColumn;
// /**
// * Data provider we will attach to this table
// */
// private ListDataProvider<T> dataProvider;
//
// /**
// * Special column sorting handler that will allow us to do more controlled
// * sorting
// */
// private ListHandler<T> columnSortHandler;
//
// /**
// * Instantiates a new sorted cell table.
// */
// public SortedCellTable() {
//
// super(1,CellTableResources.INSTANCE);
// dataProvider = new ListDataProvider<T>();
// dataProvider.addDataDisplay(this);
//
// columnSortHandler = new ListHandler<T>(dataProvider.getList()) {
//
// @Override
// public void onColumnSort(ColumnSortEvent event) {
//
// @SuppressWarnings("unchecked")
// Column<T, ?> column = (Column<T, ?>) 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<T> 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<T>() {
//
// 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<T, ?> column, Comparator<T> 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<T, ?> column, String headerName, boolean sortable) {
//
// addColumn(column, headerName);
// column.setSortable(sortable);
// if (sortable) {
// defaultSortOrderMap.put(column, true);
// }
// }
//
// /* (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<T, ?> 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<T, ?> 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<T, ?> 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<T, ?> column, Comparator<T> 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<T, ?> 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<T> list) {
//
// dataProvider.getList().clear();
// if (list != null) {
// /*for (T t : list) {
// dataProvider.getList().add(t);
// }*/
// dataProvider.getList().addAll(list);
// }
// // Do a first-time sort based on which column was set in
// // setInitialSortColumn()
// if (initialSortColumn != null) {
// Collections.sort(dataProvider.getList(), new Comparator<T>() {
//
// @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;
// }
// }
//
//
// /**
// * @return the dataProvider
// */
// public ListDataProvider<T> getDataProvider() {
//
// return dataProvider;
// }
//}
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
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.wsexplorer.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 francesco.mangiacrapa@isti.cnr.it
* Jun 6, 2016
* @param <T> the generic type
*/
public class SortedCellTable<T> extends CellTable<T> {
/**
* To keep track of the currently sorted column
*/
private Column<T, ?> currentlySortedColumn;
/**
* Tells us which way to sort a column initially
*/
private Map<Column<T, ?>, Boolean> defaultSortOrderMap = new HashMap<Column<T, ?>, Boolean>();
/**
* Comparators associated with their columns
*/
private Map<Column<T, ?>, Comparator<T>> comparators = new HashMap<Column<T, ?>, Comparator<T>>();
/**
* Column to sort when the data provider's list is refreshed using
* {@link SortedCellTable#setList(List)}
*/
private Column<T, ?> initialSortColumn;
/**
* Data provider we will attach to this table
*/
private AbstractDataProvider<T> dataProvider;
/**
* Special column sorting handler that will allow us to do more controlled
* sorting
*/
private ListHandler<T> columnSortHandler;
/**
* Instantiates a new sorted cell table.
*
* @param dataProv the data provider
*/
public SortedCellTable(AbstractDataProvider<T> dataProv) {
super(1,CellTableResources.INSTANCE);
this.dataProvider = dataProv;
if(this.dataProvider instanceof ListDataProvider){
columnSortHandler = new ListHandler<T>(((ListDataProvider<T>) this.dataProvider).getList()) {
@Override
public void onColumnSort(ColumnSortEvent event) {
@SuppressWarnings("unchecked")
Column<T, ?> column = (Column<T, ?>) 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<T> 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<T>() {
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<T, ?> column, Comparator<T> 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<T, ?> column, String headerName, boolean sortable) {
addColumn(column, headerName);
column.setSortable(sortable);
if (sortable) {
defaultSortOrderMap.put(column, true);
}
}
/* (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<T, ?> 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<T, ?> 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<T, ?> 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<T, ?> column, Comparator<T> 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<T, ?> 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<T> list) {
if(dataProvider instanceof ListDataProvider){
List<T> 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<T>() {
@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<T> getDataProvider() {
return dataProvider;
}
}

View File

@ -1,185 +0,0 @@
package org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy;
import java.util.List;
import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent;
import com.github.gwtbootstrap.client.ui.Pagination;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.event.dom.client.ContextMenuEvent;
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;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.view.client.AbstractDataProvider;
import com.google.gwt.view.client.AsyncDataProvider;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.gwt.view.client.SingleSelectionModel;
/**
* The Class AbstractItemTable.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 19, 2015
* @param <T> the generic type
*/
public abstract class AbstractItemsCellTable<T> {
protected SortedCellTable<T> sortedCellTable;
// protected ListDataProvider<T> dataProvider = new ListDataProvider<>();
protected T itemContextMenu = null;
protected boolean showMoreInfo;
protected SingleSelectionModel<T> ssm;
private HandlerManager eventBus;
/**
* Inits the table.
*
* @param pager the pager
* @param pagination the pagination
*/
public abstract void initTable(final SimplePager pager, final Pagination pagination);
/**
* Inits the abstract table.
*
* @param eventBus the event bus
* @param fireOnClick the fire on click
* @param dataProvider the data provider
*/
public void initAbstractTable(HandlerManager eventBus, boolean fireOnClick, AbstractDataProvider<T> dataProvider){
this.eventBus = eventBus;
this.showMoreInfo = fireOnClick;
sortedCellTable = new SortedCellTable<T>(dataProvider);
sortedCellTable.addStyleName("table-explorer");
// cellTable.getElement().getStyle().setOverflow(Overflow.HIDDEN);
sortedCellTable.addStyleName("table-explorer-vertical-middle");
sortedCellTable.setStriped(true);
sortedCellTable.setCondensed(true);
sortedCellTable.setWidth("100%", true);
// dataProvider.addDataDisplay(sortedCellTable);
// initTable(cellTable, null, null);
sortedCellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
ssm = new SingleSelectionModel<T>();
sortedCellTable.setSelectionModel(ssm);
ssm.addSelectionChangeHandler(new Handler() {
@Override
public void onSelectionChange(final SelectionChangeEvent event)
{
final T selectedObject = ssm.getSelectedObject();
if(selectedObject!=null){
GWT.log("Clicked: "+selectedObject);
// selectedItem(selectedObject);
if(showMoreInfo)
AbstractItemsCellTable.this.eventBus.fireEvent(new ClickItemEvent<T>(selectedObject));
}
}
});
sortedCellTable.addDomHandler(new DoubleClickHandler() {
@Override
public void onDoubleClick(final DoubleClickEvent event) {
T selected = ssm.getSelectedObject();
if (selected != null) {
GWT.log("Double Click: "+selected);
AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(selected));
}
}
},
DoubleClickEvent.getType());
MenuBar options = new MenuBar(true);
ScheduledCommand openCommand = new ScheduledCommand() {
@Override
public void execute() {
AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(itemContextMenu));
}
};
MenuItem openItem = new MenuItem("Open", openCommand);
options.addItem(openItem);
final DialogBox menuWrapper = new DialogBox(true);
menuWrapper.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
menuWrapper.getElement().getStyle().setZIndex(10000);
menuWrapper.add(options);
sortedCellTable.sinkEvents(Event.ONCONTEXTMENU);
sortedCellTable.addHandler(new ContextMenuHandler() {
@Override
public void onContextMenu(ContextMenuEvent event) {
}
}, ContextMenuEvent.getType());
}
/**
* Update items.
*
* @param items the items
* @param removeOldItems the remove old items
*/
public void updateItems(List<T> items, boolean removeOldItems) {
if(removeOldItems){
// dataProvider.getList().clear();
ssm.clear();
}
sortedCellTable.setList(items);
// dataProvider.flush();
// dataProvider.refresh();
sortedCellTable.setPageSize(items.size()+1);
sortedCellTable.redraw();
}
/**
* Gets the cell tables.
*
* @return the cell tables
*/
public SortedCellTable<T> getCellTable() {
return sortedCellTable;
}
/**
* Adds the items.
*
* @param items the items
*/
public void addItems(List<T> items){
AbstractDataProvider<T> dataProvider = sortedCellTable.getDataProvider();
if(dataProvider instanceof ListDataProvider){
List<T> ldp = ((ListDataProvider<T>) dataProvider).getList();
for (int i=0; i<items.size(); i++) {
ldp.add(i, items.get(i));
}
sortedCellTable.setPageSize(items.size()+1);
sortedCellTable.redraw();
}else if (dataProvider instanceof AsyncDataProvider){
//TODO ???
}
}
}

View File

@ -1,470 +0,0 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.gcube.portlets.widgets.wsexplorer.client.Util;
import org.gcube.portlets.widgets.wsexplorer.client.resources.WorkspaceExplorerResources;
import org.gcube.portlets.widgets.wsexplorer.client.view.SelectionItem;
import org.gcube.portlets.widgets.wsexplorer.client.view.gcubeitem.DialogShowGcubeItem;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import com.github.gwtbootstrap.client.ui.Pagination;
import com.google.gwt.cell.client.ButtonCell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.DateCell;
import com.google.gwt.cell.client.ImageResourceCell;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
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.resources.client.ImageResource;
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;
/**
* The Class PackagesTable.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 19, 2015
* @param <T> the generic type
*/
public class ItemsTable<T extends Item> extends AbstractItemsCellTable<T> implements SelectionItem{
private Column<T, ImageResource> icon;
private TextColumn<T> name;
private TextColumn<T> owner;
public DateTimeFormat dtformat = DateTimeFormat.getFormat("dd MMM hh:mm aaa yyyy");
public ImageResource info = WorkspaceExplorerResources.ICONS.infoSquare();
public AbstractDataProvider<T> dataProvider;
/**
* The Enum DISPLAY_FIELD.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 1, 2016
*/
public static enum DISPLAY_FIELD{ICON, NAME, OWNER, CREATION_DATE};
private List<DISPLAY_FIELD> displayFields;
private Column<T, Date> dateColumn;
private List<String> displayProperties;
private boolean showGcubeItemsInfo;
private DISPLAY_FIELD startSortByColumn;
private boolean isAsyncronusTable;
/**
* Instantiates a new items table.
*
* @param eventBus the event bus
* @param showMoreInfo the show more info
* @param fields the fields
* @param displayProperties the display properties
* @param showGcubeItemsInfo the show gcube items info
* @param startSortByColumn the start sort by column
* @param asyncDataProvider the async data provider
*/
public ItemsTable(HandlerManager eventBus, boolean showMoreInfo, DISPLAY_FIELD[] fields, List<String> displayProperties, boolean showGcubeItemsInfo, DISPLAY_FIELD startSortByColumn, AbstractDataProvider<T> dataProvider) {
this.dataProvider = dataProvider;
initAbstractTable(eventBus, showMoreInfo, dataProvider);
this.dataProvider.addDataDisplay(sortedCellTable);
this.startSortByColumn = startSortByColumn;
setDisplayFields(fields);
setDisplayProperties(displayProperties);
setShowGcubeItemsInfo(showGcubeItemsInfo);
this.isAsyncronusTable = dataProvider instanceof AbstractDataProvider?true:false;
initTable(null, null);
}
/**
* Sets the show gcube items info.
*
* @param showGcubeItemsInfo the new show gcube items info
*/
private void setShowGcubeItemsInfo(boolean showGcubeItemsInfo) {
this.showGcubeItemsInfo = showGcubeItemsInfo;
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.view.grid.AbstractItemsCellTable#updateItems(java.util.List, boolean)
*/
public void updateItems(List<T> items, boolean removeOldItems) {
super.updateItems(items, removeOldItems);
}
/**
* Adds the items.
*
* @param items the items
*/
public void addItems(List<T> items) {
super.addItems(items);
}
/* (non-Javadoc)
* @see org.gcube.portlets.admin.gcubereleases.client.view.AbstractPackageTable#initTable(com.google.gwt.user.cellview.client.AbstractCellTable, com.google.gwt.user.cellview.client.SimplePager, com.github.gwtbootstrap.client.ui.Pagination)
*/
@Override
public void initTable(final SimplePager pager, final Pagination pagination) {
sortedCellTable.setEmptyTableWidget(new Label("No data."));
if(this.displayFields.contains(DISPLAY_FIELD.ICON)){
//ICONS
ImageResourceCell iconResourceCell = new ImageResourceCell() {
public Set<String> getConsumedEvents() {
HashSet<String> events = new HashSet<String>();
events.add("click");
return events;
}
};
icon = new Column<T, ImageResource>(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, 25.0, Unit.PX);
}
if(this.displayFields.contains(DISPLAY_FIELD.NAME)){
//NAME
name = new TextColumn<T>() {
@Override
public String getValue(T object) {
return ((Item) object).getName();
}
//ADDING TOOLTIP
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div title=\""+((Item) object).getName()+"\">");
super.render(context, object, sb);
sb.appendHtmlConstant("</div>");
};
};
sortedCellTable.addColumn(name, "Name", true);
if(!isAsyncronusTable){
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return ((Item) o1).getName().compareTo(((Item) o2).getName());
}
};
sortedCellTable.setComparator(name, c);
}
}
if(this.displayFields.contains(DISPLAY_FIELD.OWNER)){
owner = new TextColumn<T>() {
@Override
public String getValue(T object) {
return ((Item) object).getOwner() != null ? ((Item) object).getOwner() : "";
}
};
sortedCellTable.addColumn(owner, "Owner", true);
if(!isAsyncronusTable){
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return ((Item) o1).getOwner().compareTo(((Item) o2).getOwner());
}
};
sortedCellTable.setComparator(owner, c);
}
}
if(this.displayFields.contains(DISPLAY_FIELD.CREATION_DATE)){
DateCell date = new DateCell(dtformat);
dateColumn = new Column<T, Date>(date){
@Override
public Date getValue(T object) {
return ((Item) object).getCreationDate();
}
};
sortedCellTable.addColumn(dateColumn, "Created", true);
if(!isAsyncronusTable){
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
if(o1 == null || o1.getCreationDate()==null)
return -1;
if(o2 == null || o2.getCreationDate()==null)
return 1;
Date d1 = ((Item) o1).getCreationDate();
Date d2 = ((Item) o2).getCreationDate();
// GWT.log(d1.toString() + "is after "+d2.toString() +" ? "+d2.after(d1));
if(d1.after(d2))
return 1;
else
return -1;
}
};
sortedCellTable.setComparator(dateColumn,c);
}
}
if(displayProperties!=null){
for (final String column : displayProperties) {
//NAME
TextColumn<T> textColumn = new TextColumn<T>() {
@Override
public String getValue(T object) {
Item extensionItem;
String value = null;
if(object instanceof Item){
extensionItem = object;
value = extensionItem.getGcubeProperties().get(column);
}
return value==null?"":value;
}
};
sortedCellTable.addColumn(textColumn, column, true);
if(!isAsyncronusTable){
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
if(!(o1 instanceof Item))
return -1;
if(!(o2 instanceof Item))
return 1;
Item e1 = o1;
Item e2 = o2;
String v1 = e1.getGcubeProperties().get(column);
String v2 = e2.getGcubeProperties().get(column);
if(v1==null)
return 1;
if(v2==null)
return -1;
return v1.compareToIgnoreCase(v2);
}
};
sortedCellTable.setComparator(textColumn, c);
}
}
}
if(showGcubeItemsInfo){
//ICONS
ImageResourceCell showGcubeInfo = new ImageResourceCell() {
public Set<String> getConsumedEvents() {
HashSet<String> events = new HashSet<String>();
events.add("click");
return events;
}
};
MyToolTipColumn<T, ImageResource> showGcubeInfoClm = new MyToolTipColumn<T, ImageResource>(showGcubeInfo, "Show gcube properties") {
@Override
public ImageResource getValue(T object) {
return info;
}
@Override
public void render(Context context, T object, SafeHtmlBuilder sb) {
super.render(context, object, sb);
}
/* (non-Javadoc)
* @see com.google.gwt.user.cellview.client.Column#onBrowserEvent(com.google.gwt.cell.client.Cell.Context, com.google.gwt.dom.client.Element, java.lang.Object, com.google.gwt.dom.client.NativeEvent)
*/
@Override
public void onBrowserEvent(
Context context, Element elem, T object, NativeEvent event) {
super.onBrowserEvent(context, elem, object, event);
if ("click".equals(event.getType())) {
Item item = object;
DialogShowGcubeItem dg = new DialogShowGcubeItem("Gcube Properties for: "+item.getName(), null, item, true);
// dg.setPopupPosition(event.getClientX()-Integer.parseInt(dg.getElement().getStyle().getWidth()), event.getClientY());
dg.center();
}
}
};
sortedCellTable.addColumn(showGcubeInfoClm, "", false);
sortedCellTable.setColumnWidth(showGcubeInfoClm, 32.0, Unit.PX);
}
if(startSortByColumn!=null)
switch (startSortByColumn) {
case NAME:
if(this.displayFields.contains(DISPLAY_FIELD.NAME)){
sortedCellTable.setInitialSortColumn(name);
}
break;
case OWNER:
if(this.displayFields.contains(DISPLAY_FIELD.OWNER)){
sortedCellTable.setInitialSortColumn(owner);
}
break;
case CREATION_DATE:
if(this.displayFields.contains(DISPLAY_FIELD.CREATION_DATE)){
sortedCellTable.setDefaultSortOrder(dateColumn, false); // sorts ascending on first click
sortedCellTable.setInitialSortColumn(dateColumn);
}
break;
default:
break;
}
/*final SingleSelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
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
* <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());
}
}
}
/**
* 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());
}
/**
* Sets the display properties.
*
* @param properties the new display properties
*/
public void setDisplayProperties(List<String> properties){
this.displayProperties = properties;
}
/**
* Reset columns table.
*/
public void reInitColumnsTable(){
int count = sortedCellTable.getColumnCount();
for(int i=0;i<count;i++){
sortedCellTable.removeColumn(0);
}
initTable(null, null);
}
/**
* Gets the display fields.
*
* @return the displayFields
*/
public List<DISPLAY_FIELD> getDisplayFields() {
return displayFields;
}
/**
* The Class ButtonImageCell.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 1, 2016
*/
public class ButtonImageCell extends ButtonCell{
/* (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);
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.notification.SelectionItemHandler#getSelectionItem()
*/
@Override
public T getSelectedItem() {
return ssm.getSelectedObject();
}
}

View File

@ -1,41 +0,0 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy;
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;
public abstract class MyToolTipColumn<T, C> extends Column<T, C> {
interface Templates extends SafeHtmlTemplates {
@Template("<div title=\"{0}\">")
SafeHtml startToolTip(String toolTipText);
@Template("</div>")
SafeHtml endToolTip();
}
private static final Templates TEMPLATES = GWT.create(Templates.class);
private final String toolTipText;
public MyToolTipColumn(final Cell<C> cell, final String toolTipText) {
super(cell);
this.toolTipText = toolTipText;
}
@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());
}
}

View File

@ -1,250 +0,0 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy;
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.wsexplorer.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 francesco.mangiacrapa@isti.cnr.it
* Jun 6, 2016
* @param <T> the generic type
*/
public class SortedCellTable<T> extends CellTable<T> {
/**
* To keep track of the currently sorted column
*/
private Column<T, ?> currentlySortedColumn;
/**
* Tells us which way to sort a column initially
*/
private Map<Column<T, ?>, Boolean> defaultSortOrderMap = new HashMap<Column<T, ?>, Boolean>();
/**
* Comparators associated with their columns
*/
private Map<Column<T, ?>, Comparator<T>> comparators = new HashMap<Column<T, ?>, Comparator<T>>();
/**
* Column to sort when the data provider's list is refreshed using
* {@link SortedCellTable#setList(List)}
*/
private Column<T, ?> initialSortColumn;
/**
* Data provider we will attach to this table
*/
private AbstractDataProvider<T> dataProvider;
/**
* Special column sorting handler that will allow us to do more controlled
* sorting
*/
private ListHandler<T> columnSortHandler;
/**
* Instantiates a new sorted cell table.
*
* @param dataProv the data provider
*/
public SortedCellTable(AbstractDataProvider<T> dataProv) {
super(1,CellTableResources.INSTANCE);
this.dataProvider = dataProv;
if(this.dataProvider instanceof ListDataProvider){
columnSortHandler = new ListHandler<T>(((ListDataProvider<T>) this.dataProvider).getList()) {
@Override
public void onColumnSort(ColumnSortEvent event) {
@SuppressWarnings("unchecked")
Column<T, ?> column = (Column<T, ?>) 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<T> 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<T>() {
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<T, ?> column, Comparator<T> 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<T, ?> column, String headerName, boolean sortable) {
addColumn(column, headerName);
column.setSortable(sortable);
if (sortable) {
defaultSortOrderMap.put(column, true);
}
}
/* (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<T, ?> 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<T, ?> 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<T, ?> 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<T, ?> column, Comparator<T> 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<T, ?> 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<T> list) {
if(dataProvider instanceof ListDataProvider){
List<T> 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<T>() {
@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<T> getDataProvider() {
return dataProvider;
}
}