2013-10-24 14:58:56 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-10-24 15:15:43 +02:00
|
|
|
package org.gcube.portlets.user.td.csvimportwidget.client.csvgrid;
|
2013-10-24 14:58:56 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2013-10-24 15:32:03 +02:00
|
|
|
import org.gcube.portlets.user.td.csvimportwidget.client.data.CSVRow;
|
|
|
|
import org.gcube.portlets.user.td.csvimportwidget.client.data.CSVRowKeyProvider;
|
|
|
|
import org.gcube.portlets.user.td.csvimportwidget.client.data.CSVRowValueProvider;
|
2013-10-24 14:58:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.http.client.RequestBuilder;
|
|
|
|
import com.sencha.gxt.core.client.IdentityValueProvider;
|
|
|
|
import com.sencha.gxt.data.client.loader.HttpProxy;
|
|
|
|
import com.sencha.gxt.data.shared.ListStore;
|
|
|
|
import com.sencha.gxt.data.shared.loader.DataReader;
|
|
|
|
import com.sencha.gxt.data.shared.loader.ListLoadConfig;
|
|
|
|
import com.sencha.gxt.data.shared.loader.ListLoadResult;
|
|
|
|
import com.sencha.gxt.data.shared.loader.ListLoader;
|
|
|
|
import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding;
|
|
|
|
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
|
|
|
|
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
|
|
|
|
import com.sencha.gxt.widget.core.client.grid.Grid;
|
|
|
|
import com.sencha.gxt.widget.core.client.grid.RowNumberer;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author "Giancarlo Panichi"
|
|
|
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class CSVGrid extends Grid<CSVRow> {
|
|
|
|
|
|
|
|
private static final String csvImportFileServlet="CSVImportFileServlet";
|
|
|
|
protected CSVGridView gridViewSample;
|
|
|
|
|
|
|
|
public CSVGrid()
|
|
|
|
{
|
|
|
|
super(new ListStore<CSVRow>(new CSVRowKeyProvider()), new ColumnModel<CSVRow>(new ArrayList<ColumnConfig<CSVRow,?>>()));
|
|
|
|
|
|
|
|
setHeight(200);
|
|
|
|
setBorders(true);
|
|
|
|
|
|
|
|
getView().setStripeRows(true);
|
|
|
|
setLoadMask(true);
|
|
|
|
|
|
|
|
gridViewSample = new CSVGridView();
|
|
|
|
setView(gridViewSample);
|
|
|
|
|
|
|
|
getView().setEmptyText("No data to show");
|
|
|
|
setBorders(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void configureColumns(ArrayList<String> columnNames)
|
|
|
|
{
|
|
|
|
ColumnModel<CSVRow> columnModel = createColumnModel(columnNames);
|
|
|
|
ListStore<CSVRow> store = createStore(columnNames);
|
|
|
|
reconfigure(store, columnModel);
|
|
|
|
getView().refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected ListStore<CSVRow> createStore(ArrayList<String> columnNames)
|
|
|
|
{
|
|
|
|
String path = GWT.getModuleBaseURL()+csvImportFileServlet;
|
|
|
|
Log.info("CSVImportFileServlet path:"+path);
|
|
|
|
// use a http proxy to get the data
|
|
|
|
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
|
|
|
|
|
|
|
HttpProxy<ListLoadConfig> proxy = new HttpProxy<ListLoadConfig>(builder);
|
|
|
|
|
|
|
|
|
|
|
|
// need a loader, proxy, and reader
|
|
|
|
DataReader<ListLoadResult<CSVRow>, String> reader = new CSVJsonReader();
|
|
|
|
|
|
|
|
|
|
|
|
final ListLoader<ListLoadConfig, ListLoadResult<CSVRow>> loader = new ListLoader<ListLoadConfig, ListLoadResult<CSVRow>>(proxy, reader);
|
|
|
|
|
|
|
|
ListStore<CSVRow> store = new ListStore<CSVRow>(new CSVRowKeyProvider());
|
|
|
|
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, CSVRow, ListLoadResult<CSVRow>>(store));
|
|
|
|
|
|
|
|
loader.load();
|
|
|
|
|
|
|
|
return store;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected ColumnModel<CSVRow> createColumnModel(ArrayList<String> columnNames)
|
|
|
|
{
|
|
|
|
ArrayList<ColumnConfig<CSVRow, ?>> columns = new ArrayList<ColumnConfig<CSVRow, ?>>();
|
|
|
|
|
|
|
|
columns.add(new RowNumberer<CSVRow>(new IdentityValueProvider<CSVRow>()));
|
|
|
|
|
|
|
|
for (int i = 0; i<columnNames.size(); i++) {
|
|
|
|
String columnField = "field"+(i+1);
|
|
|
|
String columnName = columnNames.get(i);
|
|
|
|
ColumnConfig<CSVRow, String> columnConfig = new ColumnConfig<CSVRow, String>(new CSVRowValueProvider(columnField), 100, columnName);
|
|
|
|
columns.add(columnConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ColumnModel<CSVRow>(columns);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the import column mask.
|
|
|
|
* @return an array of boolean where the item is <code>true</code> if the column have to be imported, <code>false</code> otherwise.
|
|
|
|
*/
|
2014-04-01 12:33:17 +02:00
|
|
|
public ArrayList<Boolean> getImportColumnsMask()
|
2013-10-24 14:58:56 +02:00
|
|
|
{
|
2014-04-01 12:33:17 +02:00
|
|
|
//boolean[] columnMask = new boolean[getColumnModel().getColumnCount()];
|
|
|
|
int limit=getColumnModel().getColumnCount();
|
|
|
|
ArrayList<Boolean> columnMask= new ArrayList<Boolean>();
|
2013-10-24 14:58:56 +02:00
|
|
|
ArrayList<Integer> excluded = gridViewSample.getExcludedColumns();
|
2014-04-01 15:30:27 +02:00
|
|
|
for (int i = 1; i<limit; i++) {
|
2014-04-01 12:33:17 +02:00
|
|
|
//columnMask[i] = !excluded.contains(i);
|
|
|
|
Boolean b=!excluded.contains(i);
|
|
|
|
columnMask.add(b);
|
|
|
|
}
|
2014-04-01 15:30:27 +02:00
|
|
|
Log.debug("Column Mask: "+columnMask);
|
2013-10-24 14:58:56 +02:00
|
|
|
return columnMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|