608 lines
15 KiB
Java
608 lines
15 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.td.client;
|
|
|
|
import org.gcube.portlets.user.td.sdmximportwidget.client.SDMXImportWizardTD;
|
|
import org.gcube.portlets.user.td.wizardwidget.client.WizardListener;
|
|
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.ExportTableEvent;
|
|
import org.gcube.portlets.user.td.client.event.ExportTableType;
|
|
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.OpenFunctionalityEvent;
|
|
import org.gcube.portlets.user.td.client.event.OpenFunctionalityType;
|
|
import org.gcube.portlets.user.td.client.event.OpenTabularResourceEvent;
|
|
import org.gcube.portlets.user.td.client.event.OpenTabularResourceType;
|
|
import org.gcube.portlets.user.td.client.event.UIStateEvent;
|
|
import org.gcube.portlets.user.td.client.event.UIStateType;
|
|
import org.gcube.portlets.user.td.csvexportwidget.client.CSVExportWizardTD;
|
|
import org.gcube.portlets.user.td.csvimportwidget.client.CSVImportWizardTD;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.TRId;
|
|
import org.gcube.portlets.user.td.informationwidget.client.TabularResourceProperties;
|
|
import org.gcube.portlets.user.td.openwidget.client.TDOpen;
|
|
import org.gcube.portlets.user.tdw.client.TabularData;
|
|
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.gwt.user.client.ui.Widget;
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
import com.google.web.bindery.event.shared.SimpleEventBus;
|
|
import com.sencha.gxt.widget.core.client.ContentPanel;
|
|
import com.sencha.gxt.widget.core.client.TabItemConfig;
|
|
import com.sencha.gxt.widget.core.client.TabPanel;
|
|
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
|
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderLayoutData;
|
|
import com.sencha.gxt.widget.core.client.event.BeforeCloseEvent;
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent;
|
|
import com.sencha.gxt.widget.core.client.event.BeforeCloseEvent.BeforeCloseHandler;
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
|
|
import com.sencha.gxt.widget.core.client.info.Info;
|
|
|
|
/**
|
|
*
|
|
* @author "Giancarlo Panichi"
|
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class TabularDataController {
|
|
// implements HasCloseHandlers<Long>, HasOpenHandlers<Long> {
|
|
|
|
protected SimpleEventBus eventBus;
|
|
protected TabularData tabularData;
|
|
protected UIStateType uiState = UIStateType.START;
|
|
protected UIProperties uiProperties = UIProperties.CLOSED;
|
|
|
|
protected ContentPanel functionalityPanel;
|
|
protected TabPanel functionalityTab;
|
|
protected int indexFunctionalityTab = 0;
|
|
protected TabularResourceProperties trProperties;
|
|
protected BorderLayoutData eastData;
|
|
|
|
/**
|
|
* Tabular Resource Id
|
|
*/
|
|
protected TRId trId;
|
|
|
|
/**
|
|
* Grid TableId
|
|
*/
|
|
protected TableId tableOpening;
|
|
|
|
public TabularDataController() {
|
|
eventBus = new SimpleEventBus();
|
|
bindToEvents();
|
|
}
|
|
|
|
/**
|
|
* @return the eventBus
|
|
*/
|
|
public EventBus getEventBus() {
|
|
return eventBus;
|
|
}
|
|
|
|
public void setTabularData(TabularData tabularData) {
|
|
this.tabularData = tabularData;
|
|
}
|
|
|
|
public ContentPanel getFunctionalityPanel() {
|
|
return functionalityPanel;
|
|
}
|
|
|
|
public void setFunctionalityPanel(ContentPanel functionalityPanel) {
|
|
this.functionalityPanel = functionalityPanel;
|
|
}
|
|
|
|
public TabPanel getFunctionalityTab() {
|
|
return functionalityTab;
|
|
}
|
|
|
|
public void setFunctionalityTab(TabPanel functionalityTab) {
|
|
this.functionalityTab = functionalityTab;
|
|
}
|
|
|
|
public BorderLayoutData getEastData() {
|
|
return eastData;
|
|
}
|
|
|
|
public void setEastData(BorderLayoutData eastData) {
|
|
this.eastData = eastData;
|
|
}
|
|
|
|
protected void bindToEvents() {
|
|
eventBus.addHandler(ImportTableEvent.TYPE,
|
|
new ImportTableEvent.ImportTableHandler() {
|
|
|
|
@Override
|
|
public void onImportTable(ImportTableEvent event) {
|
|
doImportTable(event.getImportType());
|
|
}
|
|
});
|
|
eventBus.addHandler(ExportTableEvent.TYPE,
|
|
new ExportTableEvent.ExportTableHandler() {
|
|
|
|
@Override
|
|
public void onExportTable(ExportTableEvent event) {
|
|
doExportTable(event.getExportType());
|
|
}
|
|
});
|
|
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());
|
|
}
|
|
});
|
|
eventBus.addHandler(OpenFunctionalityEvent.TYPE,
|
|
new OpenFunctionalityEvent.OpenFunctionalityHandler() {
|
|
|
|
@Override
|
|
public void onOpenFunctionality(OpenFunctionalityEvent event) {
|
|
doOpenFunctionality(event.getOpenFunctionalityType());
|
|
}
|
|
});
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.START));
|
|
|
|
}
|
|
|
|
protected void alertMessage(String reason, String details){
|
|
AlertMessageBox d = new AlertMessageBox(reason,
|
|
details);
|
|
d.addHideHandler(new HideHandler() {
|
|
|
|
@Override
|
|
public void onHide(HideEvent event) {
|
|
//
|
|
}
|
|
|
|
});
|
|
d.show();
|
|
}
|
|
|
|
protected void resumeUIState(){
|
|
if(uiState==UIStateType.TR_OPEN){
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.TR_OPEN));
|
|
} else {
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.TR_CLOSE));
|
|
}
|
|
}
|
|
|
|
protected void openTable(TRId tabularResourceId){
|
|
trId = tabularResourceId;
|
|
tableOpening = new TableId(
|
|
Constants.TD_DATASOURCE_FACTORY_ID,
|
|
trId.getTableId());
|
|
tabularData.openTable(tableOpening);
|
|
uiState = UIStateType.TR_OPEN;
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.TR_OPEN));
|
|
if(uiProperties == UIProperties.OPENED){
|
|
trProperties.update();
|
|
}
|
|
}
|
|
|
|
protected void closeTabularResources() {
|
|
if (uiState == UIStateType.TR_OPEN) {
|
|
tabularData.closeTable();
|
|
uiState = UIStateType.TR_CLOSE;
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.TR_CLOSE));
|
|
if (uiProperties == UIProperties.OPENED) {
|
|
functionalityPanel.collapse();
|
|
functionalityPanel.disable();
|
|
uiProperties = UIProperties.CLOSED;
|
|
functionalityTab.remove(trProperties);
|
|
}
|
|
}
|
|
}
|
|
protected void openWizard(){
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.WIZARD_OPEN));
|
|
}
|
|
|
|
|
|
|
|
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 doExportTable(ExportTableType exportType) {
|
|
Log.trace("doExportTable importType: " + exportType);
|
|
Info.display("Export Tabular Resource", "type: " + exportType);
|
|
try {
|
|
switch (exportType) {
|
|
case SDMX:
|
|
openSDMXExportWizard();
|
|
break;
|
|
case CSV:
|
|
openCSVExportWizard();
|
|
break;
|
|
case JSON:
|
|
openSDMXExportWizard();
|
|
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());
|
|
}
|
|
}
|
|
|
|
public void doOpenFunctionality(OpenFunctionalityType openType) {
|
|
Log.trace("doOpenFunctionality openType: " + openType);
|
|
try {
|
|
switch (openType) {
|
|
case PROPERTIES:
|
|
openFunctionalityProperties();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} catch (Exception e) {
|
|
Log.error("doOpenFunctionality Error : " + e.getLocalizedMessage());
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
protected void openFunctionalityProperties() {
|
|
if (uiState == UIStateType.TR_OPEN) {
|
|
if (uiProperties == UIProperties.OPENED) {
|
|
functionalityPanel.collapse();
|
|
functionalityPanel.disable();
|
|
uiProperties = UIProperties.CLOSED;
|
|
functionalityTab.remove(trProperties);
|
|
Info.display("Properties", "Closed");
|
|
} else {
|
|
TabItemConfig propertiesItemConf = new TabItemConfig(
|
|
"Properties", true);
|
|
|
|
trProperties = new TabularResourceProperties("TRProperties",
|
|
eventBus);
|
|
trProperties.setHeaderVisible(false);
|
|
functionalityTab.add(trProperties, propertiesItemConf);
|
|
functionalityTab
|
|
.addBeforeCloseHandler(new BeforeCloseHandler<Widget>() {
|
|
|
|
@Override
|
|
public void onBeforeClose(
|
|
BeforeCloseEvent<Widget> event) {
|
|
if (functionalityTab.getWidgetCount() == 1) {
|
|
functionalityPanel.disable();
|
|
functionalityPanel.collapse();
|
|
uiProperties = UIProperties.CLOSED;
|
|
functionalityTab.remove(trProperties);
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
/*
|
|
* Label taskLabel = new Label("Task Properties");
|
|
* taskLabel.addStyleName("pad-text"); functionalityTab
|
|
* .add(taskLabel, new TabItemConfig("Task", true));
|
|
*/
|
|
functionalityTab.setActiveWidget(functionalityTab.getWidget(0));
|
|
|
|
functionalityPanel.enable();
|
|
functionalityPanel.expand();
|
|
uiProperties = UIProperties.OPENED;
|
|
|
|
}
|
|
} else {
|
|
Info.display("Properties", "No table open");
|
|
}
|
|
};
|
|
|
|
protected void openSDMXImportWizard() {
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
SDMXImportWizardTD importWizard = new SDMXImportWizardTD(
|
|
"SDMX Import");
|
|
importWizard
|
|
.addListener(new org.gcube.portlets.user.td.sdmximportwidget.client.general.WizardListener() {
|
|
|
|
@Override
|
|
public void completed(TRId tabularResourceId) {
|
|
openTable(tabularResourceId);
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void failed(Throwable throwable,
|
|
String reason, String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
});
|
|
|
|
importWizard.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
protected void openCSVExportWizard() {
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
CSVExportWizardTD exportWizard = new CSVExportWizardTD(
|
|
"CSV Export");
|
|
|
|
exportWizard
|
|
.addListener(new WizardListener() {
|
|
@Override
|
|
public void failed(Throwable throwable,
|
|
String reason, String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void completed(TRId id) {
|
|
resumeUIState();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
});
|
|
|
|
exportWizard.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
protected void openSDMXExportWizard() {
|
|
/*
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
SDMXExportWizardTD exportWizard = new SDMXExportWizardTD(
|
|
"SDMX Export");
|
|
|
|
exportWizard
|
|
.addListener(new org.gcube.portlets.user.sdmxexportwizardtd.client.general.WizardListener() {
|
|
|
|
@Override
|
|
public void failed(Throwable throwable,
|
|
String reason, String details) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void completed(TRId id) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
|
|
}
|
|
});
|
|
|
|
exportWizard.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
*/
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
protected void openTabularResources() {
|
|
Log.info("Open Tabular Resources");
|
|
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
TDOpen tdOpen = new TDOpen("Open Tabular Resource");
|
|
|
|
tdOpen.addListener(new org.gcube.portlets.user.td.openwidget.client.general.WizardListener() {
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void completed(TRId tabularResourceId) {
|
|
openTable(tabularResourceId);
|
|
|
|
}
|
|
|
|
});
|
|
Log.info("TDOpen add Listener");
|
|
tdOpen.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void openCSVImportWizard() {
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
CSVImportWizardTD importWizard = new CSVImportWizardTD(
|
|
"CSV Import");
|
|
|
|
importWizard
|
|
.addListener(new org.gcube.portlets.user.td.csvimportwidget.client.general.WizardListener() {
|
|
|
|
@Override
|
|
public void failed(Throwable throwable,
|
|
String reason, String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void completed(TRId id) {
|
|
openTable(id);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
});
|
|
|
|
importWizard.show();
|
|
}
|
|
|
|
@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); }
|
|
*/
|
|
|
|
}
|