diff --git a/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/csvgrid/CSVGrid.java b/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/csvgrid/CSVGrid.java index 9fdd906..7815d5d 100644 --- a/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/csvgrid/CSVGrid.java +++ b/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/csvgrid/CSVGrid.java @@ -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" - * g.panichi@isti.cnr.it + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it * */ public class CSVGrid extends Grid { - - private static final String csvImportFileServlet="CSVImportFileServlet"; + + private static final String csvImportFileServlet = "CSVImportFileServlet"; protected CSVGridView gridViewSample; - public CSVGrid() - { - super(new ListStore(new CSVRowKeyProvider()), new ColumnModel(new ArrayList>())); + public CSVGrid() { + super(new ListStore(new CSVRowKeyProvider()), + new ColumnModel( + new ArrayList>())); - 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 { setBorders(true); } - public void configureColumns(ArrayList columnNames) - { + public void configureColumns(ArrayList columnNames) { ColumnModel columnModel = createColumnModel(columnNames); ListStore store = createStore(columnNames); reconfigure(store, columnModel); getView().refresh(true); } - protected ListStore createStore(ArrayList 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 createStore(ArrayList columnNames) { + ListStore store=null; - HttpProxy proxy = new HttpProxy(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 proxy = new HttpProxy( + builder); - // need a loader, proxy, and reader - DataReader, String> reader = new CSVJsonReader(); + // need a loader, proxy, and reader + DataReader, String> reader = new CSVJsonReader(); + final ListLoader> loader = new ListLoader>( + proxy, reader); - final ListLoader> loader = new ListLoader>(proxy, reader); + store = new ListStore( + new CSVRowKeyProvider()); + loader.addLoadHandler(new LoadResultListStoreBinding>( + store)); - ListStore store = new ListStore(new CSVRowKeyProvider()); - loader.addLoadHandler(new LoadResultListStoreBinding>(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 createColumnModel(ArrayList columnNames) - { - ArrayList> columns = new ArrayList>(); + protected ColumnModel createColumnModel( + ArrayList columnNames) { + ArrayList> columns = new ArrayList>(); columns.add(new RowNumberer(new IdentityValueProvider())); - for (int i = 0; i columnConfig = new ColumnConfig(new CSVRowValueProvider(columnField), 100, columnName); + ColumnConfig columnConfig = new ColumnConfig( + new CSVRowValueProvider(columnField), 100, columnName); columns.add(columnConfig); } @@ -106,20 +118,22 @@ public class CSVGrid extends Grid { /** * Returns the import column mask. - * @return an array of boolean where the item is true if the column have to be imported, false otherwise. + * + * @return an array of boolean where the item is true if the + * column have to be imported, false otherwise. */ - public ArrayList getImportColumnsMask() - { - //boolean[] columnMask = new boolean[getColumnModel().getColumnCount()]; - int limit=getColumnModel().getColumnCount(); - ArrayList columnMask= new ArrayList(); + public ArrayList getImportColumnsMask() { + // boolean[] columnMask = new + // boolean[getColumnModel().getColumnCount()]; + int limit = getColumnModel().getColumnCount(); + ArrayList columnMask = new ArrayList(); ArrayList excluded = gridViewSample.getExcludedColumns(); - for (int i = 1; i