git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-import-widget@84042 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
683c3dda24
commit
68d0e99c39
|
@ -1,119 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.csvimportwizardtd.client.csvgrid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRow;
|
||||
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRowKeyProvider;
|
||||
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRowValueProvider;
|
||||
|
||||
|
||||
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.
|
||||
*/
|
||||
public boolean[] getImportColumnsMask()
|
||||
{
|
||||
boolean[] columnMask = new boolean[getColumnModel().getColumnCount()];
|
||||
ArrayList<Integer> excluded = gridViewSample.getExcludedColumns();
|
||||
for (int i = 0; i<columnMask.length; i++) columnMask[i] = !excluded.contains(i);
|
||||
return columnMask;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.csvimportwizardtd.client.csvgrid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRow;
|
||||
import org.gcube.portlets.user.csvimportwizardtd.client.dataresource.ResourceBundle;
|
||||
|
||||
import com.google.gwt.event.logical.shared.SelectionEvent;
|
||||
import com.google.gwt.event.logical.shared.SelectionHandler;
|
||||
import com.sencha.gxt.core.client.ValueProvider;
|
||||
import com.sencha.gxt.widget.core.client.grid.GridView;
|
||||
import com.sencha.gxt.widget.core.client.grid.GridViewConfig;
|
||||
import com.sencha.gxt.widget.core.client.menu.CheckMenuItem;
|
||||
import com.sencha.gxt.widget.core.client.menu.Item;
|
||||
import com.sencha.gxt.widget.core.client.menu.Menu;
|
||||
|
||||
/**
|
||||
* @author Federico De Faveri defaveri@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public class CSVGridView extends GridView<CSVRow> {
|
||||
|
||||
protected ArrayList<Integer> excludedColumns = new ArrayList<Integer>();
|
||||
|
||||
public CSVGridView()
|
||||
{
|
||||
setViewConfig(new GridViewConfig<CSVRow>() {
|
||||
|
||||
@Override
|
||||
public String getRowStyle(CSVRow model, int rowIndex) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColStyle(CSVRow model, ValueProvider<? super CSVRow, ?> valueProvider, int rowIndex, int colIndex) {
|
||||
return excludedColumns.contains(colIndex)?ResourceBundle.INSTANCE.importCss().getColumnExcluded():"";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Menu createContextMenu(final int colIndex) {
|
||||
Menu menu = new Menu();
|
||||
|
||||
CheckMenuItem includeMenu = new CheckMenuItem("Include");
|
||||
includeMenu.setGroup("include");
|
||||
includeMenu.setChecked(!excludedColumns.contains(colIndex));
|
||||
menu.add(includeMenu);
|
||||
|
||||
includeMenu.addSelectionHandler(new SelectionHandler<Item>() {
|
||||
|
||||
@Override
|
||||
public void onSelection(SelectionEvent<Item> event) {
|
||||
excludedColumns.remove(new Integer(colIndex));
|
||||
refresh(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
CheckMenuItem excludeMenu = new CheckMenuItem("Exclude");
|
||||
excludeMenu.setGroup("include");
|
||||
excludeMenu.setChecked(excludedColumns.contains(colIndex));
|
||||
menu.add(excludeMenu);
|
||||
|
||||
excludeMenu.addSelectionHandler(new SelectionHandler<Item>() {
|
||||
|
||||
@Override
|
||||
public void onSelection(SelectionEvent<Item> event) {
|
||||
excludedColumns.add(colIndex);
|
||||
refresh(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the excluded columns by index.
|
||||
* @return an {@link ArrayList} of excluded column index.
|
||||
*/
|
||||
public ArrayList<Integer> getExcludedColumns() {
|
||||
return excludedColumns;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.csvimportwizardtd.client.csvgrid;
|
||||
|
||||
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVData;
|
||||
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRow;
|
||||
|
||||
import com.sencha.gxt.data.shared.loader.DataReader;
|
||||
import com.sencha.gxt.data.shared.loader.ListLoadResult;
|
||||
import com.sencha.gxt.data.shared.loader.ListLoadResultBean;
|
||||
|
||||
/**
|
||||
* @author "Federico De Faveri defaveri@isti.cnr.it"
|
||||
*
|
||||
*/
|
||||
public class CSVJsonReader implements DataReader<ListLoadResult<CSVRow>, String> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ListLoadResult<CSVRow> read(Object loadConfig, String json) {
|
||||
CSVData data = CSVData.getCSVData(json);
|
||||
return new ListLoadResultBean<CSVRow>(data.getRows());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue