Fixed ListStore error retrieving rows
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-import-widget@101892 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0fa9510640
commit
c0672895c5
|
@ -8,7 +8,7 @@ import java.util.ArrayList;
|
|||
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;
|
||||
|
||||
import org.gcube.portlets.user.td.wizardwidget.client.util.UtilsGXT3;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
|
@ -26,28 +26,28 @@ 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>
|
||||
* @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";
|
||||
|
||||
private static final String csvImportFileServlet = "CSVImportFileServlet";
|
||||
protected CSVGridView gridViewSample;
|
||||
|
||||
public CSVGrid()
|
||||
{
|
||||
super(new ListStore<CSVRow>(new CSVRowKeyProvider()), new ColumnModel<CSVRow>(new ArrayList<ColumnConfig<CSVRow,?>>()));
|
||||
public CSVGrid() {
|
||||
super(new ListStore<CSVRow>(new CSVRowKeyProvider()),
|
||||
new ColumnModel<CSVRow>(
|
||||
new ArrayList<ColumnConfig<CSVRow, ?>>()));
|
||||
|
||||
setHeight(200);
|
||||
setHeight(200);
|
||||
setBorders(true);
|
||||
|
||||
getView().setStripeRows(true);
|
||||
setLoadMask(true);
|
||||
|
||||
|
||||
gridViewSample = new CSVGridView();
|
||||
setView(gridViewSample);
|
||||
|
||||
|
@ -55,49 +55,61 @@ public class CSVGrid extends Grid<CSVRow> {
|
|||
setBorders(true);
|
||||
}
|
||||
|
||||
public void configureColumns(ArrayList<String> columnNames)
|
||||
{
|
||||
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);
|
||||
protected ListStore<CSVRow> createStore(ArrayList<String> columnNames) {
|
||||
ListStore<CSVRow> store=null;
|
||||
|
||||
HttpProxy<ListLoadConfig> proxy = new HttpProxy<ListLoadConfig>(builder);
|
||||
try {
|
||||
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();
|
||||
// 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);
|
||||
|
||||
final ListLoader<ListLoadConfig, ListLoadResult<CSVRow>> loader = new ListLoader<ListLoadConfig, ListLoadResult<CSVRow>>(proxy, reader);
|
||||
store = new ListStore<CSVRow>(
|
||||
new CSVRowKeyProvider());
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, CSVRow, ListLoadResult<CSVRow>>(
|
||||
store));
|
||||
|
||||
ListStore<CSVRow> store = new ListStore<CSVRow>(new CSVRowKeyProvider());
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, CSVRow, ListLoadResult<CSVRow>>(store));
|
||||
loader.load();
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
UtilsGXT3.alert("Error","Error creating the store: "+e.getLocalizedMessage());
|
||||
Log.error("Error in creating the store: "+e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
loader.load();
|
||||
|
||||
return store;
|
||||
|
||||
}
|
||||
|
||||
protected ColumnModel<CSVRow> createColumnModel(ArrayList<String> columnNames)
|
||||
{
|
||||
ArrayList<ColumnConfig<CSVRow, ?>> columns = new ArrayList<ColumnConfig<CSVRow, ?>>();
|
||||
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);
|
||||
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);
|
||||
ColumnConfig<CSVRow, String> columnConfig = new ColumnConfig<CSVRow, String>(
|
||||
new CSVRowValueProvider(columnField), 100, columnName);
|
||||
columns.add(columnConfig);
|
||||
}
|
||||
|
||||
|
@ -106,20 +118,22 @@ public class CSVGrid extends Grid<CSVRow> {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return an array of boolean where the item is <code>true</code> if the
|
||||
* column have to be imported, <code>false</code> otherwise.
|
||||
*/
|
||||
public ArrayList<Boolean> getImportColumnsMask()
|
||||
{
|
||||
//boolean[] columnMask = new boolean[getColumnModel().getColumnCount()];
|
||||
int limit=getColumnModel().getColumnCount();
|
||||
ArrayList<Boolean> columnMask= new ArrayList<Boolean>();
|
||||
public ArrayList<Boolean> getImportColumnsMask() {
|
||||
// boolean[] columnMask = new
|
||||
// boolean[getColumnModel().getColumnCount()];
|
||||
int limit = getColumnModel().getColumnCount();
|
||||
ArrayList<Boolean> columnMask = new ArrayList<Boolean>();
|
||||
ArrayList<Integer> excluded = gridViewSample.getExcludedColumns();
|
||||
for (int i = 1; i<limit; i++) {
|
||||
//columnMask[i] = !excluded.contains(i);
|
||||
Boolean b=!excluded.contains(i);
|
||||
for (int i = 1; i < limit; i++) {
|
||||
// columnMask[i] = !excluded.contains(i);
|
||||
Boolean b = !excluded.contains(i);
|
||||
columnMask.add(b);
|
||||
}
|
||||
Log.debug("Column Mask: "+columnMask);
|
||||
Log.debug("Column Mask: " + columnMask);
|
||||
return columnMask;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,14 +21,15 @@ public final class CSVRow extends JavaScriptObject {
|
|||
*/
|
||||
public String getId() {
|
||||
//FIXME
|
||||
return getField("Id");
|
||||
|
||||
return getField("id");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public native String getField(String column)
|
||||
/*-{
|
||||
return this[column];
|
||||
return this[column].toString();
|
||||
}-*/;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue