tabular-data-csv-import-widget/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/CSVErrorWindow.java

92 lines
2.6 KiB
Java

package org.gcube.portlets.user.td.csvimportwidget.client;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError;
import com.google.gwt.core.client.GWT;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.data.shared.PropertyAccess;
import com.sencha.gxt.widget.core.client.Window;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
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;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CSVErrorWindow extends Window {
private static final CSVRowErrorProperties props = GWT.create(CSVRowErrorProperties.class);
protected Grid<CSVRowError> grid;
protected ListStore<CSVRowError> store;
public CSVErrorWindow()
{
setHeadingText("CSV error details");
setModal(true);
setBlinkModal(true);
setWidth(600);
setHeight(350);
createGrid();
add(grid);
TextButton close = new TextButton("Close");
close.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
hide();
}
});
addButton(close);
setButtonAlign(BoxLayoutPack.CENTER);
}
protected void createGrid()
{
ArrayList<ColumnConfig<CSVRowError, ?>> columns = new ArrayList<ColumnConfig<CSVRowError, ?>>();
columns.add(new ColumnConfig<CSVRowError, Integer>(props.lineNumber(), 30, "# line"));
columns.add(new ColumnConfig<CSVRowError, String>(props.lineValue(), 60, "Line"));
columns.add(new ColumnConfig<CSVRowError, String>(props.errorDescription(), 160, "Error"));
ColumnModel<CSVRowError> columnModel = new ColumnModel<CSVRowError>(columns);
store = new ListStore<CSVRowError>(props.id());
grid = new Grid<CSVRowError>(store, columnModel);
grid.getView().setForceFit(true);
}
public void updateGrid(ArrayList<CSVRowError> errors)
{
store.clear();
store.addAll(errors);
}
protected interface CSVRowErrorProperties extends PropertyAccess<CSVRowError> {
ModelKeyProvider<CSVRowError> id();
ValueProvider<CSVRowError, Integer> lineNumber();
ValueProvider<CSVRowError, String> lineValue();
ValueProvider<CSVRowError, String> errorDescription();
}
}