355 lines
7.9 KiB
Java
355 lines
7.9 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.td.client;
|
|
|
|
import org.gcube.portlets.user.sdmximportwizardtd.client.SDMXImportWizardTD;
|
|
import org.gcube.portlets.user.sdmximportwizardtd.client.general.WizardListener;
|
|
import org.gcube.portlets.user.td.ciw.client.CSVImporterWidget;
|
|
import org.gcube.portlets.user.td.client.event.CloseTabularResourceEvent;
|
|
import org.gcube.portlets.user.td.client.event.CloseTabularResourceType;
|
|
import org.gcube.portlets.user.td.client.event.ImportTableEvent;
|
|
import org.gcube.portlets.user.td.client.event.ImportTableType;
|
|
import org.gcube.portlets.user.td.client.event.OpenTabularResourceEvent;
|
|
import org.gcube.portlets.user.td.client.event.OpenTabularResourceType;
|
|
import org.gcube.portlets.user.td.importer.client.TabularDataImporterListener;
|
|
import org.gcube.portlets.user.td.open.client.TDOpen;
|
|
import org.gcube.portlets.user.tdw.client.TabularData;
|
|
import org.gcube.portlets.user.tdw.shared.model.TableDefinition;
|
|
import org.gcube.portlets.user.tdw.shared.model.TableId;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.core.client.RunAsyncCallback;
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
import com.google.web.bindery.event.shared.SimpleEventBus;
|
|
import com.sencha.gxt.widget.core.client.info.Info;
|
|
/**
|
|
* @author "Federico De Faveri defaveri@isti.cnr.it"
|
|
*
|
|
*/
|
|
public class TabularDataController {
|
|
//implements HasCloseHandlers<Long>, HasOpenHandlers<Long> {
|
|
|
|
protected SimpleEventBus eventBus;
|
|
protected TabularData tabularData;
|
|
|
|
/**
|
|
* Tabular Data Id
|
|
*/
|
|
protected TableId tableOpening;
|
|
|
|
/**
|
|
* Table Open
|
|
*/
|
|
protected boolean tableOpen=false;
|
|
|
|
/**
|
|
* Table Id
|
|
*/
|
|
protected String tableId;
|
|
|
|
|
|
|
|
public TabularDataController() {
|
|
eventBus = new SimpleEventBus();
|
|
bindToEvents();
|
|
}
|
|
|
|
/**
|
|
* @return the eventBus
|
|
*/
|
|
public EventBus getEventBus() {
|
|
return eventBus;
|
|
}
|
|
|
|
|
|
public void setTabularData(TabularData tabularData){
|
|
this.tabularData=tabularData;
|
|
}
|
|
|
|
|
|
protected void bindToEvents() {
|
|
eventBus.addHandler(ImportTableEvent.TYPE,
|
|
new ImportTableEvent.ImportTableHandler() {
|
|
|
|
@Override
|
|
public void onImportTable(ImportTableEvent event) {
|
|
doImportTable(event.getImportType());
|
|
}
|
|
});
|
|
eventBus.addHandler(OpenTabularResourceEvent.TYPE,
|
|
new OpenTabularResourceEvent.OpenTabularResourceHandler() {
|
|
|
|
@Override
|
|
public void onOpenTabularResource(OpenTabularResourceEvent event) {
|
|
doOpenTabularResource(event.getOpenType());
|
|
}
|
|
});
|
|
eventBus.addHandler(CloseTabularResourceEvent.TYPE,
|
|
new CloseTabularResourceEvent.CloseTabularResourceHandler() {
|
|
|
|
@Override
|
|
public void onCloseTabularResource(CloseTabularResourceEvent event) {
|
|
doCloseTabularResource(event.getCloseType());
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
public void doImportTable(ImportTableType importType) {
|
|
Log.trace("doImportTable importType: " + importType);
|
|
Info.display("Import Tabular Resource", "type: " + importType);
|
|
try {
|
|
switch (importType) {
|
|
case SDMX:
|
|
openSDMXImportWizard();
|
|
break;
|
|
case CSV:
|
|
openCSVImportWizard();
|
|
break;
|
|
case JSON:
|
|
openCSVImportWizard();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} catch (Exception e) {
|
|
Log.error("doImportTable Error : " + e.getLocalizedMessage()+ " \n "+e.getMessage());
|
|
}
|
|
}
|
|
|
|
public void doOpenTabularResource(OpenTabularResourceType openType) {
|
|
Log.trace("doOpenTabularResource openType: " + openType);
|
|
Info.display("Open Tabular Resource", "open: " + openType);
|
|
try {
|
|
switch (openType) {
|
|
case TABLE:
|
|
openTabularResources();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} catch (Exception e) {
|
|
Log.error("doOpenTable Error : " + e.getLocalizedMessage()+ " \n "+e.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
public void doCloseTabularResource(CloseTabularResourceType closeType) {
|
|
Log.trace("doCloseTabularResource closeType: " + closeType);
|
|
Info.display("Close Tabular Resource", "close: " + closeType);
|
|
try {
|
|
switch (closeType) {
|
|
case TABLE:
|
|
closeTabularResources();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} catch (Exception e) {
|
|
Log.error("doOpenTable Error : " + e.getLocalizedMessage()+ " \n "+e.getMessage());
|
|
}
|
|
}
|
|
|
|
protected void openSDMXImportWizard() {
|
|
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
SDMXImportWizardTD importWizard= new SDMXImportWizardTD("SDMX Import");
|
|
|
|
importWizard.addListener(new WizardListener(){
|
|
|
|
@Override
|
|
public void completed() {
|
|
//importWizard.getTable();
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
});
|
|
/*
|
|
importWizard.addWizardSelectionHandler(new WizardSelectionHandler<Dataset>() {
|
|
|
|
@Override
|
|
public void onSelected(
|
|
SDMXWizardSelectionEvent<Dataset> event) {
|
|
doSDMXDatasetImport(event.getSelected());
|
|
}
|
|
|
|
@Override
|
|
public void onClosed(
|
|
SDMXWizardSelectionEvent<Dataset> event) {
|
|
|
|
}
|
|
});*/
|
|
|
|
importWizard.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
protected void closeTabularResources(){
|
|
if(tableOpen) tabularData.closeTable();
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
protected void openTabularResources() {
|
|
|
|
Log.info("Open Tabular Resources");
|
|
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
TDOpen tdOpen= new TDOpen("Tabular Resources Open");
|
|
|
|
tdOpen.addListener(new org.gcube.portlets.user.td.open.client.general.OpenListener(){
|
|
|
|
@Override
|
|
public void aborted() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void completed(String tablekey) {
|
|
|
|
tableOpening=new TableId(Constants.TD_DATASOURCE_FACTORY_ID,tablekey);
|
|
tabularData.openTable(tableOpening);
|
|
tableOpen=true;
|
|
tableId=tablekey;
|
|
|
|
}
|
|
});
|
|
Log.info("TDOpen add Listener");
|
|
tdOpen.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
protected void doSDMXDatasetImport(List<Dataset> datasets) {
|
|
Log.info("doSDMXDatasetImport: " + datasets.size());
|
|
for (Dataset d : datasets) {
|
|
Log.info("Dataset: " + d.getId() + d.getName() + d.getAgencyId());
|
|
}
|
|
|
|
}
|
|
*/
|
|
|
|
protected void openCSVImportWizard() {
|
|
/*
|
|
* GWT.runAsync(new RunAsyncCallback() {
|
|
*
|
|
* @Override public void onSuccess() {
|
|
*/
|
|
CSVImporterWidget csvImporterWidget = new CSVImporterWidget();
|
|
csvImporterWidget.show(new TabularDataImporterListener() {
|
|
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void completed() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
});
|
|
|
|
/*
|
|
* }
|
|
*
|
|
* @Override public void onFailure(Throwable reason) {
|
|
* asyncCodeLoadingFailed(reason); } });
|
|
*/
|
|
}
|
|
|
|
protected void asyncCodeLoadingFailed(Throwable reason) {
|
|
Log.error("Async code loading failed", reason);
|
|
Info.display("Async code loading failed",
|
|
"Please retry to lunch the operation");
|
|
}
|
|
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
|
|
@Override
|
|
public HandlerRegistration addCloseHandler(CloseHandler<Long> handler) {
|
|
//return eventBus.addHandler(CloseEvent.getType(), handler);
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
|
|
@Override
|
|
public HandlerRegistration addOpenHandler(OpenHandler<Long> handler) {
|
|
//return eventBus.addHandler(OpenEvent.getType(), handler);
|
|
}
|
|
*/
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
|
|
@Override
|
|
public void fireEvent(GwtEvent<?> event) {
|
|
eventBus.fireEvent(event);
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|