396 lines
12 KiB
Java
396 lines
12 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
|
|
|
|
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.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.ListHandler;
|
|
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;
|
|
|
|
/**
|
|
* 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();
|
|
// private Item selectedItem = null;
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
public ItemsTable(HandlerManager eventBus, boolean showMoreInfo, DISPLAY_FIELD[] fields, List<String> displayProperties, boolean showGcubeItemsInfo) {
|
|
super(eventBus, showMoreInfo);
|
|
setDisplayFields(fields);
|
|
setDisplayProperties(displayProperties);
|
|
setShowGcubeItemsInfo(showGcubeItemsInfo);
|
|
initTable(null, null);
|
|
}
|
|
|
|
|
|
/**
|
|
* @param showGcubeItemsInfo
|
|
*/
|
|
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) {
|
|
|
|
for (int i=0; i<items.size(); i++) {
|
|
dataProvider.getList().add(i, items.get(i));
|
|
}
|
|
|
|
}
|
|
|
|
/* (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) {
|
|
cellTable.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);
|
|
cellTable.addColumn(icon, "");
|
|
cellTable.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();
|
|
}
|
|
};
|
|
|
|
name.setSortable(true);
|
|
cellTable.addColumn(name, "Name");
|
|
|
|
// double width = displayFields.size()>1?50:90;
|
|
// abstractCellTable.setColumnWidth(name, width, Unit.PCT);
|
|
|
|
ListHandler<T> nameColumnHandler = new ListHandler<>(dataProvider.getList());
|
|
nameColumnHandler.setComparator(name, new Comparator<T>() {
|
|
@Override
|
|
public int compare(T o1, T o2) {
|
|
|
|
return ((Item) o1).getName().compareTo(((Item) o2).getName());
|
|
}
|
|
});
|
|
|
|
cellTable.addColumnSortHandler(nameColumnHandler);
|
|
|
|
}
|
|
|
|
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() : "";
|
|
}
|
|
};
|
|
|
|
owner.setSortable(true);
|
|
cellTable.addColumn(owner, "Owner");
|
|
// double width = displayFields.size()==2 ?90:40;
|
|
// abstractCellTable.setColumnWidth(owner, width, Unit.PCT);
|
|
|
|
ListHandler<T> ownerColumnHandler = new ListHandler<>(dataProvider.getList());
|
|
ownerColumnHandler.setComparator(owner, new Comparator<T>() {
|
|
@Override
|
|
public int compare(T o1, T o2) {
|
|
return ((Item) o1).getOwner().compareTo(((Item) o2).getOwner());
|
|
}
|
|
});
|
|
cellTable.addColumnSortHandler(ownerColumnHandler);
|
|
|
|
}
|
|
|
|
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();
|
|
}
|
|
};
|
|
|
|
dateColumn.setSortable(true);
|
|
ListHandler<T> dateColumnHandler = new ListHandler<>(dataProvider.getList());
|
|
dateColumnHandler.setComparator(dateColumn, new Comparator<T>() {
|
|
@Override
|
|
public int compare(T o1, T o2) {
|
|
return ((Item) o1).getCreationDate().compareTo(((Item) o2).getCreationDate());
|
|
}
|
|
});
|
|
cellTable.addColumnSortHandler(dateColumnHandler);
|
|
cellTable.addColumn(dateColumn, "Created");
|
|
}
|
|
|
|
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;
|
|
}
|
|
};
|
|
|
|
textColumn.setSortable(true);
|
|
cellTable.addColumn(textColumn, column);
|
|
|
|
ListHandler<T> textColumnHandler = new ListHandler<>(dataProvider.getList());
|
|
textColumnHandler.setComparator(textColumn, 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);
|
|
}
|
|
});
|
|
|
|
cellTable.addColumnSortHandler(textColumnHandler);
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
};
|
|
|
|
showGcubeInfoClm.setSortable(false);
|
|
cellTable.addColumn(showGcubeInfoClm, "");
|
|
cellTable.setColumnWidth(showGcubeInfoClm, 32.0, Unit.PX);
|
|
}
|
|
|
|
/*final SingleSelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
|
|
selectionModel.addSelectionChangeHandler(new Handler() {
|
|
@Override
|
|
public void onSelectionChange(SelectionChangeEvent event) {
|
|
}
|
|
});*/
|
|
}
|
|
|
|
/**
|
|
* 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 = cellTable.getColumnCount();
|
|
for(int i=0;i<count;i++){
|
|
cellTable.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();
|
|
}
|
|
}
|