181 lines
4.8 KiB
Java
181 lines
4.8 KiB
Java
package org.gcube.portlets.widgets.wsexplorer.client.grid;
|
|
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.resources.CellTableResources;
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
|
|
|
import com.github.gwtbootstrap.client.ui.CellTable;
|
|
import com.github.gwtbootstrap.client.ui.Pagination;
|
|
import com.google.gwt.core.shared.GWT;
|
|
import com.google.gwt.event.dom.client.DoubleClickEvent;
|
|
import com.google.gwt.event.dom.client.DoubleClickHandler;
|
|
import com.google.gwt.user.cellview.client.AbstractCellTable;
|
|
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
|
|
import com.google.gwt.user.cellview.client.SimplePager;
|
|
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
|
|
*/
|
|
public abstract class AbstractItemsCellTable {
|
|
|
|
protected CellTable<Item> cellTable;
|
|
protected ListDataProvider<Item> dataProvider = new ListDataProvider<Item>();
|
|
protected boolean showGroupId;
|
|
|
|
/**
|
|
* Inits the table.
|
|
*
|
|
* @param ItemTable
|
|
* the Item table
|
|
* @param pager
|
|
* the pager
|
|
* @param pagination
|
|
* the pagination
|
|
*/
|
|
public abstract void initTable(AbstractCellTable<Item> ItemTable,
|
|
final SimplePager pager, final Pagination pagination);
|
|
|
|
/**
|
|
* Instantiates a new abstract Item table.
|
|
*
|
|
* @param showGroupId
|
|
* the show group id
|
|
*/
|
|
public AbstractItemsCellTable(boolean showGroupId) {
|
|
this.showGroupId = showGroupId;
|
|
cellTable = new CellTable<Item>(1, CellTableResources.INSTANCE);
|
|
cellTable.addStyleName("table-overflow");
|
|
cellTable.setStriped(true);
|
|
cellTable.setBordered(true);
|
|
// cellTable.setCondensed(true);
|
|
cellTable.setWidth("98%", true);
|
|
dataProvider.addDataDisplay(cellTable);
|
|
initTable(cellTable, null, null);
|
|
cellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
|
|
|
|
final SingleSelectionModel<Item> ssm = new SingleSelectionModel<Item>();
|
|
cellTable.setSelectionModel(ssm);
|
|
ssm.addSelectionChangeHandler(new Handler() {
|
|
@Override
|
|
public void onSelectionChange(final SelectionChangeEvent event)
|
|
{
|
|
final Item selectedObject = ssm.getSelectedObject();
|
|
GWT.log("Clicked: "+selectedObject);
|
|
}
|
|
});
|
|
|
|
cellTable.addDomHandler(new DoubleClickHandler() {
|
|
|
|
@Override
|
|
public void onDoubleClick(final DoubleClickEvent event) {
|
|
Item selected = ssm.getSelectedObject();
|
|
if (selected != null) {
|
|
GWT.log("Double Click: "+selected);
|
|
}
|
|
}
|
|
},
|
|
DoubleClickEvent.getType());
|
|
/*
|
|
cellTable.addCellPreviewHandler(new CellPreviewEvent.Handler<Item> () {
|
|
long lastClick=-1000;
|
|
|
|
@Override
|
|
public void onCellPreview(CellPreviewEvent<Item> event) {
|
|
long clictAt = System.currentTimeMillis();
|
|
GWT.log("clickAt: "+(clictAt));
|
|
GWT.log("lastClick: "+(lastClick));
|
|
if(event.getNativeEvent().getType().contains("click")){
|
|
GWT.log(""+(clictAt-lastClick));
|
|
if(clictAt-lastClick < 300) { // dblclick on 2 clicks detected within 300 ms
|
|
Window.alert("I am a double click crafted event!");
|
|
}
|
|
lastClick = System.currentTimeMillis();
|
|
}
|
|
|
|
}
|
|
}); */
|
|
}
|
|
|
|
/**
|
|
* Adds the Items.
|
|
*
|
|
* @param Items
|
|
* the Items
|
|
*/
|
|
public void addItems(List<Item> Items) {
|
|
dataProvider.getList().clear();
|
|
|
|
for (Item pckg : Items)
|
|
addItem(pckg);
|
|
|
|
cellTable.setPageSize(Items.size() + 1);
|
|
cellTable.redraw();
|
|
}
|
|
|
|
/**
|
|
* Adds the Item.
|
|
*
|
|
* @param pckg
|
|
* the pckg
|
|
*/
|
|
private void addItem(Item pckg) {
|
|
dataProvider.getList().add(pckg);
|
|
dataProvider.flush();
|
|
dataProvider.refresh();
|
|
}
|
|
|
|
/**
|
|
* Gets the cell tables.
|
|
*
|
|
* @return the cell tables
|
|
*/
|
|
public CellTable<Item> getCellTable() {
|
|
return cellTable;
|
|
}
|
|
|
|
/**
|
|
* Gets the data provider.
|
|
*
|
|
* @return the data provider
|
|
*/
|
|
public ListDataProvider<Item> getDataProvider() {
|
|
return dataProvider;
|
|
}
|
|
|
|
/**
|
|
* Checks if is show group id.
|
|
*
|
|
* @return true, if is show group id
|
|
*/
|
|
public boolean isShowGroupId() {
|
|
return showGroupId;
|
|
}
|
|
|
|
/**
|
|
* Sets the data provider.
|
|
*
|
|
* @param dataProvider
|
|
* the new data provider
|
|
*/
|
|
public void setDataProvider(ListDataProvider<Item> dataProvider) {
|
|
this.dataProvider = dataProvider;
|
|
}
|
|
|
|
/**
|
|
* Sets the show group id.
|
|
*
|
|
* @param showGroupId
|
|
* the new show group id
|
|
*/
|
|
public void setShowGroupId(boolean showGroupId) {
|
|
this.showGroupId = showGroupId;
|
|
}
|
|
}
|