From 68d0e99c39492085e2f7eecaf19993dcc157c704 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 24 Oct 2013 13:16:16 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-import-widget@84042 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/csvgrid/CSVGrid.java | 119 ------------------ .../client/csvgrid/CSVGridView.java | 89 ------------- .../client/csvgrid/CSVJsonReader.java | 27 ---- 3 files changed, 235 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVGrid.java delete mode 100644 src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVGridView.java delete mode 100644 src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVJsonReader.java diff --git a/src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVGrid.java b/src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVGrid.java deleted file mode 100644 index 8d8c37a..0000000 --- a/src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVGrid.java +++ /dev/null @@ -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" - * g.panichi@isti.cnr.it - * - */ -public class CSVGrid extends Grid { - - private static final String csvImportFileServlet="CSVImportFileServlet"; - protected CSVGridView gridViewSample; - - public CSVGrid() - { - super(new ListStore(new CSVRowKeyProvider()), new ColumnModel(new ArrayList>())); - - 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 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); - - HttpProxy proxy = new HttpProxy(builder); - - - // need a loader, proxy, and reader - DataReader, String> reader = new CSVJsonReader(); - - - final ListLoader> loader = new ListLoader>(proxy, reader); - - ListStore store = new ListStore(new CSVRowKeyProvider()); - loader.addLoadHandler(new LoadResultListStoreBinding>(store)); - - loader.load(); - - return store; - - } - - 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); - columns.add(columnConfig); - } - - return new ColumnModel(columns); - } - - /** - * Returns the import column mask. - * @return an array of boolean where the item is true if the column have to be imported, false otherwise. - */ - public boolean[] getImportColumnsMask() - { - boolean[] columnMask = new boolean[getColumnModel().getColumnCount()]; - ArrayList excluded = gridViewSample.getExcludedColumns(); - for (int i = 0; i { - - protected ArrayList excludedColumns = new ArrayList(); - - public CSVGridView() - { - setViewConfig(new GridViewConfig() { - - @Override - public String getRowStyle(CSVRow model, int rowIndex) { - return ""; - } - - @Override - public String getColStyle(CSVRow model, ValueProvider 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() { - - @Override - public void onSelection(SelectionEvent 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() { - - @Override - public void onSelection(SelectionEvent event) { - excludedColumns.add(colIndex); - refresh(false); - } - }); - - - return menu; - } - - /** - * Returns the excluded columns by index. - * @return an {@link ArrayList} of excluded column index. - */ - public ArrayList getExcludedColumns() { - return excludedColumns; - } - -} diff --git a/src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVJsonReader.java b/src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVJsonReader.java deleted file mode 100644 index ee5496e..0000000 --- a/src/main/java/org/gcube/portlets/user/csvimportwizardtd/client/csvgrid/CSVJsonReader.java +++ /dev/null @@ -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, String> { - - /** - * {@inheritDoc} - */ - @Override - public ListLoadResult read(Object loadConfig, String json) { - CSVData data = CSVData.getCSVData(json); - return new ListLoadResultBean(data.getRows()); - } -}