Added CSVExportConfigCard
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-export-widget@86353 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7501bda5cb
commit
7fd317f079
|
@ -0,0 +1,138 @@
|
|||
package org.gcube.portlets.user.csvexportwidget.client.grid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.Scheduler;
|
||||
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
||||
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
|
||||
import com.google.gwt.event.logical.shared.SelectionHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.sencha.gxt.core.client.IdentityValueProvider;
|
||||
import com.sencha.gxt.data.client.loader.RpcProxy;
|
||||
import com.sencha.gxt.data.shared.ListStore;
|
||||
import com.sencha.gxt.data.shared.loader.ListLoadConfig;
|
||||
import com.sencha.gxt.data.shared.loader.ListLoadResult;
|
||||
import com.sencha.gxt.data.shared.loader.ListLoadResultBean;
|
||||
import com.sencha.gxt.data.shared.loader.ListLoader;
|
||||
import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding;
|
||||
import com.sencha.gxt.widget.core.client.ContentPanel;
|
||||
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
||||
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
||||
import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;
|
||||
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;
|
||||
|
||||
public class ColumnDataGridPanel extends ContentPanel implements HasSelectionHandlers<ColumnData> {
|
||||
private static final ColumnDataProperties props = GWT
|
||||
.create(ColumnDataProperties.class);
|
||||
|
||||
protected final Grid<ColumnData> grid;
|
||||
|
||||
public ColumnDataGridPanel() {
|
||||
|
||||
ColumnConfig<ColumnData, String> nameCol = new ColumnConfig<ColumnData, String>(
|
||||
props.name());
|
||||
ColumnConfig<ColumnData, String> typeNameCol = new ColumnConfig<ColumnData, String>(
|
||||
props.typeName());
|
||||
ColumnConfig<ColumnData, String> typeCodeCol = new ColumnConfig<ColumnData, String>(
|
||||
props.typeCode());
|
||||
|
||||
|
||||
List<ColumnConfig<ColumnData, ?>> l = new ArrayList<ColumnConfig<ColumnData, ?>>();
|
||||
l.add(nameCol);
|
||||
l.add(typeNameCol);
|
||||
l.add(typeCodeCol);
|
||||
ColumnModel<ColumnData> cm = new ColumnModel<ColumnData>(l);
|
||||
|
||||
IdentityValueProvider<ColumnData> identity = new IdentityValueProvider<ColumnData>();
|
||||
|
||||
|
||||
final CheckBoxSelectionModel<ColumnData> sm = new CheckBoxSelectionModel<ColumnData>(identity);
|
||||
|
||||
|
||||
ListStore<ColumnData> store = new ListStore<ColumnData>(
|
||||
props.id());
|
||||
|
||||
RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>>() {
|
||||
|
||||
public void load(ListLoadConfig loadConfig, final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
||||
loadData(loadConfig, callback);
|
||||
}
|
||||
};
|
||||
final ListLoader<ListLoadConfig, ListLoadResult<ColumnData>> loader = new ListLoader<ListLoadConfig, ListLoadResult<ColumnData>>(proxy);
|
||||
|
||||
loader.setRemoteSort(false);
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig,ColumnData , ListLoadResult<ColumnData>>(store){
|
||||
|
||||
});
|
||||
|
||||
|
||||
grid = new Grid<ColumnData>(store, cm){
|
||||
@Override
|
||||
protected void onAfterFirstAttach() {
|
||||
super.onAfterFirstAttach();
|
||||
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
loader.load();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
grid.setLoader(loader);
|
||||
grid.setSelectionModel(sm);
|
||||
grid.getView().setAutoExpandColumn(nameCol);
|
||||
grid.getView().setStripeRows(true);
|
||||
grid.getView().setColumnLines(true);
|
||||
grid.setBorders(false);
|
||||
|
||||
VerticalLayoutContainer con = new VerticalLayoutContainer();
|
||||
con.add(grid, new VerticalLayoutData(1, 1));
|
||||
setWidget(con);
|
||||
|
||||
}
|
||||
|
||||
public Grid<ColumnData> getGrid() {
|
||||
return grid;
|
||||
}
|
||||
|
||||
protected void loadData(ListLoadConfig loadConfig, final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
||||
TDGWTServiceAsync.INSTANCE.getColumns(new AsyncCallback<ArrayList<ColumnData>>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
Log.error("No load columns: "+caught.getLocalizedMessage());
|
||||
callback.onFailure(caught);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(ArrayList<ColumnData> result) {
|
||||
Log.trace("loaded "+result.size()+" columns");
|
||||
callback.onSuccess(new ListLoadResultBean<ColumnData>(result));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public List<ColumnData> getSelectedItems() {
|
||||
return grid.getSelectionModel().getSelectedItems();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addSelectionHandler(SelectionHandler<ColumnData> handler) {
|
||||
return grid.getSelectionModel().addSelectionHandler(handler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.portlets.user.csvexportwidget.client.grid;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
|
||||
import com.google.gwt.editor.client.Editor.Path;
|
||||
import com.sencha.gxt.core.client.ValueProvider;
|
||||
import com.sencha.gxt.data.shared.ModelKeyProvider;
|
||||
import com.sencha.gxt.data.shared.PropertyAccess;
|
||||
|
||||
public interface ColumnDataProperties extends
|
||||
PropertyAccess<ColumnData> {
|
||||
|
||||
@Path("id")
|
||||
ModelKeyProvider<ColumnData> id();
|
||||
|
||||
ValueProvider<ColumnData, String> name();
|
||||
|
||||
ValueProvider<ColumnData, String> typeName();
|
||||
|
||||
ValueProvider<ColumnData, String> typeCode();
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
package org.gcube.portlets.user.td.csvexportwidget.client;
|
||||
|
||||
|
||||
import org.gcube.portlets.user.csvexportwidget.client.grid.ColumnDataGridPanel;
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
||||
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.logical.shared.SelectionEvent;
|
||||
import com.google.gwt.event.logical.shared.SelectionHandler;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.user.client.Command;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.HasValue;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
|
||||
import com.sencha.gxt.core.client.util.Padding;
|
||||
import com.sencha.gxt.core.client.util.ToggleGroup;
|
||||
import com.sencha.gxt.data.shared.StringLabelProvider;
|
||||
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
||||
import com.sencha.gxt.widget.core.client.form.FieldLabel;
|
||||
import com.sencha.gxt.widget.core.client.form.FormPanel;
|
||||
import com.sencha.gxt.widget.core.client.form.Radio;
|
||||
import com.sencha.gxt.widget.core.client.form.SimpleComboBox;
|
||||
import com.sencha.gxt.widget.core.client.form.TextField;
|
||||
import com.sencha.gxt.widget.core.client.tips.ToolTip;
|
||||
import com.sencha.gxt.widget.core.client.tips.ToolTipConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class CSVExportConfigCard extends WizardCard {
|
||||
|
||||
private static final String DEFAULT_DELIMETER = ",";
|
||||
protected CSVExportSession csvExportSession;
|
||||
|
||||
protected SimpleComboBox<String> encodings;
|
||||
protected TextField customDelimiterField;
|
||||
protected Radio otherDelimiter;
|
||||
protected Radio commaDelimiter;
|
||||
protected Radio spaceDelimiter;
|
||||
protected Radio tabDelimiter;
|
||||
protected Radio semicoloDelimiter;
|
||||
|
||||
protected ColumnDataGridPanel csvColumnGridPanel;
|
||||
|
||||
public CSVExportConfigCard(final CSVExportSession csvExportSession) {
|
||||
super("CSV configuration", "");
|
||||
if (csvExportSession == null) {
|
||||
Log.error("CSVExportSession is null");
|
||||
}
|
||||
this.csvExportSession = csvExportSession;
|
||||
|
||||
FormPanel panel = createPanel();
|
||||
setContent(panel);
|
||||
|
||||
}
|
||||
|
||||
protected FormPanel createPanel() {
|
||||
FormPanel panel = new FormPanel();
|
||||
panel.setLabelWidth(90);
|
||||
panel.getElement().setPadding(new Padding(5));
|
||||
|
||||
VerticalLayoutContainer content = new VerticalLayoutContainer();
|
||||
panel.add(content);
|
||||
|
||||
encodings = new SimpleComboBox<String>(
|
||||
new StringLabelProvider<String>());
|
||||
encodings.setToolTip("The CSV file encoding");
|
||||
encodings.setTabIndex(0);
|
||||
encodings.setEditable(false);
|
||||
encodings.setForceSelection(true);
|
||||
encodings.setTriggerAction(TriggerAction.ALL);
|
||||
encodings.addSelectionHandler(new SelectionHandler<String>() {
|
||||
|
||||
@Override
|
||||
public void onSelection(SelectionEvent<String> event) {
|
||||
//updateGrid();
|
||||
}
|
||||
});
|
||||
|
||||
content.add(new FieldLabel(encodings, "File encoding"));
|
||||
|
||||
|
||||
|
||||
commaDelimiter = new Radio();
|
||||
commaDelimiter.setBoxLabel("Comma");
|
||||
commaDelimiter.setValue(true);
|
||||
|
||||
spaceDelimiter = new Radio();
|
||||
spaceDelimiter.setBoxLabel("Space");
|
||||
|
||||
tabDelimiter = new Radio();
|
||||
tabDelimiter.setBoxLabel("Tab");
|
||||
|
||||
semicoloDelimiter = new Radio();
|
||||
semicoloDelimiter.setBoxLabel("Semicolon");
|
||||
|
||||
otherDelimiter = new Radio();
|
||||
otherDelimiter.setBoxLabel("Other delimiter");
|
||||
|
||||
customDelimiterField = new TextField();
|
||||
customDelimiterField.setEnabled(false);
|
||||
customDelimiterField.setValue(DEFAULT_DELIMETER);
|
||||
customDelimiterField.setAllowBlank(false);
|
||||
customDelimiterField.setWidth(20);
|
||||
|
||||
ToggleGroup delimitersGroup = new ToggleGroup();
|
||||
delimitersGroup.add(commaDelimiter);
|
||||
delimitersGroup.add(spaceDelimiter);
|
||||
delimitersGroup.add(tabDelimiter);
|
||||
delimitersGroup.add(semicoloDelimiter);
|
||||
delimitersGroup.add(otherDelimiter);
|
||||
|
||||
delimitersGroup
|
||||
.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>() {
|
||||
|
||||
@Override
|
||||
public void onValueChange(
|
||||
ValueChangeEvent<HasValue<Boolean>> event) {
|
||||
|
||||
customDelimiterField.setEnabled(otherDelimiter
|
||||
.getValue());
|
||||
|
||||
if (!otherDelimiter.getValue())
|
||||
customDelimiterField.clearInvalid();
|
||||
else
|
||||
customDelimiterField.validate();
|
||||
|
||||
if (otherDelimiter.getValue()
|
||||
&& !customDelimiterField.isValid())
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
HorizontalPanel delimitersPanel = new HorizontalPanel();
|
||||
delimitersPanel.add(commaDelimiter);
|
||||
delimitersPanel.add(spaceDelimiter);
|
||||
delimitersPanel.add(tabDelimiter);
|
||||
delimitersPanel.add(semicoloDelimiter);
|
||||
delimitersPanel.add(otherDelimiter);
|
||||
delimitersPanel.add(customDelimiterField);
|
||||
|
||||
new ToolTip(delimitersPanel, new ToolTipConfig(
|
||||
"The delimiter use to delimit the CSV fields"));
|
||||
content.add(new FieldLabel(delimitersPanel, "Delimiter"));
|
||||
|
||||
|
||||
csvColumnGridPanel=new ColumnDataGridPanel();
|
||||
content.add(csvColumnGridPanel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
protected char getSelectedDelimiter() {
|
||||
if (otherDelimiter.getValue())
|
||||
return customDelimiterField.getValue().charAt(0);
|
||||
if (commaDelimiter.getValue())
|
||||
return ',';
|
||||
if (spaceDelimiter.getValue())
|
||||
return ' ';
|
||||
if (tabDelimiter.getValue())
|
||||
return '\t';
|
||||
if (semicoloDelimiter.getValue())
|
||||
return ';';
|
||||
return DEFAULT_DELIMETER.charAt(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setEnableBackButton(true);
|
||||
setEnableNextButton(false);
|
||||
encodings.focus();
|
||||
|
||||
TDGWTServiceAsync.INSTANCE
|
||||
.getAvailableCharset(new AsyncCallback<AvailableCharsetList>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(AvailableCharsetList result) {
|
||||
GWT.log("CharsetInfo: "
|
||||
+ result.getCharsetList().size()
|
||||
+ " charset, default: "
|
||||
+ result.getDefaultCharset());
|
||||
|
||||
for (String charset : result.getCharsetList())
|
||||
encodings.add(charset);
|
||||
|
||||
encodings.setValue(result.getDefaultCharset());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
GWT.log("Error loading charset list", caught);
|
||||
showErrorAndHide("Error loading charset list",
|
||||
"Error loading charset list", "", caught);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
Command sayNextCard = new Command() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
//CSVTableDetailCard csvTableDetailCard = new CSVTableDetailCard(
|
||||
// csvImportSession);
|
||||
//getWizardWindow()
|
||||
// .addCard(csvTableDetailCard);
|
||||
Log.info("NextCard CSVTableDetailCard");
|
||||
//getWizardWindow().nextCard();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
getWizardWindow().setNextButtonCommand(sayNextCard);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
//csvExportSession
|
||||
// .setColumnToImportMask(csvSample.getImportColumnsMask());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.portlets.user.td.csvexportwidget.client;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTService;
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||
|
@ -46,7 +46,7 @@ public class GwtTestCSVExportWizardTD extends GWTTestCase {
|
|||
delayTestFinish(7000);
|
||||
|
||||
// Send a request to the server.
|
||||
tdGXTService.getTabularResources(new AsyncCallback<List<TabResource>>() {
|
||||
tdGXTService.getTabularResources(new AsyncCallback<ArrayList<TabResource>>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
@ -56,7 +56,7 @@ public class GwtTestCSVExportWizardTD extends GWTTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<TabResource> result) {
|
||||
public void onSuccess(ArrayList<TabResource> result) {
|
||||
// Shows the first three resources.
|
||||
int i=0;
|
||||
for(TabResource tr:result){
|
||||
|
|
Loading…
Reference in New Issue