90 lines
2.4 KiB
Java
90 lines
2.4 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.td.csvimportwidget.client.csvgrid;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.gcube.portlets.user.td.csvimportwidget.client.data.CSVRow;
|
|
import org.gcube.portlets.user.td.csvimportwidget.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 "Giancarlo Panichi"
|
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class CSVGridView extends GridView<CSVRow> {
|
|
|
|
protected ArrayList<Integer> excludedColumns = new ArrayList<Integer>();
|
|
|
|
public CSVGridView()
|
|
{
|
|
setViewConfig(new GridViewConfig<CSVRow>() {
|
|
|
|
|
|
public String getRowStyle(CSVRow model, int rowIndex) {
|
|
return "";
|
|
}
|
|
|
|
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>() {
|
|
|
|
|
|
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>() {
|
|
|
|
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;
|
|
}
|
|
|
|
}
|